Boost logo

Boost :

From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2002-07-08 19:56:36


----- Original Message -----
From: "Paul Mensonides" <pmenso57_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, July 09, 2002 1:23 AM
Subject: Re: [boost] shared_ptr and ->*

> I don't know what 'bind' does exactly, but the mechanism would have to
handle
> the regular pointer-to-data-member case also. Overloading won't work,
because a
> general T::* would catch everything--including the
pointers-to-member-functions.
> The sample that I sent hijacks that with a specialized closure for that
purpose
> only. That was the purpose of the closure<U>::return_type typedef.

Yes, bind() works for pointer-to-data-member too if I remember correctly,
but there is another problem that I had forgot: bind() needs a complete
ariety specification at bind-time, which can't be known within
operator->*(). So your closure<> template seems handy for this situation.
For the original poster, the code can be written also as:

bind(fighters, p)();

Or instead than passing around a pointer to member function, you can just
use bind(fighters, _1, [other bind parameters]) which returns a functor that
should receive a my_class object (or a shared_ptr/dumb pointer to it) when
called to complete the closure and call the function. It's a more general
solution, can be stored into a boost::function<void>, and works with any
completely-bind member function instead of only those with ariety 0.

But yes, an extension to shared_ptr to handle operator->* as proposed would
be nice.

Giovanni Bajo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk