Containers

Containers are data structures that manage a collection of elements and are responsible for the allocation and deallocation of those elements. Containers typically have constructors and destructors along with operations for inserting and deleting elements.

Elements are stored in containers as whole objects; no pointers are used to access the elements in a container. This results in containers that are type safe and efficient. The STL provides two categories of containers:

·         Sequence containers store elements in sequential order. These containers group a finite set of elements in a linear arrangement. The STL includes class templates for vectors, lists, and deques.

·         Associative containers store elements based on a key value. Implemented as red-black trees, they provide efficient retrieval of elements based on their key. The STL provides class templates for maps, multimaps, sets, and multisets. Maps and multimaps allow arbitrary data to be associated with each key. Also, maps and sets only allow elements with unique keys, whereas multimaps and multisets may contain elements with duplicate keys.