< Previous | Contents | Next >
Examining Other STL Containers
The STL defines a variety of container types that fall into two basic categories— sequential and associative. With a sequential container, you can retrieve values in sequence, while an associative container lets you retrieve values based on keys. vector is an example of a sequential container.
How might you use these different container types? Consider an online, turned- based strategy game. You could use a sequential container to store a group of players that you want to cycle through in, well, sequence. On the other hand, you could use an associative container to retrieve player information in a random- access fashion by looking up a unique identifier, such as a player’s IP address.
Finally, the STL defines container adaptors that adapt one of the sequence containers. Container adaptors represent standard computer science data
Double-ended queue
Linear list
Collection of key/value pairs in which each key is associated with exactly one value
Collection of key/value pairs in which each key may be associated with more than one value
Collection in which each element is not necessarily unique Priority queue
Queue
Collection in which each element is unique Stack
Dynamic array
multiset Associative
priority_queue Adaptor
queue Adaptor
set Associative
stack Adaptor
vector Sequential
Associative
multimap
Sequential
Sequential Associative
deque
list map
Description
Table 4.1 STL Containers
Container Type
structures. Although they are not official containers, they look and feel just like them. Table 4.1 lists the container types offered by the STL.