Boost logo

Boost :

From: bill_kempf (williamkempf_at_[hidden])
Date: 2002-02-20 10:14:52


--- In boost_at_y..., "bill_kempf" <williamkempf_at_h...> wrote:
> * The controlling state of the connection type seems a little off.
> It would be nice to have an inverse to non_controlling() so that we
> can do something like:
>
> boost::connection con = sig.connect(foo).controlling();
>
> instead of:
>
> boost::connection con = sig.connect(foo);
> con.set_controlling(true);

Sorry, I brain stormed this with little thought. Obviously with how
the controlling state is implemented currently the above won't work,
since the temporary will disconnect when it's destroyed. For some
reason I thought the controlling state was ref-counted. However,
this brings up an observation. The boost::connection type acts
similar to a smart pointer such as std::auto_ptr<> or
boost::shared_ptr<>. However, it has managing characterstics that
are unique. In the above example std::auto_ptr<> would have
transferred ownership and boost::shared_ptr<> would have ref-counted
the ownership, while boost::connection() copied the ownership which
resulted in (unexpected to me) premature reclamation. I won't claim
that this new ownership mechanism is wrong, but at the very least I
think we need some explanation of this in the documentation.

Now back to the original problem I was trying to solve. Since I'd
like to avoid deriving from trackable there are instances where I can
see using "controlling" boost::connection member variables to manage
this instead. But the two lines of code required to copy the
connection and set the controlling state could be tedious when
there's a lot of connections. So as an alternative to the previous
suggestion (which won't work with out changing the implementation of
the controlling state), how about an overloaded constructor?

boost::connection con(sig.connect(foo), true /* controlling */);

We won't always be able to set this up at construction, so we would
also need an assign().

con.assign(sig.connect(foo), true /* controlling */);

Bill Kempf


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