Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2004-05-07 20:13:01


"Mark Storer" <MStorer_at_[hidden]> writes:

> 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 _R, class _Ty>
> 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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net