STD::MULTIMAP(3)

πŸ’– std::multimap< _Key, _Tp, _Compare, _Alloc > β€” Library Functions Manual, section 3 πŸ’–

okay bestie, welcome to the std::multimap< _Key, _Tp, _Compare, _Alloc > page, aka std::multimap(3). She's from the Library Functions Manual, section 3, and she's here to explain a standard container made of (key,value) pairs that you can retrieve by key in logarithmic time. no cap. πŸ’…

✨ NAME ✨

std::multimap< _Key, _Tp, _Compare, _Alloc > β€” a standard container made up of (key,value) pairs, which can be retrieved based on a key, in logarithmic time.

πŸŽ€ SYNOPSIS πŸŽ€

#include <map>

🌸 Public Types 🌸

  • typedef _Alloc allocator_type
  • typedef _Rep_type::const_iterator const_iterator
  • typedef _Alloc_traits::const_pointer const_pointer
  • typedef _Alloc_traits::const_reference const_reference
  • typedef _Rep_type::const_reverse_iterator const_reverse_iterator
  • typedef _Rep_type::difference_type difference_type
  • typedef _Rep_type::iterator iterator
  • typedef _Compare key_compare
  • typedef _Key key_type
  • typedef _Tp mapped_type
  • typedef _Alloc_traits::pointer pointer
  • typedef _Alloc_traits::reference reference
  • typedef _Rep_type::reverse_iterator reverse_iterator
  • typedef _Rep_type::size_type size_type
  • typedef std::pair< const _Key, _Tp > value_type

πŸ’… Public Member Functions πŸ’…

Okay so here's the whole roster, bestie. Every overload gets her moment. ✨

  • multimap ()=default β€” default constructor creates no elements.
  • template<typename _InputIterator> multimap (_InputIterator __first, _InputIterator __last) β€” builds a multimap from a range.
  • template<typename _InputIterator> multimap (_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type()) β€” builds a multimap from a range.
  • template<typename _InputIterator> multimap (_InputIterator __first, _InputIterator __last, const allocator_type &__a) β€” allocator-extended range constructor.
  • multimap (const _Compare &__comp, const allocator_type &__a=allocator_type()) β€” creates a multimap with no elements.
  • multimap (const allocator_type &__a) β€” allocator-extended default constructor.
  • multimap (const multimap &)=default β€” multimap copy constructor.
  • multimap (const multimap &__m, const __type_identity_t< allocator_type > &__a) β€” allocator-extended copy constructor.
  • multimap (initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type()) β€” builds a multimap from an initializer_list.
  • multimap (initializer_list< value_type > __l, const allocator_type &__a) β€” allocator-extended initialier-list constructor. (yes, "initialier" is a typo in the source, we're keeping it, it's part of her lore πŸ’€)
  • multimap (multimap &&)=default β€” multimap move constructor.
  • multimap (multimap &&__m, const __type_identity_t< allocator_type > &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal()) β€” allocator-extended move constructor.
  • ~multimap ()=default β€” the default destructor.
  • const_iterator begin () const noexcept
  • iterator begin () noexcept
  • const_iterator cbegin () const noexcept
  • const_iterator cend () const noexcept
  • void clear () noexcept
  • const_reverse_iterator crbegin () const noexcept
  • const_reverse_iterator crend () const noexcept
  • template<typename... _Args> iterator emplace (_Args &&... __args) β€” build and insert a std::pair into the multimap.
  • template<typename... _Args> iterator emplace_hint (const_iterator __pos, _Args &&... __args) β€” builds and inserts a std::pair into the multimap.
  • bool empty () const noexcept
  • const_iterator end () const noexcept
  • iterator end () noexcept
  • size_type erase (const key_type &__x) β€” erases elements according to the provided key.
  • iterator erase (const_iterator __first, const_iterator __last) β€” erases a [first,last) range of elements from a multimap.
  • allocator_type get_allocator () const noexcept β€” get a copy of the memory allocation object.
  • template<typename _InputIterator> void insert (_InputIterator __first, _InputIterator __last) β€” a template function that attempts to insert a range of elements.
  • void insert (initializer_list< value_type > __l) β€” attempts to insert a list of std::pairs into the multimap.
  • key_compare key_comp () const
  • size_type max_size () const noexcept
  • multimap & operator= (const multimap &)=default β€” multimap assignment operator.
  • multimap & operator= (initializer_list< value_type > __l) β€” multimap list assignment operator.
  • multimap & operator= (multimap &&)=default β€” move assignment operator.
  • const_reverse_iterator rbegin () const noexcept
  • reverse_iterator rbegin () noexcept
  • const_reverse_iterator rend () const noexcept
  • reverse_iterator rend () noexcept
  • size_type size () const noexcept
  • void swap (multimap &__x) noexcept(/*conditional */) β€” swaps data with another multimap.
  • value_compare value_comp () const

and here are the extra overloads that were chilling indented in the original, bestie. they're still part of the same Public Member Functions section, so don't skip them. 🫢

  • iterator insert (const value_type &__x) β€” inserts a std::pair into the multimap.
  • iterator insert (value_type &&__x) β€” inserts a std::pair into the multimap.
  • template<typename _Pair> __enable_if_t< is_constructible< value_type, _Pair >::value, iterator > insert (_Pair &&__x) β€” inserts a std::pair into the multimap.
  • iterator insert (const_iterator __position, const value_type &__x) β€” inserts a std::pair into the multimap.
  • iterator insert (const_iterator __position, value_type &&__x) β€” inserts a std::pair into the multimap.
  • template<typename _Pair> __enable_if_t< is_constructible< value_type, _Pair && >::value, iterator > insert (const_iterator __position, _Pair &&__x) β€” inserts a std::pair into the multimap.
  • iterator erase (const_iterator __position) β€” erases an element from a multimap.
  • iterator erase (iterator __position) β€” erases an element from a multimap.
  • iterator find (const key_type &__x) β€” tries to locate an element in a multimap.
  • const_iterator find (const key_type &__x) const β€” tries to locate an element in a multimap.
  • size_type count (const key_type &__x) const β€” finds the number of elements with given key.
  • bool contains (const key_type &__x) const β€” finds whether an element with the given key exists.
  • template<typename _Kt> auto contains (const _Kt &__x) const -> decltype(_M_t._M_find_tr(__x), void(), true) β€” finds whether an element with the given key exists.
  • iterator lower_bound (const key_type &__x) β€” finds the beginning of a subsequence matching given key.
  • const_iterator lower_bound (const key_type &__x) const β€” finds the beginning of a subsequence matching given key.
  • iterator upper_bound (const key_type &__x) β€” finds the end of a subsequence matching given key.
  • const_iterator upper_bound (const key_type &__x) const β€” finds the end of a subsequence matching given key.
  • std::pair< iterator, iterator > equal_range (const key_type &__x) β€” finds a subsequence matching given key.
  • std::pair< const_iterator, const_iterator > equal_range (const key_type &__x) const β€” finds a subsequence matching given key.

🫢 Friends 🫢

  • template<typename _K1, typename _T1, typename _C1, typename _A1> bool operator< (const multimap< _K1, _T1, _C1, _A1 > &, const multimap< _K1, _T1, _C1, _A1 > &)
  • template<typename _K1, typename _T1, typename _C1, typename _A1> bool operator== (const multimap< _K1, _T1, _C1, _A1 > &, const multimap< _K1, _T1, _C1, _A1 > &)

πŸ¦‹ Detailed Description πŸ¦‹

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    class std::multimap< _Key, _Tp, _Compare, _Alloc >

"A standard container made up of (key,value) pairs, which can be retrieved based on a key, in logarithmic time.

Since: C++98

⭐ Template Parameters ⭐

  • _Key β€” Type of key objects.
  • _Tp β€” Type of mapped objects.
  • _Compare β€” Comparison function object type, defaults to less<_Key>.
  • _Alloc β€” Allocator type, defaults to allocator<pair<const _Key, _Tp>. (the manpage itself has a missing > there, we're not fixing it, we're just reporting it πŸ’€)

Meets the requirements of a container, a reversible container, and an associative container (using equivalent keys). For a multimap<Key,T> the key_type is Key, the mapped_type is T, and the value_type is std::pair<const Key,T>.

Multimaps support bidirectional iterators.

The private tree data is declared exactly the same way for map and multimap; the distinction is made entirely in how the tree functions are called (*_unique versus *_equal, same as the standard).

πŸ’– Constructor & Destructor Documentation πŸ’–

okay bestie, this is the glow-up section: every single way you can birth a std::multimap into existence (and the one way she leaves πŸ’€). Spoilers: there are a LOT of constructors, because the standard library is extra like that. Every one of them is listed below, no skips, no cuts, we're doing all of them fr fr.


🍼 multimap () β€” the default one

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
std::multimap< _Key, _Tp, _Compare, _Alloc >::multimap () [default]

Default constructor creates no elements. That's it, that's the whole vibe β€” she's born empty, she's [default], she's lowkey just sitting there ready for you to fill her up later πŸ’…

🧬 multimap (const _Compare &, const allocator_type &) β€” comp + allocator

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
std::multimap< _Key, _Tp, _Compare, _Alloc >::multimap (const _Compare &
__comp, const allocator_type & __a = allocator_type()) [inline],
[explicit]

Creates a multimap with no elements. (Yes, still empty. She's just got opinions now.) This one is [inline] and [explicit], so she's not gonna get sneaky-converted behind your back, periodt.

Parameters

  • __comp β€” A comparison object. (Her taste. Her whole judgment system.)
  • __a β€” An allocator object.

πŸ“‹ multimap (const multimap &) β€” the copy constructor

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
std::multimap< _Key, _Tp, _Compare, _Alloc >::multimap (const multimap<
_Key, _Tp, _Compare, _Alloc > & ) [default]

Multimap copy constructor. Whether the allocator is copied depends on the allocator traits. That's the whole tea β€” the allocator's fate is not decided here, it's decided by the allocator traits. iykyk πŸ™ˆ

🚚 multimap (multimap &&) β€” the move constructor

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
std::multimap< _Key, _Tp, _Compare, _Alloc >::multimap (multimap< _Key,
_Tp, _Compare, _Alloc > && ) [default]

Multimap move constructor. The newly-created multimap contains the exact contents of the moved instance. The moved instance is a valid, but unspecified multimap β€” so like, she's alive, she's fine, but don't go asking her questions about herself because she doesn't remember anything anymore 😭 main character energy transferred, fr.

πŸŽ€ multimap (initializer_list< value_type >, ...) β€” the list one

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
std::multimap< _Key, _Tp, _Compare, _Alloc >::multimap
(initializer_list< value_type > __l, const _Compare & __comp =
_Compare(), const allocator_type & __a = allocator_type()) [inline]

Builds a multimap from an initializer_list. Curly braces, bestie 🫢

Parameters

  • __l β€” An initializer_list.
  • __comp β€” A comparison functor.
  • __a β€” An allocator object.

Create a multimap consisting of copies of the elements from the initializer_list. This is linear in N if the list is already sorted, and NlogN otherwise (where N is __l.size()). So if you hand her a sorted list she's fast, and if you don't she's still fine, she just has to do the work. No judgment ✨

🧺 multimap (const allocator_type &) β€” allocator-extended default

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
std::multimap< _Key, _Tp, _Compare, _Alloc >::multimap (const
allocator_type & __a) [inline],  [explicit]

Allocator-extended default constructor. You brought your own allocator, she's [inline] and [explicit], no elements, no drama.

πŸ§ΊπŸ“‹ multimap (const multimap &, const __type_identity_t< allocator_type > &) β€” allocator-extended copy

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
std::multimap< _Key, _Tp, _Compare, _Alloc >::multimap (const multimap<
_Key, _Tp, _Compare, _Alloc > & __m, const __type_identity_t<
allocator_type > & __a) [inline]

Allocator-extended copy constructor. Copy her, but your allocator is doing the allocating now. [inline], obviously πŸ’…

🧺🚚 multimap (multimap &&, const __type_identity_t< allocator_type > &) β€” allocator-extended move

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
std::multimap< _Key, _Tp, _Compare, _Alloc >::multimap (multimap< _Key,
_Tp, _Compare, _Alloc > && __m, const __type_identity_t< allocator_type
> & __a) [inline],  [noexcept]

Allocator-extended move constructor. [inline], and [noexcept] β€” she promised not to throw, and she meant it πŸ”₯

πŸ§ΊπŸŽ€ multimap (initializer_list< value_type >, const allocator_type &) β€” allocator-extended list

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
std::multimap< _Key, _Tp, _Compare, _Alloc >::multimap
(initializer_list< value_type > __l, const allocator_type & __a)
[inline]

Allocator-extended initialier-list constructor. (yes that's genuinely how the source spells it, we love her, we're not touching it πŸ’€)

🧺🌈 multimap (_InputIterator, _InputIterator, const allocator_type &) β€” allocator-extended range

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
template<typename _InputIterator> std::multimap< _Key, _Tp, _Compare,
_Alloc >::multimap (_InputIterator __first, _InputIterator __last, const
allocator_type & __a) [inline]

Allocator-extended range constructor. Two iterators, your allocator, go πŸ¦‹

🌈 multimap (_InputIterator, _InputIterator) β€” the plain range one

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
template<typename _InputIterator> std::multimap< _Key, _Tp, _Compare,
_Alloc >::multimap (_InputIterator __first, _InputIterator __last)
[inline]

Builds a multimap from a range.

Parameters

  • __first β€” An input iterator.
  • __last β€” An input iterator.

Create a multimap consisting of copies of the elements from [__first,__last). This is linear in N if the range is already sorted, and NlogN otherwise (where N is distance(__first,__last)).

πŸŒˆπŸ’… multimap (_InputIterator, _InputIterator, const _Compare &, const allocator_type &) β€” range + comp + alloc

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
template<typename _InputIterator> std::multimap< _Key, _Tp, _Compare,
_Alloc >::multimap (_InputIterator __first, _InputIterator __last, const
_Compare & __comp, const allocator_type & __a = allocator_type())
[inline]

Builds a multimap from a range. (The full deluxe version β€” everything customisable.)

Parameters

  • __first β€” An input iterator.
  • __last β€” An input iterator.
  • __comp β€” A comparison functor.
  • __a β€” An allocator object.

Create a multimap consisting of copies of the elements from [__first,__last). This is linear in N if the range is already sorted, and NlogN otherwise (where N is distance(__first,__last)).

πŸ’€ ~multimap () β€” the destructor

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
std::multimap< _Key, _Tp, _Compare, _Alloc >::~multimap () [default]

The dtor only erases the elements, and note that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. So like β€” she cleans up her own stuff, but if you stored raw pointers in there, those little guys are on YOU, bestie. She's not your memory manager. No cap 😭


πŸ”₯ Member Function Documentation πŸ”₯

and now the actual doing things part β€” all the member functions, alphabetically-ish the way the page lists them, every single one πŸ’–

⭐ begin () const

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
const_iterator std::multimap< _Key, _Tp, _Compare, _Alloc >::begin ()
const [inline],  [noexcept]

Returns a read-only (constant) iterator that points to the first pair in the multimap. Iteration is done in ascending order according to the keys. [inline], [noexcept] β€” she's chill about it.

⭐ begin ()

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
std::multimap< _Key, _Tp, _Compare, _Alloc >::begin () [inline],
[noexcept]

Returns a read/write iterator that points to the first pair in the multimap. Iteration is done in ascending order according to the keys. Same deal, but you can actually edit things this time πŸ‘‘

⭐ cbegin () const

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
const_iterator std::multimap< _Key, _Tp, _Compare, _Alloc >::cbegin ()
const [inline],  [noexcept]

Returns a read-only (constant) iterator that points to the first pair in the multimap. Iteration is done in ascending order according to the keys. The c stands for const, the const stands for no touching 🚫

⭐ cend () const

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
const_iterator std::multimap< _Key, _Tp, _Compare, _Alloc >::cend ()
const [inline],  [noexcept]

Returns a read-only (constant) iterator that points one past the last pair in the multimap. Iteration is done in ascending order according to the keys. Yes she's pointing at nothing, that's the point, that's the sentinel behavior, we stan a boundary 🫢

🧹 clear ()

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> void
std::multimap< _Key, _Tp, _Compare, _Alloc >::clear () [inline],
[noexcept]

Erases all elements in a multimap. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

bestie. if you put new'd pointers in here and then call clear(), she will happily forget them and the memory will just… sit there. forever. that's a leak. that's on you. that's the vibe. πŸ’€

πŸ” contains (const _Kt &) const

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
template<typename _Kt> auto std::multimap< _Key, _Tp, _Compare, _Alloc
>::contains (const _Kt & __x) const -> decltype(_M_t._M_find_tr(__x),
void(), true) [inline]

Finds whether an element with the given key exists. (Look at that trailing return type. Look at _M_find_tr. She's doing transparent comparator magic and she's doing it beautifully ✨)

Parameters

  • __x β€” Key of (key, value) pairs to be located.

Returns

  • True if there is any element with the specified key.

πŸ” contains (const key_type &) const

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> bool
std::multimap< _Key, _Tp, _Compare, _Alloc >::contains (const key_type &
__x) const [inline]

Finds whether an element with the given key exists. Same question, plainer signature, returns an actual bool.

Parameters

  • __x β€” Key of (key, value) pairs to be located.

Returns

  • True if there is any element with the specified key.

πŸ”’ count (const key_type &) const

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> size_type
std::multimap< _Key, _Tp, _Compare, _Alloc >::count (const key_type &
__x) const [inline]

Finds the number of elements with given key. and here's the thing bestie β€” this is a multimap, so the answer can absolutely be more than 1 πŸ‘€ that's literally her whole brand.

Parameters

  • __x β€” Key of (key, value) pairs to be located.

Returns

  • Number of elements with specified key.

⭐ crbegin () const

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
const_reverse_iterator std::multimap< _Key, _Tp, _Compare, _Alloc
>::crbegin () const [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to the last pair in the multimap. Iteration is done in descending order according to the keys. Walking backwards, looking cute, not touching anything 🌸

⭐ crend () const

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
const_reverse_iterator std::multimap< _Key, _Tp, _Compare, _Alloc
>::crend () const [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points one before the first pair in the multimap. Iteration is done in descending order according to the keys. She's the reverse sentinel. She is the end of the backwards world. iconic πŸŽ€

πŸ—οΈ emplace (_Args &&...)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
template<typename... _Args> iterator std::multimap< _Key, _Tp, _Compare,
_Alloc >::emplace (_Args &&... __args) [inline]

Build and insert a std::pair into the multimap.

Parameters

  • __args β€” Arguments used to generate a new pair instance (see std::piecewise_contruct for passing arguments to each part of the pair constructor).

Returns

  • An iterator that points to the inserted (key,value) pair.

This function builds and inserts a (key, value) pair into the multimap. Contrary to a std::map the multimap does not rely on unique keys and thus multiple pairs with the same key can be inserted.

Insertion requires logarithmic time. Construct in place, no copies, she's efficient, she's that girl πŸ’…

πŸ—οΈ emplace_hint (const_iterator, _Args &&...)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
template<typename... _Args> iterator std::multimap< _Key, _Tp, _Compare,
_Alloc >::emplace_hint (const_iterator __pos, _Args &&... __args)
[inline]

Builds and inserts a std::pair into the multimap.

  • __pos β€” an iterator that's basically a lil hint about where this pair should go πŸ‘€
  • __args β€” the arguments used to generate a new pair instance (peep std::piecewise_contruct if you wanna pass args to each part of the pair constructor separately).

Returns β€” an iterator pointing at the inserted (key,value) pair. πŸŽ€

So like, this function inserts a (key, value) pair into the multimap. And here's the tea: contrary to a std::map, the multimap does NOT rely on unique keys, so multiple pairs with the same key can absolutely be inserted. We love a container that doesn't gatekeep. ✨

Also note that the first parameter is only a hint β€” it can potentially improve insertion performance, but a bad hint would cause no gains in efficiency. So don't come with a messy hint and expect a glow-up.

For more on hinting, see: https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints

Insertion requires logarithmic time (if the hint is not taken). πŸ’…


template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> bool
    std::multimap< _Key, _Tp, _Compare, _Alloc >::empty () const [inline],
    [nodiscard],  [noexcept]

Returns true if the multimap is empty. That's it, that's the whole function. Short queen behavior. πŸ‘‘

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    const_iterator std::multimap< _Key, _Tp, _Compare, _Alloc >::end ()
    const [inline],  [noexcept]

Returns a read-only (constant) iterator that points one past the last pair in the multimap. Iteration happens in ascending order according to the keys. πŸ“ˆ

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
    std::multimap< _Key, _Tp, _Compare, _Alloc >::end () [inline],
    [noexcept]

Returns a read/write iterator that points one past the last pair in the multimap. Iteration is done in ascending order according to the keys. Same vibe, but this one lets you write. 😌

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    std::pair< iterator, iterator > std::multimap< _Key, _Tp, _Compare,
    _Alloc >::equal_range (const key_type & __x) [inline]

Finds a subsequence matching a given key. πŸ”

Parameters

  • __x β€” the key of the (key, value) pairs you're trying to locate.

Returns β€” a pair of iterators that possibly points to the subsequence matching that key.

This function is equivalent to:

std::make_pair(c.lower_bound(val),
               c.upper_bound(val))

(but it's faster than making the calls separately, bestie β€” two birds, one call πŸ¦‹)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    std::pair< const_iterator, const_iterator > std::multimap< _Key, _Tp,
    _Compare, _Alloc >::equal_range (const key_type & __x) const [inline]

Finds a subsequence matching a given key β€” the const girlie version. πŸ’œ

Parameters

  • __x β€” the key of the (key, value) pairs to be located.

Returns β€” a pair of read-only (constant) iterators that possibly points to the subsequence matching the given key.

Also equivalent to:

std::make_pair(c.lower_bound(val),
               c.upper_bound(val))

(but faster than making the calls separately, obviously πŸ’…)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> size_type
    std::multimap< _Key, _Tp, _Compare, _Alloc >::erase (const key_type &
    __x) [inline]

Erases elements according to the provided key. Bye bestie, you're gone. πŸ—‘οΈ

Parameters

  • __x β€” the key of the element to be erased.

Returns β€” the number of elements erased.

This function erases all elements located by the given key from a multimap. Big important note though: it only erases the element itself, and if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing that pointer is the user's responsibility β€” it's giving you main character energy, so handle your own pointers. 🫢

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
    std::multimap< _Key, _Tp, _Compare, _Alloc >::erase (const_iterator
    __first, const_iterator __last) [inline]

Erases a [first,last) range of elements from a multimap. 🧹

Parameters

  • __first β€” iterator pointing to the start of the range to be erased.
  • __last β€” iterator pointing to the end of the range to be erased .

Returns β€” the iterator __last.

This one erases a whole sequence of elements. And again, seriously: it only erases the elements, and if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is on you, fr fr. 😭

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
    std::multimap< _Key, _Tp, _Compare, _Alloc >::erase (const_iterator
    __position) [inline]

Erases an element from a multimap. Single-target elimination. ✨

Parameters

  • __position β€” an iterator pointing to the element to be erased.

Returns β€” an iterator pointing to the element immediately following position prior to the element being erased. If no such element exists, end() is returned.

This erases the element pointed to by the given iterator. And yes, the classic disclaimer: it only erases the element, and if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. πŸ”₯

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
    std::multimap< _Key, _Tp, _Compare, _Alloc >::erase (iterator
    __position) [inline]

Erases an element from a multimap. Same energy, non-const iterator edition. πŸ’…

Parameters

  • __position β€” an iterator pointing to the element to be erased.

Returns β€” an iterator pointing to the element immediately following position prior to the element being erased. If no such element exists, end() is returned.

This erases the element pointed to by the given iterator from the multimap. And one more time for the people in the back: it only erases the element, and if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. 🫢

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
    std::multimap< _Key, _Tp, _Compare, _Alloc >::find (const key_type &
    __x) [inline]

Tries to locate an element in a multimap. Scavenger hunt but make it O(log n). πŸ”

Parameters

  • __x β€” the key of the (key, value) pair to be located.

Returns β€” an iterator pointing to the sought-after element, or end() if not found.

Takes a key and tries to locate the element that matches it. If it succeeds, you get an iterator pointing at the sought-after pair. If not… past-the-end (end()) iterator, and honestly, we've all been there. 😭

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    const_iterator std::multimap< _Key, _Tp, _Compare, _Alloc >::find (const
    key_type & __x) const [inline]

Tries to locate an element in a multimap, but const. πŸ’œ

Parameters

  • __x β€” the key of the (key, value) pair to be located.

Returns β€” a read-only (constant) iterator pointing to the sought-after element, or end() if not found.

Same deal: takes a key and tries to locate the matching element. If it succeeds, it returns a constant iterator pointing at the pair you're after. If not, you get the past-the-end (end()) iterator. πŸ™ˆ

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    allocator_type std::multimap< _Key, _Tp, _Compare, _Alloc
    >::get_allocator () const [inline],  [noexcept]

Get a copy of the memory allocation object. That's the whole thing β€” take your allocator and go, queen. πŸ‘‘

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    template<typename _InputIterator> void std::multimap< _Key, _Tp,
    _Compare, _Alloc >::insert (_InputIterator __first, _InputIterator
    __last) [inline]

A template function that attempts to insert a range of elements. Bulk insert, no cap. πŸ“¦

Parameters

  • __first β€” iterator pointing to the start of the range to be inserted.
  • __last β€” iterator pointing to the end of the range.

Complexity similar to that of the range constructor.

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    template<typename _Pair> __enable_if_t< is_constructible< value_type,
    _Pair >::value, iterator > std::multimap< _Key, _Tp, _Compare, _Alloc
    >::insert (_Pair && __x) [inline]

Inserts a std::pair into the multimap. ✨

Parameters

  • __x β€” the pair to be inserted (see std::make_pair for easy creation of pairs).

Returns β€” an iterator that points to the inserted (key,value) pair.

This inserts a (key, value) pair into the multimap. And the moment you've all been waiting for: contrary to a std::map, the multimap does not rely on unique keys, so multiple pairs with the same key can be inserted. Duplicates are welcome here, we're inclusive. 🫢

Insertion requires logarithmic time.

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
    std::multimap< _Key, _Tp, _Compare, _Alloc >::insert (const value_type &
    __x) [inline]

Inserts a std::pair into the multimap. Same function, const value_type& flavour. πŸ“

Parameters

  • __x β€” the pair to be inserted (see std::make_pair for easy creation of pairs).

Returns β€” an iterator that points to the inserted (key,value) pair.

This inserts a (key, value) pair into the multimap. Once more with feeling: contrary to a std::map, the multimap does not rely on unique keys, so multiple pairs with the same key can be inserted.

Insertion requires logarithmic time.

Referenced by std::multimap< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::insert().
template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    template<typename _Pair> __enable_if_t< is_constructible< value_type,
    _Pair && >::value, iterator > std::multimap< _Key, _Tp, _Compare, _Alloc
    >::insert (const_iterator __position, _Pair && __x) [inline]

Inserts a std::pair into the multimap β€” this time with a hint. πŸ‘€

Parameters

  • __position β€” an iterator that serves as a hint as to where the pair should be inserted.
  • __x β€” the pair to be inserted (see std::make_pair for easy creation of pairs).

Returns β€” an iterator that points to the inserted (key,value) pair.

insert πŸ’– (the one with a hint, bestie)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
    std::multimap< _Key, _Tp, _Compare, _Alloc >::insert (const_iterator
    __position, const value_type & __x) [inline]

Inserts a std::pair into the multimap. Yes queen, we're back on insert duty ✨

Parameters

  • __position β€” an iterator that serves as a hint as to where the pair should be inserted.
  • __x β€” the pair to be inserted (peep std::make_pair for easy creation of pairs, iykyk).

Returns

  • An iterator that points to the inserted (key, value) pair. πŸŽ€

This function inserts a (key, value) pair into the multimap. And here's the tea: contrary to a std::map, the multimap does NOT rely on unique keys, and thus multiple pairs with the same key can be inserted. Not me inserting the same key five times and getting away with it πŸ’…

Note that the first parameter is only a hint and can potentially improve the performance of the insertion process. A bad hint would cause no gains in efficiency β€” so like, a wrong hint isn't a crime, it's just a waste of your time, bestie. 😭

For more on hinting, see:

https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints

Insertion requires logarithmic time (if the hint is not taken).


insert 🌸 (hint, but the pair is a move)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
    std::multimap< _Key, _Tp, _Compare, _Alloc >::insert (const_iterator
    __position, value_type && __x) [inline]

Inserts a std::pair into the multimap. Same energy, but __x gets moved in. πŸ¦‹

Parameters

  • __position β€” an iterator that serves as a hint as to where the pair should be inserted.
  • __x β€” pair to be inserted (see std::make_pair for easy creation of pairs).

Returns

  • An iterator that points to the inserted (key, value) pair.

This function inserts a (key, value) pair into the multimap. Contrary to a std::map the multimap does not rely on unique keys and thus multiple pairs with the same key can be inserted. Note that the first parameter is only a hint and can potentially improve the performance of the insertion process. A bad hint would cause no gains in efficiency.

For more on hinting, see:

https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints

Insertion requires logarithmic time (if the hint is not taken).


insert πŸŽ€ (the initializer_list one β€” bulk drop)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> void
    std::multimap< _Key, _Tp, _Compare, _Alloc >::insert (initializer_list<
    value_type > __l) [inline]

Attempts to insert a list of std::pairs into the multimap. It's giving ✨bulk era✨ β€” load the whole squad in one go.

Parameters

  • __l β€” a std::initializer_list<value_type> of pairs to be inserted.

Complexity similar to that of the range constructor.


insert πŸ’€ (no hint, straight to it)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
    std::multimap< _Key, _Tp, _Compare, _Alloc >::insert (value_type && __x)
    [inline]

Inserts a std::pair into the multimap. No __position, no hint, just vibes and a moved-in pair. 🫢

Parameters

  • __x β€” pair to be inserted (see std::make_pair for easy creation of pairs).

Returns

  • An iterator that points to the inserted (key, value) pair.

This function inserts a (key, value) pair into the multimap. Contrary to a std::map the multimap does not rely on unique keys and thus multiple pairs with the same key can be inserted.

Insertion requires logarithmic time.


key_comp 🌈

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    key_compare std::multimap< _Key, _Tp, _Compare, _Alloc >::key_comp ()
    const [inline]

Returns the key comparison object out of which the multimap was constructed. So like, the little comparator that decided all your ordering? Yeah, it's handing it back to you. πŸ‘‘


lower_bound πŸ’œ (the read/write one)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
    std::multimap< _Key, _Tp, _Compare, _Alloc >::lower_bound (const
    key_type & __x) [inline]

Finds the beginning of a subsequence matching given key. Lowkey the most underrated function in here, fr fr.

Parameters

  • __x β€” key of (key, value) pair to be located.

Returns

  • Iterator pointing to first element equal to or greater than key, or end().

This function returns the first element of a subsequence of elements that matches the given key. If unsuccessful it returns an iterator pointing to the first element that has a greater value than given key or end() if no such element exists. Iconic behaviour honestly.


lower_bound πŸ¦‹ (the const one)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    const_iterator std::multimap< _Key, _Tp, _Compare, _Alloc >::lower_bound
    (const key_type & __x) const [inline]

Finds the beginning of a subsequence matching given key. Same mission, but read-only, bestie β€” hands off the elements.

Parameters

  • __x β€” key of (key, value) pair to be located.

Returns

  • Read-only (constant) iterator pointing to first element equal to or greater than key, or end().

This function returns the first element of a subsequence of elements that matches the given key. If unsuccessful the iterator will point to the next greatest element or, if no such greater element exists, to end(). πŸ™ˆ


max_size ✨

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> size_type
    std::multimap< _Key, _Tp, _Compare, _Alloc >::max_size () const
    [inline],  [noexcept]

Returns the maximum size of the multimap. Like, how big could she possibly get? πŸ’…


operator= πŸŽ€ (copy assignment)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> multimap
    & std::multimap< _Key, _Tp, _Compare, _Alloc >::operator= (const
    multimap< _Key, _Tp, _Compare, _Alloc > & ) [default]

Multimap assignment operator. Whether the allocator is copied depends on the allocator traits. That's the whole note, don't @ me. 🫢


operator= 🌸 (initializer_list assignment)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> multimap
    & std::multimap< _Key, _Tp, _Compare, _Alloc >::operator=
    (initializer_list< value_type > __l) [inline]

Multimap list assignment operator.

Parameters

  • __l β€” an initializer_list.

This function fills a multimap with copies of the elements in the initializer list __l.

Heads up bestie: note that the assignment completely changes the multimap and that the resulting multimap's size is the same as the number of elements assigned. It's a full glow-up, not a patch-up. πŸ’€

operator= πŸ”₯ (move assignment)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> multimap
    & std::multimap< _Key, _Tp, _Compare, _Alloc >::operator= (multimap<
    _Key, _Tp, _Compare, _Alloc > && ) [default]

Move assignment operator. She's taking the goods and leaving the other one empty. Main character energy fr. πŸ‘‘


rbegin πŸ’œ (const, reverse, descending)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    const_reverse_iterator std::multimap< _Key, _Tp, _Compare, _Alloc
    >::rbegin () const [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to the last pair in the multimap. Iteration is done in descending order according to the keys. Backwards but make it fashion. πŸ¦‹


rbegin ✨ (read/write, reverse)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    reverse_iterator std::multimap< _Key, _Tp, _Compare, _Alloc >::rbegin ()
    [inline],  [noexcept]

Returns a read/write reverse iterator that points to the last pair in the multimap. Iteration is done in descending order according to the keys. Same descending vibe, but you can touch things this time. πŸ’…


rend πŸŽ€ (const, reverse, one before the first)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    const_reverse_iterator std::multimap< _Key, _Tp, _Compare, _Alloc
    >::rend () const [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to one before the first pair in the multimap. Iteration is done in descending order according to the keys. Yes, "one before the first" β€” she's the reverse-iterator equivalent of the friend who stands slightly outside the group photo. 😭


rend 🌈 (read/write, reverse)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    reverse_iterator std::multimap< _Key, _Tp, _Compare, _Alloc >::rend ()
    [inline],  [noexcept]

Returns a read/write reverse iterator that points to one before the first pair in the multimap. Iteration is done in descending order according to the keys. 🫢


size 🌸

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> size_type
    std::multimap< _Key, _Tp, _Compare, _Alloc >::size () const [inline],
    [noexcept]

Returns the size of the multimap. How many pairs are in the building. Periodt. πŸ’…


swap πŸ”₯

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> void
    std::multimap< _Key, _Tp, _Compare, _Alloc >::swap (multimap< _Key, _Tp,
    _Compare, _Alloc > & __x) [inline],  [noexcept]

Swaps data with another multimap. Trade offer: you get my pairs, I get yours. 🀝

Parameters

  • __x β€” a multimap of the same element and allocator types.

This exchanges the elements between two multimaps in constant time. (It is only swapping a pointer, an integer, and an instance of the Compare type (which itself is often stateless and empty), so it should be quite fast.) Note that the global std::swap() function is specialized such that std::swap(m1,m2) will feed to this function.

Whether the allocators are swapped depends on the allocator traits.

Referenced by std::swap(). πŸŽ€


upper_bound πŸ’œ (read/write)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> iterator
    std::multimap< _Key, _Tp, _Compare, _Alloc >::upper_bound (const
    key_type & __x) [inline]

Finds the end of a subsequence matching given key. lower_bound walks you in, upper_bound walks you out. Dynamic duo fr. ✨

Parameters

  • __x β€” key of (key, value) pair to be located.

Returns

  • Iterator pointing to the first element greater than key, or end().

upper_bound πŸ¦‹ (const)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    const_iterator std::multimap< _Key, _Tp, _Compare, _Alloc >::upper_bound
    (const key_type & __x) const [inline]

Finds the end of a subsequence matching given key. Read-only edition, because sometimes you just wanna look. πŸ‘€

Parameters

  • __x β€” key of (key, value) pair to be located.

Returns

  • Read-only (constant) iterator pointing to first iterator greater than key, or end().

🌸 value_comp() β€” the comparison object glow-up 🌸

   template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
       typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
       value_compare std::multimap< _Key, _Tp, _Compare, _Alloc >::value_comp
       () const [inline]

Okay so value_comp() returns a value comparison object β€” type value_compare β€” and it’s built from the key comparison object out of which the multimap was constructed. That’s the whole tea, no cap. πŸ¦‹

Also: the signature is marked [inline], so it’s right there in the declaration. Periodt. πŸ’…


πŸ‘‘ Author πŸ‘‘

Generated automatically by Doxygen for libstdc++ from the source code. Automated and iconic. ✨


Cute sign-off: the footer is serving libstdc++ and std::multi..., _Alloc >(3) β€” source/version and page name, with the date chillin’ in the footer too. Bestie, that’s a wrap. πŸ’–πŸŽ€πŸ«Ά

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms