|
|
| flat_multimap ()=default |
| | Default-construct an empty multimap.
|
| | flat_multimap (const container_type &cont) |
| | Construct from an existing container.
|
| | flat_multimap (container_type &&cont) |
| | Move-construct from an existing container.
|
| | flat_multimap (const allocator_type &alloc) |
| | Construct an empty multimap with a specific allocator.
|
| | flat_multimap (const container_type &cont, const allocator_type &alloc) |
| | Construct from a container and allocator.
|
| | flat_multimap (container_type &&cont, const allocator_type &alloc) |
| | Move-construct from a container using a specific allocator.
|
|
| flat_multimap (const flat_multimap &)=default |
| | Copy-construct from another flat_multimap, using a rebound default allocator.
|
| | flat_multimap (const flat_multimap &other, const allocator_type &alloc) |
| | Copy-construct from another flat_multimap, using a user-supplied allocator.
|
| | flat_multimap (flat_multimap &&) noexcept=default |
| | Move-construct from another flat_multimap, using a rebound default allocator.
|
| | flat_multimap (flat_multimap &&other, const allocator_type &alloc) |
| | Move-construct from another flat_multimap, using a user-supplied allocator.
|
|
flat_multimap & | operator= (const flat_multimap &)=default |
| | Copy assignment.
|
|
flat_multimap & | operator= (flat_multimap &&) noexcept=default |
| | Move assignment.
|
| std::pair< iterator, iterator > | equal_range (const K &k) |
| | Return the range of elements equivalent to the given key.
|
| std::pair< const_iterator, const_iterator > | equal_range (const K &k) const |
| | Return the range of elements equivalent to the given key (const overload).
|
| iterator | find (const K &k) |
| | Locate the first element with the specified key.
|
| const_iterator | find (const K &k) const |
| | Locate the first element with the specified key (const overload).
|
| template<typename... Args> |
| iterator | emplace (Args &&... args) |
| | Insert a key-value pair by constructing it from arbitrary arguments.
|
| template<typename P> |
| iterator | insert (P &&p) |
| | Insert a key-value pair into the map.
|
| iterator | erase (iterator pos) |
| | Erase the element referenced by the given iterator.
|
| iterator | erase (const_iterator pos) |
| | Erase the element referenced by the given const iterator.
|
| iterator | erase (iterator first, iterator last) |
| | Erase a range of elements.
|
| iterator | erase (const_iterator first, const_iterator last) |
| | Erase a range of elements.
|
| size_t | erase (const K &k) |
| | Erase all elements whose key compares equal to the given key.
|
| std::size_t | count (const K &key) const |
| | Count the number of elements with the specified key.
|
|
iterator | begin () |
| | Return iterator to the first element.
|
|
iterator | end () |
| | Return iterator past the last element.
|
|
const_iterator | begin () const |
| | Return const iterator to the first element.
|
|
const_iterator | end () const |
| | Return const iterator past the last element.
|
|
size_t | size () const |
| | Return the number of elements stored.
|
|
bool | empty () const |
| | Check whether the container is empty.
|
| void | clear () noexcept |
| | Remove all elements from the container.
|
| void | reserve (std::size_t n) noexcept(noexcept(storage_.reserve(n))) |
| | Reserve space for at least n elements.
|
| void | shrink_to_fit () noexcept(noexcept(storage_.shrink_to_fit())) |
| | Request that the container reduce its capacity.
|
| template<typename It> |
| void | bulk_insert (It first, It last) |
| | Insert a range of elements and restore ordering.
|
Flat ordered multimap implemented as a sorted contiguous container.
- Template Parameters
-
| K | Key type. Must be strictly ordered via operator<. |
| V | Mapped value type. |
| Alloc | Allocator type used for underlying storage. |
flat_multimap implements ordered multimap semantics by storing std::pair<K, V> elements in a contiguous container (std::vector) that is kept sorted by key.
Duplicate keys are permitted and are stored contiguously. Lookup and range queries are implemented using binary search (lower_bound, upper_bound), while insertion and erasure are expressed in terms of vector operations.
This container is optimized for:
-
range-oriented multimap semantics (
equal_range, erase(key))
-
cache-friendly traversal and lookup
-
bulk insertion and reconstruction
- Note
- All insertions and erasures may invalidate iterators.
Unlike tree-based ordered containers, no node identity or pointer stability is preserved; elements may be relocated freely within the underlying storage.
template<typename K, typename V, typename Alloc = std::allocator<std::pair<K, V>>>
Remove all elements from the container.
Resets the container to an empty state by clearing the underlying storage. The operation is equivalent to clearing a vector:
-
The size becomes zero, but the capacity is preserved.
-
No reallocation occurs.
-
Under polymorphic allocators (PMR), no element-by-element destruction or resource release takes place; the buffer is simply marked empty.
This gives clear an effectively constant-time cost. Unlike pointer-based tree structures such as those used by the standard multimap, there is no need to traverse and destroy individual nodes; the entire storage is discarded in one step.
- Note
- All iterators are invalidated.
template<typename K, typename V, typename Alloc = std::allocator<std::pair<K, V>>>
template<typename... Args>
Insert a key-value pair by constructing it from arbitrary arguments.
This function preserves the usual emplace semantics: the arguments are forwarded into a temporary std::pair<K, V>. The key and mapped value constructed in this temporary object are then forwarded into the internal insertion logic.
If the key already exists in the map, the new element is inserted after all existing equivalents.
- Parameters
-
| args | Arguments used to construct a temporary std::pair<K, V>. |
- Returns
- Iterator to the inserted element.
- Note
- All iterators are invalidated except the returned one.
template<typename K, typename V, typename Alloc = std::allocator<std::pair<K, V>>>
Erase a range of elements.
Removes all elements in the half-open range [first, last) by delegating to the non-const overload erase(iterator, iterator). The behavior, iterator invalidation rules, and returned iterator semantics exactly match those of the non-const overload.
- Parameters
-
| first | Const iterator referring to the first element to erase. |
| last | Const iterator referring to one past the last element to erase. |
- Returns
- An iterator referring to the logical successor of the last erased element, or
end() if no such element exists.
- Exceptions
-
| std::logic_error | If last precedes first. |
template<typename K, typename V, typename Alloc = std::allocator<std::pair<K, V>>>
Erase the element referenced by the given const iterator.
Removes the element pointed to by pos by delegating to the non-const overload erase(iterator). The behavior, iterator invalidation rules, and returned iterator semantics exactly match those of erase(iterator).
If pos equals end(), no removal occurs and pos is returned unchanged.
- Parameters
-
| pos | Const iterator referring to the element to erase. |
- Returns
- An iterator as the logical successor of the erased element, or
end() if no successor exists.
template<typename K, typename V, typename Alloc = std::allocator<std::pair<K, V>>>
Erase a range of elements.
Removes all elements in the half-open range [first, last) and returns an iterator to the logical successor of the last erased element.
The range [first, last) must be valid. In particular, last must not precede first. If this condition is violated, a std::logic_error is thrown.
If first == last, no elements are removed and first is returned.
If first == end(), no removal is performed and end() is returned. This is only considered valid when last == end().
- Parameters
-
| first | Iterator referring to the first element to erase. |
| last | Iterator referring to one past the last element to erase. |
- Returns
- An iterator referring to the logical successor of the last erased element, or
end() if no such element exists.
- Exceptions
-
| std::logic_error | If last precedes first. |
template<typename K, typename V, typename Alloc = std::allocator<std::pair<K, V>>>
template<typename P>
Insert a key-value pair into the map.
This overload generalizes the traditional std::pair<K, V>-based insertion interface. Instead of requiring a value_type object, any 2-element tuple-like value is accepted as long as:
-
get<0>(p) has type K (after remove_cvref)
-
get<1>(p) has type V (after remove_cvref)
This reflects the actual insertion semantics: the container consumes the key and mapped value directly. Any tuple-like pair (including std::pair, std::tuple, proxy references, and structured-binding-compatible types) is therefore permitted if its element types match exactly.
If the key already exists in the map, the new element is inserted after all existing equivalents.
- Template Parameters
-
| P | The tuple-like type providing key and mapped value. |
- Parameters
-
| p | A tuple-like value providing key and mapped value. |
- Returns
- Iterator to the inserted element.
- Note
- All iterators are invalidated except the returned one.
template<typename K, typename V, typename Alloc = std::allocator<std::pair<K, V>>>
Reserve space for at least n elements.
Requests that the underlying storage grow its capacity to at least n elements. This operation does not change the size of the container or alter any existing node indices.
Calling reserve with a value smaller than the current size is no-op, according to ISO C++11+ standards for standard containers.
With polymorphic allocators (PMR), reserve typically has minimal overhead, as the resource may enlarge the buffer without a full reallocation.
- Parameters
-
| n | Minimum capacity to reserve. |
- Note
- This operation may invalidate all iterators if reallocation occurs.