60#if __cplusplus >= 201103L
63#if __glibcxx_containers_ranges
68namespace std _GLIBCXX_VISIBILITY(default)
70_GLIBCXX_BEGIN_NAMESPACE_VERSION
71_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
73 template<
typename _Key,
typename _Compare,
typename _Alloc>
98 template<
typename _Key,
typename _Compare = std::less<_Key>,
99 typename _Alloc = std::allocator<_Key> >
102#ifdef _GLIBCXX_CONCEPT_CHECKS
104 typedef typename _Alloc::value_type _Alloc_value_type;
105# if __cplusplus < 201103L
106 __glibcxx_class_requires(_Key, _SGIAssignableConcept)
108 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
109 _BinaryFunctionConcept)
110 __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
113#if __cplusplus >= 201103L
115 "std::set must have a non-const, non-volatile value_type");
116# if __cplusplus > 201703L || defined __STRICT_ANSI__
118 "std::set must have the same value_type as its allocator");
135 rebind<_Key>::other _Key_alloc_type;
137 typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
146 typedef typename _Alloc_traits::pointer
pointer;
153 typedef typename _Rep_type::const_iterator
iterator;
161#ifdef __glibcxx_node_extract
162 using node_type =
typename _Rep_type::node_type;
163 using insert_return_type =
typename _Rep_type::insert_return_type;
170#if __cplusplus < 201103L
182 set(
const _Compare& __comp,
184 : _M_t(__comp, _Key_alloc_type(__a)) { }
196 template<
typename _InputIterator>
197 set(_InputIterator __first, _InputIterator __last)
199 { _M_t._M_insert_range_unique(__first, __last); }
213 template<
typename _InputIterator>
214 set(_InputIterator __first, _InputIterator __last,
215 const _Compare& __comp,
217 : _M_t(__comp, _Key_alloc_type(__a))
218 { _M_t._M_insert_range_unique(__first, __last); }
225#if __cplusplus < 201103L
250 const _Compare& __comp = _Compare(),
252 : _M_t(__comp, _Key_alloc_type(__a))
253 { _M_t._M_insert_range_unique(__l.begin(), __l.end()); }
258 : _M_t(_Key_alloc_type(__a)) { }
261 set(
const set& __x,
const __type_identity_t<allocator_type>& __a)
262 : _M_t(__x._M_t, _Key_alloc_type(__a)) { }
265 set(
set&& __x,
const __type_identity_t<allocator_type>& __a)
267 && _Alloc_traits::_S_always_equal())
268 : _M_t(
std::
move(__x._M_t), _Key_alloc_type(__a)) { }
272 : _M_t(_Key_alloc_type(__a))
273 { _M_t._M_insert_range_unique(__l.begin(), __l.end()); }
276 template<
typename _InputIterator>
277 set(_InputIterator __first, _InputIterator __last,
279 : _M_t(_Key_alloc_type(__a))
280 { _M_t._M_insert_range_unique(__first, __last); }
282#if __glibcxx_containers_ranges
287 template<__detail::__container_compatible_range<_Key> _Rg>
288 set(from_range_t, _Rg&& __rg,
289 const _Compare& __comp,
290 const _Alloc& __a = _Alloc())
291 : _M_t(__comp, _Key_alloc_type(__a))
295 template<__detail::__container_compatible_range<_Key> _Rg>
296 set(from_range_t, _Rg&& __rg,
const _Alloc& __a = _Alloc())
297 : _M_t(_Key_alloc_type(__a))
314#if __cplusplus < 201103L
343 _M_t._M_assign_unique(__l.begin(), __l.end());
353 {
return _M_t.key_comp(); }
357 {
return _M_t.key_comp(); }
370 {
return _M_t.begin(); }
378 end() const _GLIBCXX_NOEXCEPT
379 {
return _M_t.end(); }
388 {
return _M_t.rbegin(); }
397 {
return _M_t.rend(); }
399#if __cplusplus >= 201103L
407 {
return _M_t.begin(); }
416 {
return _M_t.end(); }
425 {
return _M_t.rbegin(); }
434 {
return _M_t.rend(); }
438 _GLIBCXX_NODISCARD
bool
440 {
return _M_t.empty(); }
445 {
return _M_t.size(); }
450 {
return _M_t.max_size(); }
467 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
468 { _M_t.swap(__x._M_t); }
471#if __cplusplus >= 201103L
485 template<
typename... _Args>
511 template<
typename... _Args>
515 return _M_t._M_emplace_hint_unique(__pos,
537 _M_t._M_insert_unique(__x);
541#if __cplusplus >= 201103L
551#ifdef __glibcxx_associative_heterogeneous_insertion
552 template <__heterogeneous_tree_key<set> _Kt>
556 auto [__left, __node] =_M_t._M_get_insert_unique_pos_tr(__k);
559 iterator __i = _M_t._M_emplace_here(
561 return { __i,
true };
592 {
return _M_t._M_insert_unique_(__position, __x); }
594#if __cplusplus >= 201103L
597 {
return _M_t._M_insert_unique_(__position,
std::move(__x)); }
600#ifdef __glibcxx_associative_heterogeneous_insertion
601 template <__heterogeneous_tree_key<set> _Kt>
603 insert(const_iterator __position, _Kt&& __k)
605 auto [__left, __node] =
606 _M_t._M_get_insert_hint_unique_pos_tr(__position, __k);
608 return _M_t._M_emplace_here(
625 template<
typename _InputIterator>
627 insert(_InputIterator __first, _InputIterator __last)
628 { _M_t._M_insert_range_unique(__first, __last); }
630#if __cplusplus >= 201103L
640 { this->
insert(__l.begin(), __l.end()); }
643#if __glibcxx_containers_ranges
650 template<__detail::__container_compatible_range<_Key> _Rg>
652 insert_range(_Rg&& __rg)
654 auto __first = ranges::begin(__rg);
655 const auto __last = ranges::end(__rg);
656 using _Rv = remove_cvref_t<ranges::range_reference_t<_Rg>>;
657 for (; __first != __last; ++__first)
658 if constexpr (is_same_v<_Rv, _Key>)
659 _M_t._M_insert_unique(*__first);
661 _M_t._M_emplace_unique(*__first);
665#ifdef __glibcxx_node_extract
668 extract(const_iterator __pos)
670 __glibcxx_assert(__pos !=
end());
671 return _M_t.extract(__pos);
677 {
return _M_t.extract(__x); }
679#ifdef __glibcxx_associative_heterogeneous_erasure
680 template <__heterogeneous_tree_key<set> _Kt>
683 {
return _M_t._M_extract_tr(__key); }
689 {
return _M_t._M_reinsert_node_unique(
std::move(__nh)); }
694 {
return _M_t._M_reinsert_node_hint_unique(__hint,
std::move(__nh)); }
696 template<
typename,
typename>
697 friend struct std::_Rb_tree_merge_helper;
699 template<
typename _Compare1>
703 using _Merge_helper = _Rb_tree_merge_helper<set, _Compare1>;
704 _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
707 template<
typename _Compare1>
712 template<
typename _Compare1>
714 merge(multiset<_Key, _Compare1, _Alloc>& __source)
716 using _Merge_helper = _Rb_tree_merge_helper<set, _Compare1>;
717 _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
720 template<
typename _Compare1>
722 merge(multiset<_Key, _Compare1, _Alloc>&& __source)
726#if __cplusplus >= 201103L
742 _GLIBCXX_ABI_TAG_CXX11
745 {
return _M_t.erase(__position); }
759 { _M_t.erase(__position); }
775 {
return _M_t._M_erase_unique(__x); }
777#ifdef __glibcxx_associative_heterogeneous_erasure
781 template <__heterogeneous_tree_key<set> _Kt>
784 {
return _M_t._M_erase_tr(__key); }
787#if __cplusplus >= 201103L
804 _GLIBCXX_ABI_TAG_CXX11
807 {
return _M_t.erase(__first, __last); }
823 { _M_t.erase(__first, __last); }
849 {
return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
851#ifdef __glibcxx_generic_associative_lookup
852 template<
typename _Kt>
854 count(
const _Kt& __x)
const
855 ->
decltype(_M_t._M_count_tr(__x))
856 {
return _M_t._M_count_tr(__x); }
860#if __cplusplus > 201703L
869 {
return _M_t.find(__x) != _M_t.end(); }
871 template<
typename _Kt>
874 ->
decltype(_M_t._M_find_tr(__x),
void(),
true)
875 {
return _M_t._M_find_tr(__x) != _M_t.end(); }
895 {
return _M_t.find(__x); }
899 {
return _M_t.find(__x); }
901#ifdef __glibcxx_generic_associative_lookup
902 template<
typename _Kt>
905 ->
decltype(
iterator{_M_t._M_find_tr(__x)})
906 {
return iterator{_M_t._M_find_tr(__x)}; }
908 template<
typename _Kt>
910 find(
const _Kt& __x)
const
930 {
return _M_t.lower_bound(__x); }
934 {
return _M_t.lower_bound(__x); }
936#ifdef __glibcxx_generic_associative_lookup
937 template<
typename _Kt>
940 ->
decltype(
iterator(_M_t._M_lower_bound_tr(__x)))
941 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
943 template<
typename _Kt>
960 {
return _M_t.upper_bound(__x); }
964 {
return _M_t.upper_bound(__x); }
966#ifdef __glibcxx_generic_associative_lookup
967 template<
typename _Kt>
970 ->
decltype(
iterator(_M_t._M_upper_bound_tr(__x)))
971 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
973 template<
typename _Kt>
999 {
return _M_t.equal_range(__x); }
1003 {
return _M_t.equal_range(__x); }
1005#ifdef __glibcxx_generic_associative_lookup
1006 template<
typename _Kt>
1012 template<
typename _Kt>
1020 template<
typename _K1,
typename _C1,
typename _A1>
1024#if __cpp_lib_three_way_comparison
1025 template<
typename _K1,
typename _C1,
typename _A1>
1026 friend __detail::__synth3way_t<_K1>
1029 template<
typename _K1,
typename _C1,
typename _A1>
1035#if __cpp_deduction_guides >= 201606
1037 template<
typename _InputIterator,
1040 typename _Allocator =
1042 typename = _RequireInputIter<_InputIterator>,
1043 typename = _RequireNotAllocator<_Compare>,
1044 typename = _RequireAllocator<_Allocator>>
1045 set(_InputIterator, _InputIterator,
1046 _Compare = _Compare(), _Allocator = _Allocator())
1048 _Compare, _Allocator>;
1050 template<
typename _Key,
typename _Compare = less<_Key>,
1051 typename _Allocator = allocator<_Key>,
1052 typename = _RequireNotAllocator<_Compare>,
1053 typename = _RequireAllocator<_Allocator>>
1055 _Compare = _Compare(), _Allocator = _Allocator())
1058 template<
typename _InputIterator,
typename _Allocator,
1059 typename = _RequireInputIter<_InputIterator>,
1060 typename = _RequireAllocator<_Allocator>>
1061 set(_InputIterator, _InputIterator, _Allocator)
1066 template<
typename _Key,
typename _Allocator,
1067 typename = _RequireAllocator<_Allocator>>
1071#if __glibcxx_containers_ranges
1074 __allocator_like _Alloc = std::allocator<ranges::range_value_t<_Rg>>>
1075 set(from_range_t, _Rg&&, _Compare = _Compare(), _Alloc = _Alloc())
1078 template<ranges::input_range _Rg, __allocator_like _Alloc>
1079 set(from_range_t, _Rg&&, _Alloc)
1094 template<
typename _Key,
typename _Compare,
typename _Alloc>
1098 {
return __x._M_t == __y._M_t; }
1100#if __cpp_lib_three_way_comparison
1115 template<
typename _Key,
typename _Compare,
typename _Alloc>
1116 inline __detail::__synth3way_t<_Key>
1117 operator<=>(
const set<_Key, _Compare, _Alloc>& __x,
1118 const set<_Key, _Compare, _Alloc>& __y)
1119 {
return __x._M_t <=> __y._M_t; }
1132 template<
typename _Key,
typename _Compare,
typename _Alloc>
1136 {
return __x._M_t < __y._M_t; }
1139 template<
typename _Key,
typename _Compare,
typename _Alloc>
1143 {
return !(__x == __y); }
1146 template<
typename _Key,
typename _Compare,
typename _Alloc>
1150 {
return __y < __x; }
1153 template<
typename _Key,
typename _Compare,
typename _Alloc>
1157 {
return !(__y < __x); }
1160 template<
typename _Key,
typename _Compare,
typename _Alloc>
1164 {
return !(__x < __y); }
1168 template<
typename _Key,
typename _Compare,
typename _Alloc>
1171 _GLIBCXX_NOEXCEPT_IF(
noexcept(__x.swap(__y)))
1174_GLIBCXX_END_NAMESPACE_CONTAINER
1176#ifdef __glibcxx_node_extract
1178 template<
typename _Val,
typename _Cmp1,
typename _Alloc,
typename _Cmp2>
1180 _Rb_tree_merge_helper<_GLIBCXX_STD_C::set<_Val, _Cmp1, _Alloc>, _Cmp2>
1183 friend class _GLIBCXX_STD_C::set<_Val, _Cmp1, _Alloc>;
1186 _S_get_tree(_GLIBCXX_STD_C::set<_Val, _Cmp2, _Alloc>& __set)
1187 {
return __set._M_t; }
1190 _S_get_tree(_GLIBCXX_STD_C::multiset<_Val, _Cmp2, _Alloc>& __set)
1191 {
return __set._M_t; }
1195_GLIBCXX_END_NAMESPACE_VERSION
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs are equal iff their members are equal.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
is_nothrow_copy_constructible
The standard allocator, as per C++03 [20.4.1].
One of the comparison functors.
Struct holding two objects (or references) of arbitrary type.
_T1 first
The first member.
_T2 second
The second member.
A standard container made up of unique keys, which can be retrieved in logarithmic time.
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.
bool contains(const key_type &__x) const
Finds whether an element with the given key exists.
set(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())
Builds a set from a range.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [__first,__last) range of elements from a set.
size_type count(const key_type &__x) const
Finds the number of elements.
_Rep_type::difference_type difference_type
set & operator=(initializer_list< value_type > __l)
Set list assignment operator.
set(set &&)=default
Set move constructor
void swap(set &__x) noexcept(/*conditional */)
Swaps data with another set.
value_compare value_comp() const
Returns the comparison object with which the set was constructed.
iterator cbegin() const noexcept
polymorphic_allocator< _Key > allocator_type
_Rep_type::const_iterator const_iterator
_Alloc_traits::const_pointer const_pointer
auto contains(const _Kt &__x) const -> decltype(_M_t._M_find_tr(__x), void(), true)
Finds whether an element with the given key exists.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
iterator erase(const_iterator __position)
Erases an element from a set.
const_iterator upper_bound(const key_type &__x) const
Finds the end of a subsequence matching given key.
void insert(initializer_list< value_type > __l)
Attempts to insert a list of elements into the set.
set(_InputIterator __first, _InputIterator __last)
Builds a set from a range.
iterator cend() const noexcept
iterator insert(const_iterator __position, value_type &&__x)
Attempts to insert an element into the set.
iterator end() const noexcept
size_type max_size() const noexcept
Returns the maximum size of the set.
std::pair< iterator, bool > insert(const value_type &__x)
Attempts to insert an element into the set.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
_Alloc_traits::const_reference const_reference
set()=default
Default constructor creates no elements.
set(const allocator_type &__a)
Allocator-extended default constructor.
std::pair< iterator, bool > emplace(_Args &&... __args)
Attempts to build and insert an element into the set.
key_compare key_comp() const
Returns the comparison object with which the set was constructed.
reverse_iterator rbegin() const noexcept
_Alloc_traits::reference reference
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
reverse_iterator crbegin() const noexcept
set(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
_Alloc_traits::pointer pointer
size_type size() const noexcept
Returns the size of the set.
_Rep_type::const_reverse_iterator const_reverse_iterator
_Rep_type::const_iterator iterator
_Rep_type::const_reverse_iterator reverse_iterator
reverse_iterator crend() const noexcept
iterator insert(const_iterator __position, const value_type &__x)
Attempts to insert an element into the set.
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
set(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
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 an initializer_list.
allocator_type get_allocator() const noexcept
Returns the allocator object with which the set was constructed.
_Rep_type::size_type size_type
set(const set &)=default
Set copy constructor.
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Attempts to insert an element into the set.
set & operator=(const set &)=default
Set assignment operator.
iterator begin() const noexcept
set(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a set with no elements.
iterator find(const key_type &__x)
Tries to locate an element in a set.
set & operator=(set &&)=default
Move assignment operator.
bool empty() const noexcept
Returns true if the set is empty.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
const_iterator find(const key_type &__x) const
Tries to locate an element in a set.
reverse_iterator rend() const noexcept
A standard container made up of elements, which can be retrieved in logarithmic time.
Uniform interface to C++98 and C++11 allocators.
A range for which ranges::begin returns an input iterator.