Boost C++ Libraries: Ticket #288: adapters for smart_ptr? https://svn.boost.org/trac10/ticket/288 <pre class="wiki">Hello, May be I just can't find this, but... I would like to use the STL algorithms on STL containers of smart_ptrs. So I need an adapter that adapts a member function of a class that is pointed to by a smart_ptr. The standard boost::mem_fun does not do this. So, I wrote this class: template &lt;template&lt;class&gt; class PTR, typename S, typename T&gt; class mem_fun_ptr_t : public std::unary_function&lt;T*, S&gt; { public: explicit mem_fun_ptr_t(S (T::*p)()) : ptr(p) {} S operator()(PTR&lt;T&gt; p) const { return ((*p).*ptr)(); } private: S (T::*ptr)(); }; template &lt;template&lt;class&gt; class PTR, typename S, typename T&gt; inline mem_fun_ptr_t&lt;PTR,S,T&gt; mem_fun_ptr(S (T::*f)()) { return mem_fun_ptr_t&lt;PTR,S,T&gt;(f); } //============================ // // usage (e.g.): // ============= // class MyClass { // public: // void method() { /* Do something */ } // }; // //... // std::vector&lt;shared_ptr&lt;MyClass&gt; &gt; myVector; // //... (fill myVector) // // std::for_each(myVector.begin(),myVector.end(), // simon::mem_fun_ptr&lt;shared_ptr&gt;(&amp;MyClass::method)); // May be I am re-inventing the wheel? (If so please tell me :^) If not, could something like this be added to boost? Thanks, Simon Robbins. robbins@physik.uni-wuppertal.de </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/288 Trac 1.4.3 Peter Dimov Fri, 01 Apr 2005 19:53:15 GMT status changed https://svn.boost.org/trac10/ticket/288#comment:1 https://svn.boost.org/trac10/ticket/288#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> </ul> <pre class="wiki">Logged In: YES user_id=305912 boost::mem_fn does this. </pre> Ticket