Re: [boost] [Smart Ptr][Bind] Implementaion of Weak Callback Function

foo = bind( &bar::slot, bind( &weak_ptr<bar>::lock, weak_ptr<bar>( bar_ptr ) ) );
Such solution may work if you would write void bar::slot() { if(!this) return; // or if(!this) throw something(); } But I this is just a hack. More then that, throwing is not good idea because generally I do not want this situation be treated as a error.
However, one of those binds must be persisting the smart pointer somewhere, because calling foo always has an effect for me, where I would expect it to segfault after the shared_ptr is reset, since lock() would return a null shared_ptr. You might be able to see the problem though, and get where you want to be.
Such "second" bind should return a "void" function that does nothing, that what I solve in weak_fn. Actually the code of weak_fn is quite simple (when using variadic templates, otherwise it is just many copies of same code for 0, 1 and N parameters). Suggestions? Comments? Artyom
HTH, Christopher _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (1)
-
Artyom