Standard Template Library
Container classes
Containers are classes that are used to hold other objects. For example,
a list is a container that holds data and links the data objects together.
There are a number of container classes in the STL.
- Lists
insertion anywhere, only sequential access.
- vector
i insertion at end, random access
- dequeues
insert at either end, random access. Used to construct stacks and queues.
- set
add,delete members, iterate over and query for members
- multisets (bags)
sets allowing duplicates.
- maps
a associative arrays, iterate over keys
- multimaps
allows multiple keys
Vector example
Vectors grow when you add elements. They are not pre-allocated like arrays.
So you can't insert randomly. Before you can insert v[10] you must insert
v[0-9]. Vectors are different from lists in that you can randomly access
elements. The vector size is the actual number of elements in the vector.
The capacity of a vector may be larger than the size as the vector will
allocate a few extra spaces when it resizes to add an element.