std::flat_map
Defined in header <flat_map>
|
||
template< class Key, |
(since C++23) | |
The flat map is a container adaptor that gives the functionality of an associative container that contains key-value pairs with unique keys. Keys are sorted by using the comparison function Compare
.
The class template flat_map
acts as a wrapper to the two underlying containers, passed as objects of type KeyContainer
and MappedContainer
respectively. The first container is sorted, and for each key its corresponding value is in the second container at the same index (offset). The number of elements in both containers is the same.
Everywhere the standard library uses the Compare requirements, uniqueness is determined by using the equivalence relation. Informally, two objects a and b are considered equivalent if neither compares less than the other: !comp(a, b) && !comp(b, a).
std::flat_map
meets the requirements of Container, ReversibleContainer, optional container requirements, and all requirements of AssociativeContainer (including logarithmic search complexity), except that:
- requirements related to nodes are not applicable,
- iterator invalidation requirements differ,
- the complexity of insertion and erasure operations is linear.
A flat map supports most AssociativeContainer's operations that use unique keys.
All member functions of std::flat_map are constexpr: it is possible to create and use std::flat_map objects in the evaluation of a constant expression.However, |
(since C++26) |
Contents |