|
|
Of all possible categories, however, the most important is the containers. A container is a type whose instances contain objects of another type. The components in this category are: Block(3C++), Graph(3C++), List(3C++), Map(3C++), and Set(3C++). The Set(3C++) component, for example, provides three different container classes representing various types of unordered collections:
As the parameter T in the above list suggests, container classes are parameterized. That is, the type of a container has, as a parameter, the type of the objects it contains. Most container type components including Block(3C++), List(3C++), Map(3C++), and Set(3C++), are implemented using template class declarations. However, Graph(3C++) is implemented using preprocessor macros.
Another common feature of container classes is a companion iterator class used to visit the objects in the container, much in the way a for-loop is used to index over the integers in a discrete range. The following example uses an iterator to display the integers in an integer Set:
#include <Set.h> #include <stream.h>
main() { Set<int> s(1,2,3,4); // the set {1,2,3,4} Setiter<int> si(s); const int* p; while (p=si.next()) { // prints {1,2,3,4} cout << *p << endl; } }