4.1 Containers

As Bjarne Stroustrup says, "One of the most useful kinds of classes is the container class, that is, a class that holds objects of some (other) type", [1], §8.1. Containers form one crucial component of STL. To sum up elements of a special type in a data structure, e.g. temperature values of an engine over a definite distance of time, is a crucial task when writing any kind of software. Containers differ in the way how the elements are arranged and if they are sorted using some kind of key.

In STL you find Sequence Containers and Associative Containers. As described in [2], "A sequence is a kind of container that organizes a finite set of objects, all of the same type, into a strictly linear arrangement". STL provides three basic kinds of Sequence Containers: Vectors, Lists and Deques, where Deque is an abbreviation for Double Ended Queue.


Figure 2: Sequence Container


As Stepanov states, "Associative containers provide an ability for fast retrieval of data based on keys".

The elements are sorted and so fast binary search is possible for data retrieval. STL provides four basic kinds of Associative Containers. If the key value must be unique in the container, this means, if for each key value only one element can be stored, Set and Map can be used. If more than one element are to be stored using the same key, Multiset and Multimap are provided.


Figure 3: Associative Container


Here is a summary including all containers provided by STL:

Sequence Containers		Vector
				Deque
				List

Associative Containers          Set
				Multiset
				Map
				Multimap      

Table 2: STL Containers


Continue with section 4.1.1

Back to index


Johannes Weidl (J.Weidl@infosys.tuwien.ac.at) - Apr 16, 1996