Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-08-27 11:18:55


From: "Douglas Gregor" <gregod_at_[hidden]>
>
> 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).

Thinking about it some more.

If we really need the above to be supported, the right approach is:

* mem_fn must recognize weak_ptr and either perform

(shared_ptr<X>(x)->*&X::foo)();

or call X::foo only when x is nonzero, and silently do nothing otherwise
(but this is only applicable to void functions.)

(I'm undecided whether this coupling is a good thing, and I'm not sure
whether lack of partial ordering on some compilers may prove a problem.)

* The signal must recognize weak_ptr too; a weak_ptr tracks the object
lifetime regardless of whether the object is-a trackable.

For this release, I think that we should leave mem_fn as is; if you decide
to implement a signal that knows about weak_ptr, a temporary workaround
would be to bind a forwarding function

void foo(weak_ptr<X> const & px)
{
    shared_ptr<X>(px)->foo();
}

instead of &X::foo.


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