61 #pragma GCC system_header 68 #if __cplusplus >= 201103L 71 #if __cplusplus > 201402L 75 namespace std _GLIBCXX_VISIBILITY(default)
77 _GLIBCXX_BEGIN_NAMESPACE_VERSION
79 #if __cplusplus > 201103L 80 # define __cpp_lib_generic_associative_lookup 201304 99 enum _Rb_tree_color { _S_red =
false, _S_black =
true };
101 struct _Rb_tree_node_base
103 typedef _Rb_tree_node_base* _Base_ptr;
104 typedef const _Rb_tree_node_base* _Const_Base_ptr;
106 _Rb_tree_color _M_color;
112 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
114 while (__x->_M_left != 0) __x = __x->_M_left;
118 static _Const_Base_ptr
119 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
121 while (__x->_M_left != 0) __x = __x->_M_left;
126 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
128 while (__x->_M_right != 0) __x = __x->_M_right;
132 static _Const_Base_ptr
133 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
135 while (__x->_M_right != 0) __x = __x->_M_right;
141 template<
typename _Key_compare>
142 struct _Rb_tree_key_compare
144 _Key_compare _M_key_compare;
146 _Rb_tree_key_compare()
147 _GLIBCXX_NOEXCEPT_IF(
148 is_nothrow_default_constructible<_Key_compare>::value)
152 _Rb_tree_key_compare(
const _Key_compare& __comp)
153 : _M_key_compare(__comp)
156 #if __cplusplus >= 201103L 158 _Rb_tree_key_compare(
const _Rb_tree_key_compare&) =
default;
160 _Rb_tree_key_compare(_Rb_tree_key_compare&& __x)
161 noexcept(is_nothrow_copy_constructible<_Key_compare>::value)
162 : _M_key_compare(__x._M_key_compare)
168 struct _Rb_tree_header
170 _Rb_tree_node_base _M_header;
171 size_t _M_node_count;
173 _Rb_tree_header() _GLIBCXX_NOEXCEPT
175 _M_header._M_color = _S_red;
179 #if __cplusplus >= 201103L 180 _Rb_tree_header(_Rb_tree_header&& __x) noexcept
182 if (__x._M_header._M_parent !=
nullptr)
186 _M_header._M_color = _S_red;
193 _M_move_data(_Rb_tree_header& __from)
195 _M_header._M_color = __from._M_header._M_color;
196 _M_header._M_parent = __from._M_header._M_parent;
197 _M_header._M_left = __from._M_header._M_left;
198 _M_header._M_right = __from._M_header._M_right;
199 _M_header._M_parent->_M_parent = &_M_header;
200 _M_node_count = __from._M_node_count;
208 _M_header._M_parent = 0;
209 _M_header._M_left = &_M_header;
210 _M_header._M_right = &_M_header;
215 template<
typename _Val>
216 struct _Rb_tree_node :
public _Rb_tree_node_base
218 typedef _Rb_tree_node<_Val>* _Link_type;
220 #if __cplusplus < 201103L 231 __gnu_cxx::__aligned_membuf<_Val> _M_storage;
235 {
return _M_storage._M_ptr(); }
239 {
return _M_storage._M_ptr(); }
243 _GLIBCXX_PURE _Rb_tree_node_base*
244 _Rb_tree_increment(_Rb_tree_node_base* __x)
throw ();
246 _GLIBCXX_PURE
const _Rb_tree_node_base*
247 _Rb_tree_increment(
const _Rb_tree_node_base* __x)
throw ();
249 _GLIBCXX_PURE _Rb_tree_node_base*
250 _Rb_tree_decrement(_Rb_tree_node_base* __x)
throw ();
252 _GLIBCXX_PURE
const _Rb_tree_node_base*
253 _Rb_tree_decrement(
const _Rb_tree_node_base* __x)
throw ();
255 template<
typename _Tp>
256 struct _Rb_tree_iterator
258 typedef _Tp value_type;
259 typedef _Tp& reference;
260 typedef _Tp* pointer;
262 typedef bidirectional_iterator_tag iterator_category;
263 typedef ptrdiff_t difference_type;
265 typedef _Rb_tree_iterator<_Tp> _Self;
266 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
267 typedef _Rb_tree_node<_Tp>* _Link_type;
269 _Rb_tree_iterator() _GLIBCXX_NOEXCEPT
273 _Rb_tree_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
278 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
281 operator->() const _GLIBCXX_NOEXCEPT
282 {
return static_cast<_Link_type
> (_M_node)->_M_valptr(); }
285 operator++() _GLIBCXX_NOEXCEPT
287 _M_node = _Rb_tree_increment(_M_node);
292 operator++(
int) _GLIBCXX_NOEXCEPT
295 _M_node = _Rb_tree_increment(_M_node);
300 operator--() _GLIBCXX_NOEXCEPT
302 _M_node = _Rb_tree_decrement(_M_node);
307 operator--(
int) _GLIBCXX_NOEXCEPT
310 _M_node = _Rb_tree_decrement(_M_node);
315 operator==(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
316 {
return __x._M_node == __y._M_node; }
319 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
320 {
return __x._M_node != __y._M_node; }
325 template<
typename _Tp>
326 struct _Rb_tree_const_iterator
328 typedef _Tp value_type;
329 typedef const _Tp& reference;
330 typedef const _Tp* pointer;
332 typedef _Rb_tree_iterator<_Tp> iterator;
334 typedef bidirectional_iterator_tag iterator_category;
335 typedef ptrdiff_t difference_type;
337 typedef _Rb_tree_const_iterator<_Tp> _Self;
338 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
339 typedef const _Rb_tree_node<_Tp>* _Link_type;
341 _Rb_tree_const_iterator() _GLIBCXX_NOEXCEPT
345 _Rb_tree_const_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
348 _Rb_tree_const_iterator(
const iterator& __it) _GLIBCXX_NOEXCEPT
349 : _M_node(__it._M_node) { }
352 _M_const_cast() const _GLIBCXX_NOEXCEPT
353 {
return iterator(const_cast<typename iterator::_Base_ptr>(_M_node)); }
357 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
360 operator->() const _GLIBCXX_NOEXCEPT
361 {
return static_cast<_Link_type
>(_M_node)->_M_valptr(); }
364 operator++() _GLIBCXX_NOEXCEPT
366 _M_node = _Rb_tree_increment(_M_node);
371 operator++(
int) _GLIBCXX_NOEXCEPT
374 _M_node = _Rb_tree_increment(_M_node);
379 operator--() _GLIBCXX_NOEXCEPT
381 _M_node = _Rb_tree_decrement(_M_node);
386 operator--(
int) _GLIBCXX_NOEXCEPT
389 _M_node = _Rb_tree_decrement(_M_node);
394 operator==(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
395 {
return __x._M_node == __y._M_node; }
398 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
399 {
return __x._M_node != __y._M_node; }
405 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
406 _Rb_tree_node_base* __x,
407 _Rb_tree_node_base* __p,
408 _Rb_tree_node_base& __header)
throw ();
411 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base*
const __z,
412 _Rb_tree_node_base& __header)
throw ();
414 #if __cplusplus >= 201402L 415 template<
typename _Cmp,
typename _SfinaeType,
typename = __
void_t<>>
416 struct __has_is_transparent
419 template<
typename _Cmp,
typename _SfinaeType>
420 struct __has_is_transparent<_Cmp, _SfinaeType,
421 __void_t<typename _Cmp::is_transparent>>
422 {
typedef void type; };
424 template<
typename _Cmp,
typename _SfinaeType>
425 using __has_is_transparent_t
426 =
typename __has_is_transparent<_Cmp, _SfinaeType>::type;
429 #if __cplusplus > 201402L 430 template<
typename _Tree1,
typename _Cmp2>
431 struct _Rb_tree_merge_helper { };
434 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
435 typename _Compare,
typename _Alloc = allocator<_Val> >
439 rebind<_Rb_tree_node<_Val> >::other _Node_allocator;
444 typedef _Rb_tree_node_base* _Base_ptr;
445 typedef const _Rb_tree_node_base* _Const_Base_ptr;
446 typedef _Rb_tree_node<_Val>* _Link_type;
447 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
452 struct _Reuse_or_alloc_node
454 _Reuse_or_alloc_node(_Rb_tree& __t)
455 : _M_root(__t._M_root()), _M_nodes(__t._M_rightmost()), _M_t(__t)
459 _M_root->_M_parent = 0;
461 if (_M_nodes->_M_left)
462 _M_nodes = _M_nodes->_M_left;
468 #if __cplusplus >= 201103L 469 _Reuse_or_alloc_node(
const _Reuse_or_alloc_node&) =
delete;
472 ~_Reuse_or_alloc_node()
473 { _M_t._M_erase(static_cast<_Link_type>(_M_root)); }
475 template<
typename _Arg>
477 #if __cplusplus < 201103L 478 operator()(
const _Arg& __arg)
480 operator()(_Arg&& __arg)
483 _Link_type __node =
static_cast<_Link_type
>(_M_extract());
486 _M_t._M_destroy_node(__node);
487 _M_t._M_construct_node(__node, _GLIBCXX_FORWARD(_Arg, __arg));
491 return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg));
501 _Base_ptr __node = _M_nodes;
502 _M_nodes = _M_nodes->_M_parent;
505 if (_M_nodes->_M_right == __node)
507 _M_nodes->_M_right = 0;
509 if (_M_nodes->_M_left)
511 _M_nodes = _M_nodes->_M_left;
513 while (_M_nodes->_M_right)
514 _M_nodes = _M_nodes->_M_right;
516 if (_M_nodes->_M_left)
517 _M_nodes = _M_nodes->_M_left;
521 _M_nodes->_M_left = 0;
538 _Alloc_node(_Rb_tree& __t)
541 template<
typename _Arg>
543 #if __cplusplus < 201103L 544 operator()(
const _Arg& __arg)
const 546 operator()(_Arg&& __arg)
const 548 {
return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg)); }
555 typedef _Key key_type;
556 typedef _Val value_type;
557 typedef value_type* pointer;
558 typedef const value_type* const_pointer;
559 typedef value_type& reference;
560 typedef const value_type& const_reference;
561 typedef size_t size_type;
562 typedef ptrdiff_t difference_type;
563 typedef _Alloc allocator_type;
566 _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
567 {
return this->_M_impl; }
569 const _Node_allocator&
570 _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
571 {
return this->_M_impl; }
574 get_allocator() const _GLIBCXX_NOEXCEPT
575 {
return allocator_type(_M_get_Node_allocator()); }
583 _M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT
586 #if __cplusplus < 201103L 588 _M_construct_node(_Link_type __node,
const value_type& __x)
591 { get_allocator().construct(__node->_M_valptr(), __x); }
595 __throw_exception_again;
600 _M_create_node(
const value_type& __x)
602 _Link_type __tmp = _M_get_node();
603 _M_construct_node(__tmp, __x);
607 template<
typename... _Args>
609 _M_construct_node(_Link_type __node, _Args&&... __args)
613 ::new(__node) _Rb_tree_node<_Val>;
614 _Alloc_traits::construct(_M_get_Node_allocator(),
616 std::forward<_Args>(__args)...);
620 __node->~_Rb_tree_node<_Val>();
622 __throw_exception_again;
626 template<
typename... _Args>
628 _M_create_node(_Args&&... __args)
630 _Link_type __tmp = _M_get_node();
631 _M_construct_node(__tmp, std::forward<_Args>(__args)...);
637 _M_destroy_node(_Link_type __p) _GLIBCXX_NOEXCEPT
639 #if __cplusplus < 201103L 640 get_allocator().destroy(__p->_M_valptr());
642 _Alloc_traits::destroy(_M_get_Node_allocator(), __p->_M_valptr());
643 __p->~_Rb_tree_node<_Val>();
648 _M_drop_node(_Link_type __p) _GLIBCXX_NOEXCEPT
650 _M_destroy_node(__p);
654 template<
typename _NodeGen>
656 _M_clone_node(_Const_Link_type __x, _NodeGen& __node_gen)
658 _Link_type __tmp = __node_gen(*__x->_M_valptr());
659 __tmp->_M_color = __x->_M_color;
666 #if _GLIBCXX_INLINE_VERSION 667 template<
typename _Key_compare>
670 template<
typename _Key_compare,
671 bool = __is_pod(_Key_compare)>
674 :
public _Node_allocator
675 ,
public _Rb_tree_key_compare<_Key_compare>
676 ,
public _Rb_tree_header
678 typedef _Rb_tree_key_compare<_Key_compare> _Base_key_compare;
681 _GLIBCXX_NOEXCEPT_IF(
682 is_nothrow_default_constructible<_Node_allocator>::value
683 && is_nothrow_default_constructible<_Base_key_compare>::value )
687 _Rb_tree_impl(
const _Rb_tree_impl& __x)
688 : _Node_allocator(_Alloc_traits::_S_select_on_copy(__x))
689 , _Base_key_compare(__x._M_key_compare)
692 #if __cplusplus < 201103L 693 _Rb_tree_impl(
const _Key_compare& __comp,
const _Node_allocator& __a)
694 : _Node_allocator(__a), _Base_key_compare(__comp)
697 _Rb_tree_impl(_Rb_tree_impl&&) =
default;
700 _Rb_tree_impl(_Node_allocator&& __a)
701 : _Node_allocator(
std::move(__a))
704 _Rb_tree_impl(_Rb_tree_impl&& __x, _Node_allocator&& __a)
705 : _Node_allocator(
std::move(__a)),
706 _Base_key_compare(
std::move(__x)),
707 _Rb_tree_header(
std::move(__x))
710 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
711 : _Node_allocator(
std::move(__a)), _Base_key_compare(__comp)
716 _Rb_tree_impl<_Compare> _M_impl;
720 _M_root() _GLIBCXX_NOEXCEPT
721 {
return this->_M_impl._M_header._M_parent; }
724 _M_root() const _GLIBCXX_NOEXCEPT
725 {
return this->_M_impl._M_header._M_parent; }
728 _M_leftmost() _GLIBCXX_NOEXCEPT
729 {
return this->_M_impl._M_header._M_left; }
732 _M_leftmost() const _GLIBCXX_NOEXCEPT
733 {
return this->_M_impl._M_header._M_left; }
736 _M_rightmost() _GLIBCXX_NOEXCEPT
737 {
return this->_M_impl._M_header._M_right; }
740 _M_rightmost() const _GLIBCXX_NOEXCEPT
741 {
return this->_M_impl._M_header._M_right; }
744 _M_begin() _GLIBCXX_NOEXCEPT
745 {
return static_cast<_Link_type
>(this->_M_impl._M_header._M_parent); }
748 _M_begin() const _GLIBCXX_NOEXCEPT
750 return static_cast<_Const_Link_type
> 751 (this->_M_impl._M_header._M_parent);
755 _M_end() _GLIBCXX_NOEXCEPT
756 {
return &this->_M_impl._M_header; }
759 _M_end() const _GLIBCXX_NOEXCEPT
760 {
return &this->_M_impl._M_header; }
762 static const_reference
763 _S_value(_Const_Link_type __x)
764 {
return *__x->_M_valptr(); }
767 _S_key(_Const_Link_type __x)
769 #if __cplusplus >= 201103L 772 static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
773 "comparison object must be invocable " 774 "with two arguments of key type");
775 # if __cplusplus >= 201703L 778 if constexpr (__is_invocable<_Compare&, const _Key&, const _Key&>{})
780 is_invocable_v<const _Compare&, const _Key&, const _Key&>,
781 "comparison object must be invocable as const");
785 return _KeyOfValue()(*__x->_M_valptr());
789 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
790 {
return static_cast<_Link_type
>(__x->_M_left); }
792 static _Const_Link_type
793 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
794 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
797 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
798 {
return static_cast<_Link_type
>(__x->_M_right); }
800 static _Const_Link_type
801 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
802 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
804 static const_reference
805 _S_value(_Const_Base_ptr __x)
806 {
return *
static_cast<_Const_Link_type
>(__x)->_M_valptr(); }
809 _S_key(_Const_Base_ptr __x)
810 {
return _S_key(static_cast<_Const_Link_type>(__x)); }
813 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
814 {
return _Rb_tree_node_base::_S_minimum(__x); }
816 static _Const_Base_ptr
817 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
818 {
return _Rb_tree_node_base::_S_minimum(__x); }
821 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
822 {
return _Rb_tree_node_base::_S_maximum(__x); }
824 static _Const_Base_ptr
825 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
826 {
return _Rb_tree_node_base::_S_maximum(__x); }
829 typedef _Rb_tree_iterator<value_type> iterator;
830 typedef _Rb_tree_const_iterator<value_type> const_iterator;
835 #if __cplusplus > 201402L 836 using node_type = _Node_handle<_Key, _Val, _Node_allocator>;
837 using insert_return_type = _Node_insert_return<
838 conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
842 pair<_Base_ptr, _Base_ptr>
843 _M_get_insert_unique_pos(
const key_type& __k);
845 pair<_Base_ptr, _Base_ptr>
846 _M_get_insert_equal_pos(
const key_type& __k);
848 pair<_Base_ptr, _Base_ptr>
849 _M_get_insert_hint_unique_pos(const_iterator __pos,
850 const key_type& __k);
852 pair<_Base_ptr, _Base_ptr>
853 _M_get_insert_hint_equal_pos(const_iterator __pos,
854 const key_type& __k);
857 #if __cplusplus >= 201103L 858 template<
typename _Arg,
typename _NodeGen>
860 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&);
863 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
865 template<
typename _Arg>
867 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
869 template<
typename _Arg>
871 _M_insert_equal_lower(_Arg&& __x);
874 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
877 _M_insert_equal_lower_node(_Link_type __z);
879 template<
typename _NodeGen>
881 _M_insert_(_Base_ptr __x, _Base_ptr __y,
882 const value_type& __v, _NodeGen&);
887 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
890 _M_insert_equal_lower(
const value_type& __x);
893 template<
typename _NodeGen>
895 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen&);
897 template<
typename _NodeGen>
899 _M_copy(
const _Rb_tree& __x, _NodeGen& __gen)
901 _Link_type __root = _M_copy(__x._M_begin(), _M_end(), __gen);
902 _M_leftmost() = _S_minimum(__root);
903 _M_rightmost() = _S_maximum(__root);
904 _M_impl._M_node_count = __x._M_impl._M_node_count;
909 _M_copy(
const _Rb_tree& __x)
911 _Alloc_node __an(*
this);
912 return _M_copy(__x, __an);
916 _M_erase(_Link_type __x);
919 _M_lower_bound(_Link_type __x, _Base_ptr __y,
923 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
924 const _Key& __k)
const;
927 _M_upper_bound(_Link_type __x, _Base_ptr __y,
931 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
932 const _Key& __k)
const;
936 #if __cplusplus < 201103L 939 _Rb_tree() =
default;
942 _Rb_tree(
const _Compare& __comp,
943 const allocator_type& __a = allocator_type())
944 : _M_impl(__comp, _Node_allocator(__a)) { }
946 _Rb_tree(
const _Rb_tree& __x)
947 : _M_impl(__x._M_impl)
949 if (__x._M_root() != 0)
950 _M_root() = _M_copy(__x);
953 #if __cplusplus >= 201103L 954 _Rb_tree(
const allocator_type& __a)
955 : _M_impl(_Node_allocator(__a))
958 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
959 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
961 if (__x._M_root() !=
nullptr)
962 _M_root() = _M_copy(__x);
965 _Rb_tree(_Rb_tree&&) =
default;
967 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
968 : _Rb_tree(
std::move(__x), _Node_allocator(__a))
972 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
true_type)
973 noexcept(is_nothrow_default_constructible<_Compare>::value)
974 : _M_impl(
std::move(__x._M_impl),
std::move(__a))
977 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
false_type)
978 : _M_impl(__x._M_impl._M_key_compare,
std::move(__a))
980 if (__x._M_root() !=
nullptr)
985 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
987 _Rb_tree(std::declval<_Rb_tree&&>(), std::declval<_Node_allocator&&>(),
988 std::declval<typename _Alloc_traits::is_always_equal>())) )
989 : _Rb_tree(
std::move(__x),
std::move(__a),
990 typename _Alloc_traits::is_always_equal{})
994 ~_Rb_tree() _GLIBCXX_NOEXCEPT
995 { _M_erase(_M_begin()); }
998 operator=(
const _Rb_tree& __x);
1003 {
return _M_impl._M_key_compare; }
1006 begin() _GLIBCXX_NOEXCEPT
1007 {
return iterator(this->_M_impl._M_header._M_left); }
1010 begin() const _GLIBCXX_NOEXCEPT
1011 {
return const_iterator(this->_M_impl._M_header._M_left); }
1014 end() _GLIBCXX_NOEXCEPT
1015 {
return iterator(&this->_M_impl._M_header); }
1018 end() const _GLIBCXX_NOEXCEPT
1019 {
return const_iterator(&this->_M_impl._M_header); }
1022 rbegin() _GLIBCXX_NOEXCEPT
1023 {
return reverse_iterator(
end()); }
1025 const_reverse_iterator
1026 rbegin() const _GLIBCXX_NOEXCEPT
1027 {
return const_reverse_iterator(
end()); }
1030 rend() _GLIBCXX_NOEXCEPT
1031 {
return reverse_iterator(
begin()); }
1033 const_reverse_iterator
1034 rend() const _GLIBCXX_NOEXCEPT
1035 {
return const_reverse_iterator(
begin()); }
1037 _GLIBCXX_NODISCARD
bool 1038 empty() const _GLIBCXX_NOEXCEPT
1039 {
return _M_impl._M_node_count == 0; }
1042 size() const _GLIBCXX_NOEXCEPT
1043 {
return _M_impl._M_node_count; }
1046 max_size() const _GLIBCXX_NOEXCEPT
1051 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value);
1054 #if __cplusplus >= 201103L 1055 template<
typename _Arg>
1056 pair<iterator, bool>
1057 _M_insert_unique(_Arg&& __x);
1059 template<
typename _Arg>
1061 _M_insert_equal(_Arg&& __x);
1063 template<
typename _Arg,
typename _NodeGen>
1065 _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1067 template<
typename _Arg>
1069 _M_insert_unique_(const_iterator __pos, _Arg&& __x)
1071 _Alloc_node __an(*
this);
1072 return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an);
1075 template<
typename _Arg,
typename _NodeGen>
1077 _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1079 template<
typename _Arg>
1081 _M_insert_equal_(const_iterator __pos, _Arg&& __x)
1083 _Alloc_node __an(*
this);
1084 return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an);
1087 template<
typename... _Args>
1088 pair<iterator, bool>
1089 _M_emplace_unique(_Args&&... __args);
1091 template<
typename... _Args>
1093 _M_emplace_equal(_Args&&... __args);
1095 template<
typename... _Args>
1097 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
1099 template<
typename... _Args>
1101 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
1103 template<
typename _Iter>
1104 using __same_value_type
1105 = is_same<value_type, typename iterator_traits<_Iter>::value_type>;
1107 template<
typename _InputIterator>
1108 __enable_if_t<__same_value_type<_InputIterator>::value>
1109 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1111 _Alloc_node __an(*
this);
1112 for (; __first != __last; ++__first)
1113 _M_insert_unique_(
end(), *__first, __an);
1116 template<
typename _InputIterator>
1117 __enable_if_t<!__same_value_type<_InputIterator>::value>
1118 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1120 for (; __first != __last; ++__first)
1121 _M_emplace_unique(*__first);
1124 template<
typename _InputIterator>
1125 __enable_if_t<__same_value_type<_InputIterator>::value>
1126 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1128 _Alloc_node __an(*
this);
1129 for (; __first != __last; ++__first)
1130 _M_insert_equal_(
end(), *__first, __an);
1133 template<
typename _InputIterator>
1134 __enable_if_t<!__same_value_type<_InputIterator>::value>
1135 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1137 _Alloc_node __an(*
this);
1138 for (; __first != __last; ++__first)
1139 _M_emplace_equal(*__first);
1142 pair<iterator, bool>
1143 _M_insert_unique(
const value_type& __x);
1146 _M_insert_equal(
const value_type& __x);
1148 template<
typename _NodeGen>
1150 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
1154 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
1156 _Alloc_node __an(*
this);
1157 return _M_insert_unique_(__pos, __x, __an);
1160 template<
typename _NodeGen>
1162 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
1165 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
1167 _Alloc_node __an(*
this);
1168 return _M_insert_equal_(__pos, __x, __an);
1171 template<
typename _InputIterator>
1173 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1175 _Alloc_node __an(*
this);
1176 for (; __first != __last; ++__first)
1177 _M_insert_unique_(
end(), *__first, __an);
1180 template<
typename _InputIterator>
1182 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1184 _Alloc_node __an(*
this);
1185 for (; __first != __last; ++__first)
1186 _M_insert_equal_(
end(), *__first, __an);
1192 _M_erase_aux(const_iterator __position);
1195 _M_erase_aux(const_iterator __first, const_iterator __last);
1198 #if __cplusplus >= 201103L 1201 _GLIBCXX_ABI_TAG_CXX11
1203 erase(const_iterator __position)
1205 __glibcxx_assert(__position !=
end());
1206 const_iterator __result = __position;
1208 _M_erase_aux(__position);
1209 return __result._M_const_cast();
1213 _GLIBCXX_ABI_TAG_CXX11
1215 erase(iterator __position)
1217 __glibcxx_assert(__position !=
end());
1218 iterator __result = __position;
1220 _M_erase_aux(__position);
1225 erase(iterator __position)
1227 __glibcxx_assert(__position !=
end());
1228 _M_erase_aux(__position);
1232 erase(const_iterator __position)
1234 __glibcxx_assert(__position !=
end());
1235 _M_erase_aux(__position);
1239 erase(
const key_type& __x);
1241 #if __cplusplus >= 201103L 1244 _GLIBCXX_ABI_TAG_CXX11
1246 erase(const_iterator __first, const_iterator __last)
1248 _M_erase_aux(__first, __last);
1249 return __last._M_const_cast();
1253 erase(iterator __first, iterator __last)
1254 { _M_erase_aux(__first, __last); }
1257 erase(const_iterator __first, const_iterator __last)
1258 { _M_erase_aux(__first, __last); }
1261 erase(
const key_type* __first,
const key_type* __last);
1264 clear() _GLIBCXX_NOEXCEPT
1266 _M_erase(_M_begin());
1272 find(
const key_type& __k);
1275 find(
const key_type& __k)
const;
1278 count(
const key_type& __k)
const;
1281 lower_bound(
const key_type& __k)
1282 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1285 lower_bound(
const key_type& __k)
const 1286 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1289 upper_bound(
const key_type& __k)
1290 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1293 upper_bound(
const key_type& __k)
const 1294 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1296 pair<iterator, iterator>
1297 equal_range(
const key_type& __k);
1299 pair<const_iterator, const_iterator>
1300 equal_range(
const key_type& __k)
const;
1302 #if __cplusplus >= 201402L 1303 template<
typename _Kt,
1304 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1306 _M_find_tr(
const _Kt& __k)
1308 const _Rb_tree* __const_this =
this;
1309 return __const_this->_M_find_tr(__k)._M_const_cast();
1312 template<
typename _Kt,
1313 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1315 _M_find_tr(
const _Kt& __k)
const 1317 auto __j = _M_lower_bound_tr(__k);
1318 if (__j !=
end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node)))
1323 template<
typename _Kt,
1324 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1326 _M_count_tr(
const _Kt& __k)
const 1328 auto __p = _M_equal_range_tr(__k);
1332 template<
typename _Kt,
1333 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1335 _M_lower_bound_tr(
const _Kt& __k)
1337 const _Rb_tree* __const_this =
this;
1338 return __const_this->_M_lower_bound_tr(__k)._M_const_cast();
1341 template<
typename _Kt,
1342 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1344 _M_lower_bound_tr(
const _Kt& __k)
const 1346 auto __x = _M_begin();
1347 auto __y = _M_end();
1349 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1355 __x = _S_right(__x);
1356 return const_iterator(__y);
1359 template<
typename _Kt,
1360 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1362 _M_upper_bound_tr(
const _Kt& __k)
1364 const _Rb_tree* __const_this =
this;
1365 return __const_this->_M_upper_bound_tr(__k)._M_const_cast();
1368 template<
typename _Kt,
1369 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1371 _M_upper_bound_tr(
const _Kt& __k)
const 1373 auto __x = _M_begin();
1374 auto __y = _M_end();
1376 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1382 __x = _S_right(__x);
1383 return const_iterator(__y);
1386 template<
typename _Kt,
1387 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1388 pair<iterator, iterator>
1389 _M_equal_range_tr(
const _Kt& __k)
1391 const _Rb_tree* __const_this =
this;
1392 auto __ret = __const_this->_M_equal_range_tr(__k);
1393 return { __ret.first._M_const_cast(), __ret.second._M_const_cast() };
1396 template<
typename _Kt,
1397 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1398 pair<const_iterator, const_iterator>
1399 _M_equal_range_tr(
const _Kt& __k)
const 1401 auto __low = _M_lower_bound_tr(__k);
1402 auto __high = __low;
1403 auto& __cmp = _M_impl._M_key_compare;
1404 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1406 return { __low, __high };
1412 __rb_verify()
const;
1414 #if __cplusplus >= 201103L 1416 operator=(_Rb_tree&&)
1417 noexcept(_Alloc_traits::_S_nothrow_move()
1418 && is_nothrow_move_assignable<_Compare>::value);
1420 template<typename _Iterator>
1422 _M_assign_unique(_Iterator, _Iterator);
1424 template<typename _Iterator>
1426 _M_assign_equal(_Iterator, _Iterator);
1432 { _M_impl._M_move_data(__x._M_impl); }
1449 #if __cplusplus > 201402L 1453 _M_reinsert_node_unique(node_type&& __nh)
1455 insert_return_type __ret;
1457 __ret.position =
end();
1460 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1462 auto __res = _M_get_insert_unique_pos(__nh._M_key());
1466 = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1467 __nh._M_ptr =
nullptr;
1468 __ret.inserted =
true;
1472 __ret.node = std::move(__nh);
1473 __ret.position = iterator(__res.first);
1474 __ret.inserted =
false;
1482 _M_reinsert_node_equal(node_type&& __nh)
1489 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1490 auto __res = _M_get_insert_equal_pos(__nh._M_key());
1492 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1494 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1495 __nh._M_ptr =
nullptr;
1502 _M_reinsert_node_hint_unique(const_iterator __hint, node_type&& __nh)
1509 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1510 auto __res = _M_get_insert_hint_unique_pos(__hint, __nh._M_key());
1513 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1514 __nh._M_ptr =
nullptr;
1517 __ret = iterator(__res.first);
1524 _M_reinsert_node_hint_equal(const_iterator __hint, node_type&& __nh)
1531 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1532 auto __res = _M_get_insert_hint_equal_pos(__hint, __nh._M_key());
1534 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1536 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1537 __nh._M_ptr =
nullptr;
1544 extract(const_iterator __pos)
1546 auto __ptr = _Rb_tree_rebalance_for_erase(
1547 __pos._M_const_cast()._M_node, _M_impl._M_header);
1548 --_M_impl._M_node_count;
1549 return {
static_cast<_Link_type
>(__ptr), _M_get_Node_allocator() };
1554 extract(
const key_type& __k)
1557 auto __pos = find(__k);
1559 __nh = extract(const_iterator(__pos));
1563 template<
typename _Compare2>
1564 using _Compatible_tree
1565 = _Rb_tree<_Key, _Val, _KeyOfValue, _Compare2, _Alloc>;
1567 template<
typename,
typename>
1568 friend class _Rb_tree_merge_helper;
1571 template<
typename _Compare2>
1573 _M_merge_unique(_Compatible_tree<_Compare2>& __src) noexcept
1575 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1576 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1579 auto __res = _M_get_insert_unique_pos(_KeyOfValue()(*__pos));
1582 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1583 auto __ptr = _Rb_tree_rebalance_for_erase(
1584 __pos._M_node, __src_impl._M_header);
1585 --__src_impl._M_node_count;
1586 _M_insert_node(__res.first, __res.second,
1587 static_cast<_Link_type>(__ptr));
1593 template<
typename _Compare2>
1595 _M_merge_equal(_Compatible_tree<_Compare2>& __src) noexcept
1597 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1598 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1601 auto __res = _M_get_insert_equal_pos(_KeyOfValue()(*__pos));
1604 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1605 auto __ptr = _Rb_tree_rebalance_for_erase(
1606 __pos._M_node, __src_impl._M_header);
1607 --__src_impl._M_node_count;
1608 _M_insert_node(__res.first, __res.second,
1609 static_cast<_Link_type>(__ptr));
1616 operator==(
const _Rb_tree& __x,
const _Rb_tree& __y)
1618 return __x.size() == __y.size()
1619 &&
std::equal(__x.begin(), __x.end(), __y.begin());
1623 operator<(
const _Rb_tree& __x,
const _Rb_tree& __y)
1626 __y.begin(), __y.end());
1629 friend bool _GLIBCXX_DEPRECATED
1630 operator!=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1631 {
return !(__x == __y); }
1633 friend bool _GLIBCXX_DEPRECATED
1634 operator>(
const _Rb_tree& __x,
const _Rb_tree& __y)
1635 {
return __y < __x; }
1637 friend bool _GLIBCXX_DEPRECATED
1638 operator<=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1639 {
return !(__y < __x); }
1641 friend bool _GLIBCXX_DEPRECATED
1642 operator>=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1643 {
return !(__x < __y); }
1646 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1647 typename _Compare,
typename _Alloc>
1649 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1650 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1653 #if __cplusplus >= 201103L 1654 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1655 typename _Compare,
typename _Alloc>
1657 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1660 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1664 _Alloc_node __an(*
this);
1666 [&__an](
const value_type& __cval)
1668 auto& __val =
const_cast<value_type&
>(__cval);
1671 _M_root() = _M_copy(__x, __lbd);
1675 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1676 typename _Compare,
typename _Alloc>
1678 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1679 _M_move_assign(_Rb_tree& __x,
true_type)
1682 if (__x._M_root() !=
nullptr)
1684 std::__alloc_on_move(_M_get_Node_allocator(),
1685 __x._M_get_Node_allocator());
1688 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1689 typename _Compare,
typename _Alloc>
1691 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1694 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1695 return _M_move_assign(__x,
true_type{});
1699 _Reuse_or_alloc_node __roan(*
this);
1701 if (__x._M_root() !=
nullptr)
1704 [&__roan](
const value_type& __cval)
1706 auto& __val =
const_cast<value_type&
>(__cval);
1709 _M_root() = _M_copy(__x, __lbd);
1714 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1715 typename _Compare,
typename _Alloc>
1716 inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1717 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1718 operator=(_Rb_tree&& __x)
1719 noexcept(_Alloc_traits::_S_nothrow_move()
1720 && is_nothrow_move_assignable<_Compare>::value)
1722 _M_impl._M_key_compare = std::move(__x._M_impl._M_key_compare);
1723 _M_move_assign(__x, __bool_constant<_Alloc_traits::_S_nothrow_move()>());
1727 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1728 typename _Compare,
typename _Alloc>
1729 template<
typename _Iterator>
1731 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1732 _M_assign_unique(_Iterator __first, _Iterator __last)
1734 _Reuse_or_alloc_node __roan(*
this);
1736 for (; __first != __last; ++__first)
1737 _M_insert_unique_(
end(), *__first, __roan);
1740 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1741 typename _Compare,
typename _Alloc>
1742 template<
typename _Iterator>
1744 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1745 _M_assign_equal(_Iterator __first, _Iterator __last)
1747 _Reuse_or_alloc_node __roan(*
this);
1749 for (; __first != __last; ++__first)
1750 _M_insert_equal_(
end(), *__first, __roan);
1754 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1755 typename _Compare,
typename _Alloc>
1756 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1757 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1758 operator=(
const _Rb_tree& __x)
1763 #if __cplusplus >= 201103L 1764 if (_Alloc_traits::_S_propagate_on_copy_assign())
1766 auto& __this_alloc = this->_M_get_Node_allocator();
1767 auto& __that_alloc = __x._M_get_Node_allocator();
1768 if (!_Alloc_traits::_S_always_equal()
1769 && __this_alloc != __that_alloc)
1774 std::__alloc_on_copy(__this_alloc, __that_alloc);
1779 _Reuse_or_alloc_node __roan(*
this);
1781 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1782 if (__x._M_root() != 0)
1783 _M_root() = _M_copy(__x, __roan);
1789 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1790 typename _Compare,
typename _Alloc>
1791 #if __cplusplus >= 201103L 1792 template<
typename _Arg,
typename _NodeGen>
1794 template<
typename _NodeGen>
1796 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1797 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1798 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1799 #
if __cplusplus >= 201103L
1804 _NodeGen& __node_gen)
1806 bool __insert_left = (__x != 0 || __p == _M_end()
1807 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1810 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1812 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1813 this->_M_impl._M_header);
1814 ++_M_impl._M_node_count;
1815 return iterator(__z);
1818 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1819 typename _Compare,
typename _Alloc>
1820 #if __cplusplus >= 201103L 1821 template<
typename _Arg>
1823 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1824 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1825 #if __cplusplus >= 201103L 1826 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1828 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1831 bool __insert_left = (__p == _M_end()
1832 || !_M_impl._M_key_compare(_S_key(__p),
1833 _KeyOfValue()(__v)));
1835 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1837 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1838 this->_M_impl._M_header);
1839 ++_M_impl._M_node_count;
1840 return iterator(__z);
1843 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1844 typename _Compare,
typename _Alloc>
1845 #if __cplusplus >= 201103L 1846 template<
typename _Arg>
1848 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1849 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1850 #if __cplusplus >= 201103L 1851 _M_insert_equal_lower(_Arg&& __v)
1853 _M_insert_equal_lower(
const _Val& __v)
1856 _Link_type __x = _M_begin();
1857 _Base_ptr __y = _M_end();
1861 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1862 _S_left(__x) : _S_right(__x);
1864 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1867 template<
typename _Key,
typename _Val,
typename _KoV,
1868 typename _Compare,
typename _Alloc>
1869 template<
typename _NodeGen>
1870 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1871 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1872 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen)
1875 _Link_type __top = _M_clone_node(__x, __node_gen);
1876 __top->_M_parent = __p;
1881 __top->_M_right = _M_copy(_S_right(__x), __top, __node_gen);
1887 _Link_type __y = _M_clone_node(__x, __node_gen);
1889 __y->_M_parent = __p;
1891 __y->_M_right = _M_copy(_S_right(__x), __y, __node_gen);
1899 __throw_exception_again;
1904 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1905 typename _Compare,
typename _Alloc>
1907 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1908 _M_erase(_Link_type __x)
1913 _M_erase(_S_right(__x));
1914 _Link_type __y = _S_left(__x);
1920 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1921 typename _Compare,
typename _Alloc>
1922 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1923 _Compare, _Alloc>::iterator
1924 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1925 _M_lower_bound(_Link_type __x, _Base_ptr __y,
1929 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1930 __y = __x, __x = _S_left(__x);
1932 __x = _S_right(__x);
1933 return iterator(__y);
1936 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1937 typename _Compare,
typename _Alloc>
1938 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1939 _Compare, _Alloc>::const_iterator
1940 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1941 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1942 const _Key& __k)
const 1945 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1946 __y = __x, __x = _S_left(__x);
1948 __x = _S_right(__x);
1949 return const_iterator(__y);
1952 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1953 typename _Compare,
typename _Alloc>
1954 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1955 _Compare, _Alloc>::iterator
1956 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1957 _M_upper_bound(_Link_type __x, _Base_ptr __y,
1961 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1962 __y = __x, __x = _S_left(__x);
1964 __x = _S_right(__x);
1965 return iterator(__y);
1968 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1969 typename _Compare,
typename _Alloc>
1970 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1971 _Compare, _Alloc>::const_iterator
1972 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1973 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1974 const _Key& __k)
const 1977 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1978 __y = __x, __x = _S_left(__x);
1980 __x = _S_right(__x);
1981 return const_iterator(__y);
1984 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1985 typename _Compare,
typename _Alloc>
1986 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1987 _Compare, _Alloc>::iterator,
1988 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1989 _Compare, _Alloc>::iterator>
1990 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1991 equal_range(
const _Key& __k)
1993 _Link_type __x = _M_begin();
1994 _Base_ptr __y = _M_end();
1997 if (_M_impl._M_key_compare(_S_key(__x), __k))
1998 __x = _S_right(__x);
1999 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
2000 __y = __x, __x = _S_left(__x);
2003 _Link_type __xu(__x);
2004 _Base_ptr __yu(__y);
2005 __y = __x, __x = _S_left(__x);
2006 __xu = _S_right(__xu);
2007 return pair<iterator,
2008 iterator>(_M_lower_bound(__x, __y, __k),
2009 _M_upper_bound(__xu, __yu, __k));
2012 return pair<iterator, iterator>(iterator(__y),
2016 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2017 typename _Compare,
typename _Alloc>
2018 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2019 _Compare, _Alloc>::const_iterator,
2020 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2021 _Compare, _Alloc>::const_iterator>
2022 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2023 equal_range(
const _Key& __k)
const 2025 _Const_Link_type __x = _M_begin();
2026 _Const_Base_ptr __y = _M_end();
2029 if (_M_impl._M_key_compare(_S_key(__x), __k))
2030 __x = _S_right(__x);
2031 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
2032 __y = __x, __x = _S_left(__x);
2035 _Const_Link_type __xu(__x);
2036 _Const_Base_ptr __yu(__y);
2037 __y = __x, __x = _S_left(__x);
2038 __xu = _S_right(__xu);
2039 return pair<const_iterator,
2040 const_iterator>(_M_lower_bound(__x, __y, __k),
2041 _M_upper_bound(__xu, __yu, __k));
2044 return pair<const_iterator, const_iterator>(const_iterator(__y),
2045 const_iterator(__y));
2048 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2049 typename _Compare,
typename _Alloc>
2051 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2053 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
2057 if (__t._M_root() != 0)
2058 _M_impl._M_move_data(__t._M_impl);
2060 else if (__t._M_root() == 0)
2061 __t._M_impl._M_move_data(_M_impl);
2064 std::swap(_M_root(),__t._M_root());
2065 std::swap(_M_leftmost(),__t._M_leftmost());
2066 std::swap(_M_rightmost(),__t._M_rightmost());
2068 _M_root()->_M_parent = _M_end();
2069 __t._M_root()->_M_parent = __t._M_end();
2070 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
2073 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
2075 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
2076 __t._M_get_Node_allocator());
2079 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2080 typename _Compare,
typename _Alloc>
2081 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2082 _Compare, _Alloc>::_Base_ptr,
2083 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2084 _Compare, _Alloc>::_Base_ptr>
2085 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2086 _M_get_insert_unique_pos(
const key_type& __k)
2088 typedef pair<_Base_ptr, _Base_ptr> _Res;
2089 _Link_type __x = _M_begin();
2090 _Base_ptr __y = _M_end();
2095 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
2096 __x = __comp ? _S_left(__x) : _S_right(__x);
2098 iterator __j = iterator(__y);
2102 return _Res(__x, __y);
2106 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
2107 return _Res(__x, __y);
2108 return _Res(__j._M_node, 0);
2111 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2112 typename _Compare,
typename _Alloc>
2113 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2114 _Compare, _Alloc>::_Base_ptr,
2115 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2116 _Compare, _Alloc>::_Base_ptr>
2117 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2118 _M_get_insert_equal_pos(
const key_type& __k)
2120 typedef pair<_Base_ptr, _Base_ptr> _Res;
2121 _Link_type __x = _M_begin();
2122 _Base_ptr __y = _M_end();
2126 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
2127 _S_left(__x) : _S_right(__x);
2129 return _Res(__x, __y);
2132 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2133 typename _Compare,
typename _Alloc>
2134 #if __cplusplus >= 201103L 2135 template<
typename _Arg>
2137 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2138 _Compare, _Alloc>::iterator,
bool>
2139 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2140 #if __cplusplus >= 201103L 2141 _M_insert_unique(_Arg&& __v)
2143 _M_insert_unique(
const _Val& __v)
2146 typedef pair<iterator, bool> _Res;
2147 pair<_Base_ptr, _Base_ptr> __res
2148 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
2152 _Alloc_node __an(*
this);
2153 return _Res(_M_insert_(__res.first, __res.second,
2154 _GLIBCXX_FORWARD(_Arg, __v), __an),
2158 return _Res(iterator(__res.first),
false);
2161 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2162 typename _Compare,
typename _Alloc>
2163 #if __cplusplus >= 201103L 2164 template<
typename _Arg>
2166 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2167 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2168 #if __cplusplus >= 201103L 2169 _M_insert_equal(_Arg&& __v)
2171 _M_insert_equal(
const _Val& __v)
2174 pair<_Base_ptr, _Base_ptr> __res
2175 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
2176 _Alloc_node __an(*
this);
2177 return _M_insert_(__res.first, __res.second,
2178 _GLIBCXX_FORWARD(_Arg, __v), __an);
2181 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2182 typename _Compare,
typename _Alloc>
2183 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2184 _Compare, _Alloc>::_Base_ptr,
2185 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2186 _Compare, _Alloc>::_Base_ptr>
2187 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2188 _M_get_insert_hint_unique_pos(const_iterator __position,
2189 const key_type& __k)
2191 iterator __pos = __position._M_const_cast();
2192 typedef pair<_Base_ptr, _Base_ptr> _Res;
2195 if (__pos._M_node == _M_end())
2198 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
2199 return _Res(0, _M_rightmost());
2201 return _M_get_insert_unique_pos(__k);
2203 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
2206 iterator __before = __pos;
2207 if (__pos._M_node == _M_leftmost())
2208 return _Res(_M_leftmost(), _M_leftmost());
2209 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
2211 if (_S_right(__before._M_node) == 0)
2212 return _Res(0, __before._M_node);
2214 return _Res(__pos._M_node, __pos._M_node);
2217 return _M_get_insert_unique_pos(__k);
2219 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2222 iterator __after = __pos;
2223 if (__pos._M_node == _M_rightmost())
2224 return _Res(0, _M_rightmost());
2225 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
2227 if (_S_right(__pos._M_node) == 0)
2228 return _Res(0, __pos._M_node);
2230 return _Res(__after._M_node, __after._M_node);
2233 return _M_get_insert_unique_pos(__k);
2237 return _Res(__pos._M_node, 0);
2240 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2241 typename _Compare,
typename _Alloc>
2242 #if __cplusplus >= 201103L 2243 template<
typename _Arg,
typename _NodeGen>
2245 template<
typename _NodeGen>
2247 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2248 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2249 _M_insert_unique_(const_iterator __position,
2250 #
if __cplusplus >= 201103L
2255 _NodeGen& __node_gen)
2257 pair<_Base_ptr, _Base_ptr> __res
2258 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
2261 return _M_insert_(__res.first, __res.second,
2262 _GLIBCXX_FORWARD(_Arg, __v),
2264 return iterator(__res.first);
2267 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2268 typename _Compare,
typename _Alloc>
2269 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2270 _Compare, _Alloc>::_Base_ptr,
2271 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2272 _Compare, _Alloc>::_Base_ptr>
2273 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2274 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
2276 iterator __pos = __position._M_const_cast();
2277 typedef pair<_Base_ptr, _Base_ptr> _Res;
2280 if (__pos._M_node == _M_end())
2283 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
2284 return _Res(0, _M_rightmost());
2286 return _M_get_insert_equal_pos(__k);
2288 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2291 iterator __before = __pos;
2292 if (__pos._M_node == _M_leftmost())
2293 return _Res(_M_leftmost(), _M_leftmost());
2294 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2296 if (_S_right(__before._M_node) == 0)
2297 return _Res(0, __before._M_node);
2299 return _Res(__pos._M_node, __pos._M_node);
2302 return _M_get_insert_equal_pos(__k);
2307 iterator __after = __pos;
2308 if (__pos._M_node == _M_rightmost())
2309 return _Res(0, _M_rightmost());
2310 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2312 if (_S_right(__pos._M_node) == 0)
2313 return _Res(0, __pos._M_node);
2315 return _Res(__after._M_node, __after._M_node);
2322 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2323 typename _Compare,
typename _Alloc>
2324 #if __cplusplus >= 201103L 2325 template<
typename _Arg,
typename _NodeGen>
2327 template<
typename _NodeGen>
2329 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2330 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2331 _M_insert_equal_(const_iterator __position,
2332 #
if __cplusplus >= 201103L
2337 _NodeGen& __node_gen)
2339 pair<_Base_ptr, _Base_ptr> __res
2340 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2343 return _M_insert_(__res.first, __res.second,
2344 _GLIBCXX_FORWARD(_Arg, __v),
2347 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2350 #if __cplusplus >= 201103L 2351 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2352 typename _Compare,
typename _Alloc>
2353 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2354 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2355 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2357 bool __insert_left = (__x != 0 || __p == _M_end()
2358 || _M_impl._M_key_compare(_S_key(__z),
2361 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2362 this->_M_impl._M_header);
2363 ++_M_impl._M_node_count;
2364 return iterator(__z);
2367 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2368 typename _Compare,
typename _Alloc>
2369 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2370 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2371 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2373 bool __insert_left = (__p == _M_end()
2374 || !_M_impl._M_key_compare(_S_key(__p),
2377 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2378 this->_M_impl._M_header);
2379 ++_M_impl._M_node_count;
2380 return iterator(__z);
2383 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2384 typename _Compare,
typename _Alloc>
2385 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2386 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2387 _M_insert_equal_lower_node(_Link_type __z)
2389 _Link_type __x = _M_begin();
2390 _Base_ptr __y = _M_end();
2394 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2395 _S_left(__x) : _S_right(__x);
2397 return _M_insert_lower_node(__y, __z);
2400 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2401 typename _Compare,
typename _Alloc>
2402 template<
typename... _Args>
2403 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2404 _Compare, _Alloc>::iterator,
bool>
2405 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2406 _M_emplace_unique(_Args&&... __args)
2408 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2412 typedef pair<iterator, bool> _Res;
2413 auto __res = _M_get_insert_unique_pos(_S_key(__z));
2415 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
2418 return _Res(iterator(__res.first),
false);
2423 __throw_exception_again;
2427 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2428 typename _Compare,
typename _Alloc>
2429 template<
typename... _Args>
2430 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2431 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2432 _M_emplace_equal(_Args&&... __args)
2434 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2438 auto __res = _M_get_insert_equal_pos(_S_key(__z));
2439 return _M_insert_node(__res.first, __res.second, __z);
2444 __throw_exception_again;
2448 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2449 typename _Compare,
typename _Alloc>
2450 template<
typename... _Args>
2451 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2452 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2453 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
2455 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2459 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
2462 return _M_insert_node(__res.first, __res.second, __z);
2465 return iterator(__res.first);
2470 __throw_exception_again;
2474 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2475 typename _Compare,
typename _Alloc>
2476 template<
typename... _Args>
2477 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2478 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2479 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2481 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2485 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
2488 return _M_insert_node(__res.first, __res.second, __z);
2490 return _M_insert_equal_lower_node(__z);
2495 __throw_exception_again;
2501 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2502 typename _Compare,
typename _Alloc>
2504 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2505 _M_erase_aux(const_iterator __position)
2508 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
2509 (const_cast<_Base_ptr>(__position._M_node),
2510 this->_M_impl._M_header));
2512 --_M_impl._M_node_count;
2515 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2516 typename _Compare,
typename _Alloc>
2518 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2519 _M_erase_aux(const_iterator __first, const_iterator __last)
2521 if (__first ==
begin() && __last ==
end())
2524 while (__first != __last)
2525 _M_erase_aux(__first++);
2528 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2529 typename _Compare,
typename _Alloc>
2530 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2531 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2532 erase(
const _Key& __x)
2534 pair<iterator, iterator> __p = equal_range(__x);
2535 const size_type __old_size = size();
2536 _M_erase_aux(__p.first, __p.second);
2537 return __old_size - size();
2540 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2541 typename _Compare,
typename _Alloc>
2543 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2544 erase(
const _Key* __first,
const _Key* __last)
2546 while (__first != __last)
2550 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2551 typename _Compare,
typename _Alloc>
2552 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2553 _Compare, _Alloc>::iterator
2554 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2555 find(
const _Key& __k)
2557 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2558 return (__j ==
end()
2559 || _M_impl._M_key_compare(__k,
2560 _S_key(__j._M_node))) ?
end() : __j;
2563 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2564 typename _Compare,
typename _Alloc>
2565 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2566 _Compare, _Alloc>::const_iterator
2567 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2568 find(
const _Key& __k)
const 2570 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2571 return (__j ==
end()
2572 || _M_impl._M_key_compare(__k,
2573 _S_key(__j._M_node))) ?
end() : __j;
2576 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2577 typename _Compare,
typename _Alloc>
2578 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2579 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2580 count(
const _Key& __k)
const 2582 pair<const_iterator, const_iterator> __p = equal_range(__k);
2587 _GLIBCXX_PURE
unsigned int 2588 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
2589 const _Rb_tree_node_base* __root)
throw ();
2591 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2592 typename _Compare,
typename _Alloc>
2594 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const 2596 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
2597 return _M_impl._M_node_count == 0 &&
begin() ==
end()
2598 && this->_M_impl._M_header._M_left == _M_end()
2599 && this->_M_impl._M_header._M_right == _M_end();
2601 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
2602 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
2604 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
2605 _Const_Link_type __L = _S_left(__x);
2606 _Const_Link_type __R = _S_right(__x);
2608 if (__x->_M_color == _S_red)
2609 if ((__L && __L->_M_color == _S_red)
2610 || (__R && __R->_M_color == _S_red))
2613 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
2615 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
2618 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
2622 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
2624 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
2629 #if __cplusplus > 201402L 2631 template<
typename _Key,
typename _Val,
typename _Sel,
typename _Cmp1,
2632 typename _Alloc,
typename _Cmp2>
2633 struct _Rb_tree_merge_helper<_Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>,
2637 friend class _Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>;
2640 _S_get_impl(_Rb_tree<_Key, _Val, _Sel, _Cmp2, _Alloc>& __tree)
2641 {
return __tree._M_impl; }
2645 _GLIBCXX_END_NAMESPACE_VERSION
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
_GLIBCXX20_CONSTEXPR complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
static _GLIBCXX_NODISCARD pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
ISO C++ entities toplevel namespace is std.
constexpr conditional< __move_if_noexcept_cond< _Tp >::value, const _Tp &, _Tp && >::type move_if_noexcept(_Tp &__x) noexcept
Conditionally convert a value to an rvalue.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
_GLIBCXX17_CONSTEXPR auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
Uniform interface to C++98 and C++11 allocators.
_GLIBCXX17_CONSTEXPR auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.