RE: [Boost-users] Re: shared_ptrs with std::mem_fn
boost::mem_fn erases the need for a separate mem_fn_ref. If http://www.boost.org/libs/bind/mem_fn.html fails to explain it to you, please ask more specific questions.
I thought I'd been pretty specific... guess not. Allow me to reiterate:
Why doesn't std::mem_fun work with a container of boost::shared_ptr?
I fiddled around with my compiler for a while (vc6), but ended up with a wildly unhelpful error message. Given the following lines of code (among others):
---
typedef std::vector
"Mark Storer"
So why won't std::mem_fun work through boost::shared_ptr's operator->?
Here's the mem_fun that ships with VC6:
--- template
class mem_fun_t : public unary_function<_Ty *, _R> { public: explicit mem_fun_t(_R (_Ty::*_Pm)()) : _Ptr(_Pm) {} _R operator()(_Ty *_P) const ^^^^^^^ {return ((_P->*_Ptr)()); } private: _R (_Ty::*_Ptr)(); }; --- The relevant portion to our discussion is: "{return ((_P->*_Ptr()); }" which can be further boiled down to: return _P->_Ptr();
No, the relevant part is the signature I highlighted above.
This looks an awful lot like it should work with a shared_ptr's operator->(). So why doesn't it?
It should be obvious now, I hope.
I admit that this is more of a C++ question than a boost one, but it's not too much of a tangent and I *am* curious.
All I have to say is "use boost::mem_fn, which works, and never touch the one in std::". -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
participants (2)
-
David Abrahams
-
Mark Storer