std::flat_multimap
<flat_map>
class Key,
class T,
class Compare = std::less <Key>,
class KeyContainer = std::vector <Key>,
class MappedContainer = std::vector <T>
The flat multimap is a container adaptor that gives the functionality of an associative container that contains key-value pairs, while permitting multiple entries with the same key value. Keys are sorted by using the comparison function Compare
.
The class template flat_multimap
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_multimap
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 multimap supports most of AssociativeContainer's operations that use equal keys.
std::flat_multimap
are constexpr: it is possible to create and use std::flat_multimap
objects in the evaluation of a constant expression.However, std::flat_multimap
objects generally cannot be constexpr, because any dynamically allocated storage must be released in the same evaluation of constant expression.
Contents
[edit] Iterator invalidation
[edit] Template parameters
Key
is not the same type as KeyContainer::value_type
.
T
is not the same type as MappedContainer::value_type
.
MappedContainer - The types of the underlying SequenceContainer to store keys and mapped values correspondingly. The iterators of such containers should satisfy LegacyRandomAccessIterator or model
random_access_iterator
. Invocations of their member functions size
and max_size
should not exit via an exception.
The standard containers std::vector and std::deque satisfy these requirements.
[edit] Member types
iterator
implementation-defined LegacyInputIterator , ConstexprIterator (since C++26) and random_access_iterator
to value_type
[edit]
const_iterator
implementation-defined LegacyInputIterator , ConstexprIterator (since C++26) and random_access_iterator
to const value_type[edit]
containers
type describing the underlying containersstruct containers
{
key_container_type keys;
mapped_container_type values;
};[edit]
[edit] Member classes
[edit] Member objects
containers
c
(private)
the adapted containers(exposition-only member object*)
key_compare
compare
(private)
the comparison function object(exposition-only member object*)
[edit] Member functions
(public member function)
Iterators
Capacity
Modifiers
Lookup
(public member function) [edit]
Observers
value_type
(public member function) [edit]
[edit] Non-member functions
[edit] Helper classes
[edit] Tags
[edit] Deduction guides
[edit] Notes
The member types iterator
and const_iterator
may be aliases to the same type. This means defining a pair of function overloads using the two types as parameter types may violate the One Definition Rule. Since iterator
is convertible to const_iterator
, a single function with a const_iterator
as parameter type will work instead.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_flat_map |
202207L |
(C++23) | std::flat_map and std::flat_multimap
|
__cpp_lib_constexpr_flat_map |
202502L |
(C++26) | constexpr std::flat_multimap
|
[edit] Example
Reason: no example
[edit] See also
(class template) [edit]