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_typetypedef _Rep_type::const_iterator const_iteratortypedef _Alloc_traits::const_pointer const_pointertypedef _Alloc_traits::const_reference const_referencetypedef _Rep_type::const_reverse_iterator const_reverse_iteratortypedef _Rep_type::difference_type difference_typetypedef _Rep_type::iterator iteratortypedef _Compare key_comparetypedef _Key key_typetypedef _Tp mapped_typetypedef _Alloc_traits::pointer pointertypedef _Alloc_traits::reference referencetypedef _Rep_type::reverse_iterator reverse_iteratortypedef _Rep_type::size_type size_typetypedef 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 aninitializer_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 noexceptiterator begin () noexceptconst_iterator cbegin () const noexceptconst_iterator cend () const noexceptvoid clear () noexceptconst_reverse_iterator crbegin () const noexceptconst_reverse_iterator crend () const noexcepttemplate<typename... _Args> iterator emplace (_Args &&... __args)β build and insert astd::pairinto the multimap.template<typename... _Args> iterator emplace_hint (const_iterator __pos, _Args &&... __args)β builds and inserts astd::pairinto the multimap.bool empty () const noexceptconst_iterator end () const noexceptiterator end () noexceptsize_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 ofstd::pairs into the multimap.key_compare key_comp () constsize_type max_size () const noexceptmultimap & 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 noexceptreverse_iterator rbegin () noexceptconst_reverse_iterator rend () const noexceptreverse_iterator rend () noexceptsize_type size () const noexceptvoid 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 astd::pairinto the multimap.iterator insert (value_type &&__x)β inserts astd::pairinto the multimap.template<typename _Pair> __enable_if_t< is_constructible< value_type, _Pair >::value, iterator > insert (_Pair &&__x)β inserts astd::pairinto the multimap.iterator insert (const_iterator __position, const value_type &__x)β inserts astd::pairinto the multimap.iterator insert (const_iterator __position, value_type &&__x)β inserts astd::pairinto the multimap.template<typename _Pair> __enable_if_t< is_constructible< value_type, _Pair && >::value, iterator > insert (const_iterator __position, _Pair &&__x)β inserts astd::pairinto 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 toless<_Key>._Allocβ Allocator type, defaults toallocator<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β Aninitializer_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 putnew'd pointers in here and then callclear(), 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
Trueif 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
Trueif 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 (seestd::piecewise_contructfor 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 (peepstd::piecewise_contructif 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 (seestd::make_pairfor 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 (seestd::make_pairfor 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 (seestd::make_pairfor 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 (peepstd::make_pairfor 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 (seestd::make_pairfor 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β astd::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 (seestd::make_pairfor 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β aninitializer_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