29 #ifndef _GLIBCXX_DEBUG_SET_H 30 #define _GLIBCXX_DEBUG_SET_H 1 37 namespace std _GLIBCXX_VISIBILITY(default)
42 template<
typename _Key,
typename _Compare = std::less<_Key>,
43 typename _Allocator = std::allocator<_Key> >
46 set<_Key, _Compare, _Allocator>, _Allocator,
47 __gnu_debug::_Safe_node_sequence>,
48 public _GLIBCXX_STD_C::set<_Key,_Compare,_Allocator>
50 typedef _GLIBCXX_STD_C::set<_Key, _Compare, _Allocator>
_Base;
58 template<
typename _ItT,
typename _SeqT,
typename _CatT>
59 friend class ::__gnu_debug::_Safe_iterator;
66 _Base_ref(
const _Base& __r) : _M_ref(__r) { }
73 typedef _Key key_type;
74 typedef _Key value_type;
75 typedef _Compare key_compare;
76 typedef _Compare value_compare;
77 typedef _Allocator allocator_type;
78 typedef typename _Base::reference reference;
79 typedef typename _Base::const_reference const_reference;
86 typedef typename _Base::size_type size_type;
87 typedef typename _Base::difference_type difference_type;
88 typedef typename _Base::pointer pointer;
89 typedef typename _Base::const_pointer const_pointer;
95 #if __cplusplus < 201103L 104 set(
const set&) =
default;
105 set(
set&&) =
default;
108 const _Compare& __comp = _Compare(),
109 const allocator_type& __a = allocator_type())
110 : _Base(__l, __comp, __a) { }
113 set(
const allocator_type& __a)
116 set(
const set& __x,
const __type_identity_t<allocator_type>& __a)
117 : _Base(__x, __a) { }
119 set(
set&& __x,
const __type_identity_t<allocator_type>& __a)
120 noexcept( noexcept(_Base(
std::move(__x), __a)) )
125 : _Base(__l, __a) { }
127 template<
typename _InputIterator>
128 set(_InputIterator __first, _InputIterator __last,
129 const allocator_type& __a)
131 __glibcxx_check_valid_constructor_range(__first, __last)),
134 #if __glibcxx_containers_ranges // C++ >= 23 139 template<std::__detail::__container_compatible_range<_Key> _Rg>
140 set(std::from_range_t __t, _Rg&& __rg,
142 const allocator_type& __a = allocator_type())
143 : _Base(__t, std::forward<_Rg>(__rg), __c, __a)
146 template<std::__detail::__container_compatible_range<_Key> _Rg>
147 set(std::from_range_t __t, _Rg&& __rg,
148 const allocator_type& __a = allocator_type())
149 : _Base(__t, std::forward<_Rg>(__rg), __a)
156 explicit set(
const _Compare& __comp,
157 const _Allocator& __a = _Allocator())
158 : _Base(__comp, __a) { }
160 template<
typename _InputIterator>
161 set(_InputIterator __first, _InputIterator __last,
162 const _Compare& __comp = _Compare(),
163 const _Allocator& __a = _Allocator())
165 __glibcxx_check_valid_constructor_range(__first, __last)),
170 : _Base(__x._M_ref) { }
172 #if __cplusplus >= 201103L 174 operator=(
const set&) =
default;
177 operator=(
set&&) =
default;
182 _Base::operator=(__l);
183 this->_M_invalidate_all();
188 using _Base::get_allocator;
192 begin() _GLIBCXX_NOEXCEPT
193 {
return iterator(_Base::begin(),
this); }
196 begin()
const _GLIBCXX_NOEXCEPT
197 {
return const_iterator(_Base::begin(),
this); }
200 end() _GLIBCXX_NOEXCEPT
201 {
return iterator(_Base::end(),
this); }
204 end()
const _GLIBCXX_NOEXCEPT
205 {
return const_iterator(_Base::end(),
this); }
208 rbegin() _GLIBCXX_NOEXCEPT
209 {
return reverse_iterator(end()); }
211 const_reverse_iterator
212 rbegin()
const _GLIBCXX_NOEXCEPT
213 {
return const_reverse_iterator(end()); }
216 rend() _GLIBCXX_NOEXCEPT
217 {
return reverse_iterator(begin()); }
219 const_reverse_iterator
220 rend()
const _GLIBCXX_NOEXCEPT
221 {
return const_reverse_iterator(begin()); }
223 #if __cplusplus >= 201103L 225 cbegin()
const noexcept
226 {
return const_iterator(_Base::begin(),
this); }
229 cend()
const noexcept
230 {
return const_iterator(_Base::end(),
this); }
232 const_reverse_iterator
233 crbegin()
const noexcept
234 {
return const_reverse_iterator(end()); }
236 const_reverse_iterator
237 crend()
const noexcept
238 {
return const_reverse_iterator(begin()); }
244 using _Base::max_size;
247 #if __cplusplus >= 201103L 248 template<
typename... _Args>
250 emplace(_Args&&... __args)
252 auto __res = _Base::emplace(std::forward<_Args>(__args)...);
253 return { { __res.first,
this }, __res.second };
256 template<
typename... _Args>
258 emplace_hint(const_iterator __pos, _Args&&... __args)
263 _Base::emplace_hint(__pos.
base(), std::forward<_Args>(__args)...),
270 insert(
const value_type& __x)
277 #if __cplusplus >= 201103L 279 insert(value_type&& __x)
281 auto __res = _Base::insert(
std::move(__x));
282 return { { __res.first,
this }, __res.second };
286 #ifdef __glibcxx_associative_heterogeneous_insertion 287 template <__heterogeneous_tree_key<set> _Kt>
291 auto __res = _Base::insert(std::forward<_Kt>(__x));
292 return { { __res.first,
this }, __res.second };
297 insert(const_iterator __position,
const value_type& __x)
300 return iterator(_Base::insert(__position.
base(), __x),
this);
303 #if __cplusplus >= 201103L 305 insert(const_iterator __position, value_type&& __x)
308 return { _Base::insert(__position.
base(),
std::move(__x)),
this };
312 #ifdef __glibcxx_associative_heterogeneous_insertion 313 template <__heterogeneous_tree_key<set> _Kt>
315 insert(const_iterator __position, _Kt&& __x)
318 auto __it = _Base::insert(__position.
base(), std::forward<_Kt>(__x));
319 return { __it,
this };
323 template <
typename _InputIterator>
325 insert(_InputIterator __first, _InputIterator __last)
328 __glibcxx_check_valid_range2(__first, __last, __dist);
330 if (__dist.
second >= __gnu_debug::__dp_sign)
331 _Base::insert(__gnu_debug::__unsafe(__first),
332 __gnu_debug::__unsafe(__last));
334 _Base::insert(__first, __last);
337 #if __cplusplus >= 201103L 340 { _Base::insert(__l); }
343 #ifdef __glibcxx_node_extract // >= C++17 && HOSTED 344 using node_type =
typename _Base::node_type;
348 extract(const_iterator __position)
352 return _Base::extract(__position.
base());
356 extract(
const key_type& __key)
358 const auto __position = find(__key);
359 if (__position != end())
360 return extract(__position);
364 # ifdef __glibcxx_associative_heterogeneous_erasure 365 template <__heterogeneous_tree_key<set> _Kt>
369 const auto __position = find(__key);
370 if (__position != end())
371 return extract(__position);
377 insert(node_type&& __nh)
379 auto __ret = _Base::insert(
std::move(__nh));
380 iterator __pos = iterator(__ret.position,
this);
381 return { __pos, __ret.inserted,
std::move(__ret.node) };
385 insert(const_iterator __hint, node_type&& __nh)
388 return { _Base::insert(__hint.
base(),
std::move(__nh)),
this };
394 #if __cplusplus >= 201103L 395 _GLIBCXX_ABI_TAG_CXX11
397 erase(const_iterator __position)
400 return { erase(__position.
base()),
this };
404 erase(_Base_const_iterator __position)
406 __glibcxx_check_erase2(__position);
408 return _Base::erase(__position);
412 erase(iterator __position)
416 _Base::erase(__position.
base());
421 erase(
const key_type& __x)
423 _Base_iterator __victim = _Base::find(__x);
424 if (__victim == _Base::end())
429 _Base::erase(__victim);
434 # ifdef __glibcxx_associative_heterogeneous_erasure 438 template <__heterogeneous_tree_key<set> _Kt>
442 auto __victims = _Base::equal_range(__x);
443 size_type __count = 0;
444 for (
auto __victim = __victims.first; __victim != __victims.second;)
447 _Base::erase(__victim++);
454 #if __cplusplus >= 201103L 455 _GLIBCXX_ABI_TAG_CXX11
457 erase(const_iterator __first, const_iterator __last)
462 for (_Base_const_iterator __victim = __first.
base();
463 __victim != __last.
base(); ++__victim)
465 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::cend(),
466 _M_message(__gnu_debug::__msg_valid_range)
467 ._M_iterator(__first,
"first")
468 ._M_iterator(__last,
"last"));
472 return { _Base::erase(__first.
base(), __last.
base()),
this };
476 erase(iterator __first, iterator __last)
481 for (_Base_iterator __victim = __first.
base();
482 __victim != __last.
base(); ++__victim)
484 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
485 _M_message(__gnu_debug::__msg_valid_range)
486 ._M_iterator(__first,
"first")
487 ._M_iterator(__last,
"last"));
490 _Base::erase(__first.
base(), __last.
base());
496 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
503 clear() _GLIBCXX_NOEXCEPT
505 this->_M_invalidate_all();
510 using _Base::key_comp;
511 using _Base::value_comp;
515 find(
const key_type& __x)
516 {
return iterator(_Base::find(__x),
this); }
521 find(
const key_type& __x)
const 522 {
return const_iterator(_Base::find(__x),
this); }
524 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 525 template<
typename _Kt,
527 typename __has_is_transparent<_Compare, _Kt>::type>
530 {
return { _Base::find(__x),
this }; }
532 template<
typename _Kt,
534 typename __has_is_transparent<_Compare, _Kt>::type>
536 find(
const _Kt& __x)
const 537 {
return { _Base::find(__x),
this }; }
543 lower_bound(
const key_type& __x)
544 {
return iterator(_Base::lower_bound(__x),
this); }
549 lower_bound(
const key_type& __x)
const 550 {
return const_iterator(_Base::lower_bound(__x),
this); }
552 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 553 template<
typename _Kt,
555 typename __has_is_transparent<_Compare, _Kt>::type>
557 lower_bound(
const _Kt& __x)
558 {
return { _Base::lower_bound(__x),
this }; }
560 template<
typename _Kt,
562 typename __has_is_transparent<_Compare, _Kt>::type>
564 lower_bound(
const _Kt& __x)
const 565 {
return { _Base::lower_bound(__x),
this }; }
569 upper_bound(
const key_type& __x)
570 {
return iterator(_Base::upper_bound(__x),
this); }
575 upper_bound(
const key_type& __x)
const 576 {
return const_iterator(_Base::upper_bound(__x),
this); }
578 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 579 template<
typename _Kt,
581 typename __has_is_transparent<_Compare, _Kt>::type>
583 upper_bound(
const _Kt& __x)
584 {
return { _Base::upper_bound(__x),
this }; }
586 template<
typename _Kt,
588 typename __has_is_transparent<_Compare, _Kt>::type>
590 upper_bound(
const _Kt& __x)
const 591 {
return { _Base::upper_bound(__x),
this }; }
595 equal_range(
const key_type& __x)
598 _Base::equal_range(__x);
599 return std::make_pair(iterator(__res.
first,
this),
600 iterator(__res.
second,
this));
606 equal_range(
const key_type& __x)
const 609 _Base::equal_range(__x);
610 return std::make_pair(const_iterator(__res.
first,
this),
611 const_iterator(__res.
second,
this));
614 #ifdef __glibcxx_generic_associative_lookup // C++ >= 14 615 template<
typename _Kt,
617 typename __has_is_transparent<_Compare, _Kt>::type>
619 equal_range(
const _Kt& __x)
621 auto __res = _Base::equal_range(__x);
622 return { { __res.first,
this }, { __res.second,
this } };
625 template<
typename _Kt,
627 typename __has_is_transparent<_Compare, _Kt>::type>
629 equal_range(
const _Kt& __x)
const 631 auto __res = _Base::equal_range(__x);
632 return { { __res.first,
this }, { __res.second,
this } };
637 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
640 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
643 #if __cpp_deduction_guides >= 201606 645 template<
typename _InputIterator,
648 typename _Allocator =
650 typename = _RequireInputIter<_InputIterator>,
651 typename = _RequireNotAllocator<_Compare>,
652 typename = _RequireAllocator<_Allocator>>
653 set(_InputIterator, _InputIterator,
654 _Compare = _Compare(), _Allocator = _Allocator())
656 _Compare, _Allocator>;
658 template<
typename _Key,
typename _Compare = less<_Key>,
659 typename _Allocator = allocator<_Key>,
660 typename = _RequireNotAllocator<_Compare>,
661 typename = _RequireAllocator<_Allocator>>
663 _Compare = _Compare(), _Allocator = _Allocator())
666 template<
typename _InputIterator,
typename _Allocator,
667 typename = _RequireInputIter<_InputIterator>,
668 typename = _RequireAllocator<_Allocator>>
669 set(_InputIterator, _InputIterator, _Allocator)
674 template<
typename _Key,
typename _Allocator,
675 typename = _RequireAllocator<_Allocator>>
676 set(initializer_list<_Key>, _Allocator)
679 #if __glibcxx_containers_ranges // C++ >= 23 680 template<ranges::input_range _Rg,
683 set(from_range_t, _Rg&&, _Compare = _Compare(), _Alloc = _Alloc())
684 ->
set<ranges::range_value_t<_Rg>, _Compare, _Alloc>;
686 template<ranges::input_range _Rg, __allocator_like _Alloc>
687 set(from_range_t, _Rg&&, _Alloc)
688 ->
set<ranges::range_value_t<_Rg>,
less<ranges::range_value_t<_Rg>>, _Alloc>;
690 #endif // deduction guides 692 template<
typename _Key,
typename _Compare,
typename _Allocator>
696 {
return __lhs._M_base() == __rhs._M_base(); }
698 #if __cpp_lib_three_way_comparison 699 template<
typename _Key,
typename _Compare,
typename _Alloc>
700 inline __detail::__synth3way_t<_Key>
703 {
return __lhs._M_base() <=> __rhs._M_base(); }
705 template<
typename _Key,
typename _Compare,
typename _Allocator>
709 {
return __lhs._M_base() != __rhs._M_base(); }
711 template<
typename _Key,
typename _Compare,
typename _Allocator>
713 operator<(const set<_Key, _Compare, _Allocator>& __lhs,
715 {
return __lhs._M_base() < __rhs._M_base(); }
717 template<
typename _Key,
typename _Compare,
typename _Allocator>
719 operator<=(const set<_Key, _Compare, _Allocator>& __lhs,
721 {
return __lhs._M_base() <= __rhs._M_base(); }
723 template<
typename _Key,
typename _Compare,
typename _Allocator>
727 {
return __lhs._M_base() >= __rhs._M_base(); }
729 template<
typename _Key,
typename _Compare,
typename _Allocator>
733 {
return __lhs._M_base() > __rhs._M_base(); }
734 #endif // three-way comparison 736 template<
typename _Key,
typename _Compare,
typename _Allocator>
740 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
741 {
return __x.swap(__y); }
#define __glibcxx_check_erase_range(_First, _Last)
#define __glibcxx_check_erase(_Position)
One of the comparison functors.
#define __glibcxx_check_insert(_Position)
ISO C++ entities toplevel namespace is std.
Class std::set with safety/checking/debug instrumentation.
Struct holding two objects of arbitrary type.
Safe class dealing with some allocator dependent operations.
Return type of insert(node_handle&&) on unique maps/sets.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Iterator & base() noexcept
Return the underlying iterator.
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
The standard allocator, as per C++03 [20.4.1].
_T2 second
The second member.
_T1 first
The first member.
constexpr _Iterator __base(_Iterator __it)
constexpr void _M_invalidate_if(_Predicate __pred) const
Traits class for iterators.