DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Getting Started

Container types

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(C++), Graph(C++), List(C++), Map(C++), and Set(C++). The Set(C++) 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(C++), List(C++), Map(C++), and Set(C++), are implemented using template class declarations. However, Graph(C++) 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;
          }
       }

Next topic: Treatment of errors
Previous topic: Low-level types

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005