ptr_vector

STL containers, iterators and algorithms are designed for values, not objects. The value semantics becomes evident when you try to store pointers in a Standard container, e.g., in a std::vector. You immediately feel the "impedance mismatch" between the Standard vector value interface and the stored pointers. One extra * (dereference) is necessary to reach the pointed-to objects. This is annoying especially when you use algorithms.

ptr_vector<T> is a wrapper for Standard vector<T*> that cuts one level of indirection for iterators and member functions. In essence, ptr_vector lets you treat a vector of pointers as if it were a vector of values. In many cases, this is exactly what you want.

ptr_vector<string> vec;

vec.push_back (new string ("Hello, "));
vec.push_back (new string ("world!"));

cout << vec[0] << vec[1] << endl;

 More information about ptr_vector

 Compiler Compatibility

Apart from the usual incompatibilities, ptr_vector should compile with most, at least modestly, Standard conforming C++ compilers and Standard libraries.

The Unit Tests were successfully compiled and run with:

 License

BSD without any advertising clause (2-clause BSD-style license)

SourceForge.net Logo