boost::bind vs boost::mem_fun (was RE: [Boost-users] Re: shared_ptrs with std::mem_fn)
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)(); }; --- <...>
No, the relevant part is the signature I highlighted above.
<...>
All I have to say is "use boost::mem_fn, which works, and never touch the one in std::".
Thanks for clearing that up, it was really bugging me. So to speak. ;) I've recently started using boost::bind, and I think I'm in love. But boost::mem_fun raises another question in my mind: Are there any cases where "boost::bind( &foo::bar, _1 )" is superior to "boost::mem_fun( &foo::bar )" (other than a few less keys to press)? I'd say that boost::bind is clearly supperior when "bar" takes a parameter, but when it does not, the water gets a little muddy. I'd imagine that you wouldn't get the long stream of error messages (expected N params not Y, expected N + 1 params, not Y, expected N + 2 ...) from bind when all the different variants miss, but is there anything else? --Mark Storer Senior Software Engineer Verity, Inc.
participants (1)
-
Mark Storer