STD::MULTISET(3)

πŸ’– NAME πŸ’–

std::multiset< _Key, _Compare, _Alloc > β€” a standard container made up of elements, which can be retrieved in logarithmic time. It's from the Library Functions Manual, section 3, iykyk. πŸ’…


✨ SYNOPSIS ✨

okay so first thing, bestie, you gotta include the header:

#include <set>

πŸŽ€ Public Types πŸŽ€

the types are giving:

  • typedef _Alloc allocator_type
  • typedef _Rep_type::const_iterator const_iterator
  • typedef _Alloc_traits::const_pointer const_pointer
  • typedef _Alloc_traits::const_reference const_reference
  • typedef _Rep_type::const_reverse_iterator const_reverse_iterator
  • typedef _Rep_type::difference_type difference_type
  • typedef _Rep_type::const_iterator iterator
  • typedef _Compare key_compare
  • typedef _Key key_type
  • typedef _Alloc_traits::pointer pointer
  • typedef _Alloc_traits::reference reference
  • typedef _Rep_type::const_reverse_iterator reverse_iterator
  • typedef _Rep_type::size_type size_type
  • typedef _Compare value_compare
  • typedef _Key value_type

πŸ’… Public Member Functions πŸ’…

  • multiset()=default β€” default constructor, creates no elements, literally zero notes.
  • template<typename _InputIterator> multiset(_InputIterator __first, _InputIterator __last) β€” builds a multiset from a range.
  • template<typename _InputIterator> multiset(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type()) β€” builds a multiset from a range.
  • template<typename _InputIterator> multiset(_InputIterator __first, _InputIterator __last, const allocator_type &__a) β€” allocator-extended range constructor.
  • multiset(const _Compare &__comp, const allocator_type &__a=allocator_type()) β€” creates a multiset with no elements.
  • multiset(const allocator_type &__a) β€” allocator-extended default constructor.
  • multiset(const multiset &)=default β€” multiset copy constructor.
  • multiset(const multiset &__m, const __type_identity_t< allocator_type > &__a) β€” allocator-extended copy constructor.
  • multiset(initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type()) β€” builds a multiset from an initializer_list.
  • multiset(initializer_list< value_type > __l, const allocator_type &__a) β€” allocator-extended initialier-list constructor.
  • multiset(multiset &&)=default β€” multiset move constructor.
  • multiset(multiset &&__m, const __type_identity_t< allocator_type > &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal()) β€” allocator-extended move constructor.
  • ~multiset()=default
  • iterator begin() const noexcept
  • iterator cbegin() const noexcept
  • iterator cend() const noexcept
  • void clear() noexcept
  • reverse_iterator crbegin() const noexcept
  • reverse_iterator crend() const noexcept
  • template<typename... _Args> iterator emplace(_Args &&... __args) β€” builds and inserts an element into the multiset.
  • template<typename... _Args> iterator emplace_hint(const_iterator __pos, _Args &&... __args) β€” builds and inserts an element into the multiset.
  • bool empty() const noexcept β€” returns true if the set is empty.
  • iterator end() const noexcept
  • size_type erase(const key_type &__x) β€” erases elements according to the provided key.
  • iterator erase(const_iterator __first, const_iterator __last) β€” erases a [first,last) range of elements from a multiset.
  • iterator erase(const_iterator __position) β€” erases an element from a multiset.
  • allocator_type get_allocator() const noexcept β€” returns the memory allocation object.
  • template<typename _InputIterator> void insert(_InputIterator __first, _InputIterator __last) β€” a template function that tries to insert a range of elements.
  • iterator insert(const value_type &__x) β€” inserts an element into the multiset.
  • iterator insert(const_iterator __position, const value_type &__x) β€” inserts an element into the multiset.
  • iterator insert(const_iterator __position, value_type &&__x)
  • void insert(initializer_list< value_type > __l) β€” attempts to insert a list of elements into the multiset.
  • iterator insert(value_type &&__x)
  • key_compare key_comp() const β€” returns the comparison object.
  • size_type max_size() const noexcept β€” returns the maximum size of the set.
  • multiset & operator=(const multiset &)=default β€” multiset assignment operator.
  • multiset & operator=(initializer_list< value_type > __l) β€” multiset list assignment operator.
  • multiset & operator=(multiset &&)=default β€” move assignment operator.
  • reverse_iterator rbegin() const noexcept
  • reverse_iterator rend() const noexcept
  • size_type size() const noexcept β€” returns the size of the set.
  • void swap(multiset &__x) noexcept(/*conditional */) β€” swaps data with another multiset.
  • value_compare value_comp() const β€” returns the comparison object.

and the indented lookup besties:

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

🀝 Friends 🀝

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

πŸ“š Detailed Description πŸ“š

template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>>
class std::multiset< _Key, _Compare, _Alloc >

A standard container made up of elements, which can be retrieved in logarithmic time.

⏳ Since ⏳

C++98

🧩 Template Parameters 🧩

  • _Key β€” Type of key objects.
  • _Compare β€” Comparison function object type, defaults to less<_Key>.
  • _Alloc β€” Allocator type, defaults to allocator<_Key>.

Meets the requirements of a container, a reversible container, and an associative container (using equivalent keys). For a multiset<Key> the key_type and value_type are Key.

Multisets support bidirectional iterators.

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

πŸŽ€ Constructor & Destructor Documentation πŸŽ€

okay bestie, sit down, hydrate, put your phone on do-not-disturb πŸ“΅ because this is the origin story of your multiset and it is LONG. every single one of these is a real one. no skips. no cuts. periodt. πŸ’…


🍼 multiset () β€” the default constructor

template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
    = std::allocator<_Key>> std::multiset< _Key, _Compare, _Alloc
    >::multiset () [default]

Default constructor creates no elements. that's it. that's the whole function. an empty multiset, zero notes, immaculate silence, just vibes ✨


🧸 multiset (const _Compare & __comp, const allocator_type & __a = allocator_type())

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

Creates a multiset with no elements. yes bestie, still empty β€” but now you picked the rules it plays by. main character energy fr fr πŸ‘‘

Parameters

  • __comp β€” the comparator to use.
  • __a β€” an allocator object.
heads up, this one is [explicit], so no sneaky implicit conversions. it said what it said. πŸ™…β€β™€οΈ

🌈 range constructor (no comparator, no allocator)

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

Builds a multiset from a range. iconic behavior honestly.

Parameters

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

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

so like… if your data's already sorted, you're basically getting the fast pass at the club 🎟️ if not, NlogN, and you wait in line like everybody else.

🌸 range constructor (with comparator + allocator)

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

Builds a multiset from a range. yes, again, but this time with opinions.

Parameters

  • __first β€” an input iterator.
  • __last β€” an input iterator.
  • __comp β€” a comparison functor.
  • __a β€” an allocator object.

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


πŸ¦‹ copy constructor

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

Multiset copy constructor. Whether the allocator is copied depends on the allocator traits. that's the tea. 🍡 allocator traits decide, not me.


🧚 move constructor

template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
    = std::allocator<_Key>> std::multiset< _Key, _Compare, _Alloc
    >::multiset (multiset< _Key, _Compare, _Alloc > && ) [default]

Multiset move constructor. The newly-created multiset contains the exact contents of the moved instance. The moved instance is a valid, but unspecified multiset.

lowkey important: after the move, the old one is valid but unspecified. don't go asking it questions about its contents, it's going through something 😭

πŸŽ€ initializer_list constructor

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

Builds a multiset from an initializer_list. curly braces bestie, we love her 🫢

Parameters

  • __l β€” an initializer_list.
  • __comp β€” a comparison functor.
  • __a β€” an allocator object.

Create a multiset consisting of copies of the elements from the list. This is linear in N if the list is already sorted, and NlogN otherwise (where N is __l.size()).


πŸ“ allocator-extended default constructor

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

Allocator-extended default constructor. that's the entire description and honestly? it ate. short, sweet, allocator-forward. πŸ’…


🌟 allocator-extended copy constructor

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

Allocator-extended copy constructor. you're copying __m, but the allocator? yours. a whole glow-up πŸ’–


⭐ allocator-extended move constructor

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

Allocator-extended move constructor. and it's [noexcept] β€” meaning it will NOT throw at you. queen behavior, no drama, no exceptions, we stan 😌


🎁 allocator-extended initialier-list constructor

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

Allocator-extended initialier-list constructor. (yes the docs spell it "initialier", it's giving typo but we're not gonna be mean about it, the function still works πŸ˜­πŸ’€)


🧁 allocator-extended range constructor

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

Allocator-extended range constructor. range in, allocator on top, multiset out. chef's kiss πŸ‘¨β€πŸ³πŸ’‹


πŸ’€ destructor

template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
    = std::allocator<_Key>> std::multiset< _Key, _Compare, _Alloc
    >::~multiset () [default]

The dtor only erases the elements, and note that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

🚨 READ THIS TWICE BESTIE. the destructor does NOT free the things your pointers point at. if your multiset holds pointers, that memory is still out there, thriving, unreferenced, and yours to deal with. no cap.

✨ Member Function Documentation ✨

now the fun part. the actual doing stuff section. buckle up πŸ¦‹


🫢 begin () const

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

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

and it's [noexcept], so it's never gonna pop off and throw at you. reliable bestie energy. 🫢

πŸŽ€ cbegin () const

template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
    = std::allocator<_Key>> iterator std::multiset< _Key, _Compare, _Alloc
    >::cbegin () const [inline],  [noexcept]

Returns a read-only (constant) iterator that points to the first element in the multiset. Iteration is done in ascending order according to the keys. (same energy as begin, just with the const-coded name so everyone knows you're not touching anything πŸ’…)


🌸 cend () const

template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
    = std::allocator<_Key>> iterator std::multiset< _Key, _Compare, _Alloc
    >::cend () const [inline],  [noexcept]

Returns a read-only (constant) iterator that points one past the last element in the multiset. Iteration is done in ascending order according to the keys.

reminder that "one past the last element" is not a real element, it's the finish line 🏁 don't dereference it, that's undefined behavior territory and we don't go there.

🧼 clear ()

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

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

okay so clear() is the "we're starting over" button, but if your elements are pointers, the pointed-to memory is still sitting there. you still own that problem. πŸ™ˆ

πŸ” contains (const _Kt & __x) const

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

Finds whether an element with the given key exists.

Parameters

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

Returns

True if there is any element with the specified key.

look at that trailing return type bestie, decltype(_M_t._M_find_tr(__x), void(), true) β€” it's giving transparent comparator, it's giving template _Kt, it's giving range. πŸ”₯

πŸ“ contains (const key_type & __x) const

template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
    = std::allocator<_Key>> bool std::multiset< _Key, _Compare, _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.

yes it's the same description as the last one. yes there are two overloads. yes you should care. this one takes a plain key_type and returns a plain bool. simple. clean. ate. ✨

πŸ”’ count (const key_type & __x) const

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

Finds the number of elements with given key.

Parameters

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

Returns

Number of elements with specified key.

and THIS is the multiset flex. a std::set would only ever give you 0 or 1. a multiset? it can give you 7. it can give you 400. it's not here to gatekeep duplicates, it's here to count them. πŸ‘‘

πŸ¦‹ crbegin () const

template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
    = std::allocator<_Key>> reverse_iterator std::multiset< _Key, _Compare,
    _Alloc >::crbegin () const [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to the last element in the multiset. Iteration is done in descending order according to the keys.

going backwards but make it const and make it safe. [noexcept] too, obviously. she's consistent. πŸ’œ

🌈 crend () const

template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
    = std::allocator<_Key>> reverse_iterator std::multiset< _Key, _Compare,
    _Alloc >::crend () const [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to the last element in the multiset. Iteration is done in descending order according to the keys. (yes, the docs describe crend with the same words as crbegin β€” that's just how the page rolls, we're keeping it, no edits 😌)


πŸ› οΈ emplace (_Args &&... __args)

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

Builds and inserts an element into the multiset.

Parameters

  • __args β€” arguments used to generate the element instance to be inserted.

Returns

An iterator that points to the inserted element.

This function inserts an element into the multiset. Contrary to a std::set the multiset does not rely on unique keys and thus multiple copies of the same element can be inserted.

Insertion requires logarithmic time.

variadic template, perfect forwarding, in-place construction. this is the "no unnecessary copies" girlie and she is THRIVING. πŸ’…

🎯 emplace_hint (const_iterator __pos, _Args &&... __args)

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

Builds and inserts an element into the multiset.

Parameters

  • __pos β€” an iterator that serves as a hint as to where the element should be inserted.
  • __args β€” arguments used to generate the element instance to be inserted.

Returns

An iterator that points to the inserted element.

This function inserts an element into the multiset. Contrary to a std::set the multiset does not rely on unique keys and thus multiple copies of the same element can be inserted.

Note that the first parameter is only a hint and can potentially improve the performance of the insertion process. A bad hint would cause no gains in efficiency.

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

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

it's called a hint bestie, not a promise. drop a good one and you get a glow-up, drop a bad one and you get absolutely nothing. the container is unbothered. 😭

🌟 empty () const

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

Returns true if the set is empty.

it's [nodiscard] β€” so if you call it and just… throw the answer away? the compiler WILL call you out. don't ignore her. πŸ™ˆ (and yeah the docs say "set" there, we're all one big happy family here, it means the multiset πŸ’–)

🏁 end () const

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

Returns a read-only (constant) iterator that points one past the last element in the multiset. Iteration is done in ascending order according to the keys.

the classic begin/end duo. read-only, [noexcept], ascending. the way that it just works every single time. no notes. πŸ’œ

🌸 equal_range β€” the non-const glow-up

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

Bestie, this one finds a subsequence matching a given key. Like, it goes and gets you the whole lil squad of duplicates, not just one of them πŸ’…

Parameters

  • __x β€” the key to be located.

Returns

  • A pair of iterators that possibly points to the subsequence matching the given key.

This function is equivalent to

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

(but it's faster than making the calls separately β€” no cap, it cheats in the best way).

This function probably only makes sense for multisets. iykyk 🫢

πŸ¦‹ equal_range β€” const edition

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

Same exact vibe as above, just read-only β€” it finds a subsequence matching a given key ✨

Parameters

  • __x β€” the key to be located.

Returns

  • A pair of iterators that possibly points to the subsequence matching the given key.

Also equivalent to

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

(but faster than doing those calls separately, periodt).

This function probably only makes sense for multisets. πŸ’–

πŸ’€ erase β€” by key

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

Erases elements according to the provided key. It's giving clean slate for that one key 😭

Parameters

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

Returns

  • The number of elements erased.

This function erases all elements located by the given key from a multiset. 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 us πŸ™ˆ


🧚 erase β€” range edition

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

Erases a [first,last) range of elements from a multiset. Slice it, delete it, slay πŸ’…

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 a multiset. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. 🌈


πŸŽ€ erase β€” one single iterator

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

Erases an element from a multiset. Just the one. Targeted deletion, main character energy πŸ‘‘

Parameters

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

Returns

  • An iterator pointing to the element immediately following position prior to the element being erased. If no such element exists, end() is returned.

This function erases an element, pointed to by the given iterator, from a multiset. 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 β€” non-const

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

Tries to locate an element in a set. Detective mode activated πŸ”

Parameters

  • __x β€” element 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. So like, always check against end(), fr fr 😭


🌸 find β€” const edition

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

Tries to locate an element in a set, but make it const ✨

Parameters

  • __x β€” element 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. Same energy, different constness 🫢


πŸ’– get_allocator

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

Returns the memory allocation object. That's it, that's the whole function. Short king πŸ‘‘ (and it's noexcept, so it will not throw at you πŸ’…)


🌈 insert β€” the range one

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

A template function that tries to insert a range of elements. Bulk insert, bulk slay ✨

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 β€” single element

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

Inserts an element into the multiset πŸŽ€

Parameters

  • __x β€” element to be inserted.

Returns

  • An iterator that points to the inserted element.

This function inserts an element into the multiset. Contrary to a std::set the multiset does not rely on unique keys and thus multiple copies of the same element can be inserted. Duplicates? In THIS house? Yes bestie, we allow it πŸ’…

Insertion requires logarithmic time.

Referenced by std::multiset< _Key, _Cmp, polymorphic_allocator< _Key > >::insert().


πŸ’œ insert β€” with a hint

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

Inserts an element into the multiset, but this time you're dropping a lil hint about where it goes πŸ‘€

Parameters

  • __position β€” an iterator that serves as a hint as to where the element should be inserted.
  • __x β€” element to be inserted.

Returns

  • An iterator that points to the inserted element.

This function inserts an element into the multiset. Contrary to a std::set the multiset does not rely on unique keys and thus multiple copies of the same element can be inserted.

Note that the first parameter is only a hint and can potentially improve the performance of the insertion process. A bad hint would cause no gains in efficiency β€” so don't just guess, bestie 😭

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

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


πŸ“ insert β€” initializer list

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

Attempts to insert a list of elements into the multiset. Curly braces go brrr πŸŽ€

Parameters

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

Complexity similar to that of the range constructor.


🧚 key_comp

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

Returns the comparison object. The little guy doing all the ordering. Respect him 🫢


⭐ lower_bound β€” non-const

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

Finds the beginning of a subsequence matching given key. Like, the start of the duplicate parade ✨

Parameters

  • __x β€” key to be located.

Returns

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

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


🌸 lower_bound β€” const edition

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

Finds the beginning of a subsequence matching given key, but read-only πŸ’œ

Parameters

  • __x β€” key to be located.

Returns

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

This function returns the first element of a subsequence of elements that matches the given key. If unsuccessful it returns an iterator pointing to the first element that has a greater value than given key or end() if no such element exists. Same facts, const vibes 🌈


πŸ’… max_size

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

Returns the maximum size of the set. The ceiling. The limit. The absolute most 😌 And yes, it's [noexcept] so it's not about to throw hands πŸ’–


πŸŽ€ operator= β€” copy assignment

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

Multiset assignment operator. Whether the allocator is copied depends on the allocator traits. Yes bestie, the allocator has opinions about being copied πŸ™ˆ


πŸ¦‹ operator= β€” from an initializer list

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

Multiset list assignment operator ✨

Parameters

  • __l β€” an initializer_list.

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

Note that the assignment completely changes the multiset and that the resulting multiset's size is the same as the number of elements assigned. It's a full glow-up, not a touch-up πŸ’…


πŸ’œ operator= β€” move assignment

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

Move assignment operator. Snatch it and go πŸƒβ™€οΈπŸ’¨


πŸ”₯ rbegin

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

Returns a read-only (constant) reverse iterator that points to the last element in the multiset. Iteration is done in descending order according to the keys β€” so it's the whole multiset walking backwards, serving looks 🫢✨

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

okay bestie, this one hands you a read-only (constant) reverse iterator that points at the last element in the multiset. iteration goes in descending order according to the keys. periodt. πŸ’…

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

gives you the size of the set. that's the whole vibe. no cap. ✨

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

swaps data with another multiset. πŸ’–

Parameters

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

this exchanges the elements between two multisets in constant time. (it's literally only swapping a pointer, an integer, and an instance of the Compare type β€” which itself is often stateless and empty β€” so it should be quite fast, slay.) note that the global std::swap() function is specialized so that std::swap(s1,s2) will feed into this function. whether the allocators are swapped depends on the allocator traits. also referenced by std::swap(). πŸ”₯

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

finds the end of a subsequence matching a given key. πŸ¦‹

Parameters

  • __x β€” key to be located.

Returns

  • iterator pointing to the first element greater than key, or end().
   template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
       = std::allocator<_Key>> const_iterator std::multiset< _Key, _Compare,
       _Alloc >::upper_bound (const key_type & __x) const [inline]

same energy, but const: finds the end of a subsequence matching a given key. 🫢

Parameters

  • __x β€” key to be located.

Returns

  • iterator pointing to the first element greater than key, or end().
   template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
       = std::allocator<_Key>> value_compare std::multiset< _Key, _Compare,
       _Alloc >::value_comp () const [inline]

returns the comparison object. that's it. iconic. πŸ‘‘

✨ Author ✨

this page was generated automatically by Doxygen for libstdc++ from the source code. no human wrote this, it's a robot slay. πŸ€–πŸ’…


source/version: libstdc++; page: std::multi...e, _Alloc >(3); date: not listed, but you know it's iconic. bye bestie! πŸ’–βœ¨

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