Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I like this piece of the <code>bind</code> source:</p> <pre><code>template&lt;class R, class F, class L&gt; class bind_t { public: typedef bind_t this_type; bind_t(F f, L const &amp; l): f_(f), l_(l) {} #define BOOST_BIND_RETURN return #include &lt;boost/bind/bind_template.hpp&gt; #undef BOOST_BIND_RETURN }; </code></pre> <p>Tells you almost all you need to know, really.</p> <p>The <code>bind_template</code> header expands to a list of inline <code>operator()</code> definitions. For example, the simplest:</p> <pre><code>result_type operator()() { list0 a; BOOST_BIND_RETURN l_(type&lt;result_type&gt;(), f_, a, 0); } </code></pre> <p>We can see the <code>BOOST_BIND_RETURN</code> macro expands to <code>return</code> at this point so the line is more like <code>return l_(type...)</code>.</p> <p>The one parameter version is here:</p> <pre><code>template&lt;class A1&gt; result_type operator()(A1 &amp; a1) { list1&lt;A1 &amp;&gt; a(a1); BOOST_BIND_RETURN l_(type&lt;result_type&gt;(), f_, a, 0); } </code></pre> <p>It's pretty similar.</p> <p>The <code>listN</code> classes are wrappers for the parameter lists. There is a lot of deep magic going on here that I don't really understand too much though. They have also overloaded <code>operator()</code> that calls the mysterious <code>unwrap</code> function. Ignoring some compiler specific overloads, it doesn't do a lot:</p> <pre><code>// unwrap template&lt;class F&gt; inline F &amp; unwrap(F * f, long) { return *f; } template&lt;class F&gt; inline F &amp; unwrap(reference_wrapper&lt;F&gt; * f, int) { return f-&gt;get(); } template&lt;class F&gt; inline F &amp; unwrap(reference_wrapper&lt;F&gt; const * f, int) { return f-&gt;get(); } </code></pre> <p>The naming convention seems to be: <code>F</code> is the type of the function parameter to <code>bind</code>. <code>R</code> is the return type. <code>L</code> tends to be a list of parameter types. There are also a lot of complications because there are no less than nine overloads for different numbers of parameters. Best not to dwell on that too much.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload