Note that there are some explanatory texts on larger screens.

plurals
  1. POAsk for an example for the limitation of boost::bind()
    text
    copied!<p>I read the explanation of the limitation at <a href="http://www.boost.org/doc/libs/1_49_0/libs/bind/bind.html#Limitations" rel="nofollow">http://www.boost.org/doc/libs/1_49_0/libs/bind/bind.html#Limitations</a> but I don't quite understand it. Can any body give me an example of that stated limitation, please?</p> <p>Let me ask this question in another way with this example:</p> <pre><code>#include &lt;boost/bind.hpp&gt; #include &lt;boost/function.hpp&gt; #include &lt;iostream&gt; #include &lt;string&gt; using namespace std; void Five(int &amp;a, int &amp;b, int &amp;c, const int &amp;d, const int &amp;e) { cerr &lt;&lt; "In Five(): " &lt;&lt; a + b + c + d + e &lt;&lt; endl; } int main() { int r = 1; const int c = 100; boost::bind(Five, _1, _2, _3, _4, _5)(r, r, r, c, r); boost::bind(Five, _1, _2, _3, _4, _5)(r, r, r, r, c); return 0; } </code></pre> <p>This code compiles just fine (without C++11 support). So, if bind even works in this case, what does "limitation" refer to? Any concrete examples, please?</p> <p>Another (better) example:</p> <pre><code>#include &lt;boost/bind.hpp&gt; #include &lt;iostream&gt; #include &lt;string&gt; using namespace std; void Two(int &amp;a, const int &amp;c) { cerr &lt;&lt; "In Two(): " &lt;&lt; a + c &lt;&lt; endl; } void Three(int &amp;a, int &amp;b, const int &amp;c) { cerr &lt;&lt; "In Three(): " &lt;&lt; a + b + c &lt;&lt; endl; } int Fun() { return 3; } int main() { int r = 1; const int c = 100; boost::bind(Two, _1, _2)(r, Fun()); // 1. OK boost::bind(Three, _1, _2, _3)(r, r, c); // 2. OK Three(r, r, Fun()); // 3. OK boost::bind(Three, _1, _2, _3)(r, r, Fun()); // 4. CE!! //??? Why 2 is OK but 4 is not ??? return 0; } </code></pre>
 

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