Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I highly recommend <a href="http://www.boost.org/doc/libs/1_53_0/libs/phoenix/doc/html/index.html" rel="nofollow">Boost.Phoenix</a>, it's my go-to library when it comes to writing functors on the fly in C++03. It is a superior alternative to Boost.Bind -- that library is showing its age.</p> <p>For instance, Phoenix let us use operators on its functors to represent an actual use of that operator when the functor is called. Thus <code>arg1 + arg2</code> is a functor that returns the sum of its first two operands. This heavily cuts down on the <code>bind</code> noise. A first attempt could look like:</p> <pre><code>bind(&amp;pair&lt;const int, int&gt;::first , *bind(static_cast&lt;const_begin_end&gt;(&amp;map&lt;int, int&gt;::begin), arg1)) ) </code></pre> <p>(<a href="http://liveworkspace.org/code/37qYCp%248" rel="nofollow">LWS demo</a>)</p> <p>But another strong point of Phoenix is that it comes with some batteries. In our case we're very much interested in <code>&lt;boost/phoenix/stl/container.hpp&gt;</code> because this includes some lazy version of the familiar containers operations, including <code>begin</code>. This is very handy in our case:</p> <pre><code>// We don't need to disambiguate which begin member we want anymore! bind(&amp;pair&lt;const int, int&gt;::first, *begin(arg1)) </code></pre> <p>(<a href="http://liveworkspace.org/code/37qYCp%247" rel="nofollow">LWS demo</a>)</p> <hr> <p>As a final note, I'll add that C++11 bind expressions are specified such that pointer-to-members work on <em>anything</em> that uses <code>operator*</code>. So out-of-the-box you can do:</p> <pre><code>bind(&amp;pair&lt;const int, int&gt;::first, bind(static_cast&lt;begin_type&gt;(&amp;std::map&lt;int, int&gt;::begin), _1)) </code></pre> <p>(<a href="http://liveworkspace.org/code/3Kg46J%247" rel="nofollow">LWS demo</a>)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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