Whenever a programmer wants to have a container of pointers to
heap-allocated objects, there is usually only one exception-safe way:
to make a container of pointer pointers like boost::shared_ptr.
This approach is suboptimal if
- the stored objects are not shared, but owned exclusively, or
- the overhead implied by pointer pointers is inappropriate
This library therefore provides standard-like containers that are for storing
heap-allocated or cloned objects (or in case of a map, the mapped object must be
a heap-allocated or cloned object). For each of the standard
containers there is a pointer container equivalent that takes ownership of
the objects in an exception safe manner. In this respect the library is intended
to solve the so-called
polymorphic class problem.
The advantages of pointer containers are
- Exception-safe pointer storage and manipulation.
- Notational convenience compared to the use of containers of pointers.
- Can be used for types that are neither Assignable nor Copy Constructible.
- No memory-overhead as containers of pointer pointers can have (see and ).
- Usually faster than using containers of pointer pointers (see and ).
- The interface is slightly changed towards the domain of pointers
instead of relying on the normal value-based interface. For example,
now it is possible for pop_back() to return the removed element.
- Propagates constness s.t. one cannot modify the objects via a const_iterator
The disadvantages are
- Less flexible than containers of smart pointers like boost::shared_ptr