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; }
763 _S_key(_Const_Link_type __x)
765 #if __cplusplus >= 201103L
768 static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
769 "comparison object must be invocable "
770 "with two arguments of key type");
771 # if __cplusplus >= 201703L
774 if constexpr (__is_invocable<_Compare&, const _Key&, const _Key&>{})
776 is_invocable_v<const _Compare&, const _Key&, const _Key&>,
777 "comparison object must be invocable as const");
781 return _KeyOfValue()(*__x->_M_valptr());
785 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
786 {
return static_cast<_Link_type
>(__x->_M_left); }
788 static _Const_Link_type
789 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
790 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
793 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
794 {
return static_cast<_Link_type
>(__x->_M_right); }
796 static _Const_Link_type
797 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
798 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
801 _S_key(_Const_Base_ptr __x)
802 {
return _S_key(
static_cast<_Const_Link_type
>(__x)); }
805 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
806 {
return _Rb_tree_node_base::_S_minimum(__x); }
808 static _Const_Base_ptr
809 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
810 {
return _Rb_tree_node_base::_S_minimum(__x); }
813 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
814 {
return _Rb_tree_node_base::_S_maximum(__x); }
816 static _Const_Base_ptr
817 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
818 {
return _Rb_tree_node_base::_S_maximum(__x); }
821 typedef _Rb_tree_iterator<value_type> iterator;
822 typedef _Rb_tree_const_iterator<value_type> const_iterator;
827 #if __cplusplus > 201402L
828 using node_type = _Node_handle<_Key, _Val, _Node_allocator>;
829 using insert_return_type = _Node_insert_return<
830 conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
834 pair<_Base_ptr, _Base_ptr>
835 _M_get_insert_unique_pos(
const key_type& __k);
837 pair<_Base_ptr, _Base_ptr>
838 _M_get_insert_equal_pos(
const key_type& __k);
840 pair<_Base_ptr, _Base_ptr>
841 _M_get_insert_hint_unique_pos(const_iterator __pos,
842 const key_type& __k);
844 pair<_Base_ptr, _Base_ptr>
845 _M_get_insert_hint_equal_pos(const_iterator __pos,
846 const key_type& __k);
849 #if __cplusplus >= 201103L
850 template<
typename _Arg,
typename _NodeGen>
852 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&);
855 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
857 template<
typename _Arg>
859 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
861 template<
typename _Arg>
863 _M_insert_equal_lower(_Arg&& __x);
866 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
869 _M_insert_equal_lower_node(_Link_type __z);
871 template<
typename _NodeGen>
873 _M_insert_(_Base_ptr __x, _Base_ptr __y,
874 const value_type& __v, _NodeGen&);
879 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
882 _M_insert_equal_lower(
const value_type& __x);
885 template<
typename _NodeGen>
887 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen&);
889 template<
typename _NodeGen>
891 _M_copy(
const _Rb_tree& __x, _NodeGen& __gen)
893 _Link_type __root = _M_copy(__x._M_begin(), _M_end(), __gen);
894 _M_leftmost() = _S_minimum(__root);
895 _M_rightmost() = _S_maximum(__root);
896 _M_impl._M_node_count = __x._M_impl._M_node_count;
901 _M_copy(
const _Rb_tree& __x)
903 _Alloc_node __an(*
this);
904 return _M_copy(__x, __an);
908 _M_erase(_Link_type __x);
911 _M_lower_bound(_Link_type __x, _Base_ptr __y,
915 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
916 const _Key& __k)
const;
919 _M_upper_bound(_Link_type __x, _Base_ptr __y,
923 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
924 const _Key& __k)
const;
928 #if __cplusplus < 201103L
931 _Rb_tree() =
default;
934 _Rb_tree(
const _Compare& __comp,
935 const allocator_type& __a = allocator_type())
936 : _M_impl(__comp, _Node_allocator(__a)) { }
938 _Rb_tree(
const _Rb_tree& __x)
939 : _M_impl(__x._M_impl)
941 if (__x._M_root() != 0)
942 _M_root() = _M_copy(__x);
945 #if __cplusplus >= 201103L
946 _Rb_tree(
const allocator_type& __a)
947 : _M_impl(_Node_allocator(__a))
950 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
951 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
953 if (__x._M_root() !=
nullptr)
954 _M_root() = _M_copy(__x);
957 _Rb_tree(_Rb_tree&&) =
default;
959 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
960 : _Rb_tree(
std::
move(__x), _Node_allocator(__a))
964 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
true_type)
965 noexcept(is_nothrow_default_constructible<_Compare>::value)
969 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
false_type)
970 : _M_impl(__x._M_impl._M_key_compare,
std::
move(__a))
972 if (__x._M_root() !=
nullptr)
977 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
979 _Rb_tree(std::declval<_Rb_tree&&>(), std::declval<_Node_allocator&&>(),
980 std::declval<typename _Alloc_traits::is_always_equal>())) )
982 typename _Alloc_traits::is_always_equal{})
986 ~_Rb_tree() _GLIBCXX_NOEXCEPT
987 { _M_erase(_M_begin()); }
990 operator=(
const _Rb_tree& __x);
995 {
return _M_impl._M_key_compare; }
998 begin() _GLIBCXX_NOEXCEPT
999 {
return iterator(this->_M_impl._M_header._M_left); }
1002 begin() const _GLIBCXX_NOEXCEPT
1003 {
return const_iterator(this->_M_impl._M_header._M_left); }
1006 end() _GLIBCXX_NOEXCEPT
1007 {
return iterator(&this->_M_impl._M_header); }
1010 end() const _GLIBCXX_NOEXCEPT
1011 {
return const_iterator(&this->_M_impl._M_header); }
1014 rbegin() _GLIBCXX_NOEXCEPT
1015 {
return reverse_iterator(
end()); }
1017 const_reverse_iterator
1018 rbegin() const _GLIBCXX_NOEXCEPT
1019 {
return const_reverse_iterator(
end()); }
1022 rend() _GLIBCXX_NOEXCEPT
1023 {
return reverse_iterator(
begin()); }
1025 const_reverse_iterator
1026 rend() const _GLIBCXX_NOEXCEPT
1027 {
return const_reverse_iterator(
begin()); }
1029 _GLIBCXX_NODISCARD
bool
1030 empty() const _GLIBCXX_NOEXCEPT
1031 {
return _M_impl._M_node_count == 0; }
1034 size() const _GLIBCXX_NOEXCEPT
1035 {
return _M_impl._M_node_count; }
1038 max_size() const _GLIBCXX_NOEXCEPT
1043 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value);
1046 #if __cplusplus >= 201103L
1047 template<
typename _Arg>
1048 pair<iterator, bool>
1049 _M_insert_unique(_Arg&& __x);
1051 template<
typename _Arg>
1053 _M_insert_equal(_Arg&& __x);
1055 template<
typename _Arg,
typename _NodeGen>
1057 _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1059 template<
typename _Arg>
1061 _M_insert_unique_(const_iterator __pos, _Arg&& __x)
1063 _Alloc_node __an(*
this);
1064 return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an);
1067 template<
typename _Arg,
typename _NodeGen>
1069 _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1071 template<
typename _Arg>
1073 _M_insert_equal_(const_iterator __pos, _Arg&& __x)
1075 _Alloc_node __an(*
this);
1076 return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an);
1079 template<
typename... _Args>
1080 pair<iterator, bool>
1081 _M_emplace_unique(_Args&&... __args);
1083 template<
typename... _Args>
1085 _M_emplace_equal(_Args&&... __args);
1087 template<
typename... _Args>
1089 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
1091 template<
typename... _Args>
1093 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
1095 template<
typename _Iter>
1096 using __same_value_type
1097 = is_same<value_type, typename iterator_traits<_Iter>::value_type>;
1099 template<
typename _InputIterator>
1100 __enable_if_t<__same_value_type<_InputIterator>::value>
1101 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1103 _Alloc_node __an(*
this);
1104 for (; __first != __last; ++__first)
1105 _M_insert_unique_(
end(), *__first, __an);
1108 template<
typename _InputIterator>
1109 __enable_if_t<!__same_value_type<_InputIterator>::value>
1110 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1112 for (; __first != __last; ++__first)
1113 _M_emplace_unique(*__first);
1116 template<
typename _InputIterator>
1117 __enable_if_t<__same_value_type<_InputIterator>::value>
1118 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1120 _Alloc_node __an(*
this);
1121 for (; __first != __last; ++__first)
1122 _M_insert_equal_(
end(), *__first, __an);
1125 template<
typename _InputIterator>
1126 __enable_if_t<!__same_value_type<_InputIterator>::value>
1127 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1129 _Alloc_node __an(*
this);
1130 for (; __first != __last; ++__first)
1131 _M_emplace_equal(*__first);
1134 pair<iterator, bool>
1135 _M_insert_unique(
const value_type& __x);
1138 _M_insert_equal(
const value_type& __x);
1140 template<
typename _NodeGen>
1142 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
1146 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
1148 _Alloc_node __an(*
this);
1149 return _M_insert_unique_(__pos, __x, __an);
1152 template<
typename _NodeGen>
1154 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
1157 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
1159 _Alloc_node __an(*
this);
1160 return _M_insert_equal_(__pos, __x, __an);
1163 template<
typename _InputIterator>
1165 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1167 _Alloc_node __an(*
this);
1168 for (; __first != __last; ++__first)
1169 _M_insert_unique_(
end(), *__first, __an);
1172 template<
typename _InputIterator>
1174 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1176 _Alloc_node __an(*
this);
1177 for (; __first != __last; ++__first)
1178 _M_insert_equal_(
end(), *__first, __an);
1184 _M_erase_aux(const_iterator __position);
1187 _M_erase_aux(const_iterator __first, const_iterator __last);
1190 #if __cplusplus >= 201103L
1193 _GLIBCXX_ABI_TAG_CXX11
1195 erase(const_iterator __position)
1197 __glibcxx_assert(__position !=
end());
1198 const_iterator __result = __position;
1200 _M_erase_aux(__position);
1201 return __result._M_const_cast();
1205 _GLIBCXX_ABI_TAG_CXX11
1207 erase(iterator __position)
1209 __glibcxx_assert(__position !=
end());
1210 iterator __result = __position;
1212 _M_erase_aux(__position);
1217 erase(iterator __position)
1219 __glibcxx_assert(__position !=
end());
1220 _M_erase_aux(__position);
1224 erase(const_iterator __position)
1226 __glibcxx_assert(__position !=
end());
1227 _M_erase_aux(__position);
1232 erase(
const key_type& __x);
1234 #if __cplusplus >= 201103L
1237 _GLIBCXX_ABI_TAG_CXX11
1239 erase(const_iterator __first, const_iterator __last)
1241 _M_erase_aux(__first, __last);
1242 return __last._M_const_cast();
1246 erase(iterator __first, iterator __last)
1247 { _M_erase_aux(__first, __last); }
1250 erase(const_iterator __first, const_iterator __last)
1251 { _M_erase_aux(__first, __last); }
1255 clear() _GLIBCXX_NOEXCEPT
1257 _M_erase(_M_begin());
1263 find(
const key_type& __k);
1266 find(
const key_type& __k)
const;
1269 count(
const key_type& __k)
const;
1272 lower_bound(
const key_type& __k)
1273 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1276 lower_bound(
const key_type& __k)
const
1277 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1280 upper_bound(
const key_type& __k)
1281 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1284 upper_bound(
const key_type& __k)
const
1285 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1287 pair<iterator, iterator>
1288 equal_range(
const key_type& __k);
1290 pair<const_iterator, const_iterator>
1291 equal_range(
const key_type& __k)
const;
1293 #if __cplusplus >= 201402L
1294 template<
typename _Kt,
1295 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1297 _M_find_tr(
const _Kt& __k)
1299 const _Rb_tree* __const_this =
this;
1300 return __const_this->_M_find_tr(__k)._M_const_cast();
1303 template<
typename _Kt,
1304 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1306 _M_find_tr(
const _Kt& __k)
const
1308 auto __j = _M_lower_bound_tr(__k);
1309 if (__j !=
end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node)))
1314 template<
typename _Kt,
1315 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1317 _M_count_tr(
const _Kt& __k)
const
1319 auto __p = _M_equal_range_tr(__k);
1323 template<
typename _Kt,
1324 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1326 _M_lower_bound_tr(
const _Kt& __k)
1328 const _Rb_tree* __const_this =
this;
1329 return __const_this->_M_lower_bound_tr(__k)._M_const_cast();
1332 template<
typename _Kt,
1333 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1335 _M_lower_bound_tr(
const _Kt& __k)
const
1337 auto __x = _M_begin();
1338 auto __y = _M_end();
1340 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1346 __x = _S_right(__x);
1347 return const_iterator(__y);
1350 template<
typename _Kt,
1351 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1353 _M_upper_bound_tr(
const _Kt& __k)
1355 const _Rb_tree* __const_this =
this;
1356 return __const_this->_M_upper_bound_tr(__k)._M_const_cast();
1359 template<
typename _Kt,
1360 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1362 _M_upper_bound_tr(
const _Kt& __k)
const
1364 auto __x = _M_begin();
1365 auto __y = _M_end();
1367 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1373 __x = _S_right(__x);
1374 return const_iterator(__y);
1377 template<
typename _Kt,
1378 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1379 pair<iterator, iterator>
1380 _M_equal_range_tr(
const _Kt& __k)
1382 const _Rb_tree* __const_this =
this;
1383 auto __ret = __const_this->_M_equal_range_tr(__k);
1384 return { __ret.first._M_const_cast(), __ret.second._M_const_cast() };
1387 template<
typename _Kt,
1388 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1389 pair<const_iterator, const_iterator>
1390 _M_equal_range_tr(
const _Kt& __k)
const
1392 auto __low = _M_lower_bound_tr(__k);
1393 auto __high = __low;
1394 auto& __cmp = _M_impl._M_key_compare;
1395 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1397 return { __low, __high };
1403 __rb_verify()
const;
1405 #if __cplusplus >= 201103L
1407 operator=(_Rb_tree&&)
1408 noexcept(_Alloc_traits::_S_nothrow_move()
1409 && is_nothrow_move_assignable<_Compare>::value);
1411 template<typename _Iterator>
1413 _M_assign_unique(_Iterator, _Iterator);
1415 template<typename _Iterator>
1417 _M_assign_equal(_Iterator, _Iterator);
1423 { _M_impl._M_move_data(__x._M_impl); }
1440 #if __cplusplus > 201402L
1444 _M_reinsert_node_unique(node_type&& __nh)
1446 insert_return_type __ret;
1448 __ret.position =
end();
1451 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1453 auto __res = _M_get_insert_unique_pos(__nh._M_key());
1457 = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1458 __nh._M_ptr =
nullptr;
1459 __ret.inserted =
true;
1464 __ret.position = iterator(__res.first);
1465 __ret.inserted =
false;
1473 _M_reinsert_node_equal(node_type&& __nh)
1480 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1481 auto __res = _M_get_insert_equal_pos(__nh._M_key());
1483 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1485 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1486 __nh._M_ptr =
nullptr;
1493 _M_reinsert_node_hint_unique(const_iterator __hint, node_type&& __nh)
1500 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1501 auto __res = _M_get_insert_hint_unique_pos(__hint, __nh._M_key());
1504 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1505 __nh._M_ptr =
nullptr;
1508 __ret = iterator(__res.first);
1515 _M_reinsert_node_hint_equal(const_iterator __hint, node_type&& __nh)
1522 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1523 auto __res = _M_get_insert_hint_equal_pos(__hint, __nh._M_key());
1525 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1527 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1528 __nh._M_ptr =
nullptr;
1535 extract(const_iterator __pos)
1537 auto __ptr = _Rb_tree_rebalance_for_erase(
1538 __pos._M_const_cast()._M_node, _M_impl._M_header);
1539 --_M_impl._M_node_count;
1540 return {
static_cast<_Link_type
>(__ptr), _M_get_Node_allocator() };
1545 extract(
const key_type& __k)
1548 auto __pos = find(__k);
1550 __nh = extract(const_iterator(__pos));
1554 template<
typename _Compare2>
1555 using _Compatible_tree
1556 = _Rb_tree<_Key, _Val, _KeyOfValue, _Compare2, _Alloc>;
1558 template<
typename,
typename>
1559 friend class _Rb_tree_merge_helper;
1562 template<
typename _Compare2>
1564 _M_merge_unique(_Compatible_tree<_Compare2>& __src) noexcept
1566 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1567 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1570 auto __res = _M_get_insert_unique_pos(_KeyOfValue()(*__pos));
1573 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1574 auto __ptr = _Rb_tree_rebalance_for_erase(
1575 __pos._M_node, __src_impl._M_header);
1576 --__src_impl._M_node_count;
1577 _M_insert_node(__res.first, __res.second,
1578 static_cast<_Link_type
>(__ptr));
1584 template<
typename _Compare2>
1586 _M_merge_equal(_Compatible_tree<_Compare2>& __src) noexcept
1588 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1589 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1592 auto __res = _M_get_insert_equal_pos(_KeyOfValue()(*__pos));
1595 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1596 auto __ptr = _Rb_tree_rebalance_for_erase(
1597 __pos._M_node, __src_impl._M_header);
1598 --__src_impl._M_node_count;
1599 _M_insert_node(__res.first, __res.second,
1600 static_cast<_Link_type
>(__ptr));
1607 operator==(
const _Rb_tree& __x,
const _Rb_tree& __y)
1609 return __x.size() == __y.size()
1610 &&
std::equal(__x.begin(), __x.end(), __y.begin());
1614 operator<(
const _Rb_tree& __x,
const _Rb_tree& __y)
1617 __y.begin(), __y.end());
1620 friend bool _GLIBCXX_DEPRECATED
1621 operator!=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1622 {
return !(__x == __y); }
1624 friend bool _GLIBCXX_DEPRECATED
1625 operator>(
const _Rb_tree& __x,
const _Rb_tree& __y)
1626 {
return __y < __x; }
1628 friend bool _GLIBCXX_DEPRECATED
1629 operator<=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1630 {
return !(__y < __x); }
1632 friend bool _GLIBCXX_DEPRECATED
1633 operator>=(
const _Rb_tree& __x,
const _Rb_tree& __y)
1634 {
return !(__x < __y); }
1637 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1638 typename _Compare,
typename _Alloc>
1640 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1641 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1644 #if __cplusplus >= 201103L
1645 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1646 typename _Compare,
typename _Alloc>
1648 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1651 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1655 _Alloc_node __an(*
this);
1657 [&__an](
const value_type& __cval)
1659 auto& __val =
const_cast<value_type&
>(__cval);
1662 _M_root() = _M_copy(__x, __lbd);
1666 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1667 typename _Compare,
typename _Alloc>
1669 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1670 _M_move_assign(_Rb_tree& __x,
true_type)
1673 if (__x._M_root() !=
nullptr)
1675 std::__alloc_on_move(_M_get_Node_allocator(),
1676 __x._M_get_Node_allocator());
1679 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1680 typename _Compare,
typename _Alloc>
1682 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1685 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1686 return _M_move_assign(__x,
true_type{});
1690 _Reuse_or_alloc_node __roan(*
this);
1692 if (__x._M_root() !=
nullptr)
1695 [&__roan](
const value_type& __cval)
1697 auto& __val =
const_cast<value_type&
>(__cval);
1700 _M_root() = _M_copy(__x, __lbd);
1705 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1706 typename _Compare,
typename _Alloc>
1707 inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1708 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1709 operator=(_Rb_tree&& __x)
1710 noexcept(_Alloc_traits::_S_nothrow_move()
1711 && is_nothrow_move_assignable<_Compare>::value)
1713 _M_impl._M_key_compare =
std::move(__x._M_impl._M_key_compare);
1714 _M_move_assign(__x, __bool_constant<_Alloc_traits::_S_nothrow_move()>());
1718 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1719 typename _Compare,
typename _Alloc>
1720 template<
typename _Iterator>
1722 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1723 _M_assign_unique(_Iterator __first, _Iterator __last)
1725 _Reuse_or_alloc_node __roan(*
this);
1727 for (; __first != __last; ++__first)
1728 _M_insert_unique_(
end(), *__first, __roan);
1731 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1732 typename _Compare,
typename _Alloc>
1733 template<
typename _Iterator>
1735 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1736 _M_assign_equal(_Iterator __first, _Iterator __last)
1738 _Reuse_or_alloc_node __roan(*
this);
1740 for (; __first != __last; ++__first)
1741 _M_insert_equal_(
end(), *__first, __roan);
1745 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1746 typename _Compare,
typename _Alloc>
1747 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1748 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1749 operator=(
const _Rb_tree& __x)
1754 #if __cplusplus >= 201103L
1755 if (_Alloc_traits::_S_propagate_on_copy_assign())
1757 auto& __this_alloc = this->_M_get_Node_allocator();
1758 auto& __that_alloc = __x._M_get_Node_allocator();
1759 if (!_Alloc_traits::_S_always_equal()
1760 && __this_alloc != __that_alloc)
1765 std::__alloc_on_copy(__this_alloc, __that_alloc);
1770 _Reuse_or_alloc_node __roan(*
this);
1772 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1773 if (__x._M_root() != 0)
1774 _M_root() = _M_copy(__x, __roan);
1780 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1781 typename _Compare,
typename _Alloc>
1782 #if __cplusplus >= 201103L
1783 template<
typename _Arg,
typename _NodeGen>
1785 template<
typename _NodeGen>
1787 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1788 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1789 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1790 #
if __cplusplus >= 201103L
1795 _NodeGen& __node_gen)
1797 bool __insert_left = (__x != 0 || __p == _M_end()
1798 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1801 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1803 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1804 this->_M_impl._M_header);
1805 ++_M_impl._M_node_count;
1806 return iterator(__z);
1809 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1810 typename _Compare,
typename _Alloc>
1811 #if __cplusplus >= 201103L
1812 template<
typename _Arg>
1814 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1815 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1816 #if __cplusplus >= 201103L
1817 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1819 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1822 bool __insert_left = (__p == _M_end()
1823 || !_M_impl._M_key_compare(_S_key(__p),
1824 _KeyOfValue()(__v)));
1826 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1828 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1829 this->_M_impl._M_header);
1830 ++_M_impl._M_node_count;
1831 return iterator(__z);
1834 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1835 typename _Compare,
typename _Alloc>
1836 #if __cplusplus >= 201103L
1837 template<
typename _Arg>
1839 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1840 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1841 #if __cplusplus >= 201103L
1842 _M_insert_equal_lower(_Arg&& __v)
1844 _M_insert_equal_lower(
const _Val& __v)
1847 _Link_type __x = _M_begin();
1848 _Base_ptr __y = _M_end();
1852 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1853 _S_left(__x) : _S_right(__x);
1855 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1858 template<
typename _Key,
typename _Val,
typename _KoV,
1859 typename _Compare,
typename _Alloc>
1860 template<
typename _NodeGen>
1861 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1862 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1863 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen)
1866 _Link_type __top = _M_clone_node(__x, __node_gen);
1867 __top->_M_parent = __p;
1872 __top->_M_right = _M_copy(_S_right(__x), __top, __node_gen);
1878 _Link_type __y = _M_clone_node(__x, __node_gen);
1880 __y->_M_parent = __p;
1882 __y->_M_right = _M_copy(_S_right(__x), __y, __node_gen);
1890 __throw_exception_again;
1895 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1896 typename _Compare,
typename _Alloc>
1898 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1899 _M_erase(_Link_type __x)
1904 _M_erase(_S_right(__x));
1905 _Link_type __y = _S_left(__x);
1911 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1912 typename _Compare,
typename _Alloc>
1913 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1914 _Compare, _Alloc>::iterator
1915 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1916 _M_lower_bound(_Link_type __x, _Base_ptr __y,
1920 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1921 __y = __x, __x = _S_left(__x);
1923 __x = _S_right(__x);
1924 return iterator(__y);
1927 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1928 typename _Compare,
typename _Alloc>
1929 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1930 _Compare, _Alloc>::const_iterator
1931 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1932 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1933 const _Key& __k)
const
1936 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1937 __y = __x, __x = _S_left(__x);
1939 __x = _S_right(__x);
1940 return const_iterator(__y);
1943 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1944 typename _Compare,
typename _Alloc>
1945 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1946 _Compare, _Alloc>::iterator
1947 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1948 _M_upper_bound(_Link_type __x, _Base_ptr __y,
1952 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1953 __y = __x, __x = _S_left(__x);
1955 __x = _S_right(__x);
1956 return iterator(__y);
1959 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1960 typename _Compare,
typename _Alloc>
1961 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1962 _Compare, _Alloc>::const_iterator
1963 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1964 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1965 const _Key& __k)
const
1968 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1969 __y = __x, __x = _S_left(__x);
1971 __x = _S_right(__x);
1972 return const_iterator(__y);
1975 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1976 typename _Compare,
typename _Alloc>
1977 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1978 _Compare, _Alloc>::iterator,
1979 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1980 _Compare, _Alloc>::iterator>
1981 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1982 equal_range(
const _Key& __k)
1984 _Link_type __x = _M_begin();
1985 _Base_ptr __y = _M_end();
1988 if (_M_impl._M_key_compare(_S_key(__x), __k))
1989 __x = _S_right(__x);
1990 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1991 __y = __x, __x = _S_left(__x);
1994 _Link_type __xu(__x);
1995 _Base_ptr __yu(__y);
1996 __y = __x, __x = _S_left(__x);
1997 __xu = _S_right(__xu);
1998 return pair<iterator,
1999 iterator>(_M_lower_bound(__x, __y, __k),
2000 _M_upper_bound(__xu, __yu, __k));
2003 return pair<iterator, iterator>(iterator(__y),
2007 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2008 typename _Compare,
typename _Alloc>
2009 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2010 _Compare, _Alloc>::const_iterator,
2011 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2012 _Compare, _Alloc>::const_iterator>
2013 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2014 equal_range(
const _Key& __k)
const
2016 _Const_Link_type __x = _M_begin();
2017 _Const_Base_ptr __y = _M_end();
2020 if (_M_impl._M_key_compare(_S_key(__x), __k))
2021 __x = _S_right(__x);
2022 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
2023 __y = __x, __x = _S_left(__x);
2026 _Const_Link_type __xu(__x);
2027 _Const_Base_ptr __yu(__y);
2028 __y = __x, __x = _S_left(__x);
2029 __xu = _S_right(__xu);
2030 return pair<const_iterator,
2031 const_iterator>(_M_lower_bound(__x, __y, __k),
2032 _M_upper_bound(__xu, __yu, __k));
2035 return pair<const_iterator, const_iterator>(const_iterator(__y),
2036 const_iterator(__y));
2039 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2040 typename _Compare,
typename _Alloc>
2042 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2044 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
2048 if (__t._M_root() != 0)
2049 _M_impl._M_move_data(__t._M_impl);
2051 else if (__t._M_root() == 0)
2052 __t._M_impl._M_move_data(_M_impl);
2055 std::swap(_M_root(),__t._M_root());
2056 std::swap(_M_leftmost(),__t._M_leftmost());
2057 std::swap(_M_rightmost(),__t._M_rightmost());
2059 _M_root()->_M_parent = _M_end();
2060 __t._M_root()->_M_parent = __t._M_end();
2061 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
2064 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
2066 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
2067 __t._M_get_Node_allocator());
2070 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2071 typename _Compare,
typename _Alloc>
2072 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2073 _Compare, _Alloc>::_Base_ptr,
2074 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2075 _Compare, _Alloc>::_Base_ptr>
2076 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2077 _M_get_insert_unique_pos(
const key_type& __k)
2079 typedef pair<_Base_ptr, _Base_ptr> _Res;
2080 _Link_type __x = _M_begin();
2081 _Base_ptr __y = _M_end();
2086 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
2087 __x = __comp ? _S_left(__x) : _S_right(__x);
2089 iterator __j = iterator(__y);
2093 return _Res(__x, __y);
2097 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
2098 return _Res(__x, __y);
2099 return _Res(__j._M_node, 0);
2102 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2103 typename _Compare,
typename _Alloc>
2104 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2105 _Compare, _Alloc>::_Base_ptr,
2106 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2107 _Compare, _Alloc>::_Base_ptr>
2108 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2109 _M_get_insert_equal_pos(
const key_type& __k)
2111 typedef pair<_Base_ptr, _Base_ptr> _Res;
2112 _Link_type __x = _M_begin();
2113 _Base_ptr __y = _M_end();
2117 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
2118 _S_left(__x) : _S_right(__x);
2120 return _Res(__x, __y);
2123 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2124 typename _Compare,
typename _Alloc>
2125 #if __cplusplus >= 201103L
2126 template<
typename _Arg>
2128 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2129 _Compare, _Alloc>::iterator,
bool>
2130 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2131 #if __cplusplus >= 201103L
2132 _M_insert_unique(_Arg&& __v)
2134 _M_insert_unique(
const _Val& __v)
2137 typedef pair<iterator, bool> _Res;
2138 pair<_Base_ptr, _Base_ptr> __res
2139 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
2143 _Alloc_node __an(*
this);
2144 return _Res(_M_insert_(__res.first, __res.second,
2145 _GLIBCXX_FORWARD(_Arg, __v), __an),
2149 return _Res(iterator(__res.first),
false);
2152 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2153 typename _Compare,
typename _Alloc>
2154 #if __cplusplus >= 201103L
2155 template<
typename _Arg>
2157 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2158 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2159 #if __cplusplus >= 201103L
2160 _M_insert_equal(_Arg&& __v)
2162 _M_insert_equal(
const _Val& __v)
2165 pair<_Base_ptr, _Base_ptr> __res
2166 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
2167 _Alloc_node __an(*
this);
2168 return _M_insert_(__res.first, __res.second,
2169 _GLIBCXX_FORWARD(_Arg, __v), __an);
2172 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2173 typename _Compare,
typename _Alloc>
2174 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2175 _Compare, _Alloc>::_Base_ptr,
2176 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2177 _Compare, _Alloc>::_Base_ptr>
2178 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2179 _M_get_insert_hint_unique_pos(const_iterator __position,
2180 const key_type& __k)
2182 iterator __pos = __position._M_const_cast();
2183 typedef pair<_Base_ptr, _Base_ptr> _Res;
2186 if (__pos._M_node == _M_end())
2189 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
2190 return _Res(0, _M_rightmost());
2192 return _M_get_insert_unique_pos(__k);
2194 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
2197 iterator __before = __pos;
2198 if (__pos._M_node == _M_leftmost())
2199 return _Res(_M_leftmost(), _M_leftmost());
2200 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
2202 if (_S_right(__before._M_node) == 0)
2203 return _Res(0, __before._M_node);
2205 return _Res(__pos._M_node, __pos._M_node);
2208 return _M_get_insert_unique_pos(__k);
2210 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2213 iterator __after = __pos;
2214 if (__pos._M_node == _M_rightmost())
2215 return _Res(0, _M_rightmost());
2216 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
2218 if (_S_right(__pos._M_node) == 0)
2219 return _Res(0, __pos._M_node);
2221 return _Res(__after._M_node, __after._M_node);
2224 return _M_get_insert_unique_pos(__k);
2228 return _Res(__pos._M_node, 0);
2231 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2232 typename _Compare,
typename _Alloc>
2233 #if __cplusplus >= 201103L
2234 template<
typename _Arg,
typename _NodeGen>
2236 template<
typename _NodeGen>
2238 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2239 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2240 _M_insert_unique_(const_iterator __position,
2241 #
if __cplusplus >= 201103L
2246 _NodeGen& __node_gen)
2248 pair<_Base_ptr, _Base_ptr> __res
2249 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
2252 return _M_insert_(__res.first, __res.second,
2253 _GLIBCXX_FORWARD(_Arg, __v),
2255 return iterator(__res.first);
2258 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2259 typename _Compare,
typename _Alloc>
2260 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2261 _Compare, _Alloc>::_Base_ptr,
2262 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2263 _Compare, _Alloc>::_Base_ptr>
2264 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2265 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
2267 iterator __pos = __position._M_const_cast();
2268 typedef pair<_Base_ptr, _Base_ptr> _Res;
2271 if (__pos._M_node == _M_end())
2274 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
2275 return _Res(0, _M_rightmost());
2277 return _M_get_insert_equal_pos(__k);
2279 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2282 iterator __before = __pos;
2283 if (__pos._M_node == _M_leftmost())
2284 return _Res(_M_leftmost(), _M_leftmost());
2285 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2287 if (_S_right(__before._M_node) == 0)
2288 return _Res(0, __before._M_node);
2290 return _Res(__pos._M_node, __pos._M_node);
2293 return _M_get_insert_equal_pos(__k);
2298 iterator __after = __pos;
2299 if (__pos._M_node == _M_rightmost())
2300 return _Res(0, _M_rightmost());
2301 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2303 if (_S_right(__pos._M_node) == 0)
2304 return _Res(0, __pos._M_node);
2306 return _Res(__after._M_node, __after._M_node);
2313 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2314 typename _Compare,
typename _Alloc>
2315 #if __cplusplus >= 201103L
2316 template<
typename _Arg,
typename _NodeGen>
2318 template<
typename _NodeGen>
2320 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2321 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2322 _M_insert_equal_(const_iterator __position,
2323 #
if __cplusplus >= 201103L
2328 _NodeGen& __node_gen)
2330 pair<_Base_ptr, _Base_ptr> __res
2331 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2334 return _M_insert_(__res.first, __res.second,
2335 _GLIBCXX_FORWARD(_Arg, __v),
2338 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2341 #if __cplusplus >= 201103L
2342 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2343 typename _Compare,
typename _Alloc>
2344 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2345 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2346 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2348 bool __insert_left = (__x != 0 || __p == _M_end()
2349 || _M_impl._M_key_compare(_S_key(__z),
2352 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2353 this->_M_impl._M_header);
2354 ++_M_impl._M_node_count;
2355 return iterator(__z);
2358 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2359 typename _Compare,
typename _Alloc>
2360 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2361 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2362 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2364 bool __insert_left = (__p == _M_end()
2365 || !_M_impl._M_key_compare(_S_key(__p),
2368 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2369 this->_M_impl._M_header);
2370 ++_M_impl._M_node_count;
2371 return iterator(__z);
2374 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2375 typename _Compare,
typename _Alloc>
2376 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2377 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2378 _M_insert_equal_lower_node(_Link_type __z)
2380 _Link_type __x = _M_begin();
2381 _Base_ptr __y = _M_end();
2385 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2386 _S_left(__x) : _S_right(__x);
2388 return _M_insert_lower_node(__y, __z);
2391 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2392 typename _Compare,
typename _Alloc>
2393 template<
typename... _Args>
2394 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2395 _Compare, _Alloc>::iterator,
bool>
2396 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2397 _M_emplace_unique(_Args&&... __args)
2399 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2403 typedef pair<iterator, bool> _Res;
2404 auto __res = _M_get_insert_unique_pos(_S_key(__z));
2406 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
2409 return _Res(iterator(__res.first),
false);
2414 __throw_exception_again;
2418 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2419 typename _Compare,
typename _Alloc>
2420 template<
typename... _Args>
2421 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2422 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2423 _M_emplace_equal(_Args&&... __args)
2425 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2429 auto __res = _M_get_insert_equal_pos(_S_key(__z));
2430 return _M_insert_node(__res.first, __res.second, __z);
2435 __throw_exception_again;
2439 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2440 typename _Compare,
typename _Alloc>
2441 template<
typename... _Args>
2442 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2443 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2444 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
2446 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2450 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
2453 return _M_insert_node(__res.first, __res.second, __z);
2456 return iterator(__res.first);
2461 __throw_exception_again;
2465 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2466 typename _Compare,
typename _Alloc>
2467 template<
typename... _Args>
2468 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2469 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2470 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2472 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2476 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
2479 return _M_insert_node(__res.first, __res.second, __z);
2481 return _M_insert_equal_lower_node(__z);
2486 __throw_exception_again;
2492 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2493 typename _Compare,
typename _Alloc>
2495 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2496 _M_erase_aux(const_iterator __position)
2499 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
2500 (
const_cast<_Base_ptr
>(__position._M_node),
2501 this->_M_impl._M_header));
2503 --_M_impl._M_node_count;
2506 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2507 typename _Compare,
typename _Alloc>
2509 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2510 _M_erase_aux(const_iterator __first, const_iterator __last)
2512 if (__first ==
begin() && __last ==
end())
2515 while (__first != __last)
2516 _M_erase_aux(__first++);
2519 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2520 typename _Compare,
typename _Alloc>
2521 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2522 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2523 erase(
const _Key& __x)
2525 pair<iterator, iterator> __p = equal_range(__x);
2526 const size_type __old_size = size();
2527 _M_erase_aux(__p.first, __p.second);
2528 return __old_size - size();
2531 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2532 typename _Compare,
typename _Alloc>
2533 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2534 _Compare, _Alloc>::iterator
2535 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2536 find(
const _Key& __k)
2538 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2539 return (__j ==
end()
2540 || _M_impl._M_key_compare(__k,
2541 _S_key(__j._M_node))) ?
end() : __j;
2544 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2545 typename _Compare,
typename _Alloc>
2546 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2547 _Compare, _Alloc>::const_iterator
2548 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2549 find(
const _Key& __k)
const
2551 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2552 return (__j ==
end()
2553 || _M_impl._M_key_compare(__k,
2554 _S_key(__j._M_node))) ?
end() : __j;
2557 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2558 typename _Compare,
typename _Alloc>
2559 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2560 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2561 count(
const _Key& __k)
const
2563 pair<const_iterator, const_iterator> __p = equal_range(__k);
2568 _GLIBCXX_PURE
unsigned int
2569 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
2570 const _Rb_tree_node_base* __root)
throw ();
2572 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2573 typename _Compare,
typename _Alloc>
2575 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const
2577 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
2578 return _M_impl._M_node_count == 0 &&
begin() ==
end()
2579 && this->_M_impl._M_header._M_left == _M_end()
2580 && this->_M_impl._M_header._M_right == _M_end();
2582 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
2583 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
2585 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
2586 _Const_Link_type __L = _S_left(__x);
2587 _Const_Link_type __R = _S_right(__x);
2589 if (__x->_M_color == _S_red)
2590 if ((__L && __L->_M_color == _S_red)
2591 || (__R && __R->_M_color == _S_red))
2594 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
2596 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
2599 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
2603 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
2605 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
2610 #if __cplusplus > 201402L
2612 template<
typename _Key,
typename _Val,
typename _Sel,
typename _Cmp1,
2613 typename _Alloc,
typename _Cmp2>
2614 struct _Rb_tree_merge_helper<_Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>,
2618 friend class _Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>;
2621 _S_get_impl(_Rb_tree<_Key, _Val, _Sel, _Cmp2, _Alloc>& __tree)
2622 {
return __tree._M_impl; }
2626 _GLIBCXX_END_NAMESPACE_VERSION