• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>FAQ</title>
5<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../index.html" title="CallableTraits">
8<link rel="up" href="../index.html" title="CallableTraits">
9<link rel="prev" href="reference.html" title="Reference Documentation">
10<link rel="next" href="building.html" title="Building the test suite">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="reference.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="building.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h2 class="title" style="clear: both">
27<a name="callable_traits.faq"></a><a class="link" href="faq.html" title="FAQ">FAQ</a>
28</h2></div></div></div>
29<h4>
30<a name="callable_traits.faq.h0"></a>
31      <span class="phrase"><a name="callable_traits.faq.reasons"></a></span><a class="link" href="faq.html#callable_traits.faq.reasons">Why
32      should I use <code class="literal">Boost.CallableTraits</code>?</a>
33    </h4>
34<p>
35      If you are not writing generic code, you should not use <code class="literal">Boost.CallableTraits</code>.
36    </p>
37<p>
38      If you <span class="emphasis"><em>are</em></span> writing generic code, take a moment to skim
39      your header files, and see if you can find code that looks like this:
40    </p>
41<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Return</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">First</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Second</span><span class="special">&gt;</span>
42<span class="keyword">class</span> <span class="identifier">foo</span><span class="special">&lt;</span><span class="identifier">Return</span><span class="special">(</span><span class="identifier">First</span><span class="special">,</span> <span class="identifier">Second</span><span class="special">)&gt;</span> <span class="special">{</span>
43    <span class="comment">//    ^^^^^^^^^^^^^^^^^^^^^</span>
44<span class="special">};</span>
45</pre>
46<p>
47      Or maybe something like this:
48    </p>
49<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Return</span><span class="special">,</span> <span class="keyword">class</span> <span class="special">...</span><span class="identifier">Args</span><span class="special">&gt;</span>
50<span class="keyword">class</span> <span class="identifier">foo</span><span class="special">&lt;</span><span class="identifier">Return</span><span class="special">(*)(</span><span class="identifier">Args</span><span class="special">...)&gt;</span> <span class="special">{</span>
51    <span class="comment">//    ^^^^^^^^^^^^^^^^^^</span>
52<span class="special">};</span>
53</pre>
54<p>
55      Or, if you are <span class="bold"><strong>really</strong></span> unlucky, something like
56      this:
57    </p>
58<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Return</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="special">...</span><span class="identifier">Args</span><span class="special">&gt;</span>
59<span class="keyword">class</span> <span class="identifier">foo</span><span class="special">&lt;</span><span class="identifier">Return</span><span class="special">(</span><span class="identifier">T</span><span class="special">::*)(</span><span class="identifier">Args</span><span class="special">...,</span> <span class="special">...)</span> <span class="keyword">const</span> <span class="keyword">volatile</span> <span class="special">&amp;</span> <span class="keyword">noexcept</span><span class="special">&gt;</span> <span class="special">{</span>
60    <span class="comment">//    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
61<span class="special">};</span>
62</pre>
63<p>
64      With <code class="literal">Boost.CallableTraits</code>, you can get rid of all of these
65      template specializations (unless you deal with platform-specific calling conventions,
66      for now). Even if you are only specializing a simple function type like <code class="computeroutput"><span class="identifier">Return</span><span class="special">(</span><span class="identifier">Args</span><span class="special">...)</span></code>, <code class="literal">Boost.CallableTraits</code>
67      might be useful to you. You may find that <code class="literal">Boost.CallableTraits</code>
68      can help make your code more readable, more maintainable, more generic, and
69      less error-prone.
70    </p>
71<p>
72      <code class="literal">Boost.CallableTraits</code> is well-tested on many platforms.
73      <code class="literal">Boost.CallableTraits</code> correctly handles many corner cases
74      that are often overlooked. The need for a proper library solution grows as
75      more features are added to C++.
76    </p>
77<h4>
78<a name="callable_traits.faq.h1"></a>
79      <span class="phrase"><a name="callable_traits.faq.boost_is_a_massive_dependency_do"></a></span><a class="link" href="faq.html#callable_traits.faq.boost_is_a_massive_dependency_do">Boost
80      is a massive dependency. Do I really need it?</a>
81    </h4>
82<p>
83      Nope! <code class="literal">Boost.CallableTraits</code> doesn't have any dependencies,
84      so all you need are the <code class="literal">Boost.CallableTraits</code> headers.
85    </p>
86<h4>
87<a name="callable_traits.faq.h2"></a>
88      <span class="phrase"><a name="callable_traits.faq.why_use_reference_collapsing_rul"></a></span><a class="link" href="faq.html#callable_traits.faq.why_use_reference_collapsing_rul">Why
89      use reference collapsing rules when adding member function ref-qualifiers?</a>
90    </h4>
91<p>
92      Although arbitrary, the reference collapsing rules are well-defined and already
93      known to many template metaprogrammers. Anything else would be a burden to
94      memorize. This also parallels the metafunctions provided in <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">type_traits</span><span class="special">&gt;</span></code>.
95    </p>
96<h4>
97<a name="callable_traits.faq.h3"></a>
98      <span class="phrase"><a name="callable_traits.faq.many_features_in_this_library_ca"></a></span><a class="link" href="faq.html#callable_traits.faq.many_features_in_this_library_ca">Many
99      features in this library cause a "substitution failure" when the
100      template constraints are violated. Does this mean that I can violate the constraints
101      in a SFINAE context, as long as there is another legal substitute?</a>
102    </h4>
103<p>
104      Yes. The SFINAE-ability of violated constraints has been tested extensively
105      on supported compilers. Achieving this required some messy code in the public
106      header files.
107    </p>
108<h4>
109<a name="callable_traits.faq.h4"></a>
110      <span class="phrase"><a name="callable_traits.faq.what_about_calling_conventions"></a></span><a class="link" href="faq.html#callable_traits.faq.what_about_calling_conventions">What
111      about calling conventions?</a>
112    </h4>
113<p>
114      I originally implemented features for these. However, these features necessitated
115      many, many more platform-specific test cases. The code is still designed to
116      accommodate such features, so I would consider adding them in the future if
117      there is sufficient interest.
118    </p>
119</div>
120<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
121<td align="left"></td>
122<td align="right"><div class="copyright-footer">Copyright © 2016-2018 Barrett Adair<p>
123        Distributed under the Boost Software License, Version 1.0. (See accompanying
124        file LICENSE.md or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
125      </p>
126</div></td>
127</tr></table>
128<hr>
129<div class="spirit-nav">
130<a accesskey="p" href="reference.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="building.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
131</div>
132</body>
133</html>
134