61#pragma GCC system_header
68#if __cplusplus >= 201103L
71#if __cplusplus > 201402L
75namespace 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; }
318#if ! __cpp_lib_three_way_comparison
320 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
321 {
return __x._M_node != __y._M_node; }
327 template<
typename _Tp>
328 struct _Rb_tree_const_iterator
330 typedef _Tp value_type;
331 typedef const _Tp& reference;
332 typedef const _Tp* pointer;
334 typedef _Rb_tree_iterator<_Tp> iterator;
336 typedef bidirectional_iterator_tag iterator_category;
337 typedef ptrdiff_t difference_type;
339 typedef _Rb_tree_const_iterator<_Tp> _Self;
340 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
341 typedef const _Rb_tree_node<_Tp>* _Link_type;
343 _Rb_tree_const_iterator() _GLIBCXX_NOEXCEPT
347 _Rb_tree_const_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
350 _Rb_tree_const_iterator(
const iterator& __it) _GLIBCXX_NOEXCEPT
351 : _M_node(__it._M_node) { }
354 _M_const_cast() const _GLIBCXX_NOEXCEPT
355 {
return iterator(
const_cast<typename iterator::_Base_ptr
>(_M_node)); }
359 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
362 operator->() const _GLIBCXX_NOEXCEPT
363 {
return static_cast<_Link_type
>(_M_node)->_M_valptr(); }
366 operator++() _GLIBCXX_NOEXCEPT
368 _M_node = _Rb_tree_increment(_M_node);
373 operator++(
int) _GLIBCXX_NOEXCEPT
376 _M_node = _Rb_tree_increment(_M_node);
381 operator--() _GLIBCXX_NOEXCEPT
383 _M_node = _Rb_tree_decrement(_M_node);
388 operator--(
int) _GLIBCXX_NOEXCEPT
391 _M_node = _Rb_tree_decrement(_M_node);
396 operator==(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
397 {
return __x._M_node == __y._M_node; }
399#if ! __cpp_lib_three_way_comparison
401 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
402 {
return __x._M_node != __y._M_node; }
409 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
410 _Rb_tree_node_base* __x,
411 _Rb_tree_node_base* __p,
412 _Rb_tree_node_base& __header)
throw ();
415 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base*
const __z,
416 _Rb_tree_node_base& __header)
throw ();
418#if __cplusplus > 201402L
419 template<
typename _Tree1,
typename _Cmp2>
420 struct _Rb_tree_merge_helper { };
423 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
424 typename _Compare,
typename _Alloc = allocator<_Val> >
428 rebind<_Rb_tree_node<_Val> >::other _Node_allocator;
433 typedef _Rb_tree_node_base* _Base_ptr;
434 typedef const _Rb_tree_node_base* _Const_Base_ptr;
435 typedef _Rb_tree_node<_Val>* _Link_type;
436 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
441 struct _Reuse_or_alloc_node
443 _Reuse_or_alloc_node(_Rb_tree& __t)
444 : _M_root(__t._M_root()), _M_nodes(__t._M_rightmost()), _M_t(__t)
448 _M_root->_M_parent = 0;
450 if (_M_nodes->_M_left)
451 _M_nodes = _M_nodes->_M_left;
457#if __cplusplus >= 201103L
458 _Reuse_or_alloc_node(
const _Reuse_or_alloc_node&) =
delete;
461 ~_Reuse_or_alloc_node()
462 { _M_t._M_erase(
static_cast<_Link_type
>(_M_root)); }
464 template<
typename _Arg>
466 operator()(_GLIBCXX_FWDREF(_Arg) __arg)
468 _Link_type __node =
static_cast<_Link_type
>(_M_extract());
471 _M_t._M_destroy_node(__node);
472 _M_t._M_construct_node(__node, _GLIBCXX_FORWARD(_Arg, __arg));
476 return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg));
486 _Base_ptr __node = _M_nodes;
487 _M_nodes = _M_nodes->_M_parent;
490 if (_M_nodes->_M_right == __node)
492 _M_nodes->_M_right = 0;
494 if (_M_nodes->_M_left)
496 _M_nodes = _M_nodes->_M_left;
498 while (_M_nodes->_M_right)
499 _M_nodes = _M_nodes->_M_right;
501 if (_M_nodes->_M_left)
502 _M_nodes = _M_nodes->_M_left;
506 _M_nodes->_M_left = 0;
523 _Alloc_node(_Rb_tree& __t)
526 template<
typename _Arg>
528 operator()(_GLIBCXX_FWDREF(_Arg) __arg)
const
529 {
return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg)); }
536 typedef _Key key_type;
537 typedef _Val value_type;
538 typedef value_type* pointer;
539 typedef const value_type* const_pointer;
540 typedef value_type& reference;
541 typedef const value_type& const_reference;
542 typedef size_t size_type;
543 typedef ptrdiff_t difference_type;
544 typedef _Alloc allocator_type;
547 _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
548 {
return this->_M_impl; }
550 const _Node_allocator&
551 _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
552 {
return this->_M_impl; }
555 get_allocator() const _GLIBCXX_NOEXCEPT
556 {
return allocator_type(_M_get_Node_allocator()); }
564 _M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT
567#if __cplusplus < 201103L
569 _M_construct_node(_Link_type __node,
const value_type& __x)
572 { get_allocator().construct(__node->_M_valptr(), __x); }
576 __throw_exception_again;
581 _M_create_node(
const value_type& __x)
583 _Link_type __tmp = _M_get_node();
584 _M_construct_node(__tmp, __x);
588 template<
typename... _Args>
590 _M_construct_node(_Link_type __node, _Args&&... __args)
594 ::new(__node) _Rb_tree_node<_Val>;
595 _Alloc_traits::construct(_M_get_Node_allocator(),
597 std::forward<_Args>(__args)...);
601 __node->~_Rb_tree_node<_Val>();
603 __throw_exception_again;
607 template<
typename... _Args>
609 _M_create_node(_Args&&... __args)
611 _Link_type __tmp = _M_get_node();
612 _M_construct_node(__tmp, std::forward<_Args>(__args)...);
618 _M_destroy_node(_Link_type __p) _GLIBCXX_NOEXCEPT
620#if __cplusplus < 201103L
621 get_allocator().destroy(__p->_M_valptr());
623 _Alloc_traits::destroy(_M_get_Node_allocator(), __p->_M_valptr());
624 __p->~_Rb_tree_node<_Val>();
629 _M_drop_node(_Link_type __p) _GLIBCXX_NOEXCEPT
631 _M_destroy_node(__p);
635 template<
bool _MoveValue,
typename _NodeGen>
637 _M_clone_node(_Link_type __x, _NodeGen& __node_gen)
639#if __cplusplus >= 201103L
640 using _Vp =
typename conditional<_MoveValue,
642 const value_type&>::type;
645 = __node_gen(_GLIBCXX_FORWARD(_Vp, *__x->_M_valptr()));
646 __tmp->_M_color = __x->_M_color;
653#if _GLIBCXX_INLINE_VERSION
654 template<
typename _Key_compare>
657 template<
typename _Key_compare,
658 bool = __is_pod(_Key_compare)>
661 :
public _Node_allocator
662 ,
public _Rb_tree_key_compare<_Key_compare>
663 ,
public _Rb_tree_header
665 typedef _Rb_tree_key_compare<_Key_compare> _Base_key_compare;
668 _GLIBCXX_NOEXCEPT_IF(
669 is_nothrow_default_constructible<_Node_allocator>::value
670 && is_nothrow_default_constructible<_Base_key_compare>::value )
674 _Rb_tree_impl(
const _Rb_tree_impl& __x)
675 : _Node_allocator(_Alloc_traits::_S_select_on_copy(__x))
676 , _Base_key_compare(__x._M_key_compare)
680#if __cplusplus < 201103L
681 _Rb_tree_impl(
const _Key_compare& __comp,
const _Node_allocator& __a)
682 : _Node_allocator(__a), _Base_key_compare(__comp)
685 _Rb_tree_impl(_Rb_tree_impl&&)
686 noexcept( is_nothrow_move_constructible<_Base_key_compare>::value )
690 _Rb_tree_impl(_Node_allocator&& __a)
691 : _Node_allocator(
std::
move(__a))
694 _Rb_tree_impl(_Rb_tree_impl&& __x, _Node_allocator&& __a)
695 : _Node_allocator(
std::
move(__a)),
696 _Base_key_compare(
std::
move(__x)),
697 _Rb_tree_header(
std::
move(__x))
700 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
701 : _Node_allocator(
std::
move(__a)), _Base_key_compare(__comp)
706 _Rb_tree_impl<_Compare> _M_impl;
710 _M_root() _GLIBCXX_NOEXCEPT
711 {
return this->_M_impl._M_header._M_parent; }
714 _M_root() const _GLIBCXX_NOEXCEPT
715 {
return this->_M_impl._M_header._M_parent; }
718 _M_leftmost() _GLIBCXX_NOEXCEPT
719 {
return this->_M_impl._M_header._M_left; }
722 _M_leftmost() const _GLIBCXX_NOEXCEPT
723 {
return this->_M_impl._M_header._M_left; }
726 _M_rightmost() _GLIBCXX_NOEXCEPT
727 {
return this->_M_impl._M_header._M_right; }
730 _M_rightmost() const _GLIBCXX_NOEXCEPT
731 {
return this->_M_impl._M_header._M_right; }
734 _M_mbegin() const _GLIBCXX_NOEXCEPT
735 {
return static_cast<_Link_type
>(this->_M_impl._M_header._M_parent); }
738 _M_begin() _GLIBCXX_NOEXCEPT
739 {
return _M_mbegin(); }
742 _M_begin() const _GLIBCXX_NOEXCEPT
744 return static_cast<_Const_Link_type
>
745 (this->_M_impl._M_header._M_parent);
749 _M_end() _GLIBCXX_NOEXCEPT
750 {
return &this->_M_impl._M_header; }
753 _M_end() const _GLIBCXX_NOEXCEPT
754 {
return &this->_M_impl._M_header; }
757 _S_key(_Const_Link_type __x)
759#if __cplusplus >= 201103L
762 static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
763 "comparison object must be invocable "
764 "with two arguments of key type");
765# if __cplusplus >= 201703L
768 if constexpr (__is_invocable<_Compare&, const _Key&, const _Key&>{})
770 is_invocable_v<const _Compare&, const _Key&, const _Key&>,
771 "comparison object must be invocable as const");
775 return _KeyOfValue()(*__x->_M_valptr());
779 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
780 {
return static_cast<_Link_type
>(__x->_M_left); }
782 static _Const_Link_type
783 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
784 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
787 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
788 {
return static_cast<_Link_type
>(__x->_M_right); }
790 static _Const_Link_type
791 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
792 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
795 _S_key(_Const_Base_ptr __x)
796 {
return _S_key(
static_cast<_Const_Link_type
>(__x)); }
799 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
800 {
return _Rb_tree_node_base::_S_minimum(__x); }
802 static _Const_Base_ptr
803 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
804 {
return _Rb_tree_node_base::_S_minimum(__x); }
807 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
808 {
return _Rb_tree_node_base::_S_maximum(__x); }
810 static _Const_Base_ptr
811 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
812 {
return _Rb_tree_node_base::_S_maximum(__x); }
815 typedef _Rb_tree_iterator<value_type> iterator;
816 typedef _Rb_tree_const_iterator<value_type> const_iterator;
821#if __cplusplus > 201402L
822 using node_type = _Node_handle<_Key, _Val, _Node_allocator>;
823 using insert_return_type = _Node_insert_return<
824 conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
828 pair<_Base_ptr, _Base_ptr>
829 _M_get_insert_unique_pos(
const key_type& __k);
831 pair<_Base_ptr, _Base_ptr>
832 _M_get_insert_equal_pos(
const key_type& __k);
834 pair<_Base_ptr, _Base_ptr>
835 _M_get_insert_hint_unique_pos(const_iterator __pos,
836 const key_type& __k);
838 pair<_Base_ptr, _Base_ptr>
839 _M_get_insert_hint_equal_pos(const_iterator __pos,
840 const key_type& __k);
843#if __cplusplus >= 201103L
844 template<
typename _Arg,
typename _NodeGen>
846 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&);
849 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
851 template<
typename _Arg>
853 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
855 template<
typename _Arg>
857 _M_insert_equal_lower(_Arg&& __x);
860 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
863 _M_insert_equal_lower_node(_Link_type __z);
865 template<
typename _NodeGen>
867 _M_insert_(_Base_ptr __x, _Base_ptr __y,
868 const value_type& __v, _NodeGen&);
873 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
876 _M_insert_equal_lower(
const value_type& __x);
879 enum { __as_lvalue, __as_rvalue };
881 template<
bool _MoveValues,
typename _NodeGen>
883 _M_copy(_Link_type, _Base_ptr, _NodeGen&);
885 template<
bool _MoveValues,
typename _NodeGen>
887 _M_copy(
const _Rb_tree& __x, _NodeGen& __gen)
890 _M_copy<_MoveValues>(__x._M_mbegin(), _M_end(), __gen);
891 _M_leftmost() = _S_minimum(__root);
892 _M_rightmost() = _S_maximum(__root);
893 _M_impl._M_node_count = __x._M_impl._M_node_count;
898 _M_copy(
const _Rb_tree& __x)
900 _Alloc_node __an(*
this);
901 return _M_copy<__as_lvalue>(__x, __an);
905 _M_erase(_Link_type __x);
908 _M_lower_bound(_Link_type __x, _Base_ptr __y,
912 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
913 const _Key& __k)
const;
916 _M_upper_bound(_Link_type __x, _Base_ptr __y,
920 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
921 const _Key& __k)
const;
925#if __cplusplus < 201103L
928 _Rb_tree() =
default;
931 _Rb_tree(
const _Compare& __comp,
932 const allocator_type& __a = allocator_type())
933 : _M_impl(__comp, _Node_allocator(__a)) { }
935 _Rb_tree(
const _Rb_tree& __x)
936 : _M_impl(__x._M_impl)
938 if (__x._M_root() != 0)
939 _M_root() = _M_copy(__x);
942#if __cplusplus >= 201103L
943 _Rb_tree(
const allocator_type& __a)
944 : _M_impl(_Node_allocator(__a))
947 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
948 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
950 if (__x._M_root() !=
nullptr)
951 _M_root() = _M_copy(__x);
954 _Rb_tree(_Rb_tree&&) =
default;
956 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
957 : _Rb_tree(
std::
move(__x), _Node_allocator(__a))
961 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
true_type)
962 noexcept(is_nothrow_default_constructible<_Compare>::value)
966 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a,
false_type)
967 : _M_impl(__x._M_impl._M_key_compare,
std::
move(__a))
969 if (__x._M_root() !=
nullptr)
974 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
976 _Rb_tree(std::declval<_Rb_tree&&>(), std::declval<_Node_allocator&&>(),
977 std::declval<typename _Alloc_traits::is_always_equal>())) )
983 ~_Rb_tree() _GLIBCXX_NOEXCEPT
984 { _M_erase(_M_begin()); }
987 operator=(
const _Rb_tree& __x);
992 {
return _M_impl._M_key_compare; }
995 begin() _GLIBCXX_NOEXCEPT
996 {
return iterator(this->_M_impl._M_header._M_left); }
999 begin() const _GLIBCXX_NOEXCEPT
1000 {
return const_iterator(this->_M_impl._M_header._M_left); }
1003 end() _GLIBCXX_NOEXCEPT
1004 {
return iterator(&this->_M_impl._M_header); }
1007 end() const _GLIBCXX_NOEXCEPT
1008 {
return const_iterator(&this->_M_impl._M_header); }
1011 rbegin() _GLIBCXX_NOEXCEPT
1012 {
return reverse_iterator(
end()); }
1014 const_reverse_iterator
1015 rbegin() const _GLIBCXX_NOEXCEPT
1016 {
return const_reverse_iterator(
end()); }
1019 rend() _GLIBCXX_NOEXCEPT
1020 {
return reverse_iterator(
begin()); }
1022 const_reverse_iterator
1023 rend() const _GLIBCXX_NOEXCEPT
1024 {
return const_reverse_iterator(
begin()); }
1026 _GLIBCXX_NODISCARD
bool
1027 empty() const _GLIBCXX_NOEXCEPT
1028 {
return _M_impl._M_node_count == 0; }
1031 size() const _GLIBCXX_NOEXCEPT
1032 {
return _M_impl._M_node_count; }
1035 max_size() const _GLIBCXX_NOEXCEPT
1040 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value);
1043#if __cplusplus >= 201103L
1044 template<
typename _Arg>
1045 pair<iterator, bool>
1046 _M_insert_unique(_Arg&& __x);
1048 template<
typename _Arg>
1050 _M_insert_equal(_Arg&& __x);
1052 template<
typename _Arg,
typename _NodeGen>
1054 _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1056 template<
typename _Arg>
1058 _M_insert_unique_(const_iterator __pos, _Arg&& __x)
1060 _Alloc_node __an(*
this);
1061 return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an);
1064 template<
typename _Arg,
typename _NodeGen>
1066 _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1068 template<
typename _Arg>
1070 _M_insert_equal_(const_iterator __pos, _Arg&& __x)
1072 _Alloc_node __an(*
this);
1073 return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an);
1076 template<
typename... _Args>
1077 pair<iterator, bool>
1078 _M_emplace_unique(_Args&&... __args);
1080 template<
typename... _Args>
1082 _M_emplace_equal(_Args&&... __args);
1084 template<
typename... _Args>
1086 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
1088 template<
typename... _Args>
1090 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
1092 template<
typename _Iter>
1093 using __same_value_type
1094 = is_same<value_type, typename iterator_traits<_Iter>::value_type>;
1096 template<
typename _InputIterator>
1097 __enable_if_t<__same_value_type<_InputIterator>::value>
1098 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1100 _Alloc_node __an(*
this);
1101 for (; __first != __last; ++__first)
1102 _M_insert_unique_(
end(), *__first, __an);
1105 template<
typename _InputIterator>
1106 __enable_if_t<!__same_value_type<_InputIterator>::value>
1107 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1109 for (; __first != __last; ++__first)
1110 _M_emplace_unique(*__first);
1113 template<
typename _InputIterator>
1114 __enable_if_t<__same_value_type<_InputIterator>::value>
1115 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1117 _Alloc_node __an(*
this);
1118 for (; __first != __last; ++__first)
1119 _M_insert_equal_(
end(), *__first, __an);
1122 template<
typename _InputIterator>
1123 __enable_if_t<!__same_value_type<_InputIterator>::value>
1124 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1126 _Alloc_node __an(*
this);
1127 for (; __first != __last; ++__first)
1128 _M_emplace_equal(*__first);
1131 pair<iterator, bool>
1132 _M_insert_unique(
const value_type& __x);
1135 _M_insert_equal(
const value_type& __x);
1137 template<
typename _NodeGen>
1139 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
1143 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
1145 _Alloc_node __an(*
this);
1146 return _M_insert_unique_(__pos, __x, __an);
1149 template<
typename _NodeGen>
1151 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
1154 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
1156 _Alloc_node __an(*
this);
1157 return _M_insert_equal_(__pos, __x, __an);
1160 template<
typename _InputIterator>
1162 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1164 _Alloc_node __an(*
this);
1165 for (; __first != __last; ++__first)
1166 _M_insert_unique_(
end(), *__first, __an);
1169 template<
typename _InputIterator>
1171 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1173 _Alloc_node __an(*
this);
1174 for (; __first != __last; ++__first)
1175 _M_insert_equal_(
end(), *__first, __an);
1181 _M_erase_aux(const_iterator __position);
1184 _M_erase_aux(const_iterator __first, const_iterator __last);
1187#if __cplusplus >= 201103L
1190 _GLIBCXX_ABI_TAG_CXX11
1192 erase(const_iterator __position)
1194 __glibcxx_assert(__position !=
end());
1195 const_iterator __result = __position;
1197 _M_erase_aux(__position);
1198 return __result._M_const_cast();
1202 _GLIBCXX_ABI_TAG_CXX11
1204 erase(iterator __position)
1206 __glibcxx_assert(__position !=
end());
1207 iterator __result = __position;
1209 _M_erase_aux(__position);
1214 erase(iterator __position)
1216 __glibcxx_assert(__position !=
end());
1217 _M_erase_aux(__position);
1221 erase(const_iterator __position)
1223 __glibcxx_assert(__position !=
end());
1224 _M_erase_aux(__position);
1229 erase(
const key_type& __x);
1231#if __cplusplus >= 201103L
1234 _GLIBCXX_ABI_TAG_CXX11
1236 erase(const_iterator __first, const_iterator __last)
1238 _M_erase_aux(__first, __last);
1239 return __last._M_const_cast();
1243 erase(iterator __first, iterator __last)
1244 { _M_erase_aux(__first, __last); }
1247 erase(const_iterator __first, const_iterator __last)
1248 { _M_erase_aux(__first, __last); }
1252 clear() _GLIBCXX_NOEXCEPT
1254 _M_erase(_M_begin());
1260 find(
const key_type& __k);
1263 find(
const key_type& __k)
const;
1266 count(
const key_type& __k)
const;
1269 lower_bound(
const key_type& __k)
1270 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1273 lower_bound(
const key_type& __k)
const
1274 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1277 upper_bound(
const key_type& __k)
1278 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1281 upper_bound(
const key_type& __k)
const
1282 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1284 pair<iterator, iterator>
1285 equal_range(
const key_type& __k);
1287 pair<const_iterator, const_iterator>
1288 equal_range(
const key_type& __k)
const;
1290#if __cplusplus >= 201402L
1291 template<
typename _Kt,
1292 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1294 _M_find_tr(
const _Kt& __k)
1296 const _Rb_tree* __const_this =
this;
1297 return __const_this->_M_find_tr(__k)._M_const_cast();
1300 template<
typename _Kt,
1301 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1303 _M_find_tr(
const _Kt& __k)
const
1305 auto __j = _M_lower_bound_tr(__k);
1306 if (__j !=
end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node)))
1311 template<
typename _Kt,
1312 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1314 _M_count_tr(
const _Kt& __k)
const
1316 auto __p = _M_equal_range_tr(__k);
1320 template<
typename _Kt,
1321 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1323 _M_lower_bound_tr(
const _Kt& __k)
1325 const _Rb_tree* __const_this =
this;
1326 return __const_this->_M_lower_bound_tr(__k)._M_const_cast();
1329 template<
typename _Kt,
1330 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1332 _M_lower_bound_tr(
const _Kt& __k)
const
1334 auto __x = _M_begin();
1335 auto __y = _M_end();
1337 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1343 __x = _S_right(__x);
1344 return const_iterator(__y);
1347 template<
typename _Kt,
1348 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1350 _M_upper_bound_tr(
const _Kt& __k)
1352 const _Rb_tree* __const_this =
this;
1353 return __const_this->_M_upper_bound_tr(__k)._M_const_cast();
1356 template<
typename _Kt,
1357 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1359 _M_upper_bound_tr(
const _Kt& __k)
const
1361 auto __x = _M_begin();
1362 auto __y = _M_end();
1364 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1370 __x = _S_right(__x);
1371 return const_iterator(__y);
1374 template<
typename _Kt,
1375 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1376 pair<iterator, iterator>
1377 _M_equal_range_tr(
const _Kt& __k)
1379 const _Rb_tree* __const_this =
this;
1380 auto __ret = __const_this->_M_equal_range_tr(__k);
1381 return { __ret.first._M_const_cast(), __ret.second._M_const_cast() };
1384 template<
typename _Kt,
1385 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1386 pair<const_iterator, const_iterator>
1387 _M_equal_range_tr(
const _Kt& __k)
const
1389 auto __low = _M_lower_bound_tr(__k);
1390 auto __high = __low;
1391 auto& __cmp = _M_impl._M_key_compare;
1392 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1394 return { __low, __high };
1400 __rb_verify()
const;
1402#if __cplusplus >= 201103L
1404 operator=(_Rb_tree&&)
1405 noexcept(_Alloc_traits::_S_nothrow_move()
1406 && is_nothrow_move_assignable<_Compare>::value);
1408 template<typename _Iterator>
1410 _M_assign_unique(_Iterator, _Iterator);
1412 template<typename _Iterator>
1414 _M_assign_equal(_Iterator, _Iterator);
1420 { _M_impl._M_move_data(__x._M_impl); }
1437#if __cplusplus > 201402L
1441 _M_reinsert_node_unique(node_type&& __nh)
1443 insert_return_type __ret;
1445 __ret.position =
end();
1448 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1450 auto __res = _M_get_insert_unique_pos(__nh._M_key());
1454 = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1455 __nh._M_ptr =
nullptr;
1456 __ret.inserted =
true;
1461 __ret.position = iterator(__res.first);
1462 __ret.inserted =
false;
1470 _M_reinsert_node_equal(node_type&& __nh)
1477 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1478 auto __res = _M_get_insert_equal_pos(__nh._M_key());
1480 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1482 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1483 __nh._M_ptr =
nullptr;
1490 _M_reinsert_node_hint_unique(const_iterator __hint, node_type&& __nh)
1497 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1498 auto __res = _M_get_insert_hint_unique_pos(__hint, __nh._M_key());
1501 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1502 __nh._M_ptr =
nullptr;
1505 __ret = iterator(__res.first);
1512 _M_reinsert_node_hint_equal(const_iterator __hint, node_type&& __nh)
1519 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1520 auto __res = _M_get_insert_hint_equal_pos(__hint, __nh._M_key());
1522 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1524 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1525 __nh._M_ptr =
nullptr;
1532 extract(const_iterator __pos)
1534 auto __ptr = _Rb_tree_rebalance_for_erase(
1535 __pos._M_const_cast()._M_node, _M_impl._M_header);
1536 --_M_impl._M_node_count;
1537 return {
static_cast<_Link_type
>(__ptr), _M_get_Node_allocator() };
1542 extract(
const key_type& __k)
1545 auto __pos = find(__k);
1547 __nh = extract(const_iterator(__pos));
1551 template<
typename _Compare2>
1552 using _Compatible_tree
1553 = _Rb_tree<_Key, _Val, _KeyOfValue, _Compare2, _Alloc>;
1555 template<
typename,
typename>
1556 friend class _Rb_tree_merge_helper;
1559 template<
typename _Compare2>
1561 _M_merge_unique(_Compatible_tree<_Compare2>& __src)
noexcept
1563 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1564 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1567 auto __res = _M_get_insert_unique_pos(_KeyOfValue()(*__pos));
1570 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1571 auto __ptr = _Rb_tree_rebalance_for_erase(
1572 __pos._M_node, __src_impl._M_header);
1573 --__src_impl._M_node_count;
1574 _M_insert_node(__res.first, __res.second,
1575 static_cast<_Link_type
>(__ptr));
1581 template<
typename _Compare2>
1583 _M_merge_equal(_Compatible_tree<_Compare2>& __src)
noexcept
1585 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1586 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1589 auto __res = _M_get_insert_equal_pos(_KeyOfValue()(*__pos));
1592 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1593 auto __ptr = _Rb_tree_rebalance_for_erase(
1594 __pos._M_node, __src_impl._M_header);
1595 --__src_impl._M_node_count;
1596 _M_insert_node(__res.first, __res.second,
1597 static_cast<_Link_type
>(__ptr));
1604 operator==(
const _Rb_tree& __x,
const _Rb_tree& __y)
1606 return __x.size() == __y.size()
1607 && std::equal(__x.begin(), __x.end(), __y.begin());
1610#if __cpp_lib_three_way_comparison
1612 operator<=>(
const _Rb_tree& __x,
const _Rb_tree& __y)
1614 if constexpr (
requires {
typename __detail::__synth3way_t<_Val>; })
1615 return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
1616 __y.begin(), __y.end(),
1617 __detail::__synth3way);
1621 operator<(
const _Rb_tree& __x,
const _Rb_tree& __y)
1623 return std::lexicographical_compare(__x.begin(), __x.end(),
1624 __y.begin(), __y.end());
1629 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1630 typename _Compare,
typename _Alloc>
1632 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1633 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1636#if __cplusplus >= 201103L
1637 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1638 typename _Compare,
typename _Alloc>
1640 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1643 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1647 constexpr bool __move = !__move_if_noexcept_cond<value_type>::value;
1648 _Alloc_node __an(*
this);
1649 _M_root() = _M_copy<__move>(__x, __an);
1650 if _GLIBCXX17_CONSTEXPR (__move)
1655 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1656 typename _Compare,
typename _Alloc>
1658 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1659 _M_move_assign(_Rb_tree& __x,
true_type)
1662 if (__x._M_root() !=
nullptr)
1664 std::__alloc_on_move(_M_get_Node_allocator(),
1665 __x._M_get_Node_allocator());
1668 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1669 typename _Compare,
typename _Alloc>
1671 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1674 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1675 return _M_move_assign(__x,
true_type{});
1679 _Reuse_or_alloc_node __roan(*
this);
1681 if (__x._M_root() !=
nullptr)
1683 _M_root() = _M_copy<__as_rvalue>(__x, __roan);
1688 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1689 typename _Compare,
typename _Alloc>
1690 inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1691 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1692 operator=(_Rb_tree&& __x)
1693 noexcept(_Alloc_traits::_S_nothrow_move()
1694 && is_nothrow_move_assignable<_Compare>::value)
1696 _M_impl._M_key_compare =
std::move(__x._M_impl._M_key_compare);
1697 _M_move_assign(__x, __bool_constant<_Alloc_traits::_S_nothrow_move()>());
1701 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1702 typename _Compare,
typename _Alloc>
1703 template<
typename _Iterator>
1705 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1706 _M_assign_unique(_Iterator __first, _Iterator __last)
1708 _Reuse_or_alloc_node __roan(*
this);
1710 for (; __first != __last; ++__first)
1711 _M_insert_unique_(
end(), *__first, __roan);
1714 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1715 typename _Compare,
typename _Alloc>
1716 template<
typename _Iterator>
1718 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1719 _M_assign_equal(_Iterator __first, _Iterator __last)
1721 _Reuse_or_alloc_node __roan(*
this);
1723 for (; __first != __last; ++__first)
1724 _M_insert_equal_(
end(), *__first, __roan);
1728 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1729 typename _Compare,
typename _Alloc>
1730 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1731 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1732 operator=(
const _Rb_tree& __x)
1737#if __cplusplus >= 201103L
1738 if (_Alloc_traits::_S_propagate_on_copy_assign())
1740 auto& __this_alloc = this->_M_get_Node_allocator();
1741 auto& __that_alloc = __x._M_get_Node_allocator();
1742 if (!_Alloc_traits::_S_always_equal()
1743 && __this_alloc != __that_alloc)
1748 std::__alloc_on_copy(__this_alloc, __that_alloc);
1753 _Reuse_or_alloc_node __roan(*
this);
1755 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1756 if (__x._M_root() != 0)
1757 _M_root() = _M_copy<__as_lvalue>(__x, __roan);
1763 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1764 typename _Compare,
typename _Alloc>
1765#if __cplusplus >= 201103L
1766 template<
typename _Arg,
typename _NodeGen>
1768 template<
typename _NodeGen>
1770 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1771 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1772 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1773#
if __cplusplus >= 201103L
1778 _NodeGen& __node_gen)
1780 bool __insert_left = (__x != 0 || __p == _M_end()
1781 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1784 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1786 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1787 this->_M_impl._M_header);
1788 ++_M_impl._M_node_count;
1789 return iterator(__z);
1792 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1793 typename _Compare,
typename _Alloc>
1794#if __cplusplus >= 201103L
1795 template<
typename _Arg>
1797 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1798 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1799#if __cplusplus >= 201103L
1800 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1802 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1805 bool __insert_left = (__p == _M_end()
1806 || !_M_impl._M_key_compare(_S_key(__p),
1807 _KeyOfValue()(__v)));
1809 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1811 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1812 this->_M_impl._M_header);
1813 ++_M_impl._M_node_count;
1814 return iterator(__z);
1817 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1818 typename _Compare,
typename _Alloc>
1819#if __cplusplus >= 201103L
1820 template<
typename _Arg>
1822 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1823 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1824#if __cplusplus >= 201103L
1825 _M_insert_equal_lower(_Arg&& __v)
1827 _M_insert_equal_lower(
const _Val& __v)
1830 _Link_type __x = _M_begin();
1831 _Base_ptr __y = _M_end();
1835 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1836 _S_left(__x) : _S_right(__x);
1838 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1841 template<
typename _Key,
typename _Val,
typename _KoV,
1842 typename _Compare,
typename _Alloc>
1843 template<
bool _MoveValues,
typename _NodeGen>
1844 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1845 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1846 _M_copy(_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen)
1849 _Link_type __top = _M_clone_node<_MoveValues>(__x, __node_gen);
1850 __top->_M_parent = __p;
1856 _M_copy<_MoveValues>(_S_right(__x), __top, __node_gen);
1862 _Link_type __y = _M_clone_node<_MoveValues>(__x, __node_gen);
1864 __y->_M_parent = __p;
1866 __y->_M_right = _M_copy<_MoveValues>(_S_right(__x),
1875 __throw_exception_again;
1880 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1881 typename _Compare,
typename _Alloc>
1883 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1884 _M_erase(_Link_type __x)
1889 _M_erase(_S_right(__x));
1890 _Link_type __y = _S_left(__x);
1896 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1897 typename _Compare,
typename _Alloc>
1898 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1899 _Compare, _Alloc>::iterator
1900 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1901 _M_lower_bound(_Link_type __x, _Base_ptr __y,
1905 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1906 __y = __x, __x = _S_left(__x);
1908 __x = _S_right(__x);
1909 return iterator(__y);
1912 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1913 typename _Compare,
typename _Alloc>
1914 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1915 _Compare, _Alloc>::const_iterator
1916 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1917 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1918 const _Key& __k)
const
1921 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1922 __y = __x, __x = _S_left(__x);
1924 __x = _S_right(__x);
1925 return const_iterator(__y);
1928 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1929 typename _Compare,
typename _Alloc>
1930 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1931 _Compare, _Alloc>::iterator
1932 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1933 _M_upper_bound(_Link_type __x, _Base_ptr __y,
1937 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1938 __y = __x, __x = _S_left(__x);
1940 __x = _S_right(__x);
1941 return iterator(__y);
1944 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1945 typename _Compare,
typename _Alloc>
1946 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1947 _Compare, _Alloc>::const_iterator
1948 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1949 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1950 const _Key& __k)
const
1953 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1954 __y = __x, __x = _S_left(__x);
1956 __x = _S_right(__x);
1957 return const_iterator(__y);
1960 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1961 typename _Compare,
typename _Alloc>
1962 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1963 _Compare, _Alloc>::iterator,
1964 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1965 _Compare, _Alloc>::iterator>
1966 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1967 equal_range(
const _Key& __k)
1969 _Link_type __x = _M_begin();
1970 _Base_ptr __y = _M_end();
1973 if (_M_impl._M_key_compare(_S_key(__x), __k))
1974 __x = _S_right(__x);
1975 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1976 __y = __x, __x = _S_left(__x);
1979 _Link_type __xu(__x);
1980 _Base_ptr __yu(__y);
1981 __y = __x, __x = _S_left(__x);
1982 __xu = _S_right(__xu);
1983 return pair<iterator,
1984 iterator>(_M_lower_bound(__x, __y, __k),
1985 _M_upper_bound(__xu, __yu, __k));
1988 return pair<iterator, iterator>(iterator(__y),
1992 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1993 typename _Compare,
typename _Alloc>
1994 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1995 _Compare, _Alloc>::const_iterator,
1996 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1997 _Compare, _Alloc>::const_iterator>
1998 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1999 equal_range(
const _Key& __k)
const
2001 _Const_Link_type __x = _M_begin();
2002 _Const_Base_ptr __y = _M_end();
2005 if (_M_impl._M_key_compare(_S_key(__x), __k))
2006 __x = _S_right(__x);
2007 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
2008 __y = __x, __x = _S_left(__x);
2011 _Const_Link_type __xu(__x);
2012 _Const_Base_ptr __yu(__y);
2013 __y = __x, __x = _S_left(__x);
2014 __xu = _S_right(__xu);
2015 return pair<const_iterator,
2016 const_iterator>(_M_lower_bound(__x, __y, __k),
2017 _M_upper_bound(__xu, __yu, __k));
2020 return pair<const_iterator, const_iterator>(const_iterator(__y),
2021 const_iterator(__y));
2024 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2025 typename _Compare,
typename _Alloc>
2027 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2029 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
2033 if (__t._M_root() != 0)
2034 _M_impl._M_move_data(__t._M_impl);
2036 else if (__t._M_root() == 0)
2037 __t._M_impl._M_move_data(_M_impl);
2041 std::swap(_M_leftmost(),__t._M_leftmost());
2042 std::swap(_M_rightmost(),__t._M_rightmost());
2044 _M_root()->_M_parent = _M_end();
2045 __t._M_root()->_M_parent = __t._M_end();
2046 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
2049 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
2051 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
2052 __t._M_get_Node_allocator());
2055 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2056 typename _Compare,
typename _Alloc>
2057 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2058 _Compare, _Alloc>::_Base_ptr,
2059 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2060 _Compare, _Alloc>::_Base_ptr>
2061 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2062 _M_get_insert_unique_pos(
const key_type& __k)
2064 typedef pair<_Base_ptr, _Base_ptr> _Res;
2065 _Link_type __x = _M_begin();
2066 _Base_ptr __y = _M_end();
2071 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
2072 __x = __comp ? _S_left(__x) : _S_right(__x);
2074 iterator __j = iterator(__y);
2078 return _Res(__x, __y);
2082 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
2083 return _Res(__x, __y);
2084 return _Res(__j._M_node, 0);
2087 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2088 typename _Compare,
typename _Alloc>
2089 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2090 _Compare, _Alloc>::_Base_ptr,
2091 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2092 _Compare, _Alloc>::_Base_ptr>
2093 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2094 _M_get_insert_equal_pos(
const key_type& __k)
2096 typedef pair<_Base_ptr, _Base_ptr> _Res;
2097 _Link_type __x = _M_begin();
2098 _Base_ptr __y = _M_end();
2102 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
2103 _S_left(__x) : _S_right(__x);
2105 return _Res(__x, __y);
2108 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2109 typename _Compare,
typename _Alloc>
2110#if __cplusplus >= 201103L
2111 template<
typename _Arg>
2113 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2114 _Compare, _Alloc>::iterator,
bool>
2115 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2116#if __cplusplus >= 201103L
2117 _M_insert_unique(_Arg&& __v)
2119 _M_insert_unique(
const _Val& __v)
2122 typedef pair<iterator, bool> _Res;
2123 pair<_Base_ptr, _Base_ptr> __res
2124 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
2128 _Alloc_node __an(*
this);
2129 return _Res(_M_insert_(__res.first, __res.second,
2130 _GLIBCXX_FORWARD(_Arg, __v), __an),
2134 return _Res(iterator(__res.first),
false);
2137 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2138 typename _Compare,
typename _Alloc>
2139#if __cplusplus >= 201103L
2140 template<
typename _Arg>
2142 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2143 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2144#if __cplusplus >= 201103L
2145 _M_insert_equal(_Arg&& __v)
2147 _M_insert_equal(
const _Val& __v)
2150 pair<_Base_ptr, _Base_ptr> __res
2151 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
2152 _Alloc_node __an(*
this);
2153 return _M_insert_(__res.first, __res.second,
2154 _GLIBCXX_FORWARD(_Arg, __v), __an);
2157 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2158 typename _Compare,
typename _Alloc>
2159 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2160 _Compare, _Alloc>::_Base_ptr,
2161 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2162 _Compare, _Alloc>::_Base_ptr>
2163 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2164 _M_get_insert_hint_unique_pos(const_iterator __position,
2165 const key_type& __k)
2167 iterator __pos = __position._M_const_cast();
2168 typedef pair<_Base_ptr, _Base_ptr> _Res;
2171 if (__pos._M_node == _M_end())
2174 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
2175 return _Res(0, _M_rightmost());
2177 return _M_get_insert_unique_pos(__k);
2179 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
2182 iterator __before = __pos;
2183 if (__pos._M_node == _M_leftmost())
2184 return _Res(_M_leftmost(), _M_leftmost());
2185 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
2187 if (_S_right(__before._M_node) == 0)
2188 return _Res(0, __before._M_node);
2190 return _Res(__pos._M_node, __pos._M_node);
2193 return _M_get_insert_unique_pos(__k);
2195 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2198 iterator __after = __pos;
2199 if (__pos._M_node == _M_rightmost())
2200 return _Res(0, _M_rightmost());
2201 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
2203 if (_S_right(__pos._M_node) == 0)
2204 return _Res(0, __pos._M_node);
2206 return _Res(__after._M_node, __after._M_node);
2209 return _M_get_insert_unique_pos(__k);
2213 return _Res(__pos._M_node, 0);
2216 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2217 typename _Compare,
typename _Alloc>
2218#if __cplusplus >= 201103L
2219 template<
typename _Arg,
typename _NodeGen>
2221 template<
typename _NodeGen>
2223 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2224 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2225 _M_insert_unique_(const_iterator __position,
2226#
if __cplusplus >= 201103L
2231 _NodeGen& __node_gen)
2233 pair<_Base_ptr, _Base_ptr> __res
2234 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
2237 return _M_insert_(__res.first, __res.second,
2238 _GLIBCXX_FORWARD(_Arg, __v),
2240 return iterator(__res.first);
2243 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2244 typename _Compare,
typename _Alloc>
2245 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2246 _Compare, _Alloc>::_Base_ptr,
2247 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2248 _Compare, _Alloc>::_Base_ptr>
2249 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2250 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
2252 iterator __pos = __position._M_const_cast();
2253 typedef pair<_Base_ptr, _Base_ptr> _Res;
2256 if (__pos._M_node == _M_end())
2259 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
2260 return _Res(0, _M_rightmost());
2262 return _M_get_insert_equal_pos(__k);
2264 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2267 iterator __before = __pos;
2268 if (__pos._M_node == _M_leftmost())
2269 return _Res(_M_leftmost(), _M_leftmost());
2270 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2272 if (_S_right(__before._M_node) == 0)
2273 return _Res(0, __before._M_node);
2275 return _Res(__pos._M_node, __pos._M_node);
2278 return _M_get_insert_equal_pos(__k);
2283 iterator __after = __pos;
2284 if (__pos._M_node == _M_rightmost())
2285 return _Res(0, _M_rightmost());
2286 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2288 if (_S_right(__pos._M_node) == 0)
2289 return _Res(0, __pos._M_node);
2291 return _Res(__after._M_node, __after._M_node);
2298 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2299 typename _Compare,
typename _Alloc>
2300#if __cplusplus >= 201103L
2301 template<
typename _Arg,
typename _NodeGen>
2303 template<
typename _NodeGen>
2305 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2306 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2307 _M_insert_equal_(const_iterator __position,
2308#
if __cplusplus >= 201103L
2313 _NodeGen& __node_gen)
2315 pair<_Base_ptr, _Base_ptr> __res
2316 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2319 return _M_insert_(__res.first, __res.second,
2320 _GLIBCXX_FORWARD(_Arg, __v),
2323 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2326#if __cplusplus >= 201103L
2327 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2328 typename _Compare,
typename _Alloc>
2329 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2330 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2331 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2333 bool __insert_left = (__x != 0 || __p == _M_end()
2334 || _M_impl._M_key_compare(_S_key(__z),
2337 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2338 this->_M_impl._M_header);
2339 ++_M_impl._M_node_count;
2340 return iterator(__z);
2343 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2344 typename _Compare,
typename _Alloc>
2345 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2346 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2347 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2349 bool __insert_left = (__p == _M_end()
2350 || !_M_impl._M_key_compare(_S_key(__p),
2353 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2354 this->_M_impl._M_header);
2355 ++_M_impl._M_node_count;
2356 return iterator(__z);
2359 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2360 typename _Compare,
typename _Alloc>
2361 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2362 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2363 _M_insert_equal_lower_node(_Link_type __z)
2365 _Link_type __x = _M_begin();
2366 _Base_ptr __y = _M_end();
2370 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2371 _S_left(__x) : _S_right(__x);
2373 return _M_insert_lower_node(__y, __z);
2376 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2377 typename _Compare,
typename _Alloc>
2378 template<
typename... _Args>
2379 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2380 _Compare, _Alloc>::iterator,
bool>
2381 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2382 _M_emplace_unique(_Args&&... __args)
2384 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2388 typedef pair<iterator, bool> _Res;
2389 auto __res = _M_get_insert_unique_pos(_S_key(__z));
2391 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
2394 return _Res(iterator(__res.first),
false);
2399 __throw_exception_again;
2403 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2404 typename _Compare,
typename _Alloc>
2405 template<
typename... _Args>
2406 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2407 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2408 _M_emplace_equal(_Args&&... __args)
2410 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2414 auto __res = _M_get_insert_equal_pos(_S_key(__z));
2415 return _M_insert_node(__res.first, __res.second, __z);
2420 __throw_exception_again;
2424 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2425 typename _Compare,
typename _Alloc>
2426 template<
typename... _Args>
2427 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2428 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2429 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
2431 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2435 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
2438 return _M_insert_node(__res.first, __res.second, __z);
2441 return iterator(__res.first);
2446 __throw_exception_again;
2450 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2451 typename _Compare,
typename _Alloc>
2452 template<
typename... _Args>
2453 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2454 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2455 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2457 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2461 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
2464 return _M_insert_node(__res.first, __res.second, __z);
2466 return _M_insert_equal_lower_node(__z);
2471 __throw_exception_again;
2477 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2478 typename _Compare,
typename _Alloc>
2480 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2481 _M_erase_aux(const_iterator __position)
2484 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
2485 (
const_cast<_Base_ptr
>(__position._M_node),
2486 this->_M_impl._M_header));
2488 --_M_impl._M_node_count;
2491 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2492 typename _Compare,
typename _Alloc>
2494 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2495 _M_erase_aux(const_iterator __first, const_iterator __last)
2497 if (__first ==
begin() && __last ==
end())
2500 while (__first != __last)
2501 _M_erase_aux(__first++);
2504 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2505 typename _Compare,
typename _Alloc>
2506 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2507 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2508 erase(
const _Key& __x)
2510 pair<iterator, iterator> __p = equal_range(__x);
2511 const size_type __old_size =
size();
2512 _M_erase_aux(__p.first, __p.second);
2513 return __old_size -
size();
2516 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2517 typename _Compare,
typename _Alloc>
2518 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2519 _Compare, _Alloc>::iterator
2520 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2521 find(
const _Key& __k)
2523 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2524 return (__j ==
end()
2525 || _M_impl._M_key_compare(__k,
2526 _S_key(__j._M_node))) ?
end() : __j;
2529 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2530 typename _Compare,
typename _Alloc>
2531 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2532 _Compare, _Alloc>::const_iterator
2533 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2534 find(
const _Key& __k)
const
2536 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2537 return (__j ==
end()
2538 || _M_impl._M_key_compare(__k,
2539 _S_key(__j._M_node))) ?
end() : __j;
2542 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2543 typename _Compare,
typename _Alloc>
2544 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2545 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2546 count(
const _Key& __k)
const
2548 pair<const_iterator, const_iterator> __p = equal_range(__k);
2553 _GLIBCXX_PURE
unsigned int
2554 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
2555 const _Rb_tree_node_base* __root)
throw ();
2557 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2558 typename _Compare,
typename _Alloc>
2560 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const
2562 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
2563 return _M_impl._M_node_count == 0 &&
begin() ==
end()
2564 && this->_M_impl._M_header._M_left == _M_end()
2565 && this->_M_impl._M_header._M_right == _M_end();
2567 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
2568 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
2570 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
2571 _Const_Link_type __L = _S_left(__x);
2572 _Const_Link_type __R = _S_right(__x);
2574 if (__x->_M_color == _S_red)
2575 if ((__L && __L->_M_color == _S_red)
2576 || (__R && __R->_M_color == _S_red))
2579 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
2581 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
2584 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
2588 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
2590 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
2595#if __cplusplus > 201402L
2597 template<
typename _Key,
typename _Val,
typename _Sel,
typename _Cmp1,
2598 typename _Alloc,
typename _Cmp2>
2599 struct _Rb_tree_merge_helper<_Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>,
2603 friend class _Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>;
2606 _S_get_impl(_Rb_tree<_Key, _Val, _Sel, _Cmp2, _Alloc>& __tree)
2607 {
return __tree._M_impl; }
2611_GLIBCXX_END_NAMESPACE_VERSION
constexpr duration< __common_rep_t< _Rep2, _Rep1 >, _Period > operator*(const _Rep1 &__s, const duration< _Rep2, _Period > &__d)
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
ISO C++ entities toplevel namespace is std.
constexpr auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
constexpr auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
__detected_or_t< typename is_empty< _Alloc >::type, __equal, _Alloc > is_always_equal
Whether all instances of the allocator type compare equal.
Uniform interface to C++98 and C++11 allocators.
static constexpr pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
static constexpr void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
static constexpr size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.