Boost logo

Boost :

From: Johan Torp (johan.torp_at_[hidden])
Date: 2007-09-13 17:20:47


Simon Richter-2 wrote:
>
> That would be very similar to a ptr_* container that assumes ownership
> of the object, with a common base class for all the objects to
> facilitate destruction.
>

Glad to get some response :)

Requiring a common base class/interface is a huge demand. This would couple
client code a lot for the sake of such a small utility and it wouldn't be
directly compatible with already existing classes.

The proposed "heap" has very different semantics compared to a container.
Once you put something in the heap you never want to access it again. All
you want to achieve is delayed and synchronized destruction.

You can achieve similar functionality using a std::vector<boost::any> in
which you insert boost::shared_ptrs. The syntax is a lot worse though and
more importantly, more difficult to understand.

Compare:

  std::vector<boost::any> keep_alive;
  // Always use named smart ptrs
  boost::shared_ptr<boost::signals::scoped_connection>
    connection(new boost::signals::scoped_connection(signal, slot));
  keep_alive.push_back(connection);

  boost::heap keep_alive;
  keep_alive.put(new boost::signals::scoped_connection(signal, slot));

In the latter case we clearly signal something - we're not interested in the
connection variable, only it's lifetime.

Johan

-- 
View this message in context: http://www.nabble.com/RFC---lifetime-management-tf4425074.html#a12663742
Sent from the Boost - Dev mailing list archive at Nabble.com.

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