Container
classes are an essential part of object-oriented programming; they are another
way to simplify and hide the details of a program and to speed the process of
program development. In addition, they provide a great deal of safety and
flexibility by replacing the primitive arrays and relatively crude data
structure techniques found in C.
Because
the client programmer needs containers, it’s essential that they be easy
to use. This is where the
template
comes in. With templates the syntax for source-code reuse (as opposed to
object-code reuse provided by inheritance and composition) becomes trivial
enough for the novice user. In fact, reusing code with templates is notably
easier than inheritance and composition.
Although
you’ve learned about creating container and iterator classes in this
book, in practice it’s much more expedient to learn the containers and
iterators that come with your compiler or, failing that, to buy a library from
a third-party vendor.
[41]
The standard C++ library includes a very complete but nonexhaustive set of
containers and iterators.
The
issues involved with container-class design have been touched upon in this
chapter, but you may have gathered that they can go much further. A complicated
container-class library may cover all sorts of additional issues, including
persistence (introduced in Chapter 15) and garbage collection (introduced in
Chapter 11), as well as additional ways to handle the ownership problem.
[41]
See, for example, Rogue Wave, which has a well-designed set of C++ tools for
all platforms.