Boost logo

Boost :

From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2007-01-11 16:18:11

On 1/11/07, Yuval Ronen <ronen_yuval_at_[hidden]> wrote:
> In the following code:
> struct A
> {
> void func();
> }
> int main()
> {
> shared_ptr<A> a(new A);
> boost::bind(&A::func, a);
> }
> the bind() call returns a function object which holds the shared_ptr by
> value (it's one of the shared owners). This is an important feature I'm
> using, because sometimes the functor is the last owner left standing,
> and I want to keep A alive until the functor's destructor (actually, I
> don't really like this design, but I'm talking about legacy code here).
> Replacing boost::bind with lambda::bind doesn't compile. Is this feature
> not supported by lambda::bind? If not supported now, is it planned to be
> supported in the future? Can I in the mean time implement this feature
> in my code with relative ease?
> Thanks,
> Yuval

boost::bind 'knows about' shared_ptr, lambda::bind doesn't. Something like

using namespace boost::lambda;
bind(&A::func, bind(&shared_ptr<A>::get, a));

should work (I think - I've not tried it).

Stuart Dootson

Boost list run by bdawes at, gregod at, cpdaniel at, john at