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;
60 typedef _Key key_type;
61 typedef _Key value_type;
62 typedef _Compare key_compare;
63 typedef _Compare value_compare;
64 typedef _Allocator allocator_type;
65 typedef typename _Base::reference reference;
66 typedef typename _Base::const_reference const_reference;
73 typedef typename _Base::size_type size_type;
74 typedef typename _Base::difference_type difference_type;
75 typedef typename _Base::pointer pointer;
76 typedef typename _Base::const_pointer const_pointer;
82 #if __cplusplus < 201103L 95 const _Compare& __comp = _Compare(),
96 const allocator_type& __a = allocator_type())
97 :
_Base(__l, __comp, __a) { }
100 set(
const allocator_type& __a)
103 set(
const set& __x,
const allocator_type& __a)
104 :
_Base(__x, __a) { }
106 set(
set&& __x,
const allocator_type& __a)
107 noexcept( noexcept(
_Base(std::move(__x._M_base()), __a)) )
108 :
_Safe(std::move(__x._M_safe()), __a),
109 _Base(std::move(__x._M_base()), __a) { }
112 :
_Base(__l, __a) { }
114 template<
typename _InputIterator>
115 set(_InputIterator __first, _InputIterator __last,
116 const allocator_type& __a)
117 :
_Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
119 __gnu_debug::__base(__last), __a) { }
124 explicit set(
const _Compare& __comp,
125 const _Allocator& __a = _Allocator())
126 :
_Base(__comp, __a) { }
128 template<
typename _InputIterator>
129 set(_InputIterator __first, _InputIterator __last,
130 const _Compare& __comp = _Compare(),
131 const _Allocator& __a = _Allocator())
132 :
_Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
134 __gnu_debug::__base(__last),
140 #if __cplusplus < 201103L 142 operator=(
const set& __x)
144 this->_M_safe() = __x;
150 operator=(
const set&) =
default;
153 operator=(
set&&) =
default;
159 this->_M_invalidate_all();
164 using _Base::get_allocator;
168 begin() _GLIBCXX_NOEXCEPT
169 {
return iterator(_Base::begin(),
this); }
172 begin()
const _GLIBCXX_NOEXCEPT
176 end() _GLIBCXX_NOEXCEPT
177 {
return iterator(_Base::end(),
this); }
180 end()
const _GLIBCXX_NOEXCEPT
184 rbegin() _GLIBCXX_NOEXCEPT
188 rbegin()
const _GLIBCXX_NOEXCEPT
192 rend() _GLIBCXX_NOEXCEPT
196 rend()
const _GLIBCXX_NOEXCEPT
199 #if __cplusplus >= 201103L 201 cbegin()
const noexcept
205 cend()
const noexcept
209 crbegin()
const noexcept
213 crend()
const noexcept
220 using _Base::max_size;
223 #if __cplusplus >= 201103L 224 template<
typename... _Args>
226 emplace(_Args&&... __args)
228 auto __res = _Base::emplace(std::forward<_Args>(__args)...);
233 template<
typename... _Args>
239 std::forward<_Args>(__args)...),
245 insert(
const value_type& __x)
252 #if __cplusplus >= 201103L 254 insert(value_type&& __x)
257 = _Base::insert(std::move(__x));
267 return iterator(_Base::insert(__position.
base(), __x),
this);
270 #if __cplusplus >= 201103L 275 return iterator(_Base::insert(__position.
base(), std::move(__x)),
280 template <
typename _InputIterator>
282 insert(_InputIterator __first, _InputIterator __last)
285 __glibcxx_check_valid_range2(__first, __last, __dist);
287 if (__dist.
second >= __gnu_debug::__dp_sign)
288 _Base::insert(__gnu_debug::__unsafe(__first),
289 __gnu_debug::__unsafe(__last));
291 _Base::insert(__first, __last);
294 #if __cplusplus >= 201103L 297 { _Base::insert(__l); }
300 #if __cplusplus > 201402L 301 using node_type =
typename _Base::node_type;
302 using insert_return_type = _Node_insert_return<iterator, node_type>;
309 return _Base::extract(__position.
base());
313 extract(
const key_type& __key)
315 const auto __position = find(__key);
316 if (__position != end())
317 return extract(__position);
322 insert(node_type&& __nh)
324 auto __ret = _Base::insert(std::move(__nh));
326 return { __pos, __ret.inserted, std::move(__ret.node) };
333 return iterator(_Base::insert(__hint.
base(), std::move(__nh)),
this);
339 #if __cplusplus >= 201103L 353 _Base::erase(__position.
base());
358 erase(
const key_type& __x)
361 if (__victim == _Base::end())
366 _Base::erase(__victim);
371 #if __cplusplus >= 201103L 379 __victim != __last.
base(); ++__victim)
381 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
382 _M_message(__gnu_debug::__msg_valid_range)
383 ._M_iterator(__first,
"first")
384 ._M_iterator(__last,
"last"));
397 __victim != __last.
base(); ++__victim)
399 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
400 _M_message(__gnu_debug::__msg_valid_range)
401 ._M_iterator(__first,
"first")
402 ._M_iterator(__last,
"last"));
405 _Base::erase(__first.
base(), __last.
base());
411 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
418 clear() _GLIBCXX_NOEXCEPT
420 this->_M_invalidate_all();
425 using _Base::key_comp;
426 using _Base::value_comp;
430 find(
const key_type& __x)
431 {
return iterator(_Base::find(__x),
this); }
436 find(
const key_type& __x)
const 439 #if __cplusplus > 201103L 440 template<
typename _Kt,
442 typename __has_is_transparent<_Compare, _Kt>::type>
445 {
return { _Base::find(__x),
this }; }
447 template<
typename _Kt,
449 typename __has_is_transparent<_Compare, _Kt>::type>
451 find(
const _Kt& __x)
const 452 {
return { _Base::find(__x),
this }; }
458 lower_bound(
const key_type& __x)
459 {
return iterator(_Base::lower_bound(__x),
this); }
464 lower_bound(
const key_type& __x)
const 467 #if __cplusplus > 201103L 468 template<
typename _Kt,
470 typename __has_is_transparent<_Compare, _Kt>::type>
472 lower_bound(
const _Kt& __x)
473 {
return { _Base::lower_bound(__x),
this }; }
475 template<
typename _Kt,
477 typename __has_is_transparent<_Compare, _Kt>::type>
479 lower_bound(
const _Kt& __x)
const 480 {
return { _Base::lower_bound(__x),
this }; }
484 upper_bound(
const key_type& __x)
485 {
return iterator(_Base::upper_bound(__x),
this); }
490 upper_bound(
const key_type& __x)
const 493 #if __cplusplus > 201103L 494 template<
typename _Kt,
496 typename __has_is_transparent<_Compare, _Kt>::type>
498 upper_bound(
const _Kt& __x)
499 {
return { _Base::upper_bound(__x),
this }; }
501 template<
typename _Kt,
503 typename __has_is_transparent<_Compare, _Kt>::type>
505 upper_bound(
const _Kt& __x)
const 506 {
return { _Base::upper_bound(__x),
this }; }
510 equal_range(
const key_type& __x)
513 _Base::equal_range(__x);
521 equal_range(
const key_type& __x)
const 524 _Base::equal_range(__x);
529 #if __cplusplus > 201103L 530 template<
typename _Kt,
532 typename __has_is_transparent<_Compare, _Kt>::type>
534 equal_range(
const _Kt& __x)
536 auto __res = _Base::equal_range(__x);
537 return { { __res.first,
this }, { __res.second,
this } };
540 template<
typename _Kt,
542 typename __has_is_transparent<_Compare, _Kt>::type>
544 equal_range(
const _Kt& __x)
const 546 auto __res = _Base::equal_range(__x);
547 return { { __res.first,
this }, { __res.second,
this } };
552 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
555 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
558 #if __cpp_deduction_guides >= 201606 560 template<
typename _InputIterator,
563 typename _Allocator =
565 typename = _RequireInputIter<_InputIterator>,
566 typename = _RequireAllocator<_Allocator>>
567 set(_InputIterator, _InputIterator,
568 _Compare = _Compare(), _Allocator = _Allocator())
570 _Compare, _Allocator>;
572 template<
typename _Key,
typename _Compare = less<_Key>,
573 typename _Allocator = allocator<_Key>,
574 typename = _RequireAllocator<_Allocator>>
576 _Compare = _Compare(), _Allocator = _Allocator())
579 template<
typename _InputIterator,
typename _Allocator,
580 typename = _RequireInputIter<_InputIterator>,
581 typename = _RequireAllocator<_Allocator>>
582 set(_InputIterator, _InputIterator, _Allocator)
587 template<
typename _Key,
typename _Allocator,
588 typename = _RequireAllocator<_Allocator>>
594 template<
typename _Key,
typename _Compare,
typename _Allocator>
598 {
return __lhs._M_base() == __rhs._M_base(); }
600 template<
typename _Key,
typename _Compare,
typename _Allocator>
604 {
return __lhs._M_base() != __rhs._M_base(); }
606 template<
typename _Key,
typename _Compare,
typename _Allocator>
608 operator<(
const set<_Key, _Compare, _Allocator>& __lhs,
609 const set<_Key, _Compare, _Allocator>& __rhs)
610 {
return __lhs._M_base() < __rhs._M_base(); }
612 template<
typename _Key,
typename _Compare,
typename _Allocator>
614 operator<=(
const set<_Key, _Compare, _Allocator>& __lhs,
615 const set<_Key, _Compare, _Allocator>& __rhs)
616 {
return __lhs._M_base() <= __rhs._M_base(); }
618 template<
typename _Key,
typename _Compare,
typename _Allocator>
620 operator>=(
const set<_Key, _Compare, _Allocator>& __lhs,
621 const set<_Key, _Compare, _Allocator>& __rhs)
622 {
return __lhs._M_base() >= __rhs._M_base(); }
624 template<
typename _Key,
typename _Compare,
typename _Allocator>
626 operator>(
const set<_Key, _Compare, _Allocator>& __lhs,
627 const set<_Key, _Compare, _Allocator>& __rhs)
628 {
return __lhs._M_base() > __rhs._M_base(); }
630 template<
typename _Key,
typename _Compare,
typename _Allocator>
632 swap(set<_Key, _Compare, _Allocator>& __x,
633 set<_Key, _Compare, _Allocator>& __y)
634 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
635 {
return __x.swap(__y); }
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
One of the comparison functors.
Struct holding two objects of arbitrary type.
The standard allocator, as per [20.4].
#define __glibcxx_check_erase(_Position)
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
#define __glibcxx_check_insert(_Position)
ISO C++ entities toplevel namespace is std.
_Iterator & base() noexcept
Return the underlying iterator.
void _M_invalidate_if(_Predicate __pred)
#define __glibcxx_check_erase_range(_First, _Last)
_T1 first
second_type is the second bound type
A standard container made up of unique keys, which can be retrieved in logarithmic time.
Class std::set with safety/checking/debug instrumentation.
_T2 second
first is a copy of the first object
Safe class dealing with some allocator dependent operations.