STD::SET(3)
π NAME π
okay so, welcome to the manual page for std::set< ..., _Alloc >(3) from the Library Functions Manual π
and ngl bestie, she's iconic. The actual full name is std::set< _Key, _Compare, _Alloc > and she is a standard container made up of unique keys, which can be retrieved in logarithmic time β¨ no cap, that's the whole flex.
πΈ SYNOPSIS πΈ
#include <set>
π Public Types
These are the public typedefs π«Ά (the little name tags every set carries around):
typedef _Key key_typeβ public typedef, it's literally just your_Keyπtypedef _Key value_typeβ public typedef. yes bestie, it's_Keyagain. same girl, different name.typedef _Compare key_compareβ public typedef, your_Compare.typedef _Compare value_compareβ public typedef, also your_Compare.typedef _Alloc allocator_typeβ public typedef, your_Allocπ
and then the iterator-related typedefs π¦ (the ones that make the iteration girlies thrive):
typedef _Alloc_traits::pointer pointerβ iterator-related typedeftypedef _Alloc_traits::const_pointer const_pointerβ iterator-related typedeftypedef _Alloc_traits::reference referenceβ iterator-related typedeftypedef _Alloc_traits::const_reference const_referenceβ iterator-related typedeftypedef _Rep_type::const_iterator iteratorβ iterator-related typedef. yes,iteratoris aconst_iteratorhere. it's giving "you can't touch my keys" energy π₯typedef _Rep_type::const_iterator const_iteratorβ iterator-related typedeftypedef _Rep_type::const_reverse_iterator reverse_iteratorβ iterator-related typedeftypedef _Rep_type::const_reverse_iterator const_reverse_iteratorβ iterator-related typedeftypedef _Rep_type::size_type size_typeβ iterator-related typedeftypedef _Rep_type::difference_type difference_typeβ iterator-related typedef
π¦ Public Member Functions
buckle up, there's a LOT of them, and I'm not skipping a single one π
set ()=defaultβ default constructor, creates no elements. empty girl, clean slate πΈtemplate<typename _InputIterator> set (_InputIterator __first, _InputIterator __last)β builds a set from a range π«Άtemplate<typename _InputIterator> set (_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())β also builds a set from a range, but now you're bringing your own__compand allocator β¨template<typename _InputIterator> set (_InputIterator __first, _InputIterator __last, const allocator_type &__a)β allocator-extended range constructor πset (const _Compare &__comp, const allocator_type &__a=allocator_type())β creates a set with no elements, but with your comparison object and allocator πset (const allocator_type &__a)β allocator-extended default constructor πset (const set &)=defaultβ set copy constructor. copying is self-care πset (const set &__x, const __type_identity_t< allocator_type > &__a)β allocator-extended copy constructor π¦set (initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type())β builds a set from aninitializer_listβset (initializer_list< value_type > __l, const allocator_type &__a)β allocator-extended initializer-list constructor πset (set &&)=defaultβ set move constructor. she's moving out, and she's taking the vibes with her π¨set (set &&__x, const __type_identity_t< allocator_type > &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal())β allocator-extended move constructor, with thenoexceptcondition copied exactly, no cap π₯~set ()=defaultβ destructor πiterator begin () const noexceptiterator cbegin () const noexceptiterator cend () const noexceptvoid clear () noexceptreverse_iterator crbegin () const noexceptreverse_iterator crend () const noexcepttemplate<typename... _Args> std::pair< iterator, bool > emplace (_Args &&... __args)β attempts to build and insert an element into the set π«Άtemplate<typename... _Args> iterator emplace_hint (const_iterator __pos, _Args &&... __args)β attempts to insert an element into the set, with a hint about where πbool empty () const noexceptβ returnstrueif the set is empty πΈiterator end () const noexceptsize_type erase (const key_type &__x)β erases elements according to the provided key. bye bestie πiterator erase (const_iterator __first, const_iterator __last)β erases a[__first,__last)range of elements from a set β¨iterator erase (const_iterator __position)β erases an element from a set π¦allocator_type get_allocator () const noexceptβ returns the allocator object with which the set was constructed πtemplate<typename _InputIterator> void insert (_InputIterator __first, _InputIterator __last)β a template function that attempts to insert a range of elements πstd::pair< iterator, bool > insert (const value_type &__x)β attempts to insert an element into the set πvoid insert (initializer_list< value_type > __l)β attempts to insert a list of elements into the set βstd::pair< iterator, bool > insert (value_type &&__x)β (no description given, she's just here, being mysterious π)key_compare key_comp () constβ returns the comparison object with which the set was constructed πsize_type max_size () const noexceptβ returns the maximum size of the set π₯set & operator= (const set &)=defaultβ set assignment operator πset & operator= (initializer_list< value_type > __l)β set list assignment operator π«Άset & operator= (set &&)=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 (set &__x) noexcept(/*conditional */)β swaps data with another set. thenoexceptis conditional, exactly as written, don't come for me πvalue_compare value_comp () constβ returns the comparison object with which the set was constructed π
π« ...more Public Member Functions (yes there's a second batch, she's thorough)
iterator insert (const_iterator __position, const value_type &__x)β attempts to insert an element into the set π¦iterator insert (const_iterator __position, value_type &&__x)β attempts to insert an element into the 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_t._M_find_tr(__x), void(), true)β also finds whether an element with the given key exists, but templated π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 set< _K1, _C1, _A1 > &, const set< _K1, _C1, _A1 > &)template<typename _K1, typename _C1, typename _A1> bool operator== (const set< _K1, _C1, _A1 > &, const set< _K1, _C1, _A1 > &)
π Detailed Description π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>>
class std::set< _Key, _Compare, _Alloc >
so this is "a standard container made up of unique keys, which can be retrieved in logarithmic time." β¨ queen behaviour, honestly.
Since: C++98 π (she's been that girl since forever)
π 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 unique keys) π
Sets support bidirectional iterators π₯
π«Ά heads up bestie: the private tree data is declared exactly the same way forsetandmultiset; the distinction is made entirely in how the tree functions are called (*_uniqueversus*_equal, same as the standard). so like, same tree, different attitude π
β¨ Member Typedef Documentation β¨
okay so these are the typedefs, bestie β the little aliases that make std::set go brrr. Every single one is here, no skips, periodt. π
allocator_typeβ public typedef energy β¨
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Alloc std::set< _Key, _Compare, _Alloc >::allocator_type
Public typedefs. π
const_iteratorβ iterator-related, no cap π¦
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Rep_type::const_iterator std::set< _Key, _Compare, _Alloc >::const_iterator
Iterator-related typedefs. π
const_pointerβ pointer but make it const π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Alloc_traits::const_pointer std::set< _Key, _Compare, _Alloc >::const_pointer
Iterator-related typedefs. β¨
const_referenceβ reference but const, iconic π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Alloc_traits::const_reference std::set< _Key, _Compare, _Alloc >::const_reference
Iterator-related typedefs. π¦
const_reverse_iteratorβ reverse iterator but const π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Rep_type::const_reverse_iterator std::set< _Key, _Compare, _Alloc >::const_reverse_iterator
Iterator-related typedefs. π
difference_typeβ the difference type, fr fr π₯
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Rep_type::difference_type std::set< _Key, _Compare, _Alloc >::difference_type
Iterator-related typedefs. π
iteratorβ the iterator, main character energy π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Rep_type::const_iterator std::set< _Key, _Compare, _Alloc >::iterator
Iterator-related typedefs. β¨
key_compareβ public typedef, slay π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Compare std::set< _Key, _Compare, _Alloc >::key_compare
Public typedefs. π
key_typeβ the key type, periodt π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Key std::set< _Key, _Compare, _Alloc >::key_type
Public typedefs. π
pointerβ pointer vibes π¦
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Alloc_traits::pointer std::set< _Key, _Compare, _Alloc >::pointer
Iterator-related typedefs. β¨
referenceβ reference energy π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Alloc_traits::reference std::set< _Key, _Compare, _Alloc >::reference
Iterator-related typedefs. π
reverse_iteratorβ reverse iterator, no cap π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Rep_type::const_reverse_iterator std::set< _Key, _Compare, _Alloc >::reverse_iterator
Iterator-related typedefs. π¦
size_typeβ size type, iconic β
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Rep_type::size_type std::set< _Key, _Compare, _Alloc >::size_type
Iterator-related typedefs. π
value_compareβ public typedef, ate π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Compare std::set< _Key, _Compare, _Alloc >::value_compare
Public typedefs. β¨
value_typeβ the value type, bestie π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> typedef _Key std::set< _Key, _Compare, _Alloc >::value_type
Public typedefs. π
π οΈ Constructor & Destructor Documentation π οΈ
set()β the default constructor, bestie πΈ
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> std::set< _Key, _Compare, _Alloc >::set ()
[default] β Default constructor creates no elements. π
set(const _Compare & __comp, const allocator_type & __a = allocator_type())β creates a set with no elements π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> std::set< _Key, _Compare, _Alloc >::set (const _Compare & __comp, const allocator_type & __a = allocator_type())
[inline], [explicit] β Creates a set with no elements.
Parameters
__compβ Comparator to use.__aβ An allocator object. β¨
set(_InputIterator __first, _InputIterator __last)β range constructor, iconic π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> template<typename _InputIterator> std::set< _Key, _Compare, _Alloc >::set (_InputIterator __first, _InputIterator __last)
[inline] β Builds a set from a range.
Parameters
__firstβ An input iterator.__lastβ An input iterator.
Create a set 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)). β¨
set(_InputIterator __first, _InputIterator __last, const _Compare & __comp, const allocator_type & __a = allocator_type())β range constructor with extras π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> template<typename _InputIterator> std::set< _Key, _Compare, _Alloc >::set (_InputIterator __first, _InputIterator __last, const _Compare & __comp, const allocator_type & __a = allocator_type())
[inline] β Builds a set from a range.
Parameters
__firstβ An input iterator.__lastβ An input iterator.__compβ A comparison functor.__aβ An allocator object.
Create a set 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)). π¦
set(const set< _Key, _Compare, _Alloc > & )β copy constructor, slay π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> std::set< _Key, _Compare, _Alloc >::set (const set< _Key, _Compare, _Alloc > & )
[default] β Set copy constructor. Whether the allocator is copied depends on the allocator traits. π¦
set(set< _Key, _Compare, _Alloc > && )β move constructor, main character energy π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> std::set< _Key, _Compare, _Alloc >::set (set< _Key, _Compare, _Alloc > && )
[default] β Set move constructor The newly-created set contains the exact contents of the moved instance. The moved instance is a valid, but unspecified, set. π
set(initializer_list< value_type > __l, const _Compare & __comp = _Compare(), const allocator_type & __a = allocator_type())β initializer_list constructor, ate π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> std::set< _Key, _Compare, _Alloc >::set (initializer_list< value_type > __l, const _Compare & __comp = _Compare(), const allocator_type & __a = allocator_type())
[inline] β Builds a set from an initializer_list.
Parameters
__lβ An initializer_list.__compβ A comparison functor.__aβ An allocator object.
Create a set consisting of copies of the elements in the list. This is linear in N if the list is already sorted, and NlogN otherwise (where N is __l.size()). β¨
set(const allocator_type & __a)β allocator-extended default constructor π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> std::set< _Key, _Compare, _Alloc >::set (const allocator_type & __a)
[inline], [explicit] β Allocator-extended default constructor. π
set(const set< _Key, _Compare, _Alloc > & __x, const __type_identity_t< allocator_type > & __a)β allocator-extended copy constructor π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> std::set< _Key, _Compare, _Alloc >::set (const set< _Key, _Compare, _Alloc > & __x, const __type_identity_t< allocator_type > & __a)
[inline] β Allocator-extended copy constructor. π¦
set(set< _Key, _Compare, _Alloc > && __x, const __type_identity_t< allocator_type > & __a)β allocator-extended move constructor π₯
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> std::set< _Key, _Compare, _Alloc >::set (set< _Key, _Compare, _Alloc > && __x, const __type_identity_t< allocator_type > & __a)
[inline], [noexcept] β Allocator-extended move constructor. β¨
set(initializer_list< value_type > __l, const allocator_type & __a)β allocator-extended initialier-list constructor π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> std::set< _Key, _Compare, _Alloc >::set (initializer_list< value_type > __l, const allocator_type & __a)
[inline] β Allocator-extended initialier-list constructor. π
set(_InputIterator __first, _InputIterator __last, const allocator_type & __a)β allocator-extended range constructor π¦
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> template<typename _InputIterator> std::set< _Key, _Compare, _Alloc >::set (_InputIterator __first, _InputIterator __last, const allocator_type & __a)
[inline] β Allocator-extended range constructor. π
~set()β destructor, bye bestie π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> std::set< _Key, _Compare, _Alloc >::~set ()
[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. π«Ά
π Member Function Documentation π
begin() constβ first element energy β¨
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> iterator std::set< _Key, _Compare, _Alloc >::begin () const
[inline], [noexcept] β Returns a read-only (constant) iterator that points to the first element in the set. Iteration is done in ascending order according to the keys. π
cbegin() constβ const first element, no cap π¦
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> iterator std::set< _Key, _Compare, _Alloc >::cbegin () const
[inline], [noexcept] β Returns a read-only (constant) iterator that points to the first element in the set. Iteration is done in ascending order according to the keys. β¨
cend() constβ one past the last, iconic π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> iterator std::set< _Key, _Compare, _Alloc >::cend () const
[inline], [noexcept] β Returns a read-only (constant) iterator that points one past the last element in the set. Iteration is done in ascending order according to the keys. π
clear()β erase everything, periodt π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> void std::set< _Key, _Compare, _Alloc >::clear ()
[inline], [noexcept] β Erases all elements in a set. 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. π«Ά
contains(const _Kt & __x) constβ does it exist? bestie check π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> template<typename _Kt> auto std::set< _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 an element with the specified key. β¨
contains(const key_type & __x) constβ same vibe, different signature π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> bool std::set< _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 an element with the specified key. π¦
count(const key_type & __x) constβ count 'em π₯
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> size_type std::set< _Key, _Compare, _Alloc >::count (const key_type & __x) const
[inline] β Finds the number of elements.
Parameters
__xβ Element to located.
Returns
- Number of elements with specified key.
This function only makes sense for multisets; for set the result will either be 0 (not present) or 1 (present). π
crbegin() constβ last element reverse energy π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc = std::allocator<_Key>> reverse_iterator std::set< _Key, _Compare, _Alloc >::crbegin () const
[inline], [noexcept] β Returns a read-only (constant) iterator that points to the last element in the set. Iteration is done in descending order according to the keys. π
crend π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> reverse_iterator std::set< _Key, _Compare,
_Alloc >::crend () const [inline], [noexcept]
Okay so this one hands you a read-only (constant) reverse iterator that points to the last pair in the set. Iteration is done in descending order according to the keys. It's giving reverse main character energy, fr. β¨
emplace π οΈ
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> template<typename... _Args> std::pair< iterator,
bool > std::set< _Key, _Compare, _Alloc >::emplace (_Args &&... __args)
[inline]
Attempts to build and insert an element into the set. Like, it's trying its best.
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 set. A set relies on unique keys and thus an element is only inserted if it is not already present in the set. No duplicates, periodt.
Insertion requires logarithmic time. π
emplace_hint π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> template<typename... _Args> iterator std::set<
_Key, _Compare, _Alloc >::emplace_hint (const_iterator __pos, _Args
&&... __args) [inline]
Attempts to insert an element into the set.
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 don't just throw any old iterator in there, bestie. π
For more on hinting, see: https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
Insertion requires logarithmic time (if the hint is not taken). β³
empty π«
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> bool std::set< _Key, _Compare, _Alloc >::empty
() const [inline], [nodiscard], [noexcept]
Returns true if the set is empty. That's it. That's the vibe check. β¨
end π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> iterator std::set< _Key, _Compare, _Alloc >::end
() const [inline], [noexcept]
Returns a read-only (constant) iterator that points one past the last element in the set. Iteration is done in ascending order according to the keys. Classic past-the-end behavior, no cap.
equal_range (non-const) π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> std::pair< iterator, iterator > std::set< _Key,
_Compare, _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 is equivalent to
std::make_pair(c.lower_bound(val),
c.upper_bound(val))
(but is faster than making the calls separately). Speed demon behavior. π
This function probably only makes sense for multisets. For a plain set? Eh, it's giving extra. π€·
equal_range (const) πβ¨
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> std::pair< const_iterator, const_iterator >
std::set< _Key, _Compare, _Alloc >::equal_range (const key_type & __x)
const [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 is equivalent to
std::make_pair(c.lower_bound(val),
c.upper_bound(val))
(but is faster than making the calls separately).
This function probably only makes sense for multisets. Again, just saying. π«Ά
erase (by key) π§Ή
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> size_type std::set< _Key, _Compare, _Alloc
>::erase (const key_type & __x) [inline]
Erases elements according to the provided key. Bye bestie. π
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 a 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. So like, don't expect it to clean up your new'd stuff. That's on you, babe. π
erase (range) ποΈ
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> iterator std::set< _Key, _Compare, _Alloc
>::erase (const_iterator __first, const_iterator __last) [inline]
Erases a [__first,__last) range of elements from a set. Half-open range, iconic.
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 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. Same pointer warning, same energy. π«
erase (single iterator) π―
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> iterator std::set< _Key, _Compare, _Alloc
>::erase (const_iterator __position) [inline]
Erases an element from a set.
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 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. You know the drill. π
find (non-const) π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> iterator std::set< _Key, _Compare, _Alloc
>::find (const key_type & __x) [inline]
Tries to locate an element in a set.
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. So either you find it or you get the end. Dramatic. π
find (const) πβ¨
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> const_iterator std::set< _Key, _Compare, _Alloc
>::find (const key_type & __x) const [inline]
Tries to locate an element in a set.
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. Same as above but const, so it's giving read-only mystery. π΅οΈ
get_allocator π§Ί
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> allocator_type std::set< _Key, _Compare, _Alloc
>::get_allocator () const [inline], [noexcept]
Returns the allocator object with which the set was constructed. It's the set's little memory manager bestie. β¨
insert (range) π₯
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> template<typename _InputIterator> void std::set<
_Key, _Compare, _Alloc >::insert (_InputIterator __first, _InputIterator
__last) [inline]
A template function that attempts to insert a range of elements.
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. So like, same vibe as construction. π
insert (single value) π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> std::pair< iterator, bool > std::set< _Key,
_Compare, _Alloc >::insert (const value_type & __x) [inline]
Attempts to insert an element into the set.
Parameters
__xβ Element to be inserted.
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 insert an element into the set. A set relies on unique keys and thus an element is only inserted if it is not already present in the set. No duplicates, no exceptions. Periodt.
Insertion requires logarithmic time. β³
Referenced by std::set< _Key, _Cmp, polymorphic_allocator< _Key > >::insert().
insert (hint + const value) πͺ
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> iterator std::set< _Key, _Compare, _Alloc
>::insert (const_iterator __position, const value_type & __x) [inline]
Attempts to insert an element into the set.
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 element with key of
__x(may or may not be the element passed in).
This function is not concerned about whether the insertion took place, and thus does not return a boolean like the single-argument insert() does. Note that the first parameter is only a hint and can potentially improve the performance of the insertion process. A bad hint would cause no gains in efficiency. So hint wisely, bestie. π§
For more on hinting, see: https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
If a heterogeneous key __k matches a range of elements, an iterator to the first is returned. Interesting. π
Insertion requires logarithmic time (if the hint is not taken).
insert (hint + rvalue) π
template<typename _Key, typename _Compare = std::less<_Key>, typename _Alloc
= std::allocator<_Key>> iterator std::set< _Key, _Compare, _Alloc
>::insert (const_iterator __position, value_type && __x) [inline]
Attempts to insert an element into the set.
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 element with key of
__x(may or may not be the element passed in).
π insert (the hinted one) π
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
iterator std::set< _Key, _Compare, _Alloc >::insert(const_iterator __position,
const value_type & __x)
okay so this one does not care whether the insertion actually happened or not β like, it's not gonna hand you a boolean back the way the single-argument insert() does. bestie just does the thing. π
also, heads up: that first parameter is only a hint. it can potentially make the insertion faster, but a bad hint gives you no gains in efficiency at all β so no pressure, it's not a promise, it's a vibe suggestion.
for more on hinting, see:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
if a heterogeneous key __k matches a range of elements, you get an iterator to the first one. π―
insertion needs logarithmic time (unless the hint gets taken, iykyk).
π₯ insert β but make it a whole list π₯
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
void std::set< _Key, _Compare, _Alloc >::insert(initializer_list< value_type > __l)
(marked [inline])
attempts to insert a list of elements into the set. yes queen, bulk insert. π
Parameters
__lβ astd::initializer_list<value_type>of the elements to be inserted.
Complexity β similar to that of the range constructor. slay, that's it. β¨
π key_comp π
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
key_compare std::set< _Key, _Compare, _Alloc >::key_comp() const
(marked [inline])
returns the comparison object that the set was constructed with. that's the whole thing, she's simple like that. π
πΈ lower_bound (the regular one) πΈ
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
iterator std::set< _Key, _Compare, _Alloc >::lower_bound(const key_type & __x)
(marked [inline])
finds the beginning of a subsequence matching the given key.
Parameters
__xβ key to be located.
Returns
- an iterator pointing to the first element equal to or greater than the key, or
end().
so basically: this returns the first element of a subsequence of elements that matches the given key. if that doesn't work out, you get an iterator pointing to the first element that has a greater value than the given key β or end() if no such element even exists. no cap. π
πΈ lower_bound β const edition πΈ
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
const_iterator std::set< _Key, _Compare, _Alloc >::lower_bound(const key_type & __x) const
(marked [inline])
finds the beginning of a subsequence matching the given key.
Parameters
__xβ key to be located.
Returns
- an iterator pointing to the first element equal to or greater than the key, or
end().
same deal as above, literally identical energy: returns the first element of a subsequence matching the given key, and if that fails you get the first element with a greater value than the given key, or end() if there's nothing there. π
π max_size π
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
size_type std::set< _Key, _Compare, _Alloc >::max_size() const
(marked [inline], [noexcept])
returns the maximum size of the set. big girl numbers only. π₯
π operator= (copy assignment) π
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
set & std::set< _Key, _Compare, _Alloc >::operator=(const set< _Key, _Compare, _Alloc > &)
(marked [default])
set assignment operator. whether the allocator gets copied depends on the allocator traits β so that part's not up to me, bestie. π«Ά
π operator= (list assignment) π
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
set & std::set< _Key, _Compare, _Alloc >::operator=(initializer_list< value_type > __l)
(marked [inline])
set list assignment operator. π
Parameters
__lβ aninitializer_list.
this function fills a set with copies of the elements in the initializer list __l.
β οΈ note that the assignment completely changes the set β like, fully new identity β and the resulting set's size is the same as the number of elements assigned. main character makeover energy, fr fr.
π operator= (move assignment) π
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
set & std::set< _Key, _Compare, _Alloc >::operator=(set< _Key, _Compare, _Alloc > &&)
(marked [default])
move assignment operator. she's moving, not copying. π«
π¦ rbegin π¦
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
reverse_iterator std::set< _Key, _Compare, _Alloc >::rbegin() const
(marked [inline], [noexcept])
returns a read-only (constant) iterator that points to the last element in the set. iteration is done in descending order according to the keys. so we're going backwards and we're thriving. πΊ
π¦ rend π¦
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
reverse_iterator std::set< _Key, _Compare, _Alloc >::rend() const
(marked [inline], [noexcept])
returns a read-only (constant) reverse iterator that points to the last pair in the set. iteration is done in descending order according to the keys. yes, same descending-order vibe as rbegin β they're a matching set, periodt. β¨
π size π
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
size_type std::set< _Key, _Compare, _Alloc >::size() const
(marked [inline], [noexcept])
returns the size of the set. how many besties are in the building. π
π swap π
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
void std::set< _Key, _Compare, _Alloc >::swap(set< _Key, _Compare, _Alloc > & __x)
(marked [inline], [noexcept])
swaps data with another set. π
Parameters
__xβ a set of the same element and allocator types.
this exchanges the elements between two sets in constant time. and like β 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. it's giving effortless. π
note that the global std::swap() function is specialized such that std::swap(s1,s2) will feed to this function. cute, right? π
whether the allocators are swapped depends on the allocator traits.
referenced by std::swap().
π upper_bound (the regular one) π
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
iterator std::set< _Key, _Compare, _Alloc >::upper_bound(const key_type & __x)
(marked [inline])
finds the end of a subsequence matching the given key.
Parameters
__xβ key to be located.
Returns
- an iterator pointing to the first element greater than the key, or
end().
π upper_bound β const edition π
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
const_iterator std::set< _Key, _Compare, _Alloc >::upper_bound(const key_type & __x) const
(marked [inline])
finds the end of a subsequence matching the given key.
Parameters
__xβ key to be located.
Returns
- an iterator pointing to the first element greater than the key, or
end().
yep, exact same energy as the non-const one. the const girlies get the same deal. π
π value_comp π
template<typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key>>
value_compare std::set< _Key, _Compare, _Alloc >::value_comp() const
(marked [inline])
returns the comparison object that the set was constructed with. she and key_comp are twinning, honestly. β¨
βοΈ Author βοΈ
generated automatically by Doxygen for libstdc++ from the source code. so like, not a human author, just a robot doing its little thing and honestly? slay. π€π
and that's a wrap on std::set< ..., _Alloc >(3), bestie!! π you made it all the way to the end of the page, which is main character energy for real. this page came to you from libstdc++ and it's filed under std::set< ..., _Alloc >(3) in section 3 β go forth and insert 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