STD::MAP(3)

πŸ’– NAME πŸ’–

okay so real talk: this page lives in the Library Functions Manual, section 3, and it's all about std::map< ...e, _Alloc >. πŸ’…

Bestie, std::map< _Key, _Tp, _Compare, _Alloc > is a standard container made up of (key,value) pairs, which can be retrieved based on a key, in logarithmic time. That's it, that's the whole vibe β€” you put stuff in, you look it up by key, and the lookup is logarithmic. ✨


πŸ¦‹ 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 ✨

heads up bestie: this is the long part. Every single one is here, no skips, no cap. 🫢
  • map ()=default β€” default constructor, creates no elements. It's giving empty πŸ’€
  • template<typename _InputIterator> map (_InputIterator __first, _InputIterator __last) β€” builds a map from a range.
  • template<typename _InputIterator> map (_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type()) β€” builds a map from a range.
  • template<typename _InputIterator> map (_InputIterator __first, _InputIterator __last, const allocator_type &__a) β€” allocator-extended range constructor.
  • map (const _Compare &__comp, const allocator_type &__a=allocator_type()) β€” creates a map with no elements.
  • map (const allocator_type &__a) β€” allocator-extended default constructor.
  • map (const map &)=default β€” map copy constructor. twin energy πŸ‘―
  • map (const map &__m, const __type_identity_t< allocator_type > &__a) β€” allocator-extended copy constructor.
  • map (initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type()) β€” builds a map from an initializer_list.
  • map (initializer_list< value_type > __l, const allocator_type &__a) β€” allocator-extended initialier-list constructor.
  • map (map &&)=default β€” map move constructor. ✈️
  • map (map &&__m, const __type_identity_t< allocator_type > &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal()) β€” allocator-extended move constructor.
  • ~map ()=default β€” destructor. bye bestie 🫢
  • template<__heterogeneous_tree_key< map > _Kt> mapped_type & at (const _Kt &__k)
  • template<__heterogeneous_tree_key< map > _Kt> const mapped_type & at (const _Kt &__k) const
  • mapped_type & at (const key_type &__k) β€” access to map data.
  • const mapped_type & at (const key_type &__k) const
  • 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> std::pair< iterator, bool > emplace (_Args &&... __args) β€” attempts to build and insert a std::pair into the map.
  • template<typename... _Args> iterator emplace_hint (const_iterator __pos, _Args &&... __args) β€” attempts to build and insert a std::pair into the map.
  • bool empty () const noexcept
  • const_iterator end () const noexcept
  • iterator end () noexcept
  • iterator erase (const_iterator __first, const_iterator __last) β€” erases a [first,last) range of elements from a map.
  • allocator_type get_allocator () const noexcept β€” get a copy of the memory allocation object.
  • template<typename _InputIterator> void insert (_InputIterator __first, _InputIterator __last) β€” template function that attempts to insert a range of elements.
  • void insert (std::initializer_list< value_type > __list) β€” attempts to insert a list of std::pairs into the map.
  • key_compare key_comp () const
  • size_type max_size () const noexcept
  • map & operator= (const map &)=default β€” map assignment operator.
  • map & operator= (initializer_list< value_type > __l) β€” map list assignment operator.
  • map & operator= (map &&)=default β€” move assignment operator.
  • template<__heterogeneous_tree_key< map > _Kt> mapped_type & operator[] (_Kt &&__k)
  • mapped_type & operator[] (const key_type &__k) β€” subscript ( [] ) access to map data.
  • mapped_type & operator[] (key_type &&__k)
  • 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 (map &__x) noexcept(/*conditional */) β€” swaps data with another map.
  • value_compare value_comp () const

πŸŽ€ the overloaded besties πŸŽ€

these ones hang out in their own little group, same descriptions as above, all listed, all accounted for:

  • std::pair< iterator, bool > insert (const value_type &__x) β€” attempts to insert a std::pair into the map.
  • std::pair< iterator, bool > insert (value_type &&__x) β€” attempts to insert a std::pair into the map.
  • template<typename _Pair> __enable_if_t< is_constructible< value_type, _Pair >::value, pair< iterator, bool > > insert (_Pair &&__x) β€” attempts to insert a std::pair into the map.
  • iterator insert (const_iterator __position, const value_type &__x) β€” attempts to insert a std::pair into the map.
  • iterator insert (const_iterator __position, value_type &&__x) β€” attempts to insert a std::pair into the map.
  • template<typename _Pair> __enable_if_t< is_constructible< value_type, _Pair >::value, iterator > insert (const_iterator __position, _Pair &&__x) β€” attempts to insert a std::pair into the map.
  • iterator erase (const_iterator __position) β€” erases an element from a map.
  • iterator erase (iterator __position) β€” erases an element from a map.
  • size_type erase (const key_type &__x) β€” erases elements according to the provided key.
  • template<__heterogeneous_tree_key< map > _Kt> size_type erase (_Kt &&__x) β€” erases elements according to the provided key.
  • iterator find (const key_type &__x) β€” tries to locate an element in a map.
  • const_iterator find (const key_type &__x) const β€” tries to locate an element in a map.
  • 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> __detail::__synth3way_t< pair< const _K1, _T1 > > operator<=> (const map< _K1, _T1, _C1, _A1 > &, const map< _K1, _T1, _C1, _A1 > &)
  • template<typename _K1, typename _T1, typename _C1, typename _A1> bool operator== (const map< _K1, _T1, _C1, _A1 > &, const map< _K1, _T1, _C1, _A1 > &)

πŸ’œ Detailed Description πŸ’œ

the whole class, in its full glory, exactly as declared:

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    class std::map< _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 β€” yes bestie, it's been iconic since 1998 πŸ‘‘

🧚 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>.

okay so more facts, keep up bestie:

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

Maps 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). πŸ’…


and we are SO not done, bestie β€” there's more of this page coming. don't go anywhere. πŸ’–

πŸŽ€ CONSTRUCTOR & DESTRUCTOR DOCUMENTATION πŸŽ€

okay bestie, this is the part where we learn how to make a map πŸ’… every single one of these is a way to birth a map, and there are SO many. Don't panic. We go one at a time.


🌸 map () β€” the default constructor

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

Default constructor creates no elements. That's it. Empty map, zero thoughts, no notes. It's giving "just woke up, nothing scheduled" energy. ✨


πŸ¦‹ map (const _Compare & __comp, const allocator_type & __a = allocator_type())

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

Creates a map with no elements β€” but this time you get to hand it a comparison object and an allocator. Empty map, but customised. She's empty but she has ✨opinions✨.

Parameters

  • __comp β€” A comparison object.
  • __a β€” An allocator object.
Heads up: this one is marked [explicit], so no sneaky implicit conversions, bestie. 🫢

πŸ’œ map (const map< _Key, _Tp, _Compare, _Alloc > & ) β€” copy constructor

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

Map copy constructor. Whether the allocator is copied depends on the allocator traits β€” so don't assume, it literally depends on the traits. allocator_traits said "it depends" and meant it. 😭


🧚 map (map< _Key, _Tp, _Compare, _Alloc > && ) β€” move constructor

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

Map move constructor. The newly-created map contains the exact contents of the moved instance. The moved instance is a valid, but unspecified, map β€” so it's alive but it's not okay, it's just valid. Think of it as "she left the group chat but she's still technically in it." πŸ’€


🌈 map (initializer_list< value_type > __l, const _Compare & __comp = _Compare(), const allocator_type & __a = allocator_type())

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

Builds a map from an initializer_list. The curly-brace baddie. πŸ”₯

Parameters

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

Create a map consisting of copies of the elements in the initializer_list __l. This is linear in N if the range is already sorted, and NlogN otherwise (where N is __l.size()). Sorting already done = free speed. Slay. ⭐


πŸŽ€ map (const allocator_type & __a)

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

Allocator-extended default constructor. Empty map, but it brought its own allocator. Fancy empty. πŸ’…

Also [explicit], so no implicit nonsense, we stan. 🫢

πŸ’– map (const map< _Key, _Tp, _Compare, _Alloc > & __m, const __type_identity_t< allocator_type > & __a)

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

Allocator-extended copy constructor. Same copy energy as before, but you're handing her the allocator yourself. __type_identity_t is there doing its little job of keeping the deduction honest. iykyk ✨


πŸ¦‹ map (map< _Key, _Tp, _Compare, _Alloc > && __m, const __type_identity_t< allocator_type > & __a)

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

Allocator-extended move constructor. And it's noexcept β€” the rare and beautiful no-throw move. No cap, this is the good one. πŸ“


🌸 map (initializer_list< value_type > __l, const allocator_type & __a)

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

Allocator-extended initializer-list constructor. Curly braces + your own allocator = a match made in heaven. πŸ’œ


🧚 map (_InputIterator __first, _InputIterator __last, const allocator_type & __a)

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

Allocator-extended range constructor. Yeah it's a template template situation, she's nested, she's doing the most, and she's valid. Main character template energy. πŸ‘‘


🌈 map (_InputIterator __first, _InputIterator __last)

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

Builds a map from a range. 🫢

Parameters

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

Create a map 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)).

Note the range is half-open β€” __first in, __last out. Don't be out here including __last, bestie. πŸ™ˆ

πŸ’œ map (_InputIterator __first, _InputIterator __last, const _Compare & __comp, const allocator_type & __a = allocator_type())

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

Builds a map from a range β€” but now with a comparison functor in the mix. Range and vibes. πŸ”₯

Parameters

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

Create a map 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)).


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

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
std::map< _Key, _Tp, _Compare, _Alloc >::~map () [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.

🚨 THIS IS THE IMPORTANT ONE. The destructor does not delete what your pointers point at. It deletes the pointer values sitting in the map, not the things they point to. If you new'd it, you own it. Clean it up yourself or you're leaking. Not a vibe. 😭

πŸ’– MEMBER FUNCTION DOCUMENTATION πŸ’–

okay so now the map is born and we get to do stuff with it. Here's every member function, no skips, no cuts. ✨


🌸 at (const key_type & __k)

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
mapped_type & std::map< _Key, _Tp, _Compare, _Alloc >::at (const key_type & __k)
    [inline]

Access to map data. Gimme the value at this key, right now, no debate. πŸ’…

Parameters

  • __k β€” The key for which data should be retrieved.

Returns

A reference to the data whose key is equivalent to __k, if such a data is present in the map.

Exceptions

std::out_of_range β€” If no such data is present.

If a heterogeneous key __k matches a range of elements, the first is chosen.

She THROWS if the key isn't there. at does not play. If you want "idk make one up," that's operator[]'s whole personality (covered elsewhere, bestie). 🫢

πŸ¦‹ begin () const

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

Returns a read-only (constant) iterator that points to the first pair in the map. Iteration is done in ascending order according to the keys. ✨


πŸ’œ begin ()

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

Returns a read/write iterator that points to the first pair in the map. Iteration is done in ascending order according to the keys.

Same as above but you can actually edit through this one. Read/write. Handle with care, bestie. 🫢

πŸŽ€ cbegin () const

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

Returns a read-only (constant) iterator that points to the first pair in the map. Iteration is done in ascending order according to the keys. It's begin() const's twin, always const, always chill. πŸ’œ


πŸ¦‹ cend () const

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

Returns a read-only (constant) iterator that points one past the last pair in the map. Iteration is done in ascending order according to the keys. Classic end sentinel behaviour β€” you never dereference this one. Never. πŸ™ˆ


🌈 clear ()

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

Erases all elements in a map. 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.

🚨 Same warning as the destructor, bestie, and it matters just as much: clear() does not free what your pointers point at. Pointers gone, pointees still there, memory still leaked. You own it. 😭

🧚 contains (const _Kt & __x) 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::map< _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. The heterogeneous-key version β€” you can ask with a type that isn't literally key_type. Look at that trailing return type doing gymnastics. Ate. πŸ”₯

Parameters

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

Returns

True if there is an element with the specified key.


πŸ’– contains (const key_type & __x) const

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

Finds whether an element with the given key exists. Same question, boring-old-key_type edition. Returns a plain bool instead of that fancy decltype business. 😌

Parameters

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

Returns

True if there is an element with the specified key.


🌸 count (const key_type & __x) const

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

Finds the number of elements with given key. She's out here counting. πŸ“

Parameters

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

Returns

Number of elements with specified key.

This function only makes sense for multimaps; for map the result will either be 0 (not present) or 1 (present).

Real talk: on a map this is basically a fancier contains. She really shines on a multimap, where the answer can be more than 1. Bestie, know which container you're in. 🫢

πŸ¦‹ 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::map< _Key, _Tp, _Compare, _Alloc >::crbegin () const
    [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to the last pair in the map. Iteration is done in descending order according to the keys. Walking backwards, but make it const. πŸ’…


πŸ’œ 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::map< _Key, _Tp, _Compare, _Alloc >::crend () const
    [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points one before the first pair in the map. Iteration is done in descending order according to the keys. The reverse-world sentinel. Don't touch. πŸ™ˆ


🌈 emplace (_Args &&... __args)

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

Attempts to build and insert a std::pair into the map. Builds it in place, no extra copy, we love efficiency in this house. ✨

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

A pair, of which the first element is an iterator that points to the possibly inserted pair, and the second is a bool that is true if the pair was actually inserted.

Note the word "attempts" β€” if the key was already chilling in the map, nothing gets inserted and that bool comes back false, with the iterator pointing at the existing element. Not a failure, just a "she's already here." πŸ’€

So this function is out here trying to build and insert a (key, value) pair straight into the map. But bestie, a map only does unique keys β€” so a pair only actually gets inserted if its first element (the key) isn't already chilling in the map. ✨

Insertion requires logarithmic time, periodt.


emplace_hint() β€” the hint-hint girlie πŸŽ€

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

Attempts to build and insert a std::pair into the map. lowkey iconic.

Parameters

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

Returns

An iterator pointing at the element whose key comes from the std::pair built out of __args β€” and yeah, it may or may not be that exact std::pair, we don't gatekeep.

This function does not care whether the insertion actually happened, so no boolean coming back like the single-argument emplace() gives you. Also note: that first parameter is only a hint, and it can potentially boost insertion performance. A bad hint? Zero gains, bestie. Nothing. πŸ™ˆ

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

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

Referenced by std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::emplace(), and std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::insert().


empty() πŸ’€

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

Returns true if the map is empty. (Which is why begin() would equal end() β€” that's the vibe check.) 🫢


end() (const version) πŸ‘‘

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

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


end() (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::map< _Key, _Tp, _Compare, _Alloc >::end () [inline],  [noexcept]

Returns a read/write iterator that points one past the last pair in the map. Iteration is done in ascending order according to the keys. Same energy, but you can touch stuff. ✨

Referenced by std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::at(), std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::emplace(), std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::insert(), and std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::operator[]().


equal_range() 🌸

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

Finds a subsequence matching the given key. detective mode fr fr πŸ”

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 the given key.

This function is equivalent to

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

(but it's faster than making those calls separately, slay).

This function probably only makes sense for multimaps. πŸ€·β€β™€οΈ


equal_range() (const version) πŸ¦‹

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::map< _Key, _Tp,
    _Compare, _Alloc >::equal_range (const key_type & __x) const [inline]

Finds a subsequence matching the given key, but make it read-only.

Parameters

  • __x β€” 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.

This one is also equivalent to

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

(again, faster than doing it separately ✨).

And again: this function probably only makes sense for multimaps.


erase() β€” by heterogeneous key πŸ”₯

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

Erases elements according to the provided key. bye bestie πŸ‘‹

Parameters

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

Returns

The number of elements erased.

This function erases all the elements located by the given key from a map. And a very important note: this function only erases the element. If the element is itself a pointer, the pointed-to memory is not touched in any way. Managing that pointer is on you, bestie β€” user's responsibility, no cap. ⚠️


erase() β€” by const key_type& πŸ’œ

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

Erases elements according to the provided key.

Parameters

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

Returns

The number of elements erased.

Erases all the elements located by the given key from a map. Same disclaimer as before and it's giving important: it only erases the element β€” if that element is a pointer, the pointed-to memory is untouched. You're the main character managing that pointer. 🫑


erase() β€” the range one βœ‚οΈ

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

Erases a [first,last) range of elements from a map. wipeout πŸ’…

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 function erases a whole sequence of elements from a map. And yeah β€” it only erases the elements. If an element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. ⭐


erase() β€” by const_iterator position 🎯

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

Erases an element from a map.

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 function erases an element, pointed to by the given iterator, from a map. Note (again, because it matters): 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. πŸ’€


erase() β€” by iterator position ✨

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

Erases an element from a map.

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.

Erases an element, pointed to by the given iterator, from a map. And yup, the classic: it only erases the element β€” 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. πŸ™ˆ


find() πŸ“

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

Tries to locate an element in a map. scavenger hunt era πŸ”

Parameters

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

Returns

Iterator pointing to the sought-after element, or end() if it's not found.

This function takes a key and tries to locate the element that matches it. If it succeeds, you get an iterator pointing to the sought-after pair. If it fails? You get the past-the-end (end()) iterator. 🫢


find() β€” const version 🧚

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

Tries to locate an element in a map.

Parameters

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

Returns

Read-only (constant) iterator pointing to the sought-after element, or end() if not found.

Takes a key, tries to locate the element it matches. Success = a constant iterator pointing to the sought-after pair. Failure = the past-the-end (end()) iterator. That's the whole story. πŸ’œ


get_allocator() πŸŽ€

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

Get a copy of the memory allocation object. that's it, that's the whole function. ✨


insert() β€” the range one 🌈

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

Template function that attempts to insert a range of elements. bringing the whole friend group in πŸ’…

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.


insert() β€” the _Pair&& one ⭐

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, pair< iterator, bool > > std::map< _Key, _Tp, _Compare,
    _Alloc >::insert (_Pair && __x) [inline]

Attempts to insert a std::pair into the map.

Parameters

  • __x β€” the pair you wanna insert (peep std::make_pair if you want the easy way to build pairs, bestie 🫢).

Returns

  • a pair where .first is an iterator pointing at the possibly-inserted pair, and .second is a bool that's true if the pair actually got inserted. πŸ’…

So here's the tea: this function attempts to insert a (key, value) pair into the map. A map runs on unique keys, so a pair only gets inserted if its first element (the key) isn't already chillin' in the map. No duplicates, no exceptions, periodt.

Insertion requires logarithmic time.

Referenced by std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::insert(), and std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::operator[]().

🌟 the const-ref one, but make it official

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

Attempts to insert a std::pair into the map. Iconic behaviour, honestly.

Parameters

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

Returns

  • a pair, of which the first element is an iterator that points to the possibly inserted pair, and the second is a bool that is true if the pair was actually inserted.

This function attempts to insert a (key, value) pair into the map. A map relies on unique keys and thus a pair is only inserted if its first element (the key) is not already present in the map.

Insertion requires logarithmic time.

Referenced by std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::insert(), and std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::operator[]().

πŸŽ€ the _Pair&& hint girlie

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::map< _Key, _Tp, _Compare, _Alloc
    >::insert (const_iterator __position, _Pair && __x) [inline]

Attempts to insert a std::pair into the map. ✨

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 element with key of __x (may or may not be the pair passed in).

This function is not concerned about whether the insertion took place, and thus does not return a boolean like the single-argument insert() does. 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 β€” like, none, zero, nada. 😭

See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints for more on hinting. iykyk.

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


πŸ’œ the const value_type& + hint combo

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

Attempts to insert a std::pair into the map.

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 element with key of __x (may or may not be the pair passed in).

This function is not concerned about whether the insertion took place, and thus does not return a boolean like the single-argument insert() does. 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.

See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints for more on hinting.

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


πŸ¦‹ the value_type&& + hint combo (move edition)

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

Attempts to insert a std::pair into the map.

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 element with key of __x (may or may not be the pair passed in).

This function is not concerned about whether the insertion took place, and thus does not return a boolean like the single-argument insert() does. 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.

See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints for more on hinting.

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


🌸 insert a whole list, main character energy

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

Attempts to insert a list of std::pairs into the map. Bulk insert slay. πŸ’…

Parameters

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

Complexity similar to that of the range constructor.


⭐ the rvalue value_type&& one

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

Attempts to insert a std::pair into the map.

Parameters

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

Returns

  • a pair, of which the first element is an iterator that points to the possibly inserted pair, and the second is a bool that is true if the pair was actually inserted.

This function attempts to insert a (key, value) pair into the map. A map relies on unique keys and thus a pair is only inserted if its first element (the key) is not already present in the map.

Insertion requires logarithmic time.


πŸ‘‘ key_comp() β€” the comparison object, exposed

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

Returns the key comparison object out of which the map was constructed. It's giving ✨origin story✨.

Referenced by std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::at(), std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::emplace(), std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::insert(), and std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::operator[]().

πŸ“ lower_bound() β€” where the subsequence starts

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

Finds the beginning of a subsequence matching given key. πŸ”

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.

Referenced by std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::at(), std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::emplace(), std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::insert(), and std::map< _Key, _Tp, _Cmp, polymorphic_allocator< pair< const _Key, _Tp > > >::operator[]().

🧚 lower_bound() const β€” same but read-only

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

Finds the beginning of a subsequence matching given key.

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 it returns an iterator pointing to the first element that has a greater value than given key or end() if no such element exists.


🌈 max_size() β€” the ceiling

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

Returns the maximum size of the map. That's it, that's the whole vibe. πŸ“


πŸ’– operator= β€” copy assignment

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

Map assignment operator. Whether the allocator is copied depends on the allocator traits. (Yeah, that's on the allocator traits, not on you. πŸ™ˆ)


πŸŽ€ operator= β€” the initializer_list one

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

Map list assignment operator.

Parameters

  • __l β€” an initializer_list.

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

Note that the assignment completely changes the map and that the resulting map's size is the same as the number of elements assigned. No leftovers, no crumbs, full reset bestie. πŸ’…

πŸ¦‹ operator= β€” move assignment

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

Move assignment operator. 🚚✨


πŸ”₯ operator[] β€” subscript access, the iconic one

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    mapped_type & std::map< _Key, _Tp, _Compare, _Alloc >::operator[] (const
    key_type & __k) [inline]

Subscript ( [] ) access to map data. The one everybody reaches for first, no cap.

Parameters

  • __k β€” the key for which data should be retrieved.

Returns

  • a reference to the data of the (key,data) pair.

so the subscript ( [] ) operator allows for easy lookup. it returns data associated with the key specified in subscript. if the key does not exist, a pair with that key is created using default values, which is then returned. so it's not just lookup, it also creates a default pair if you ask for something that's not there πŸ’…. if a heterogeneous key matches a range of elements, the first one is chosen. and lookup? requires logarithmic time. so it's fast but not magic.


🌸 rbegin() const β€” read-only reverse iterator, last pair first 🌸

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

returns a read-only (constant) reverse iterator that points to the last pair in the map. iteration is done in descending order according to the keys. so you're going backwards, bestie, and you can't change anything. periodt.


πŸ”₯ rbegin() β€” read/write reverse iterator, last pair first πŸ”₯

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

returns a read/write reverse iterator that points to the last pair in the map. iteration is done in descending order according to the keys. now you can actually modify stuff, slay.


✨ rend() const β€” read-only reverse iterator, one before first ✨

template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >>
    const_reverse_iterator std::map< _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 map. iteration is done in descending order according to the keys. it's the reverse end, the boundary, the vibe check of the reverse world.


πŸ¦‹ rend() β€” read/write reverse iterator, one before first πŸ¦‹

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

returns a read/write reverse iterator that points to one before the first pair in the map. iteration is done in descending order according to the keys. yes, it's the mirror of rbegin() but for the end. iconic.


πŸŽ€ size() β€” how many elements? πŸŽ€

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

returns the size of the map. literally the number of elements, no cap. so you know how big your map is, bestie.


πŸ’… swap() β€” trade data with another map πŸ’…

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

swaps data with another map. __x is a map of the same element and allocator types.

this exchanges the elements between two maps in constant time. (it's 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. so it's fast, but allocator swapping is a whole thing. iykyk.


🌈 upper_bound(const key_type & __x) β€” end of a matching subsequence 🌈

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

finds the end of a subsequence matching given key. __x is the key of the (key, value) pair to be located.

returns an iterator pointing to the first element greater than key, or end(). so it's like, you give it a key, it gives you the first thing after that key. no cap.


πŸ’œ upper_bound(const key_type & __x) const β€” read-only version πŸ’œ

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

finds the end of a subsequence matching given key. __x is the key of the (key, value) pair to be located.

returns a read-only (constant) iterator pointing to first iterator greater than key, or end(). same vibe as the non-const one but you can't touch anything. periodt.


⭐ value_comp() β€” comparison object, but for values ⭐

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

returns a value comparison object, built from the key comparison object out of which the map was constructed. so it's like the map's compare but wrapped for values. iykyk.


πŸ‘‘ Author πŸ‘‘

generated automatically by Doxygen for libstdc++ from the source code. so not a human author, just doxygen doing its thing. iconic.


this page is brought to you by libstdc++ and it's the std::map< ...e, _Alloc >(3) manual page. no date shown, but it's giving classic libstdc++ energy. periodt πŸ’…βœ¨

πŸ“¦ 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