Pointer Container Library

Tutorial

The tutorial shows you the most simple usage of the
library. It is assumed that the reader is familiar
with the use of standard containers. Although
the tutorial is devided into sections, it is recommended
that you read it all from top to bottom.

The sequence containers are used when you do not need to
keep an ordering on your elements. You can basically
expect all operations of the normal standard containers
to be available. So, for example, with a ptr_deque
and ptr_list object you can say:

If the OO hierarchy thus allows cloning, we need to tell the
pointer containers how cloning is to be done. This is simply
done by defining a free-standing function, new_clone(),
in the same namespace as
the object hierarchy:

inline animal* new_clone( const animal& a )
{
return a.clone();
}

That is all, now a lot of functions in a pointer container
can exploit the cloneability of the animal objects. For example

You can think of auto_type as a non-copyable form of
std::auto_ptr. Notice that when you release an object, the
pointer is removed from the container and the containers size
shrinks. For containers that store nulls, we can exploit that
auto_type is convertible to bool:

if( ptr_vector< nullable<T> >::auto_type r = vec.pop_back() )
{
...
}

You can also release the entire container if you
want to return it from a function

Every time there is a function that takes a T* parameter, there is
also a function taking an std::auto_ptr<U> parameter. This is of course done
to make the library intregrate seamlessly with std::auto_ptr. For example

std::ptr_vector<Base> vec;
vec.push_back( new Base );

is complemented by

std::auto_ptr<Derived> p( new Derived );
vec.push_back( p );

Notice that the template argument for std::auto_ptr does not need to
follow the template argument for ptr_vector as long as Derived*
can be implicitly converted to Base*.