STD::UNORDERED_SET(3)

hey bestie ๐Ÿ’– welcome to the manual page for std::unordered_set< _Value, _Hash, _Pred, _Alloc >(3) from the Library Functions Manual. it's giving iconic container energy, and we're about to go through every single detail together, no skips, no cap. ๐Ÿซถโœจ

โœจ NAME โœจ

std::unordered_set< _Value, _Hash, _Pred, _Alloc > โ€” A standard container composed of unique keys (containing at most one of each key value) in which the elements' keys are the elements themselves. ๐Ÿ’…

๐Ÿ’– SYNOPSIS ๐Ÿ’–

#include <unordered_set>

๐ŸŒธ Public Types ๐ŸŒธ

okay so first up, the public typedefs. they're giving "yes, I'm part of the type system" energy:

  • typedef _Hashtable::key_type key_type โ€” Public typedefs.
  • typedef _Hashtable::value_type value_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.

and these ones are the iterator-related typedefs, aka the backstage crew that makes iteration work:

  • 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 ๐Ÿ‘‘

bestie, there are so many member functions, and we're listing every one. periodt. ๐Ÿ’…

  • unordered_set ()=default โ€” Default constructor. โœจ
  • template<typename _InputIterator> unordered_set (_InputIterator __first, _InputIterator __last, const allocator_type &__a)
  • template<typename _InputIterator> unordered_set (_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type &__a)
  • template<typename _InputIterator> unordered_set (_InputIterator __first, _InputIterator __last, size_type __n, const hasher &__hf, const allocator_type &__a)
  • template<typename _InputIterator> unordered_set (_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_set from a range. ๐ŸŒˆ
  • unordered_set (const allocator_type &__a) โ€” Creates an unordered_set with no elements.
  • unordered_set (const unordered_set &)=default โ€” Copy constructor.
  • unordered_set (const unordered_set &__uset, const allocator_type &__a)
  • unordered_set (initializer_list< value_type > __l, const allocator_type &__a)
  • unordered_set (initializer_list< value_type > __l, size_type __n, const allocator_type &__a)
  • unordered_set (initializer_list< value_type > __l, size_type __n, const hasher &__hf, const allocator_type &__a)
  • unordered_set (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_set from an initializer_list. ๐ŸŽ€
  • unordered_set (size_type __n, const allocator_type &__a)
  • unordered_set (size_type __n, const hasher &__hf, const allocator_type &__a)
  • unordered_set (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_set (unordered_set &&)=default โ€” Move constructor.
  • unordered_set (unordered_set &&__uset, const allocator_type &__a) โ€” noexcept(noexcept(_Hashtable(std::move(__uset._M_h), __a)))
  • size_type bucket_count () const noexcept โ€” Returns the number of buckets of the unordered_set.
  • size_type bucket_size (size_type __n) const
  • const_iterator cbegin () const noexcept
  • const_iterator cend () const noexcept
  • void clear () noexcept
  • template<typename... _Args> std::pair< iterator, bool > emplace (_Args &&... __args) โ€” Attempts to build and insert an element into the unordered_set.
  • template<typename... _Args> iterator emplace_hint (const_iterator __pos, _Args &&... __args) โ€” Attempts to insert an element into the unordered_set.
  • bool empty () const noexcept โ€” Returns true if the unordered_set is empty.
  • template<__heterogeneous_hash_key< unordered_set > _Kt> size_type erase (_Kt &&__x)
  • size_type erase (const key_type &__x) โ€” Erases elements according to the provided key.
  • iterator erase (const_iterator __first, const_iterator __last) โ€” Erases a [__first,__last) range of elements from an unordered_set.
  • allocator_type get_allocator () const noexcept โ€” Returns the allocator object used by the unordered_set.
  • hasher hash_function () const โ€” Returns the hash functor object with which the unordered_set was constructed.
  • template<typename _InputIterator> void insert (_InputIterator __first, _InputIterator __last) โ€” A template function that attempts to insert a range of elements.
  • void insert (initializer_list< value_type > __l) โ€” Attempts to insert a list of elements into the unordered_set.
  • key_equal key_eq () const โ€” Returns the key comparison object with which the unordered_set 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_set.
  • float max_load_factor () const noexcept โ€” Returns a positive number that the unordered_set tries to keep the load factor less than or equal to.
  • void max_load_factor (float __z) โ€” Change the unordered_set maximum load factor.
  • size_type max_size () const noexcept โ€” Returns the maximum size of the unordered_set.
  • unordered_set & operator= (const unordered_set &)=default โ€” Copy assignment operator.
  • unordered_set & operator= (initializer_list< value_type > __l) โ€” Unordered_set list assignment operator.
  • unordered_set & operator= (unordered_set &&)=default โ€” Move assignment operator.
  • void rehash (size_type __n) โ€” May rehash the unordered_set.
  • void reserve (size_type __n) โ€” Prepare the unordered_set for a specified number of elements.
  • size_type size () const noexcept โ€” Returns the size of the unordered_set.
  • void swap (unordered_set &__x) noexcept(noexcept(_M_h.swap(__x._M_h))) โ€” Swaps data with another unordered_set.

and then the original has this next block, still under Public Member Functions, and yes we're including it all:

  • iterator begin () noexcept
  • const_iterator begin () const noexcept
  • iterator end () noexcept
  • const_iterator end () const noexcept
  • std::pair< iterator, bool > insert (const value_type &__x) โ€” Attempts to insert an element into the unordered_set.
  • std::pair< iterator, bool > insert (value_type &&__x) โ€” Attempts to insert an element into the unordered_set.
  • template<__heterogeneous_hash_key< unordered_set > _Kt> std::pair< iterator, bool > insert (_Kt &&__x) โ€” Attempts to insert an element into the unordered_set.
  • iterator insert (const_iterator __hint, const value_type &__x) โ€” Attempts to insert an element into the unordered_set.
  • iterator insert (const_iterator __hint, value_type &&__x) โ€” Attempts to insert an element into the unordered_set.
  • template<__heterogeneous_hash_key< unordered_set > _Kt> iterator insert (const_iterator, _Kt &&__x) โ€” Attempts to insert an element into the unordered_set.
  • iterator erase (const_iterator __position) โ€” Erases an element from an unordered_set.
  • iterator erase (iterator __position) โ€” Erases an element from an unordered_set.
  • iterator find (const key_type &__x) โ€” Tries to locate an element in an unordered_set.
  • const_iterator find (const key_type &__x) const โ€” Tries to locate an element in an unordered_set.
  • size_type count (const key_type &__x) const โ€” Finds the number of elements.
  • 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_h._M_find_tr(__x), void(), true) โ€” Finds whether an element with the given key exists.
  • 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.
  • size_type bucket (const key_type &__key) const
  • template<__heterogeneous_hash_key< unordered_set > _Kt> size_type bucket (const _Kt &__key) const
  • local_iterator begin (size_type __n) โ€” Returns a read-only (constant) iterator pointing to the first bucket element.
  • const_local_iterator begin (size_type __n) const โ€” Returns a read-only (constant) iterator pointing to the first bucket element.
  • const_local_iterator cbegin (size_type __n) const โ€” Returns a read-only (constant) iterator pointing to the first bucket element.
  • local_iterator end (size_type __n) โ€” Returns a read-only (constant) iterator pointing to one past the last bucket elements.
  • const_local_iterator end (size_type __n) const โ€” Returns a read-only (constant) iterator pointing to one past the last bucket elements.
  • const_local_iterator cend (size_type __n) const โ€” Returns a read-only (constant) iterator pointing to one past the last bucket elements.

๐Ÿซถ Friends ๐Ÿซถ

  • template<typename _Value1, typename _Hash1, typename _Pred1, typename _Alloc1> bool operator== (const unordered_set< _Value1, _Hash1, _Pred1, _Alloc1 > &, const unordered_set< _Value1, _Hash1, _Pred1, _Alloc1 > &) โ€” friend declaration, exactly as written.

๐Ÿ’ซ Detailed Description ๐Ÿ’ซ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
class std::unordered_set< _Value, _Hash, _Pred, _Alloc >"A standard container composed of unique keys (containing at most one of each key value) in which the elements' keys are the elements themselves.

Since

C++11

Template Parameters

  • _Value โ€” Type of key objects.
  • _Hash โ€” Hashing function object type, defaults to hash<_Value>.
  • _Pred โ€” Predicate function object type, defaults to equal_to<_Value>.
  • _Alloc โ€” Allocator type, defaults to allocator<_Key>.

Meets the requirements of a container, and unordered associative container

Base is _Hashtable, dispatched at compile time via template alias __uset_hashtable.

๐ŸŽ€ Member Typedef Documentation ๐ŸŽ€

ok bestie so before we get into the fun stuff, here's the receipts on every single nickname this class hands out ๐Ÿ’… these are the typedefs โ€” the little aliases unordered_set uses so you don't have to type out the whole cursed template soup every time. Two flavours here: the Public typedefs (the ones you actually touch) and the Iterator-related typedefs (the ones that make loops work). Both are just aliases pointing back at _Hashtable. No cap.


allocator_type

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::allocator_type std::unordered_set< _Value, _Hash, _Pred,
    _Alloc >::allocator_type

Public typedefs. it's literally just _Hashtable's allocator type, wearing a little name tag โœจ


const_iterator

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::const_iterator std::unordered_set< _Value, _Hash, _Pred,
    _Alloc >::const_iterator

Iterator-related typedefs. your read-only lil iterator, straight from _Hashtable ๐Ÿฆ‹


const_local_iterator

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::const_local_iterator std::unordered_set< _Value, _Hash,
    _Pred, _Alloc >::const_local_iterator

Iterator-related typedefs. same vibe but it only walks one bucket, and it's const ๐Ÿงบ


const_pointer

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::const_pointer std::unordered_set< _Value, _Hash, _Pred,
    _Alloc >::const_pointer

Iterator-related typedefs. pointer but make it not let you change anything ๐Ÿ™ˆ


const_reference

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::const_reference std::unordered_set< _Value, _Hash, _Pred,
    _Alloc >::const_reference

Iterator-related typedefs. a reference that's locked, look don't touch energy ๐Ÿ’–


difference_type

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::difference_type std::unordered_set< _Value, _Hash, _Pred,
    _Alloc >::difference_type

Iterator-related typedefs. for when you subtract two iterators and need to know "how far apart were these two fr" ๐Ÿ“


hasher

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::hasher std::unordered_set< _Value, _Hash, _Pred, _Alloc
    >::hasher

Public typedefs. the hash functor type โ€” the thing that turns your values into bucket addresses ๐ŸŽฏ


iterator

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::iterator std::unordered_set< _Value, _Hash, _Pred, _Alloc
    >::iterator

Iterator-related typedefs. the main character iterator, for begin() / end() loops and everything you actually do ๐Ÿ’ซ


key_equal

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::key_equal std::unordered_set< _Value, _Hash, _Pred, _Alloc
    >::key_equal

Public typedefs. the key equality functor โ€” how it decides two keys are "the same key" ๐Ÿค


key_type

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::key_type std::unordered_set< _Value, _Hash, _Pred, _Alloc
    >::key_type

Public typedefs. the type of the keys in the set ๐Ÿ”‘


local_iterator

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::local_iterator std::unordered_set< _Value, _Hash, _Pred,
    _Alloc >::local_iterator

Iterator-related typedefs. walks a single bucket, non-const edition ๐Ÿšถโ€โ™€๏ธ


pointer

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::pointer std::unordered_set< _Value, _Hash, _Pred, _Alloc
    >::pointer

Iterator-related typedefs. pointer, but the allocator's flavour of it ๐Ÿ‘‘


reference

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::reference std::unordered_set< _Value, _Hash, _Pred, _Alloc
    >::reference

Iterator-related typedefs. reference, allocator-flavoured ๐ŸŒˆ


size_type

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::size_type std::unordered_set< _Value, _Hash, _Pred, _Alloc
    >::size_type

Iterator-related typedefs. the unsigned number type for sizes and bucket counts ๐Ÿ”ข


value_type

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> typedef
    _Hashtable::value_type std::unordered_set< _Value, _Hash, _Pred, _Alloc
    >::value_type

Public typedefs. the type of the actual elements sitting in the set ๐Ÿ“


๐Ÿ’– Constructor & Destructor Documentation ๐Ÿ’–

here's where you actually make one of these bad boys. seven ways to build a set, pick your fighter โœจ

unordered_set ()

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>>
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::unordered_set ()
    [default]

Default constructor. boom, empty set, no thoughts head empty ๐Ÿซง


unordered_set (size_type __n, const hasher & __hf = hasher(), const key_equal & __eql = key_equal(), const allocator_type & __a = allocator_type())

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>>
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::unordered_set
    (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. (yes bestie, same sentence, it's the docs' whole personality ๐Ÿ’€ โ€” it makes an empty set.)

Parameters

  • __n โ€” Minimal initial number of buckets. ๐Ÿชฃ
  • __hf โ€” A hash functor.
  • __eql โ€” A key equality functor.
  • __a โ€” An allocator object.

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

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> template<typename
    _InputIterator> std::unordered_set< _Value, _Hash, _Pred, _Alloc
    >::unordered_set (_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_set from a range. the "copy this whole stretch of stuff into a set" move ๐ŸŒธ

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_set consisting of copies of the elements from [__first,__last). This is linear in N (where N is distance(__first,__last)). โฑ๏ธ


unordered_set (const unordered_set< _Value, _Hash, _Pred, _Alloc > & )

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>>
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::unordered_set (const
    unordered_set< _Value, _Hash, _Pred, _Alloc > & ) [default]

Copy constructor. twin telepathy, but for sets ๐Ÿ‘ฏโ€โ™€๏ธ


unordered_set (unordered_set< _Value, _Hash, _Pred, _Alloc > && )

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>>
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::unordered_set
    (unordered_set< _Value, _Hash, _Pred, _Alloc > && ) [default]

Move constructor. grab their stuff, they don't need it anymore ๐Ÿƒโ€โ™€๏ธ๐Ÿ’จ


unordered_set (const allocator_type & __a)

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>>
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::unordered_set (const
    allocator_type & __a) [inline], [explicit]

Creates an unordered_set with no elements. empty, but with your allocator. bespoke โœจ

Parameters

  • __a โ€” An allocator object.

unordered_set (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())

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>>
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::unordered_set
    (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_set from an initializer_list. the {1, 2, 3} treatment, iconic ๐ŸŽ€

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_set consisting of copies of the elements in the list. This is linear in N (where N is __l.size()). โฑ๏ธ


๐ŸŒˆ Member Function Documentation ๐ŸŒˆ

and now, the actual functions. buckle up bestie, we start with the iterators ๐Ÿ’…

begin () const

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> const_iterator
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::begin () const
    [inline], [noexcept]

Returns a read-only (constant) iterator that points to the first element in the unordered_set. ๐Ÿฆ‹


begin ()

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> iterator
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::begin () [inline],
    [noexcept]

Returns a read-only (constant) iterator that points to the first element in the unordered_set.

ok so yes, the docs genuinely repeat the exact same sentence here as the const one ๐Ÿ˜ญ that's just what it says, no cap. reporting faithfully, that's the job ๐Ÿซก

begin (size_type __n)

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> local_iterator
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::begin (size_type
    __n) [inline]

Returns a read-only (constant) iterator pointing to the first bucket element. bucket-level access, we're going deeper ๐Ÿชฃโœจ

Parameters

  • __n โ€” The bucket index.

Returns

  • A read-only local iterator.

begin (size_type __n) const

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

Returns a read-only (constant) iterator pointing to the first bucket element. same deal, const version ๐ŸงŠ

Parameters

  • __n โ€” The bucket index.

Returns

  • A read-only local iterator.

bucket_count () const

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> size_type
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::bucket_count ()
    const [inline], [noexcept]

Returns the number of buckets of the unordered_set. how many lil cubbies is this thing rocking rn ๐Ÿชฃ๐Ÿ”ข


cbegin () const

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> const_iterator
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::cbegin () const
    [inline], [noexcept]

Returns a read-only (constant) iterator that points to the first element in the unordered_set. the c stands for "chill, you cannot modify this" ๐Ÿ’…


cbegin (size_type __n) const

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>>
    const_local_iterator std::unordered_set< _Value, _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 () const

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> const_iterator
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::cend () const
    [inline], [noexcept]

Returns a read-only (constant) iterator that points one past the last element in the unordered_set. that classic "you've gone too far, stop here" sentinel ๐Ÿ›‘


cend (size_type __n) const

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

Returns a read-only (constant) iterator pointing to one past the last bucket elements. bucket's over, nothing to see past here ๐ŸŒธ

Parameters

  • __n โ€” The bucket index.

Returns

  • A read-only local iterator.

clear () ๐Ÿงนโœจ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> void
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::clear () [inline],
    [noexcept]

Erases all the elements in an unordered_set. Periodt, the whole thing, gone. ๐Ÿซง

Okay but listen โ€” this function only erases the elements. If the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. So like, it's giving "I cleaned my room by shoving everything in the closet" energy. The closet (your pointed-to memory) is still full, bestie. That's on you. ๐Ÿ’€

contains (the _Kt one) ๐Ÿ”๐Ÿ’–

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> template<typename
    _Kt> auto std::unordered_set< _Value, _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. It's a vibe check for your set, fr fr. โœจ

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 _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> bool
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::contains (const
    key_type & __x) const [inline]

Finds whether an element with the given key exists. Same energy, different signature. ๐ŸŒธ

Parameters

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

Returns

True if there is any element with the specified key. ๐Ÿ‘‘


count ๐Ÿ”ข

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

Finds the number of elements. Like, how many of these do we have, bestie? ๐Ÿงฎ

Parameters

  • __x โ€” Element to located.

Returns

Number of elements with specified key.

Real talk: this function only makes sense for unordered_multisets. For an unordered_set the result will either be 0 (not present) or 1 (present). So it's giving "yes or no" cosplaying as "how many". ๐Ÿ™ˆ

emplace ๐Ÿ—๏ธ๐Ÿ’…

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

Attempts to build and insert an element into the unordered_set. Build-a-bear but for container elements. ๐Ÿงธโœจ

Parameters

  • __args โ€” Arguments used to generate an element.

Returns

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

This function attempts to build and insert an element into the unordered_set. An unordered_set relies on unique keys and thus an element is only inserted if it is not already present in the unordered_set. No duplicates allowed, this is a strict guest list. ๐Ÿšซ

Insertion requires amortized constant time. โšก


emplace_hint ๐Ÿ—๏ธ๐Ÿ“

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>>
    template<typename... _Args> iterator std::unordered_set< _Value, _Hash,
    _Pred, _Alloc >::emplace_hint (const_iterator __pos, _Args &&... __args)
    [inline]

Attempts to insert an element into the unordered_set. Same as emplace but you get to drop a little hint. ๐Ÿ”ฎ

Parameters

  • __pos โ€” An iterator that serves as a hint as to where the element should be inserted.
  • __args โ€” Arguments used to generate the element to be inserted.

Returns

An iterator that points to the element with key equivalent to the one generated from __args (may or may not be the element itself).

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. So like, hint if you want, but don't be weird about it. ๐Ÿ˜ญ

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

Insertion requires amortized constant time. โšก


empty () ๐Ÿซ™

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

Returns true if the unordered_set is empty. Is your set empty? Yes or no, iconic, no notes. ๐Ÿ’–


end () (const version) ๐Ÿ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> const_iterator
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::end () const
    [inline],  [noexcept]

Returns a read-only (constant) iterator that points one past the last element in the unordered_set. The classic past-the-end. ๐Ÿฆ‹


end () (non-const version) ๐Ÿโœจ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> iterator
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::end () [inline],
    [noexcept]

Returns a read-only (constant) iterator that points one past the last element in the unordered_set. Yes, the description says read-only even here, that's just how it is, we don't make the rules. ๐Ÿ’…


end (size_type __n) (non-const) ๐Ÿชฃ๐Ÿ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> local_iterator
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::end (size_type __n)
    [inline]

Returns a read-only (constant) iterator pointing to one past the last bucket elements. Bucket-level business. ๐Ÿงบ

Parameters

  • __n โ€” The bucket index.

Returns

A read-only local iterator.


end (size_type __n) (const) ๐Ÿชฃ๐Ÿ๐Ÿ’œ

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

Returns a read-only (constant) iterator pointing to one past the last bucket elements. Same as above but const, she's consistent. ๐ŸŒˆ

Parameters

  • __n โ€” The bucket index.

Returns

A read-only local iterator.


equal_range (const key_type & __x) (non-const) ๐ŸŽฏ

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

Finds a subsequence matching given key. ๐Ÿ“

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 multisets. So like... it's here, it works, but bestie it's not really for us. ๐Ÿคท

equal_range (const key_type & __x) (const) ๐ŸŽฏ๐Ÿ’œ

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

Finds a subsequence matching given key. Const edition, she's the same girl in a different outfit. ๐ŸŒธ

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 multisets. Again. Noted. ๐Ÿ™ˆ

erase (const key_type & __x) โœ‚๏ธ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> size_type
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::erase (const
    key_type & __x) [inline]

Erases elements according to the provided key. Bye byeeee ๐Ÿ‘‹

Parameters

  • __x โ€” Key of element to be erased.

Returns

The number of elements erased.

This function erases all the elements located by the given key from an unordered_set. For an unordered_set the result of this function can only be 0 (not present) or 1 (present).

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. Same warning, same energy, do not forget it. ๐Ÿ’€

erase (const_iterator __first, const_iterator __last) โœ‚๏ธโœ‚๏ธ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> iterator
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::erase
    (const_iterator __first, const_iterator __last) [inline]

Erases a [__first,__last) range of elements from an unordered_set. Range delete, the cleanup era. ๐Ÿงผ

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

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. ๐Ÿซถ

erase (const_iterator __position) โœ‚๏ธ๐Ÿ“

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> iterator
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::erase
    (const_iterator __position) [inline]

Erases an element from an unordered_set. Just the one. Targeted. ๐Ÿ’…

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

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. ๐Ÿ˜ญ

erase (iterator __position) โœ‚๏ธ๐Ÿ”ฅ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred =
    equal_to<_Value>, typename _Alloc = allocator<_Value>> iterator
    std::unordered_set< _Value, _Hash, _Pred, _Alloc >::erase (iterator
    __position) [inline]

Erases an element from an unordered_set. Yes this is the non-const twin, she's here too. ๐Ÿ‘‘

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

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 (const key_type & __x) (non-const) ๐Ÿ•ต๏ธโ€โ™€๏ธ

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

Tries to locate an element in an unordered_set. Detective mode activated. ๐Ÿ”Ž

Parameters

  • __x โ€” Element to be located.

Returns

Iterator pointing to 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. Found or not found, she'll let you know. ๐Ÿ’–


find (const key_type & __x) (const) ๐Ÿ•ต๏ธโ€โ™€๏ธ๐Ÿ’œ

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

Tries to locate an element in an unordered_set. Const detective, same case, different badge. ๐Ÿฆ‹

  • Parameters
    • __x โ€” the element you're trying to locate ๐Ÿ•ต๏ธโ€โ™€๏ธ
  • Returns
    • an iterator pointing at the element you were looking for, or end() if it's not there ๐Ÿ˜ญ

Okay so real talk: this one takes a key and goes hunting for the element that matches it. Match found? You get an iterator pointing right at your sought-after element. No match? You get the past-the-end iterator โ€” that's end() โ€” and you just have to deal with that emotionally. ๐Ÿ’€


get_allocator()

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
allocator_type std::unordered_set< _Value, _Hash, _Pred, _Alloc >::get_allocator () const [inline], [noexcept]

Hands you back the allocator object that this unordered_set is using. That's it, that's the whole vibe. ๐ŸŽ€


hash_function()

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
hasher std::unordered_set< _Value, _Hash, _Pred, _Alloc >::hash_function () const [inline]

Returns the hash functor object that your unordered_set was constructed with. The exact one. No substitutions. โœจ


insert() โ€” the range one ๐ŸŒˆ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
template<typename _InputIterator>
void std::unordered_set< _Value, _Hash, _Pred, _Alloc >::insert (_InputIterator __first, _InputIterator __last) [inline]

A template function that attempts to insert a whole range of elements. Bulk insertion, bestie, we love efficiency. ๐Ÿ’…

  • Parameters
    • __first โ€” iterator pointing to the start of the range you're inserting
    • __last โ€” iterator pointing to the end of the range

Complexity? Similar to that of the range constructor. (iykyk ๐Ÿ‘‘)


insert() โ€” the heterogeneous key one ๐Ÿฆ‹

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
template<__heterogeneous_hash_key< unordered_set > _Kt>
std::pair< iterator, bool > std::unordered_set< _Value, _Hash, _Pred, _Alloc >::insert (_Kt && __x) [inline]

Attempts to insert an element into the unordered_set.

  • Parameters
    • __x โ€” the element to be inserted
  • Returns
    • a pair, where the first element is an iterator pointing to the possibly-inserted element, and the second is a bool that's true if the element was actually inserted ๐Ÿ”ฅ

So here's the tea: this function attempts to insert an element. But an unordered_set runs on unique keys โ€” it's a no-duplicates zone, no cap โ€” so an element only gets inserted if it is not already present in the unordered_set. If it's already there, the insert simply does not happen. Periodt.

Insertion requires amortized constant time. โšก


insert() โ€” the const value_type& one ๐Ÿ“

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

Attempts to insert an element into the unordered_set.

  • Parameters
    • __x โ€” the element to be inserted
  • Returns
    • a pair, where the first element is an iterator pointing to the possibly-inserted element, and the second is a bool that's true if the element was actually inserted ๐Ÿ’–

Same story as above: unique keys only, so it only goes in if it isn't already chilling in there.

Insertion requires amortized constant time. โšก


insert() โ€” the hint + const value_type& one โœจ

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

Attempts to insert an element into the unordered_set.

  • Parameters
    • __hint โ€” an iterator that serves as a hint as to where the element should be inserted
    • __x โ€” the element to be inserted
  • Returns
    • an iterator that points to the element with key of __x โ€” which may or may not be the element you passed in ๐Ÿ‘€

This one genuinely does not care whether the insertion actually took place, which is why it does not return a boolean like the single-argument insert() does. Not its problem.

Note that the first parameter is only a hint, and it can potentially improve the performance of the insertion process. A bad hint would cause no gains in efficiency. So likeโ€ฆ try, bestie, but don't stress. ๐Ÿ™ˆ

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

Insertion requires amortized constant. โšก


insert() โ€” the hint + value_type&& one ๐Ÿงš

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
iterator std::unordered_set< _Value, _Hash, _Pred, _Alloc >::insert (const_iterator __hint, value_type && __x) [inline]

Attempts to insert an element into the unordered_set.

  • Parameters
    • __hint โ€” an iterator that serves as a hint as to where the element should be inserted
    • __x โ€” the element to be inserted
  • Returns
    • an iterator that points to the element with key of __x โ€” may or may not be the element passed in ๐Ÿ‘‘

Again: not concerned about whether the insertion took place, so no boolean, unlike the single-argument insert(). The first parameter is only a hint and can potentially improve performance โ€” a bad hint causes no gains in efficiency.

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

Insertion requires amortized constant. โšก


insert() โ€” the hint + heterogeneous key one ๐Ÿ’œ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
template<__heterogeneous_hash_key< unordered_set > _Kt>
iterator std::unordered_set< _Value, _Hash, _Pred, _Alloc >::insert (const_iterator , _Kt && __x) [inline]

Attempts to insert an element into the unordered_set.

  • Parameters
    • __hint โ€” an iterator that serves as a hint as to where the element should be inserted
    • __x โ€” the element to be inserted
  • Returns
    • an iterator that points to the element with key of __x โ€” may or may not be the element passed in ๐ŸŒธ

You already know the drill: it doesn't care whether the insertion happened, so no bool like the single-argument insert() gives you. The first parameter is only a hint and can potentially improve performance. A bad hint would cause no gains in efficiency.

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

Insertion requires amortized constant. โšก


insert() โ€” the initializer_list one ๐ŸŽ€

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
void std::unordered_set< _Value, _Hash, _Pred, _Alloc >::insert (initializer_list< value_type > __l) [inline]

Attempts to insert a list of elements into the unordered_set. Drop the whole list in at once, iconic behaviour honestly. โœจ

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

Complexity similar to that of the range constructor. ๐ŸŒˆ


insert() โ€” the value_type&& one ๐Ÿ”ฅ

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

Attempts to insert an element into the unordered_set.

  • Parameters
    • __x โ€” the element to be inserted
  • Returns
    • a pair, where the first element is an iterator that points to the possibly inserted element, and the second is a bool that is true if the element was actually inserted ๐Ÿซถ

Yep, unique keys again โ€” an element only gets inserted if it is not already present in the unordered_set.

Insertion requires amortized constant time. โšก


key_eq()

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
key_equal std::unordered_set< _Value, _Hash, _Pred, _Alloc >::key_eq () const [inline]

Returns the key comparison object that the unordered_set was constructed with. The literal one you gave it. ๐Ÿ’…


load_factor()

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
float std::unordered_set< _Value, _Hash, _Pred, _Alloc >::load_factor () const [inline], [noexcept]

Returns the average number of elements per bucket. That's the whole sentence, that's the whole function. ๐Ÿฆ‹


max_bucket_count()

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
size_type std::unordered_set< _Value, _Hash, _Pred, _Alloc >::max_bucket_count () const [inline], [noexcept]

Returns the maximum number of buckets this unordered_set can have. ๐Ÿ‘‘


max_load_factor() โ€” the getter ๐ŸŒธ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
float std::unordered_set< _Value, _Hash, _Pred, _Alloc >::max_load_factor () const [inline], [noexcept]

Returns a positive number that the unordered_set tries to keep the load factor less than or equal to. It's the ceiling it's always reaching for. ๐ŸŽ€


max_load_factor() โ€” the setter ๐Ÿงš

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
void std::unordered_set< _Value, _Hash, _Pred, _Alloc >::max_load_factor (float __z) [inline]

Change the unordered_set maximum load factor. New ceiling, who dis. โœจ

  • Parameters
    • __z โ€” the new maximum load factor

max_size()

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
size_type std::unordered_set< _Value, _Hash, _Pred, _Alloc >::max_size () const [inline], [noexcept]

Returns the maximum size of the unordered_set. Big numbers, bestie. ๐Ÿ’œ


operator= โ€” copy assignment ๐Ÿ’–

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
unordered_set & std::unordered_set< _Value, _Hash, _Pred, _Alloc >::operator= (const unordered_set< _Value, _Hash, _Pred, _Alloc > & ) [default]

Copy assignment operator. Defaulted, no drama. ๐Ÿซถ


operator= โ€” initializer_list assignment ๐ŸŒˆ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
unordered_set & std::unordered_set< _Value, _Hash, _Pred, _Alloc >::operator= (initializer_list< value_type > __l) [inline]

Unordered_set list assignment operator.

  • Parameters
    • __l โ€” an initializer_list

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

Note that the assignment completely changes the unordered_set and that the resulting unordered_set's size is the same as the number of elements assigned. Like, it does not merge. It replaces. Gone, replaced, new era. ๐Ÿ’€

operator= โ€” move assignment ๐Ÿ”ฅ

template<typename _Value, typename _Hash = hash<_Value>, typename _Pred = equal_to<_Value>, typename _Alloc = allocator<_Value>>
unordered_set & std::unordered_set< _Value, _Hash, _Pred, _Alloc >::operator= (unordered_set< _Value, _Hash, _Pred, _Alloc > && ) [default]

Move assignment operator. Defaulted, and yes it's giving main character energy. ๐Ÿ‘‘

  • rehash(size_type __n) โ€” bestie, this one may rehash the unordered_set. That "may" is doing a lot of heavy lifting, so listen up.

Parameters

  • __n โ€” the new number of buckets, periodt.

Okay so the tea: rehashing only happens if the new number of buckets respects the unordered_set's max load factor. That's it, that's the rule. Don't come for me if nothing visibly moves. ๐Ÿ’…

  • reserve(size_type __n) โ€” gets your unordered_set all prepped and cute for a specific number of elements. โœจ

Parameters

  • __n โ€” number of elements required.

And the math? Literally just this: same as rehash(ceil(n / max_load_factor())). No cap. ๐Ÿงฎ

  • size() โ€” const, [inline], [noexcept] โ€” returns the size of the unordered_set. That's it. That's the whole vibe. How many things are in there? Now you know. ๐Ÿ’–
  • swap(unordered_set< _Value, _Hash, _Pred, _Alloc > & __x) โ€” [inline], [noexcept] โ€” swaps data with another unordered_set. Trading places, main character style. ๐Ÿ”„

Parameters

  • __x โ€” an unordered_set of the same element and allocator types. (Same types only, bestie โ€” no mixing.)

This exchanges the elements between two sets in constant time. Constant. Time. We love an O(1) moment. ๐Ÿ‘‘

And note this lil detail: the global std::swap() function is specialized such that std::swap(s1,s2) will feed to this function. So you can just call it the normal way and it'll route itself here. Iconic behavior honestly.


๐ŸŒธ Author ๐ŸŒธ

Generated automatically by Doxygen for libstdc++ from the source code. So nobody hand-wrote this, it just appeared, fully formed, like a butterfly. ๐Ÿฆ‹


That's the whole page, bestie! ๐Ÿ’– This one's from libstdc++, and the page date is the same as always โ€” go check your local copy for the exact stamp, iykyk. 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