Tools.h++ Manual

13-4 104011 Tandem Computers Incorporated
13
13.3 Types of templates
Intrusive lists
For a collection of type T, intrusive lists are lists where type T inherits directly
from the link type itself
1
. The results are optimal in space and time, but
require you to honor the inheritance hierarchy.
Value-based collections
Value-based collections copy the object in and out of the collection. A very
familiar example of a value-based "collection" is the C array:
int v[100]; /* A 100 element array of ints */
int i = 7;
v[2] = i;
The statement "
v[2] = i
" copies the value of
i
into the array at index 2. What
resides within the array is a distinct copy, separate from the original object
i
.
Value-based collections can contain more complicated objects too. Here's an
example of a vector of
RWCStrings
:
/* A 100 element array of RWCStrings: */
RWTValVector<RWCString> v(100);
RWCString s("A string");
v[2] = s;
Just as with the array of ints, the statement "
v[2] = s
" copies the value of
s
into the vector at index 2. The object that lies within the vector is distinct and
separate from the original object
s
.
1. See Stroustrup, The C++ Programming Language, Second Edition, Addison-Westley, 1991, for a description
of intrusive lists.