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_typetypedef _Rep_type::const_iterator const_iteratortypedef _Alloc_traits::const_pointer const_pointertypedef _Alloc_traits::const_reference const_referencetypedef _Rep_type::const_reverse_iterator const_reverse_iteratortypedef _Rep_type::difference_type difference_typetypedef _Rep_type::const_iterator iteratortypedef _Compare key_comparetypedef _Key key_typetypedef _Alloc_traits::pointer pointertypedef _Alloc_traits::reference referencetypedef _Rep_type::const_reverse_iterator reverse_iteratortypedef _Rep_type::size_type size_typetypedef _Compare value_comparetypedef _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()=defaultiterator begin() const noexceptiterator cbegin() const noexceptiterator cend() const noexceptvoid clear() noexceptreverse_iterator crbegin() const noexceptreverse_iterator crend() const noexcepttemplate<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 noexceptsize_type erase(const key_type &__x)β erases elements according to the provided key.iterator erase(const_iterator __first, const_iterator __last)β erases a [first,last) range of elements from a 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 noexceptreverse_iterator rend() const noexceptsize_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 toless<_Key>._Allocβ Allocator type, defaults toallocator<_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β aninitializer_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 plainkey_typeand returns a plainbool. 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. astd::setwould only ever give you0or1. a multiset? it can give you7. it can give you400. 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 classicbegin/endduo. 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
positionprior 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β astd::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β aninitializer_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