Tools.h++ Manual
104011 Tandem Computers Incorporated 13-3
13
want to declare a
BaseVector
class that holds the length of any vector. We
would then derive the template-based vectors Vector from this. Of course, the
code required to return the length of a vector is trivial, and so it turns out that
in practice it isn't worth doing this.
Factoring out commonality
For a more substantial example, take a look at the intrusive linked-list class
RWTIsvSlist<T>
. This is a linked list of types
T
which are required to inherit
from class
RWIsvSlink
. This class contains a "next" field, consisting of a
pointer to the next link. A few moments reflection will convince you that we
don't really need to know the derived type of the link to actually walk the list.
We need only know that it inherits from
RWIsvSlink
. Furthermore, given an
existing link, we don't even need to know its type to add or remove it from the
list!
Hence, all this code can be factored out, compiled once, and forgotten.
13.2 Naming scheme
All of the template class names start with "RWT", followed by a three letter
code:
Isv
Intrusive lists
Val
Value-based
Ptr
Pointer-based
Hence,
RWTValOrderedVector<T>
is a value-based template for an ordered
vector of type
T
.