The Containers library is a generic collection of class templates and algorithms that allow programmers to easily implement common data structures like queues, lists and stacks. There are three classes of containers -- sequence containers, associative containers, and unordered associative containers -- each of which is designed to support a different set of operations.
The container manages the storage space that is allocated for its elements and provides member functions to access them, either directly or through iterators (objects with properties similar to pointers).
Most containers have at least several member functions in common, and share functionalities. Which container is the best for the particular application depends not only on the offered functionality, but also on its efficiency for different workloads.
Sequence containers implement data structures which can be accessed sequentially.
(since C++11) | static contiguous array (class template) |
dynamic contiguous array (class template) |
|
double-ended queue (class template) |
|
(since C++11) | singly-linked list (class template) |
doubly-linked list (class template) |
Associative containers implement sorted data structures that can be quickly searched (O(log n) complexity).
collection of unique keys, sorted by keys (class template) |
|
collection of key-value pairs, sorted by keys, keys are unique (class template) |
|
collection of keys, sorted by keys (class template) |
|
collection of key-value pairs, sorted by keys (class template) |
Unordered associative containers implement unsorted (hashed) data structures that can be quickly searched (O(1) amortized, O(n) worst-case complexity).
(since C++11) | collection of unique keys, hashed by keys (class template) |
(since C++11) | collection of key-value pairs, hashed by keys, keys are unique (class template) |
(since C++11) | collection of keys, hashed by keys (class template) |
(since C++11) | collection of key-value pairs, hashed by keys (class template) |
Container adaptors provide a different interface for sequential containers.
adapts a container to provide stack (LIFO data structure) (class template) |
|
adapts a container to provide queue (FIFO data structure) (class template) |
|
adapts a container to provide priority queue (class template) |
Thread safety
| (since C++11) |
- functions present in C++03 | |
- functions present since C++11 | |
- functions present since C++17 |
(A PDF version of this table is available at File:container-library-overview-2012-12-27.pdf.).
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/container