Boost logo

Boost :

Subject: Re: [boost] [Smart Ptr][Bind] Implementaion of Weak Callback Function
From: bnv (bnv_at_[hidden])
Date: 2009-03-21 17:39:34


Artyom <artyomtnk <at> yahoo.com> writes:

> Hello,
>
> Today boost::bind allows to use shared_ptr to ensure that
> when the function is called the object exists:
>
> shared_ptr<bar> bar_ptr;
> function<void()> foo;
>
> foo=bind(&bar::slot,bar_ptr)
>
> Now even if we call bar_ptr.reset() the object is still owned by foo.
> But in some cases this is not good enough. This may create cyclic
> dependecies if A has shared_ptr to B and gives it a callback to A
> cyclic dependecy is created, so sometimes it would be useful to
> be able to provide weak bind function that is called iff the
> object exists -- that uses weak_ptr insteas of shared one.

<snip>

I can't comment on whether the direction is correct, but would be in support of
such a capability having recently run into the same need.

However, I seem to recall something like this coming up before and the rationale
for not supporting it is was that the behavior to follow when the weak pointer
is expired is subjective. That is, in some cases you may want an exception, and
in other you may want nothing to happen.

-Brian


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