Boost C++ Libraries: Ticket #2128: Add the ability to implicitly traverse reference wrappers https://svn.boost.org/trac10/ticket/2128 <p> Please add the following to boost: </p> <p> namespace boost { </p> <p> template&lt;class T&gt; T* get_pointer( reference_wrapper&lt;T&gt; const &amp; r ) { </p> <blockquote> <p> return r.get_pointer(); </p> </blockquote> <p> } </p> <p> } </p> <hr /> <p> Code demonstrating the issue: </p> <p> #include &lt;boost/bind.hpp&gt; #include &lt;boost/ref.hpp&gt; #include &lt;string&gt; </p> <p> <em> Define a simple class for our example class Crayon { public: </em></p> <blockquote> <p> explicit Crayon(const std::string &amp;color=std::string()):m_color(color) {} const std::string &amp;<a class="missing wiki">GetColor</a>() const {return m_color;} </p> </blockquote> <p> private: </p> <blockquote> <p> std::string m_color; </p> </blockquote> <p> }; </p> <p> int main(int argc, char *argv[]) { </p> <blockquote> <p> using namespace std; using namespace boost; </p> </blockquote> <blockquote> <p> Crayon cr("blue"); boost::reference_wrapper&lt;const Crayon&gt; crefCr(cr); </p> </blockquote> <blockquote> <p> <em> This doesn't compile, however, even though the reference_wrapper class template has </em> an overloaded operator T&amp; () const function std::string colorFromConstRef2(boost::bind(&amp;Crayon::<a class="missing wiki">GetColor</a>,_1)(crefCr)); </p> </blockquote> <p> } </p> <hr /> <p> Peter Dimov's reply: </p> <p> It doesn't because of the mem_fn behavior that bind inherits. The argument is not a reference to Crayon and so is assumed to be a smart pointer to Crayon. mem_fn then tries to invoke get_pointer() on it to obtain a Crayon*. You should be able to make it compile by adding a get_pointer overload for reference_wrapper: </p> <p> namespace boost { </p> <p> template&lt;class T&gt; T* get_pointer( reference_wrapper&lt;T&gt; const &amp; r ) { </p> <blockquote> <p> return r.get_pointer(); </p> </blockquote> <p> } </p> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2128 Trac 1.4.3 Peter Dimov Thu, 21 Aug 2008 14:55:59 GMT status, milestone changed https://svn.boost.org/trac10/ticket/2128#comment:1 https://svn.boost.org/trac10/ticket/2128#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.36.0</span> → <span class="trac-field-new">Boost 1.37.0</span> </li> </ul> Ticket Peter Dimov Sat, 28 Feb 2009 17:00:33 GMT milestone changed https://svn.boost.org/trac10/ticket/2128#comment:2 https://svn.boost.org/trac10/ticket/2128#comment:2 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.37.0</span> → <span class="trac-field-new">Boost 1.39.0</span> </li> </ul> Ticket Peter Dimov Sun, 01 Mar 2009 17:04:16 GMT <link>https://svn.boost.org/trac10/ticket/2128#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2128#comment:3</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/51512" title="Refs #2128 (fixed in trunk.)">[51512]</a>) Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2128" title="#2128: Feature Requests: Add the ability to implicitly traverse reference wrappers (closed: fixed)">#2128</a> (fixed in trunk.) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Mon, 02 Mar 2009 16:55:45 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2128#comment:4 https://svn.boost.org/trac10/ticket/2128#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Merged to release with <a class="changeset" href="https://svn.boost.org/trac10/changeset/51534" title="Merge [51512] to release. Closes #2128.">[51534]</a>. </p> Ticket