Containers
The fundamental purpose of a container is to store multiple objects in a single container object. Different kinds of containers have different characteristics, such as speed, size, and ease of use. The choice of container depends on the characteristics and behavior you require.
In C++, the containers are implemented as class templates, so you
can store anything in a container. (Well, almost anything. The type must
have value semantics, which means it must behave as
an ordinary value, such as an int.
Values can be copied and assigned freely. An original and its copy must
compare as equal. Some containers impose additional
restrictions.)
Standard Containers
The standard containers fall into two categories: sequence and associative containers. A sequence container preserves the original order in which items were added to the container. An associative container keeps items in ascending order (you can define the order relation) to speed up searching. The standard containers are:
dequeA deque (double-ended queue) is a sequence container that supports fast insertions and deletions at the beginning and end of the container. Inserting or deleting at any other position is slow, but indexing to any item is fast. Items are not stored contiguously. The header is
<deque>.listA list is a sequence container that supports rapid insertion or deletion at any position but does not support random access. Items are not stored contiguously. The header is
<list>.mapmultimapA map (or dictionary) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access