Boost logo

Boost :

From: Douglas Paul Gregor (gregod_at_[hidden])
Date: 2002-08-27 09:55:04


On Tue, 27 Aug 2002, Peter Dimov wrote:
> From: "Douglas Gregor" <gregod_at_[hidden]>
> > >
> > > Also, get_pointer for weak_ptr was deliberately omitted as dangerous.
> Why
> > > do you need it?
> >
> > void bar(weak_ptr<X> x)
> > {
> > some_signal.connect(bind(&X::foo, x));
> > }
> >
> > We need to get to the X* for the base-pointer conversion to trackable*
> (for
> > the automatic signal/slot disconnections).
>
> But that's exactly why I didn't add get_pointer for weak_ptr. bind(&X::foo,
> x) is only valid when get_pointer is present; but there is no reason to bind
> a member function to a weak pointer, because you can't detect from within
> the member function whether "this" is zero (meaning that the weak pointer
> has been zeroed.)

But in this case, we _can_ detect when "this" is zero if it is a trackable
object. "this" is zero only when the object it refers to has been
destroyed; however, the destruction of that object will disconnect the
signal/slot connection that contains the weak_ptr, so a null "this"
pointer won't ever show up in a slot call. Interestingly, this means that
shared_ptr generally shouldn't be used within slots because the slot might
be the only thing keeping both ends of the connection alive. (I smell a
FAQ entry...)

> Relying on get_pointer is OK (once we get the weak_ptr situation sorted
> out), but I'd like to keep the smart pointer headers as dependency free as
> possible.

Okay. I'll remove the dependency on type_traits.

        Doug


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