STD::UNORDERED_MAP(3)

๐Ÿฆ‹ STD::UNORDERED_MAP ๐Ÿ’…

okay so bestie, you just cracked open the Library Functions Manual and landed on section 3 โ€” the one where we talk about functions and containers and all the C++ goodies. and the star of today's episode? std::unordered_map. no cap. ๐ŸŽ€

the whole thing lives under the template signature

std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >

so like, five template params, one icon. periodt. ๐Ÿ’…


โœจ NAME โœจ

std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc > โ€” a standard container composed of unique keys (containing at most one of each key value) that associates values of another type with the keys. ๐Ÿ’–

like, literally: keys stay unique, values tag along with them, and the container holds the whole situationship together. it's giving matchmaker energy fr fr. ๐Ÿซถ


part 2 is loading, don't go anywhere ๐ŸŒธ

SYNOPSIS โœจ

okay bestie, this is the whole vibe of std::unordered_map ๐Ÿ’–. it's giving I have all the typedefs and functions you'll ever need โœจ. let's get into it, no cap.

Public Types ๐Ÿท๏ธ

these are the types you're gonna be working with, periodt ๐Ÿ’….

Public typedefs โœจ

  • typedef _Hashtable::key_type key_type โ€” Public typedefs. ๐Ÿ’–
  • typedef _Hashtable::value_type value_type โ€” Public typedefs. ๐Ÿ’–
  • typedef _Hashtable::mapped_type mapped_type โ€” Public typedefs. ๐Ÿ’–
  • typedef _Hashtable::hasher hasher โ€” Public typedefs. ๐Ÿ’–
  • typedef _Hashtable::key_equal key_equal โ€” Public typedefs. ๐Ÿ’–
  • typedef _Hashtable::allocator_type allocator_type โ€” Public typedefs. ๐Ÿ’–
  • typedef _Hashtable::pointer pointer โ€” Iterator-related typedefs. ๐Ÿฆ‹
  • typedef _Hashtable::const_pointer const_pointer โ€” Iterator-related typedefs. ๐Ÿฆ‹
  • typedef _Hashtable::reference reference โ€” Iterator-related typedefs. ๐Ÿฆ‹
  • typedef _Hashtable::const_reference const_reference โ€” Iterator-related typedefs. ๐Ÿฆ‹
  • typedef _Hashtable::iterator iterator โ€” Iterator-related typedefs. ๐Ÿฆ‹
  • typedef _Hashtable::const_iterator const_iterator โ€” Iterator-related typedefs. ๐Ÿฆ‹
  • typedef _Hashtable::local_iterator local_iterator โ€” Iterator-related typedefs. ๐Ÿฆ‹
  • typedef _Hashtable::const_local_iterator const_local_iterator โ€” Iterator-related typedefs. ๐Ÿฆ‹
  • typedef _Hashtable::size_type size_type โ€” Iterator-related typedefs. ๐Ÿฆ‹
  • typedef _Hashtable::difference_type difference_type โ€” Iterator-related typedefs. ๐Ÿฆ‹

Public Member Functions ๐Ÿ› ๏ธ

okay so this is the whole function menu. it's long but we're gonna get through it together, fr fr ๐Ÿ’ช. every single overload is here, no skips.

  • unordered_map () = default โ€” Default constructor. ๐Ÿ’–
  • ```cpp template<typename _InputIterator> unordered_map (_InputIterator __first, _InputIterator __last, const allocator_type &__a)

- ```cpp
template<typename _InputIterator> unordered_map (_InputIterator __first,
    _InputIterator __last, size_type __n, const allocator_type &__a)
  • ```cpp template<typename _InputIterator> unordered_map (_InputIterator __first, _InputIterator __last, size_type __n, const hasher &__hf, const allocator_type &__a)

- ```cpp
template<typename _InputIterator> unordered_map (_InputIterator __first,
    _InputIterator __last, size_type __n=0, const hasher &__hf=hasher(),
    const key_equal &__eql=key_equal(), const allocator_type
    &__a=allocator_type())

Builds an unordered_map from a range. ๐ŸŒˆ

  • unordered_map (const allocator_type &__a) โ€” Creates an unordered_map with no elements. ๐Ÿซถ
  • unordered_map (const unordered_map &)=default โ€” Copy constructor. ๐Ÿ‘ฏ
  • ```cpp unordered_map (const unordered_map &__umap, const allocator_type &__a)

- ```cpp
unordered_map (initializer_list< value_type > __l, const allocator_type
    &__a)
  • ```cpp unordered_map (initializer_list< value_type > __l, size_type __n, const allocator_type &__a)

- ```cpp
unordered_map (initializer_list< value_type > __l, size_type __n, const
    hasher &__hf, const allocator_type &__a)
  • ```cpp unordered_map (initializer_list< value_type > __l, size_type __n=0, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Builds an unordered_map from an initializer_list. ๐ŸŽ€

- ```cpp
unordered_map (size_type __n, const allocator_type &__a)
  • ```cpp unordered_map (size_type __n, const hasher &__hf, const allocator_type &__a)

- ```cpp
unordered_map (size_type __n, const hasher &__hf=hasher(), const
    key_equal &__eql=key_equal(), const allocator_type
    &__a=allocator_type())

Default constructor creates no elements. ๐Ÿ˜ญ

  • unordered_map (unordered_map &&)=default โ€” Move constructor. ๐Ÿš€
  • ```cpp unordered_map (unordered_map &&__umap, const allocator_type &__a) noexcept(noexcept(_Hashtable(std::move(__umap._M_h), __a)))

- **`iterator begin () noexcept`**

- **`local_iterator begin (size_type __n)`** โ€” Returns a read/write iterator pointing to the first bucket element. ๐Ÿชฃ

- **`size_type bucket_count () const noexcept`** โ€” Returns the number of buckets of the unordered_map. ๐Ÿ”ข

- **`size_type bucket_size (size_type __n) const`**

- **`void clear () noexcept`**

- ```cpp
template<typename... _Args> std::pair< iterator, bool > emplace (_Args
    &&... __args)

Attempts to build and insert a std::pair into the unordered_map. ๐Ÿ’…

  • ```cpp template<typename... _Args> iterator emplace_hint (const_iterator __pos, _Args &&... __args)
Attempts to build and insert a std::pair into the unordered_map. ๐Ÿ’…

- **`bool empty () const noexcept`** โ€” Returns true if the unordered_map is empty. ๐Ÿซ™

- **`iterator end () noexcept`**

- **`local_iterator end (size_type __n)`** โ€” Returns a read/write iterator pointing to one past the last bucket elements. ๐Ÿ

- ```cpp
iterator erase (const_iterator __first, const_iterator __last)

Erases a [__first,__last) range of elements from an unordered_map. โœ‚๏ธ

  • allocator_type get_allocator () const noexcept โ€” Returns the allocator object used by the unordered_map. ๐Ÿงบ
  • hasher hash_function () const โ€” Returns the hash functor object with which the unordered_map was constructed. #๏ธโƒฃ
  • ```cpp template<typename _InputIterator> void insert (_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements. ๐Ÿ“ฅ

- ```cpp
void insert (initializer_list< value_type > __l)

Attempts to insert a list of elements into the unordered_map. ๐Ÿ“

  • key_equal key_eq () const โ€” Returns the key comparison object with which the unordered_map was constructed. โš–๏ธ
  • float load_factor () const noexcept โ€” Returns the average number of elements per bucket. โš–๏ธ
  • size_type max_bucket_count () const noexcept โ€” Returns the maximum number of buckets of the unordered_map. ๐Ÿชฃ
  • float max_load_factor () const noexcept โ€” Returns a positive number that the unordered_map tries to keep the load factor less than or equal to. ๐Ÿ“ˆ
  • void max_load_factor (float __z) โ€” Change the unordered_map maximum load factor. ๐Ÿ”ง
  • size_type max_size () const noexcept โ€” Returns the maximum size of the unordered_map. ๐Ÿ“
  • unordered_map & operator= (const unordered_map &)=default โ€” Copy assignment operator. ๐Ÿ“‹
  • unordered_map & operator= (initializer_list< value_type > __l) โ€” Unordered_map list assignment operator. ๐Ÿ“
  • unordered_map & operator= (unordered_map &&)=default โ€” Move assignment operator. ๐Ÿšš
  • void rehash (size_type __n) โ€” May rehash the unordered_map. ๐Ÿ”„
  • void reserve (size_type __n) โ€” Prepare the unordered_map for a specified number of elements. ๐ŸŽŸ๏ธ
  • size_type size () const noexcept โ€” Returns the size of the unordered_map. ๐Ÿ“
  • ```cpp void swap (unordered_map &__x) noexcept(noexcept(_M_h.swap(__x._M_h)))
Swaps data with another unordered_map. ๐Ÿ”„

- **`const_iterator begin () const noexcept`**

- **`const_iterator cbegin () const noexcept`**

- **`const_iterator end () const noexcept`**

- **`const_iterator cend () const noexcept`**

- ```cpp
std::pair< iterator, bool > insert (const value_type &__x)

Attempts to insert a std::pair into the unordered_map. ๐Ÿ’–

  • ```cpp std::pair< iterator, bool > insert (value_type &&__x)
Attempts to insert a std::pair into the unordered_map. ๐Ÿ’–

- ```cpp
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 unordered_map. ๐Ÿ’–

  • ```cpp iterator insert (const_iterator __hint, const value_type &__x)
Attempts to insert a std::pair into the unordered_map. ๐Ÿ’–

- ```cpp
iterator insert (const_iterator __hint, value_type &&__x)

Attempts to insert a std::pair into the unordered_map. ๐Ÿ’–

  • ```cpp template<typename _Pair> __enable_if_t< is_constructible< value_type, _Pair && >::value, iterator > insert (const_iterator __hint, _Pair &&__x)
Attempts to insert a std::pair into the unordered_map. ๐Ÿ’–

- ```cpp
iterator erase (const_iterator __position)

Erases an element from an unordered_map. โœ‚๏ธ

  • ```cpp iterator erase (iterator __position)
Erases an element from an unordered_map. โœ‚๏ธ

- ```cpp
size_type erase (const key_type &__x)

Erases elements according to the provided key. ๐Ÿ”‘

  • ```cpp template<__heterogeneous_hash_key< unordered_map > _Kt> size_type erase (_Kt &&__x)
Erases elements according to the provided key. ๐Ÿ”‘

- ```cpp
iterator find (const key_type &__x)

Tries to locate an element in an unordered_map. ๐Ÿ”

  • ```cpp const_iterator find (const key_type &__x) const
Tries to locate an element in an unordered_map. ๐Ÿ”

- ```cpp
size_type count (const key_type &__x) const

Finds the number of elements. ๐Ÿ”ข

  • ```cpp bool contains (const key_type &__x) const
Finds whether an element with the given key exists. โœ…

- ```cpp
template<typename _Kt> auto contains (const _Kt &__x) const ->
    decltype(_M_h._M_find_tr(__x), void(), true)

Finds whether an element with the given key exists. โœ…

  • ```cpp std::pair< iterator, iterator > equal_range (const key_type &__x)
Finds a subsequence matching given key. ๐Ÿ”Ž

- ```cpp
std::pair< const_iterator, const_iterator > equal_range (const
    key_type &__x) const

Finds a subsequence matching given key. ๐Ÿ”Ž

  • ```cpp mapped_type & operator[] (const key_type &__k)
Subscript ( [] ) access to unordered_map data. ๐Ÿ—๏ธ

- ```cpp
mapped_type & operator[] (key_type &&__k)

Subscript ( [] ) access to unordered_map data. ๐Ÿ—๏ธ

  • ```cpp template<__heterogeneous_hash_key< unordered_map > _Kt> mapped_type & operator[] (_Kt &&__k)
Subscript ( [] ) access to unordered_map data. ๐Ÿ—๏ธ

- ```cpp
mapped_type & at (const key_type &__k)

Access to unordered_map data. ๐Ÿ”“

  • ```cpp template<__heterogeneous_hash_key< unordered_map > _Kt> mapped_type & at (const _Kt &__k)
Access to unordered_map data. ๐Ÿ”“

- ```cpp
const mapped_type & at (const key_type &__k) const

Access to unordered_map data. ๐Ÿ”“

  • ```cpp template<__heterogeneous_hash_key< unordered_map > _Kt> const mapped_type & at (const _Kt &__k) const
Access to unordered_map data. ๐Ÿ”“

- ```cpp
size_type bucket (const key_type &__key) const
  • ```cpp template<__heterogeneous_hash_key< unordered_map > _Kt> size_type bucket (const _Kt &__key) const

- ```cpp
const_local_iterator begin (size_type __n) const

Returns a read-only (constant) iterator pointing to the first bucket element. ๐Ÿชฃ

  • ```cpp const_local_iterator cbegin (size_type __n) const
Returns a read-only (constant) iterator pointing to the first
bucket element. ๐Ÿชฃ

- ```cpp
const_local_iterator end (size_type __n) const

Returns a read-only (constant) iterator pointing to one past the last bucket elements. ๐Ÿ

  • ```cpp const_local_iterator cend (size_type __n) const
Returns a read-only (constant) iterator pointing to one past the
last bucket elements. ๐Ÿ

> not me listing every single overload like my life depends on it ๐Ÿ’€ but we did it bestie, we did it.

## Friends ๐Ÿค

- ```cpp
template<typename _Key1, typename _Tp1, typename _Hash1, typename
    _Pred1, typename _Alloc1> bool operator== (const unordered_map<
    _Key1, _Tp1, _Hash1, _Pred1, _Alloc1 > &, const unordered_map<
    _Key1, _Tp1, _Hash1, _Pred1, _Alloc1 > &)

โœจ Detailed Description โœจ

okay so here's the whole vibe of std::unordered_map. she is, and I quote, a class:

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>>
    class std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >

"A standard container composed of unique keys (containing at most one of each key value) that associates values of another type with the keys. โ€” bestie that's just a dictionary and she ATE ๐Ÿ’…

Since: C++11 ๐ŸŽ€

Template Parameters ๐ŸŒธ

  • _Key โ€” type of key objects.
  • _Tp โ€” type of mapped objects.
  • _Hash โ€” hashing function object type, defaults to hash<_Key>.
  • _Pred โ€” predicate function object type, defaults to equal_to<_Key>.
  • _Alloc โ€” allocator type, defaults to std::allocator<std::pair<const _Key, _Tp>>.

Meets the requirements of a container, and unordered associative container โ€” yes queen, she's certified, she passed the vibe check โœ…

The resulting value type of the container is std::pair<const _Key, _Tp>. ๐Ÿซถ

Base is _Hashtable, dispatched at compile time via template alias __umap_hashtable. lowkey iconic implementation detail, no cap.


๐Ÿ’– Member Typedef Documentation ๐Ÿ’–

every single one of these is a member of that exact same class template from up top (you know the one โ€” template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>>), so just mentally copy-paste the header in front of each, mwah ๐Ÿ˜Œ

  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::allocator_type โ€” public typedefs ๐Ÿ’œ
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::const_iterator โ€” iterator-related typedefs
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::const_local_iterator โ€” iterator-related typedefs
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::const_pointer โ€” iterator-related typedefs
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::const_reference โ€” iterator-related typedefs
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::difference_type โ€” iterator-related typedefs
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::hasher โ€” public typedefs ๐Ÿ’œ
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::iterator โ€” iterator-related typedefs
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::key_equal โ€” public typedefs ๐Ÿ’œ
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::key_type โ€” public typedefs ๐Ÿ’œ
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::local_iterator โ€” iterator-related typedefs
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::mapped_type โ€” public typedefs ๐Ÿ’œ
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::pointer โ€” iterator-related typedefs
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::reference โ€” iterator-related typedefs
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::size_type โ€” iterator-related typedefs
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::value_type โ€” public typedefs ๐Ÿ’œ

sixteen of them. she's thorough and we love that for her ๐Ÿ’…


๐Ÿงš Constructor & Destructor Documentation ๐Ÿงš

all of these live inside that same big template header, you know the drill by now bestie โœจ

  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map () [default] โ€” Default constructor ๐ŸŒฑ
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (size_type __n, const hasher & __hf = hasher(), const key_equal & __eql = key_equal(), const allocator_type & __a = allocator_type()) [inline], [explicit] โ€” Default constructor creates no elements.
    • Parameters
      • __n โ€” minimal initial number of buckets.
      • __hf โ€” a hash functor.
      • __eql โ€” a key equality functor.
      • __a โ€” an allocator object.
  • template<typename _InputIterator> std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (_InputIterator __first, _InputIterator __last, size_type __n = 0, const hasher & __hf = hasher(), const key_equal & __eql = key_equal(), const allocator_type & __a = allocator_type()) [inline] โ€” Builds an unordered_map from a range. ๐Ÿฆ‹
    • Parameters
      • __first โ€” an input iterator.
      • __last โ€” an input iterator.
      • __n โ€” minimal initial number of buckets.
      • __hf โ€” a hash functor.
      • __eql โ€” a key equality functor.
      • __a โ€” an allocator object.
    • Create an unordered_map consisting of copies of the elements from [__first,__last). This is linear in N (where N is distance(__first,__last)). so like, it does the thing, fast, we stan ๐Ÿ”ฅ
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (const unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc > & ) [default] โ€” Copy constructor. twin where have you been ๐Ÿ‘ฏ
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc > && ) [default] โ€” Move constructor. she's leaving but she's taking everything with her, periodt ๐Ÿ’จ
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (const allocator_type & __a) [inline], [explicit] โ€” Creates an unordered_map with no elements.
    • Parameters
      • __a โ€” an allocator object.
  • std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (initializer_list< value_type > __l, size_type __n = 0, const hasher & __hf = hasher(), const key_equal & __eql = key_equal(), const allocator_type & __a = allocator_type()) [inline] โ€” Builds an unordered_map from an initializer_list. ๐ŸŽ€
    • Parameters
      • __l โ€” an initializer_list.
      • __n โ€” minimal initial number of buckets.
      • __hf โ€” a hash functor.
      • __eql โ€” a key equality functor.
      • __a โ€” an allocator object.
    • Create an unordered_map consisting of copies of the elements in the list. This is linear in N (where N is __l.size()). ๐Ÿงฎ

๐ŸŒˆ Member Function Documentation ๐ŸŒˆ

the at girlies ๐Ÿ’…

all three of these are members of the same template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> class, okurrr โœจ

  • template<__heterogeneous_hash_key< unordered_map > _Kt> mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::at (const _Kt & __k) [inline] โ€” Access to unordered_map data. ๐Ÿ”
    • Parameters
      • __k โ€” the key for which data should be retrieved.
    • Returns
      • A reference to the data whose key is equal to __k, if such a data is present in the unordered_map.
    • Exceptions
      • std::out_of_range if no such data is present. she will THROW, do not test her ๐Ÿ˜ญ
  • template<__heterogeneous_hash_key< unordered_map > _Kt> const mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::at (const _Kt & __k) const [inline] โ€” Access to unordered_map data. ๐Ÿ”
    • Parameters
      • __k โ€” the key for which data should be retrieved.
    • Returns
      • A reference to the data whose key is equal to __k, if such a data is present in the unordered_map.
    • Exceptions
      • std::out_of_range if no such data is present. same energy, still throwing ๐Ÿ’€
  • mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::at (const key_type & __k) [inline] โ€” Access to unordered_map data. ๐Ÿ”
    • Parameters
      • __k โ€” the key for which data should be retrieved.
    • Returns
      • A reference to the data whose key is equal to __k, if such a data is present in the unordered_map.
Exceptions: std::out_of_range if no such data is present. ๐Ÿ’€ that's the vibe for the overload above, and it's the vibe for this one too, bestie.

โœจ at (the const girlie) โœจ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::at (const key_type & __k) const [inline]

Access to unordered_map data. It's giving "hand me the thing" energy but make it read-only. ๐ŸŽ€

Parameters

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

Returns

A reference to the data whose key is equal to __k, if such a data is present in the unordered_map. ๐Ÿ‘‘

Exceptions

  • std::out_of_range โ€” if no such data is present. No key, no data, we're throwing. ๐Ÿ˜ญ

๐ŸŒธ begin (const) ๐ŸŒธ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::begin () const [inline],  [noexcept]

Returns a read-only (constant) iterator that points to the first element in the unordered_map. Look but don't touch, periodt. ๐Ÿ’…

๐Ÿฆ‹ begin ๐Ÿฆ‹

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::begin () [inline],  [noexcept]

Returns a read/write iterator that points to the first element in the unordered_map. Now you can actually edit things, main character energy fr fr. โœจ

๐Ÿงš begin (bucket edition) ๐Ÿงš

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::begin (size_type __n) [inline]

Returns a read/write iterator pointing to the first bucket element. Yes bestie, you can poke around inside one single bucket. ๐Ÿชฃ

Parameters

  • __n โ€” the bucket index.

Returns

A read/write local iterator.

๐Ÿ’œ begin (bucket + const) ๐Ÿ’œ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::begin (size_type __n) const [inline]

Returns a read-only (constant) iterator pointing to the first bucket element.

Parameters

  • __n โ€” the bucket index.

Returns

A read-only local iterator.


๐ŸŽ€ bucket_count ๐ŸŽ€

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::bucket_count () const [inline],  [noexcept]

Returns the number of buckets of the unordered_map. That's it, that's the whole job. ๐ŸŒˆ


โญ cbegin โญ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::cbegin () const [inline],  [noexcept]

Returns a read-only (constant) iterator that points to the first element in the unordered_map. The "c" stands for const, iykyk. ๐Ÿ’–

๐Ÿ“ cbegin (bucket) ๐Ÿ“

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::cbegin (size_type __n) const [inline]

Returns a read-only (constant) iterator pointing to the first bucket element.

Parameters

  • __n โ€” the bucket index.

Returns

A read-only local iterator.


๐Ÿ’ซ cend ๐Ÿ’ซ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::cend () const [inline],  [noexcept]

Returns a read-only (constant) iterator that points one past the last element in the unordered_map. Not the last element itself โ€” past it. Classic off-by-one's cooler sibling. ๐Ÿ‘‘

๐Ÿซถ cend (bucket) ๐Ÿซถ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::cend (size_type __n) const [inline]

Returns a read-only (constant) iterator pointing to one past the last bucket elements.

Parameters

  • __n โ€” the bucket index.

Returns

A read-only local iterator.


๐Ÿงน clear ๐Ÿงน

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::clear () [inline],  [noexcept]

Erases all elements in an unordered_map. Fresh start, blank slate, cleanse era. โœจ

Heads up bestie: this function 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 the user's responsibility. So if you thought clear() would clean up after your newsโ€ฆ no ma'am. ๐Ÿ˜ญ

๐Ÿ” contains (the template one) ๐Ÿ”

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> template<typename _Kt> auto std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::contains (const _Kt & __x) const -> decltype(_M_h._M_find_tr(__x), void(), true) [inline]

Finds whether an element with the given key exists. The vibe check of the container world. ๐Ÿ’…

Parameters

  • __x โ€” key of elements to be located.

Returns

True if there is any element with the specified key.

๐Ÿ”Ž contains (the key_type one) ๐Ÿ”Ž

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> bool std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::contains (const key_type & __x) const [inline]

Finds whether an element with the given key exists.

Parameters

  • __x โ€” key of elements to be located.

Returns

True if there is any element with the specified key.


๐Ÿงฎ count ๐Ÿงฎ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::count (const key_type & __x) const [inline]

Finds the number of elements.

Parameters

  • __x โ€” key to count.

Returns

Number of elements with specified key.

Real talk: this function only makes sense for unordered_multimap; for unordered_map the result will either be 0 (not present) or 1 (present). So it's not really counting, it's just โœจconfirmingโœจ. ๐Ÿ’€


๐ŸŒŸ emplace ๐ŸŒŸ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> template<typename... _Args> std::pair< iterator, bool > std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::emplace (_Args &&... __args) [inline]

Attempts to build and insert a std::pair into the unordered_map. Construction in place, no copies wasted, we love a resourceful queen. ๐Ÿ‘‘

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.

This function attempts to build and insert a (key, value) pair into the unordered_map. An unordered_map relies on unique keys and thus a pair is only inserted if its first element (the key) is not already present in the unordered_map. No duplicates allowed, we run a strict door policy here. ๐Ÿšช

Insertion requires amortized constant time.


๐ŸŽฏ emplace_hint ๐ŸŽฏ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> template<typename... _Args> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::emplace_hint (const_iterator __pos, _Args &&... __args) [inline]

Attempts to build and insert a std::pair into the unordered_map. Same energy as emplace, but now with a hint. ๐Ÿ’ญ

Parameters

  • __pos โ€” an iterator that serves as a hint as to where the pair should be inserted.
  • __args โ€” arguments used to generate a new pair instance (see std::piecewise_contruct for passing arguments to each part of the pair constructor).

Returns

An iterator that points to the element with key of the std::pair built from __args (may or may not be that std::pair).

This function is not concerned about whether the insertion took place, and thus does not return a boolean like the single-argument emplace() 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. It's a suggestion, not a command, bestie. ๐Ÿ™ˆ

See

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

Insertion requires amortized constant time.


๐Ÿซง empty ๐Ÿซง

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> bool std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::empty () const [inline],  [nodiscard],  [noexcept]

Returns true if the unordered_map is empty. Yes she's [nodiscard] โ€” do not ignore her answer, that's rude. ๐Ÿ˜ค


๐Ÿ end (const) ๐Ÿ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::end () const [inline],  [noexcept]

Returns a read-only (constant) iterator that points one past the last element in the unordered_map.

๐Ÿ end ๐Ÿ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::end () [inline],  [noexcept]

Returns a read/write iterator that points one past the last element in the unordered_map.

๐Ÿชฃ end (bucket) ๐Ÿชฃ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::end (size_type __n) [inline]

Returns a read/write iterator pointing to one past the last bucket elements.

Parameters

  • __n โ€” the bucket index.

Returns

A read/write local iterator.

๐Ÿชฃ end (bucket + const) ๐Ÿชฃ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::end (size_type __n) const [inline]

Returns a read-only (constant) iterator pointing to one past the last bucket elements.

Parameters

  • __n โ€” the bucket index.

Returns

A read-only local iterator.


๐ŸŽ equal_range ๐ŸŽ

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> std::pair< iterator, iterator > std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::equal_range (const key_type & __x) [inline]

Finds a subsequence matching given key. It's giving two-for-one deal, a whole pair of iterators. ๐Ÿ’…

Parameters

  • __x โ€” key to be located.

Returns

Pair of iterators that possibly points to the subsequence matching given key.

This function probably only makes sense for unordered_multimap. ๐Ÿ’€

๐Ÿฆ‹ equal_range โ€” the const girlie

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> std::pair< const_iterator, const_iterator >
    std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::equal_range
    (const key_type & __x) const [inline]

Finds a subsequence matching given key. bestie it's giving "where are my people at" energy โœจ

Parameters

  • __x โ€” the key you want located ๐Ÿ”

Returns

  • a pair of iterators that possibly points to the subsequence matching the given key ๐Ÿซถ
This function probably only makes sense for unordered_multimap. ๐Ÿ’€ (yes, again. she said what she said.)

๐ŸŽ€ erase โ€” the heterogeneous key one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> template<__heterogeneous_hash_key< unordered_map > _Kt>
    size_type std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::erase
    (_Kt && __x) [inline]

Erases elements according to the provided key. bye felicia ๐Ÿ‘‹

Parameters

  • __x โ€” key of the element to be erased ๐Ÿ”ช

Returns

  • the number of elements erased ๐Ÿ”ข

okay so real talk: this function erases all the elements located by the given key from an unordered_map. And for an unordered_map the result of this function can only be 0 (not present) or 1 (present). no in-between, no drama, just math ๐Ÿ’…

โš ๏ธ Note that this function only erases the element, and that 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. that's on you bestie, not on the container ๐Ÿ˜ญ

๐ŸŒธ erase โ€” the const key_type one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _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 ๐Ÿ”ข

same deal, different overload. This function erases all the elements located by the given key from an unordered_map. For an unordered_map the result of this function can only be 0 (not present) or 1 (present). And again:

โš ๏ธ This function 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. ๐Ÿซ 

๐Ÿงš erase โ€” the range one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::erase (const_iterator __first, const_iterator __last) [inline]

Erases a [__first,__last) range of elements from an unordered_map. a whole squad, gone ๐Ÿ’€

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 sequence of elements from an unordered_map.

โš ๏ธ Note that this function only erases the elements, and that 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. fr fr, it's your pointer, your problem ๐Ÿ™ˆ

๐Ÿ’œ erase โ€” the const_iterator __position one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::erase (const_iterator __position) [inline]

Erases an element from an unordered_map. one singular element. targeted. iconic ๐ŸŽฏ

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 an unordered_map.

โš ๏ธ Note that this function only erases the element, and that 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. no cap ๐Ÿ’€

โญ erase โ€” the iterator __position one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::erase (iterator __position) [inline]

Erases an element from an unordered_map. the non-const twin, she's the same girl, different fit โœจ

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 an unordered_map.

โš ๏ธ Note that this function only erases the element, and that 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 โ€” the non-const one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::find (const key_type & __x) [inline]

Tries to locate an element in an unordered_map. she's searching, she's looking, she's manifesting ๐Ÿ•ต๏ธโ€โ™€๏ธ

Parameters

  • __x โ€” key to be located ๐Ÿ”‘

Returns

  • iterator pointing to the sought-after element, or end() if not found ๐Ÿ˜ญ

This function takes a key and tries to locate the element with which the key matches. If successful the function returns an iterator pointing to the sought after element. If unsuccessful it returns the past-the-end (end()) iterator. the way that end() is always there for you ๐Ÿซถ


๐Ÿ” find โ€” the const one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> const_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::find (const key_type & __x) const [inline]

Tries to locate an element in an unordered_map.

Parameters

  • __x โ€” key to be located ๐Ÿ”‘

Returns

  • iterator pointing to the sought-after element, or end() if not found ๐Ÿ˜ญ

Same search, same energy, but this one hands you a const_iterator. This function takes a key and tries to locate the element with which the key matches. If successful the function returns an iterator pointing to the sought after element. If unsuccessful it returns the past-the-end (end()) iterator. slay โœจ


๐ŸŽ€ get_allocator

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> allocator_type std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::get_allocator () const [inline],  [noexcept]

Returns the allocator object used by the unordered_map. she's giving you the keys to the allocator, no questions asked ๐Ÿ—๏ธ


๐ŸŒˆ hash_function

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> hasher std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
    >::hash_function () const [inline]

Returns the hash functor object with which the unordered_map was constructed. the whole vibe this container was built on, handed right back to you ๐Ÿซถโœจ


๐Ÿ’– insert โ€” the range one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> template<typename _InputIterator> void std::unordered_map<
    _Key, _Tp, _Hash, _Pred, _Alloc >::insert (_InputIterator __first,
    _InputIterator __last) [inline]

A template function that attempts to insert a range of elements. come in, the whole crew ๐Ÿ’ƒ

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 _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> template<typename _Pair> __enable_if_t< is_constructible<
    value_type, _Pair && >::value, pair< iterator, bool > >
    std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::insert (_Pair &&
    __x) [inline]

Attempts to insert a std::pair into the unordered_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 unordered_map. An unordered_map relies on unique keys and thus a pair is only inserted if its first element (the key) is not already present in the unordered_map. no dupes allowed bestie ๐Ÿ™…โ€โ™€๏ธ

Insertion requires amortized constant time. fast fr fr โšก


๐Ÿ’– insert โ€” the const value_type & one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> std::pair< iterator, bool > std::unordered_map< _Key, _Tp,
    _Hash, _Pred, _Alloc >::insert (const value_type & __x) [inline]

Attempts to insert a std::pair into the unordered_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 unordered_map. An unordered_map relies on unique keys and thus a pair is only inserted if its first element (the key) is not already present in the unordered_map.

Insertion requires amortized constant time. โšก


โœจ insert โ€” the const_iterator __hint + _Pair && one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> template<typename _Pair> __enable_if_t< is_constructible<
    value_type, _Pair && >::value, iterator > std::unordered_map< _Key, _Tp,
    _Hash, _Pred, _Alloc >::insert (const_iterator __hint, _Pair && __x)
    [inline]

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

Parameters

  • __hint โ€” 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. she's unbothered ๐Ÿ’…

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โ€ฆ don't stress the hint too much bestie ๐Ÿ˜ญ

See

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

for more on hinting. iykyk ๐Ÿ“š

Insertion requires amortized constant time. โšก


๐Ÿฆ‹ insert โ€” the const_iterator __hint + const value_type & one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::insert (const_iterator __hint, const value_type & __x)
    [inline]

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

๐Ÿซฃ and that's where this part ends, bestie โ€” the rest of this overload's lore is coming up next. don't go anywhere ๐Ÿ’–

Okay bestie, we were literally mid-sentence on the hinted insert โ€” here's the rest of that one, no cap ๐Ÿ’–

  • __hint โ€” an iterator that serves as a hint as to where the pair should be inserted.
  • __x โ€” the pair to be inserted (peep std::make_pair if you want easy creation of pairs).

Returns โ€” an iterator that points to the element with key of __x (it may or may not be the pair passed in, so don't get attached ๐Ÿซถ).

This function is not concerned about whether the insertion actually took place, so it does not return a boolean like the single-argument insert() does. And heads up: that first parameter is only a hint โ€” it can potentially improve the performance of the insertion process, but a bad hint would cause no gains in efficiency. So like, hint responsibly.

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

Insertion requires amortized constant time. โœจ


insert (const_iterator __hint, value_type && __x) โ€” the move-y hinted one ๐Ÿฆ‹

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::insert (const_iterator __hint, value_type && __x) [inline]

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

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

Returns โ€” an iterator that points to the 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 amortized constant time.


insert (initializer_list< value_type > __l) โ€” the bulk drop ๐ŸŽ€

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
    >::insert (initializer_list< value_type > __l) [inline]

Attempts to insert a list of elements into the unordered_map. It's giving "dump the whole squad in at once" energy ๐Ÿ’…

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

Complexity similar to that of the range constructor.


insert (value_type && __x) โ€” the single move-in ๐Ÿ“

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> std::pair< iterator, bool > std::unordered_map< _Key, _Tp,
    _Hash, _Pred, _Alloc >::insert (value_type && __x) [inline]

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

  • __x โ€” the 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. So yes, this one does tell you if it slayed or not. ๐Ÿ‘‘

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

Insertion requires amortized constant time.


key_eq

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> key_equal std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::key_eq () const [inline]

Returns the key comparison object with which the unordered_map was constructed. That's it, that's the whole function. Short queen. ๐Ÿงš


load_factor

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> float std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
    >::load_factor () const [inline],  [noexcept]

Returns the average number of elements per bucket. Yes, it's a float. Yes, [noexcept]. We love a low-stress getter. ๐Ÿ’œ


max_bucket_count

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::max_bucket_count () const [inline],  [noexcept]

Returns the maximum number of buckets of the unordered_map. The absolute ceiling, the final boss of bucket counts. ๐ŸŒˆ


max_load_factor (the getter)

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> float std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
    >::max_load_factor () const [inline],  [noexcept]

Returns a positive number that the unordered_map tries to keep the load factor less than or equal to. It's a goal, not a promise, iykyk. โญ


max_load_factor (the setter)

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
    >::max_load_factor (float __z) [inline]

Change the unordered_map maximum load factor.

  • __z โ€” the new maximum load factor.

max_size

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::max_size () const [inline],  [noexcept]

Returns the maximum size of the unordered_map. Hypothetically. In theory. Don't try to get there bestie, your RAM will simply pass away. ๐Ÿ’€


operator= โ€” copy assignment

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> unordered_map & std::unordered_map< _Key, _Tp, _Hash,
    _Pred, _Alloc >::operator= (const unordered_map< _Key, _Tp, _Hash,
    _Pred, _Alloc > & ) [default]

Copy assignment operator. Compiler-said-so, [default] and all. ๐Ÿ’–


operator= โ€” list assignment

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> unordered_map & std::unordered_map< _Key, _Tp, _Hash,
    _Pred, _Alloc >::operator= (initializer_list< value_type > __l) [inline]

Unordered_map list assignment operator.

  • __l โ€” an initializer_list.

This function fills an unordered_map with copies of the elements in the initializer list __l.

Note that the assignment completely changes the unordered_map, and that the resulting unordered_map's size is the same as the number of elements assigned. Full glow-up, total replacement. ๐Ÿ™ˆ

operator= โ€” move assignment

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> unordered_map & std::unordered_map< _Key, _Tp, _Hash,
    _Pred, _Alloc >::operator= (unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc > && ) [default]

Move assignment operator. Also [default], also iconic. โœจ


operator[] โ€” the heterogeneous key one

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> template<__heterogeneous_hash_key< unordered_map > _Kt>
    mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
    >::operator[] (_Kt && __k) [inline]

Subscript ( [] ) access to unordered_map data.

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

Returns โ€” a reference to the data of the (key,data) pair.

Allows for easy lookup with the subscript ( [] ) operator. 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 like, sneaky โ€” it will make the thing. ๐Ÿซถ

Lookup requires constant time.


operator[] โ€” const key_type &

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::operator[] (const key_type & __k) [inline]

Subscript ( [] ) access to unordered_map data.

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

Returns โ€” a reference to the data of the (key,data) pair.

Allows for easy lookup with the subscript ( [] ) operator. 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.

Lookup requires constant time.


operator[] โ€” key_type &&

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::operator[] (key_type && __k) [inline]

Subscript ( [] ) access to unordered_map data.

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

Returns โ€” a reference to the data of the (key,data) pair.

Allows for easy lookup with the subscript ( [] ) operator. 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.

Lookup requires constant time. Three flavors of the same slay. ๐Ÿ’…


rehash

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
    >::rehash (size_type __n) [inline]

May rehash the unordered_map. Emphasis on may, bestie.

  • __n โ€” the new number of buckets.

Rehash will occur only if the new number of buckets respect the unordered_map maximum load factor. So sometimes it just looks at your request and politely declines. ๐Ÿ˜ญ


reserve

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
    >::reserve (size_type __n) [inline]

Prepare the unordered_map for a specified number of elements. Manifesting capacity. ๐ŸŒธ

  • __n โ€” number of elements required.

Same as rehash(ceil(n / max_load_factor())).


size

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred,
    _Alloc >::size () const [inline],  [noexcept]

Returns the size of the unordered_map. The headcount. The roster. The [noexcept] little icon it is. ๐Ÿ‘‘


swap

template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
    _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
    _Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
    >::swap (unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc > & __x)
    [inline],  [noexcept]

Swaps data with another unordered_map.

  • __x โ€” an unordered_map of the same element and allocator types.

This exchanges the elements between two unordered_map in constant time. Note that the global std::swap() function is specialized such that std::swap(m1,m2) will feed to this function. Trade offer: you get my buckets, I get yours. ๐Ÿค


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Generated automatically by Doxygen for libstdc++ from the source code.


And that's a wrap on the whole std::unordered_map saga, bestie โ€” every last flag, default, [noexcept] and hint, accounted for. ๐Ÿ’– This beauty lives in the libstdc++ manual set, page std::unord...d, _Alloc >(3), and it came to you courtesy of Doxygen auto-generating it straight from the source code. Go forth and hash responsibly. ๐ŸŽ€โœจ๐Ÿฆ‹

๐Ÿ“ฆ 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