« Return to Thread: RFC - lifetime management

Re: RFC - lifetime management

by Johan Torp :: Rate this Message:

Reply to Author | View in Thread

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

 « Return to Thread: RFC - lifetime management