Lumiera
0.pre.03
»edit your freedom«
|
Go to the source code of this file.
Some wrappers for coping with ownership problems.
Working with collections of objects, especially in conjunction with polymorphism, can be challenging when we are bound to care for lifecycle and ownership for the contained classes. There are several solutions, including the boost::ptr_container library or lib::ScopedPtrVect, the use of shared_ptr or even a garbage collector. Sometimes circumstances rather call for a very simple or lightweight solution though.
ScopedPtrHolder is a simple extension to std::unique_ptr, enabling to use it within STL containers if we stick to a specific protocol. The idea is to permit copying as long as the unique_ptr is empty. This can be used to allow for extension of the STL container on demand, i.e. to handle the typical situation of a registry which is initialised lazily, but only released in a controlled fashion.
ScopedHolder implements a similar concept for in-place storage of noncopyable objects within STL containers.
While the added copy operations (secured with the "empty" requirement) are enough to use those holders within fixed sized STL containers, supporting dynamic growth (like in std::vector::resize() ) additionally requires a facility to transfer the lifecycle management control between holder instances. This is the purpose of the transfer_control
friend function.
Definition in file scoped-holder.hpp.
Classes | |
class | ScopedHolder< TY > |
Inline buffer holding and owning an object similar to unique_ptr. More... | |
class | ScopedPtrHolder< B > |
Extension to std::unique_ptr, allowing copy operations on empty pointers (i.e. More... | |
Namespaces | |
lib | |
Implementation namespace for support and library code. | |