Containers library

Curated hub for choosing the right C++ container family: sequence, associative, unordered, adaptor, fixed-capacity, and view-like access tools.

The containers area is where most data-structure choices start in the C++ standard library. This hub helps you choose the right container family first, then the right concrete type, instead of starting from a flat list of names.

Use this page for owning containers and closely related access surfaces. Strings, Ranges, and Algorithms remain separate hubs and are linked here only where the boundary matters.

# Start Here

Sequence containers

General-purpose owning sequences when element order matters and you care about growth, insertion position, or iterator stability.

Ordered associative containers

Key-based lookup with deterministic sorted order, tree-style traversal, and ordered range queries.

Unordered associative containers

Hash-table lookup when average-case key access matters more than sorted order or ordered traversal.

Container adaptors

Restricted interfaces layered on top of an underlying container when you want stack, queue, or priority semantics directly.

Fixed-capacity and contiguous storage

Use compile-time or fixed-capacity storage when size constraints are known and allocation strategy matters.

Views and access surfaces

Non-owning or layout-oriented views when you need to pass or interpret data without taking ownership.

# Quick Choice Map

If you need...Start withWhyCommon alternatives
A default owning sequencevectorContiguous storage, fast random access, and the best general-purpose default for most value sequences.deque, list
Cheap insertion/removal at both endsdequeEfficient front/back growth without the pointer-heavy tradeoffs of linked lists.vector, list
Frequent splicing or stable node ownershiplist or forward_listNode-based structure favors stable references and link-level operations over cache locality.deque, vector
Sorted key lookup and ordered iterationmap or setTree-based ordering gives deterministic traversal and range queries such as lower/upper bound.unordered_map, flat_map
Fast average-case key lookupunordered_map or unordered_setHash-based access is usually the starting point when ordering is irrelevant.map, flat_map
Sorted associative storage with flat contiguous backingflat_map or flat_setOffers sorted semantics with vector-like storage tradeoffs, useful when lookup and locality dominate mutation cost.map, unordered_map
A stack, FIFO queue, or heap-style priority interfacestack, queue, or priority_queueThese adaptors intentionally expose a narrower API than their underlying storage container.deque, vector
Non-owning access to contiguous dataspanA view over existing memory when you do not want ownership or reallocation behavior.mdspan, ranges views
Multidimensional indexing without owning storagemdspanModels extents, layout, and accessor policy for array-like multidimensional data.span, array

# Container Families

FamilyRepresentative typesUse it for
Sequence containersvector, deque, list, forward_listOwning ordered collections where element position matters more than key lookup.
Ordered associative containersmap, set, multimap, multisetSorted key-based storage with logarithmic lookup and ordered traversal.
Unordered associative containersunordered_map, unordered_set, unordered_multimap, unordered_multisetHash-based key lookup when iteration order is not part of the problem.
Container adaptorsstack, queue, priority_queueRestricted queue/stack/priority interfaces layered over another container.
Fixed-capacity and contiguous toolsarray, inplace_vector, vectorStorage with strong locality properties where capacity model is a major choice.
View-like access surfacesspan, mdspanData access without ownership, especially for APIs, slices, and multidimensional layouts.
Flat associative additionsflat_map, flat_set, flat_multimap, flat_multisetSorted associative semantics backed by flat storage, introduced for newer locality-oriented use cases.

# Ownership And Access Model

ModelChoose it whenTypical types
Owning dynamic containerYou want the container to manage element lifetime and usually allow growth or mutation.vector, map, unordered_map
Owning fixed-size storageThe size or capacity model is constrained up front and allocation behavior matters.array, inplace_vector
Non-owning contiguous viewYou are borrowing data from elsewhere and want to pass it safely without copying.span
Non-owning multidimensional viewYou need indexing and layout metadata over existing multidimensional storage.mdspan
Interface adaptor over another containerYou want queue, stack, or heap behavior and intentionally do not want the full underlying container API.stack, queue, priority_queue

# Recent Standard Additions

StandardNotable additionsWhy it changes navigation
C++11array, forward_list, unordered associative containersIntroduced modern fixed-size and hash-based container choices into the main decision tree.
C++20spanMade non-owning contiguous views a first-class route instead of treating borrowed arrays as raw pointers only.
C++23flat_map, flat_set, mdspanAdded locality-oriented sorted associative containers and multidimensional access models.
C++26inplace_vectorProvides a standard fixed-capacity vector-like option between `array` and dynamically growing `vector`.

Ranges

Use ranges when the main problem is traversal pipelines, lazy views, and adaptor composition rather than container ownership.

Strings

`basic_string` and `basic_string_view` often feel container-like, but text, encodings, literals, and conversion concerns live in the string hub.

Named requirements

Use the requirements pages when you need the formal semantic contracts shared by container families.

See also