23 Containers library [containers]

23.6 Container adaptors [container.adaptors]

23.6.9 Class template flat_multimap [flat.multimap]

23.6.9.1 Overview [flat.multimap.overview]

A flat_multimap is a container adaptor that provides an associative container interface that supports equivalent keys (i.e., possibly containing multiple copies of the same key value) and provides for fast retrieval of values of another type T based on the keys.
flat_multimap supports iterators that meet the Cpp17InputIterator requirements and model the random_access_iterator concept ([iterator.concept.random.access]).
A flat_multimap meets all of the requirements for a container ([container.reqmts]) and for a reversible container ([container.rev.reqmts]), plus the optional container requirements ([container.opt.reqmts]).
flat_multimap meets the requirements of an associative container ([associative.reqmts]), except that:
  • it does not meet the requirements related to node handles ([container.node]),
  • it does not meet the requirements related to iterator invalidation, and
  • the time complexity of the operations that insert or erase a single element from the map is linear, including the ones that take an insertion position iterator.
[Note 1: 
A flat_multimap does not meet the additional requirements of an allocator-aware container ([container.alloc.reqmts]).
— end note]
A flat_multimap also provides most operations described in [associative.reqmts] for equal keys.
This means that a flat_multimap supports the a_eq operations in [associative.reqmts] but not the a_uniq operations.
For a flat_multimap<Key, T> the key_type is Key and the value_type is pair<Key, T>.
Except as otherwise noted, operations on flat_multimap are equivalent to those of flat_map, except that flat_multimap operations do not remove or replace elements with equal keys.
[Example 1: 
flat_multimap constructors and emplace do not erase non-unique elements after sorting them.
— end example]
A flat_multimap maintains the following invariants:
  • it contains the same number of keys and values;
  • the keys are sorted with respect to the comparison object; and
  • the value at offset off within the value container is the value associated with the key at offset off within the key container.
If any member function in [flat.multimap.defn] exits via an exception, the invariants are restored.
[Note 2: 
This can result in the flat_multimap being emptied.
— end note]
Any type C that meets the sequence container requirements ([sequence.reqmts]) can be used to instantiate flat_multimap, as long as C​::​iterator meets the Cpp17RandomAccessIterator requirements and invocations of member functions C​::​size and C​::​max_size do not exit via an exception.
In particular, vector ([vector]) and deque ([deque]) can be used.
[Note 3: 
vector<bool> is not a sequence container.
— end note]
The program is ill-formed if Key is not the same type as KeyContainer​::​value_type or T is not the same type as MappedContainer​::​value_type.
The effect of calling a constructor that takes both key_container_type and mapped_container_type arguments with containers of different sizes is undefined.
The effect of calling a constructor or member function that takes a sorted_equivalent_t argument with a container, containers, or range that are not sorted with respect to key_comp() is undefined.