Boost logo

Boost Users :

Subject: Re: [Boost-users] "weak" binding to member?
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2011-09-12 21:21:24


On 9/12/2011 12:41 PM, Igor R wrote:
>> I don't know what you mean by that.
>
>
> I mean that you can pass a weak_ptr along with the binder:
>
> void setYourFunctor(const function<void(void)> &func, const
> weak_ptr<void> &track)
> {
> // store "func" and "track"
> func_ = func;
> track_ = track;
> }
>
> // Now in the place where "func_" should be called:
> void call()
> {
> shared_ptr<void> p = track_.lock();
> if (p)
> func_();
> }
>
> // Now use it this way:
> shared_ptr<YourClass> ptr = ...;
> setYourFunctor(bind(&YourClass::doSomething, ptr.get()), ptr);

I see: assume that the raw pointer value doesn't change, and just use the weak ptr to
ensure that it's still valid, but it is not necessary to pass the pointer to the call each
time.


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