62#pragma GCC system_header
70#if __cplusplus >= 201103L
73#if __cplusplus > 201402L
77namespace std _GLIBCXX_VISIBILITY(default)
79_GLIBCXX_BEGIN_NAMESPACE_VERSION
97 enum _Rb_tree_color { _S_red =
false, _S_black =
true };
99 struct _Rb_tree_node_base
101 typedef _Rb_tree_node_base* _Base_ptr;
102 typedef const _Rb_tree_node_base* _Const_Base_ptr;
104 _Rb_tree_color _M_color;
110 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
112 while (__x->_M_left != 0) __x = __x->_M_left;
116 static _Const_Base_ptr
117 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
119 while (__x->_M_left != 0) __x = __x->_M_left;
124 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
126 while (__x->_M_right != 0) __x = __x->_M_right;
130 static _Const_Base_ptr
131 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
133 while (__x->_M_right != 0) __x = __x->_M_right;
139 template<
typename _Key_compare>
140 struct _Rb_tree_key_compare
142 _Key_compare _M_key_compare;
144 _Rb_tree_key_compare()
145 _GLIBCXX_NOEXCEPT_IF(
146 is_nothrow_default_constructible<_Key_compare>::value)
150 _Rb_tree_key_compare(
const _Key_compare& __comp)
151 : _M_key_compare(__comp)
154#if __cplusplus >= 201103L
156 _Rb_tree_key_compare(
const _Rb_tree_key_compare&) =
default;
158 _Rb_tree_key_compare(_Rb_tree_key_compare&& __x)
159 noexcept(is_nothrow_copy_constructible<_Key_compare>::value)
160 : _M_key_compare(__x._M_key_compare)
166 struct _Rb_tree_header
168 _Rb_tree_node_base _M_header;
169 size_t _M_node_count;
171 _Rb_tree_header() _GLIBCXX_NOEXCEPT
173 _M_header._M_color = _S_red;
177#if __cplusplus >= 201103L
178 _Rb_tree_header(_Rb_tree_header&& __x)
noexcept
180 if (__x._M_header._M_parent !=
nullptr)
184 _M_header._M_color = _S_red;
191 _M_move_data(_Rb_tree_header& __from)
193 _M_header._M_color = __from._M_header._M_color;
194 _M_header._M_parent = __from._M_header._M_parent;
195 _M_header._M_left = __from._M_header._M_left;
196 _M_header._M_right = __from._M_header._M_right;
197 _M_header._M_parent->_M_parent = &_M_header;
198 _M_node_count = __from._M_node_count;
206 _M_header._M_parent = 0;
207 _M_header._M_left = &_M_header;
208 _M_header._M_right = &_M_header;
213 template<
typename _Val>
214 struct _Rb_tree_node :
public _Rb_tree_node_base
216 typedef _Rb_tree_node<_Val>* _Link_type;
218#if __cplusplus < 201103L
229 __gnu_cxx::__aligned_membuf<_Val> _M_storage;
233 {
return _M_storage._M_ptr(); }
237 {
return _M_storage._M_ptr(); }
241 _GLIBCXX_PURE _Rb_tree_node_base*
242 _Rb_tree_increment(_Rb_tree_node_base* __x)
throw ();
244 _GLIBCXX_PURE
const _Rb_tree_node_base*
245 _Rb_tree_increment(
const _Rb_tree_node_base* __x)
throw ();
247 _GLIBCXX_PURE _Rb_tree_node_base*
248 _Rb_tree_decrement(_Rb_tree_node_base* __x)
throw ();
250 _GLIBCXX_PURE
const _Rb_tree_node_base*
251 _Rb_tree_decrement(
const _Rb_tree_node_base* __x)
throw ();
253 template<
typename _Tp>
254 struct _Rb_tree_iterator
256 typedef _Tp value_type;
257 typedef _Tp& reference;
258 typedef _Tp* pointer;
260 typedef bidirectional_iterator_tag iterator_category;
261 typedef ptrdiff_t difference_type;
263 typedef _Rb_tree_iterator<_Tp> _Self;
264 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
265 typedef _Rb_tree_node<_Tp>* _Link_type;
267 _Rb_tree_iterator() _GLIBCXX_NOEXCEPT
271 _Rb_tree_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
276 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
279 operator->() const _GLIBCXX_NOEXCEPT
280 {
return static_cast<_Link_type
> (_M_node)->_M_valptr(); }
283 operator++() _GLIBCXX_NOEXCEPT
285 _M_node = _Rb_tree_increment(_M_node);
290 operator++(
int) _GLIBCXX_NOEXCEPT
293 _M_node = _Rb_tree_increment(_M_node);
298 operator--() _GLIBCXX_NOEXCEPT
300 _M_node = _Rb_tree_decrement(_M_node);
305 operator--(
int) _GLIBCXX_NOEXCEPT
308 _M_node = _Rb_tree_decrement(_M_node);
313 operator==(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
314 {
return __x._M_node == __y._M_node; }
316#if ! __cpp_lib_three_way_comparison
318 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
319 {
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; }
397#if ! __cpp_lib_three_way_comparison
399 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
400 {
return __x._M_node != __y._M_node; }
406 __attribute__((__nonnull__))
408 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
409 _Rb_tree_node_base* __x,
410 _Rb_tree_node_base* __p,
411 _Rb_tree_node_base& __header)
throw ();
413 __attribute__((__nonnull__,__returns_nonnull__))
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 = __conditional_t<_MoveValue,
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 for (; __first != __last; ++__first)
1127 _M_emplace_equal(*__first);
1130 pair<iterator, bool>
1131 _M_insert_unique(
const value_type& __x);
1134 _M_insert_equal(
const value_type& __x);
1136 template<
typename _NodeGen>
1138 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
1142 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
1144 _Alloc_node __an(*
this);
1145 return _M_insert_unique_(__pos, __x, __an);
1148 template<
typename _NodeGen>
1150 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
1153 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
1155 _Alloc_node __an(*
this);
1156 return _M_insert_equal_(__pos, __x, __an);
1159 template<
typename _InputIterator>
1161 _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
1163 _Alloc_node __an(*
this);
1164 for (; __first != __last; ++__first)
1165 _M_insert_unique_(
end(), *__first, __an);
1168 template<
typename _InputIterator>
1170 _M_insert_range_equal(_InputIterator __first, _InputIterator __last)
1172 _Alloc_node __an(*
this);
1173 for (; __first != __last; ++__first)
1174 _M_insert_equal_(
end(), *__first, __an);
1180 _M_erase_aux(const_iterator __position);
1183 _M_erase_aux(const_iterator __first, const_iterator __last);
1186#if __cplusplus >= 201103L
1189 _GLIBCXX_ABI_TAG_CXX11
1191 erase(const_iterator __position)
1193 __glibcxx_assert(__position !=
end());
1194 const_iterator __result = __position;
1196 _M_erase_aux(__position);
1197 return __result._M_const_cast();
1201 _GLIBCXX_ABI_TAG_CXX11
1203 erase(iterator __position)
1205 __glibcxx_assert(__position !=
end());
1206 iterator __result = __position;
1208 _M_erase_aux(__position);
1213 erase(iterator __position)
1215 __glibcxx_assert(__position !=
end());
1216 _M_erase_aux(__position);
1220 erase(const_iterator __position)
1222 __glibcxx_assert(__position !=
end());
1223 _M_erase_aux(__position);
1228 erase(
const key_type& __x);
1230#if __cplusplus >= 201103L
1233 _GLIBCXX_ABI_TAG_CXX11
1235 erase(const_iterator __first, const_iterator __last)
1237 _M_erase_aux(__first, __last);
1238 return __last._M_const_cast();
1242 erase(iterator __first, iterator __last)
1243 { _M_erase_aux(__first, __last); }
1246 erase(const_iterator __first, const_iterator __last)
1247 { _M_erase_aux(__first, __last); }
1251 clear() _GLIBCXX_NOEXCEPT
1253 _M_erase(_M_begin());
1259 find(
const key_type& __k);
1262 find(
const key_type& __k)
const;
1265 count(
const key_type& __k)
const;
1268 lower_bound(
const key_type& __k)
1269 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1272 lower_bound(
const key_type& __k)
const
1273 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1276 upper_bound(
const key_type& __k)
1277 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1280 upper_bound(
const key_type& __k)
const
1281 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1283 pair<iterator, iterator>
1284 equal_range(
const key_type& __k);
1286 pair<const_iterator, const_iterator>
1287 equal_range(
const key_type& __k)
const;
1289#if __cplusplus >= 201402L
1290 template<
typename _Kt,
1291 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1293 _M_find_tr(
const _Kt& __k)
1295 const _Rb_tree* __const_this =
this;
1296 return __const_this->_M_find_tr(__k)._M_const_cast();
1299 template<
typename _Kt,
1300 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1302 _M_find_tr(
const _Kt& __k)
const
1304 auto __j = _M_lower_bound_tr(__k);
1305 if (__j !=
end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node)))
1310 template<
typename _Kt,
1311 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1313 _M_count_tr(
const _Kt& __k)
const
1315 auto __p = _M_equal_range_tr(__k);
1319 template<
typename _Kt,
1320 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1322 _M_lower_bound_tr(
const _Kt& __k)
1324 const _Rb_tree* __const_this =
this;
1325 return __const_this->_M_lower_bound_tr(__k)._M_const_cast();
1328 template<
typename _Kt,
1329 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1331 _M_lower_bound_tr(
const _Kt& __k)
const
1333 auto __x = _M_begin();
1334 auto __y = _M_end();
1336 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1342 __x = _S_right(__x);
1343 return const_iterator(__y);
1346 template<
typename _Kt,
1347 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1349 _M_upper_bound_tr(
const _Kt& __k)
1351 const _Rb_tree* __const_this =
this;
1352 return __const_this->_M_upper_bound_tr(__k)._M_const_cast();
1355 template<
typename _Kt,
1356 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1358 _M_upper_bound_tr(
const _Kt& __k)
const
1360 auto __x = _M_begin();
1361 auto __y = _M_end();
1363 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1369 __x = _S_right(__x);
1370 return const_iterator(__y);
1373 template<
typename _Kt,
1374 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1375 pair<iterator, iterator>
1376 _M_equal_range_tr(
const _Kt& __k)
1378 const _Rb_tree* __const_this =
this;
1379 auto __ret = __const_this->_M_equal_range_tr(__k);
1380 return { __ret.first._M_const_cast(), __ret.second._M_const_cast() };
1383 template<
typename _Kt,
1384 typename _Req = __has_is_transparent_t<_Compare, _Kt>>
1385 pair<const_iterator, const_iterator>
1386 _M_equal_range_tr(
const _Kt& __k)
const
1388 auto __low = _M_lower_bound_tr(__k);
1389 auto __high = __low;
1390 auto& __cmp = _M_impl._M_key_compare;
1391 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1393 return { __low, __high };
1399 __rb_verify()
const;
1401#if __cplusplus >= 201103L
1403 operator=(_Rb_tree&&)
1404 noexcept(_Alloc_traits::_S_nothrow_move()
1405 && is_nothrow_move_assignable<_Compare>::value);
1407 template<typename _Iterator>
1409 _M_assign_unique(_Iterator, _Iterator);
1411 template<typename _Iterator>
1413 _M_assign_equal(_Iterator, _Iterator);
1419 { _M_impl._M_move_data(__x._M_impl); }
1436#if __glibcxx_node_extract
1440 _M_reinsert_node_unique(node_type&& __nh)
1442 insert_return_type __ret;
1444 __ret.position =
end();
1447 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1449 auto __res = _M_get_insert_unique_pos(__nh._M_key());
1453 = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1455 __ret.inserted =
true;
1460 __ret.position = iterator(__res.first);
1461 __ret.inserted =
false;
1469 _M_reinsert_node_equal(node_type&& __nh)
1476 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1477 auto __res = _M_get_insert_equal_pos(__nh._M_key());
1479 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1481 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1489 _M_reinsert_node_hint_unique(const_iterator __hint, node_type&& __nh)
1496 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1497 auto __res = _M_get_insert_hint_unique_pos(__hint, __nh._M_key());
1500 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1504 __ret = iterator(__res.first);
1511 _M_reinsert_node_hint_equal(const_iterator __hint, node_type&& __nh)
1518 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1519 auto __res = _M_get_insert_hint_equal_pos(__hint, __nh._M_key());
1521 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1523 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1531 extract(const_iterator __pos)
1533 auto __ptr = _Rb_tree_rebalance_for_erase(
1534 __pos._M_const_cast()._M_node, _M_impl._M_header);
1535 --_M_impl._M_node_count;
1536 return {
static_cast<_Link_type
>(__ptr), _M_get_Node_allocator() };
1541 extract(
const key_type& __k)
1544 auto __pos = find(__k);
1546 __nh = extract(const_iterator(__pos));
1550 template<
typename _Compare2>
1551 using _Compatible_tree
1552 = _Rb_tree<_Key, _Val, _KeyOfValue, _Compare2, _Alloc>;
1554 template<
typename,
typename>
1555 friend struct _Rb_tree_merge_helper;
1558 template<
typename _Compare2>
1560 _M_merge_unique(_Compatible_tree<_Compare2>& __src)
noexcept
1562 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1563 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1566 auto __res = _M_get_insert_unique_pos(_KeyOfValue()(*__pos));
1569 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1570 auto __ptr = _Rb_tree_rebalance_for_erase(
1571 __pos._M_node, __src_impl._M_header);
1572 --__src_impl._M_node_count;
1573 _M_insert_node(__res.first, __res.second,
1574 static_cast<_Link_type
>(__ptr));
1580 template<
typename _Compare2>
1582 _M_merge_equal(_Compatible_tree<_Compare2>& __src)
noexcept
1584 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1585 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1588 auto __res = _M_get_insert_equal_pos(_KeyOfValue()(*__pos));
1591 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1592 auto __ptr = _Rb_tree_rebalance_for_erase(
1593 __pos._M_node, __src_impl._M_header);
1594 --__src_impl._M_node_count;
1595 _M_insert_node(__res.first, __res.second,
1596 static_cast<_Link_type
>(__ptr));
1603 operator==(
const _Rb_tree& __x,
const _Rb_tree& __y)
1605 return __x.size() == __y.size()
1606 && std::equal(__x.begin(), __x.end(), __y.begin());
1609#if __cpp_lib_three_way_comparison
1611 operator<=>(
const _Rb_tree& __x,
const _Rb_tree& __y)
1613 if constexpr (
requires {
typename __detail::__synth3way_t<_Val>; })
1615 __y.begin(), __y.end(),
1616 __detail::__synth3way);
1620 operator<(
const _Rb_tree& __x,
const _Rb_tree& __y)
1622 return std::lexicographical_compare(__x.begin(), __x.end(),
1623 __y.begin(), __y.end());
1628#if __cplusplus >= 201103L
1632 template<
typename... _Args>
1633 _Auto_node(_Rb_tree& __t, _Args&&... __args)
1635 _M_node(__t._M_create_node(
std::
forward<_Args>(__args)...))
1641 _M_t._M_drop_node(_M_node);
1644 _Auto_node(_Auto_node&& __n)
1645 : _M_t(__n._M_t), _M_node(__n._M_node)
1646 { __n._M_node =
nullptr; }
1650 {
return _S_key(_M_node); }
1653 _M_insert(pair<_Base_ptr, _Base_ptr> __p)
1655 auto __it = _M_t._M_insert_node(__p.first, __p.second, _M_node);
1661 _M_insert_equal_lower()
1663 auto __it = _M_t._M_insert_equal_lower_node(_M_node);
1674 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1675 typename _Compare,
typename _Alloc>
1677 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1678 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1681#if __cplusplus >= 201103L
1682 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1683 typename _Compare,
typename _Alloc>
1685 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1688 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1692 constexpr bool __move = !__move_if_noexcept_cond<value_type>::value;
1693 _Alloc_node __an(*
this);
1694 _M_root() = _M_copy<__move>(__x, __an);
1695 if _GLIBCXX17_CONSTEXPR (__move)
1700 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1701 typename _Compare,
typename _Alloc>
1703 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1704 _M_move_assign(_Rb_tree& __x,
true_type)
1707 if (__x._M_root() !=
nullptr)
1709 std::__alloc_on_move(_M_get_Node_allocator(),
1710 __x._M_get_Node_allocator());
1713 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1714 typename _Compare,
typename _Alloc>
1716 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1719 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1720 return _M_move_assign(__x,
true_type{});
1724 _Reuse_or_alloc_node __roan(*
this);
1726 if (__x._M_root() !=
nullptr)
1728 _M_root() = _M_copy<__as_rvalue>(__x, __roan);
1733 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1734 typename _Compare,
typename _Alloc>
1735 inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1736 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1737 operator=(_Rb_tree&& __x)
1738 noexcept(_Alloc_traits::_S_nothrow_move()
1739 && is_nothrow_move_assignable<_Compare>::value)
1741 _M_impl._M_key_compare =
std::move(__x._M_impl._M_key_compare);
1742 _M_move_assign(__x, __bool_constant<_Alloc_traits::_S_nothrow_move()>());
1746 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1747 typename _Compare,
typename _Alloc>
1748 template<
typename _Iterator>
1750 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1751 _M_assign_unique(_Iterator __first, _Iterator __last)
1753 _Reuse_or_alloc_node __roan(*
this);
1755 for (; __first != __last; ++__first)
1756 _M_insert_unique_(
end(), *__first, __roan);
1759 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1760 typename _Compare,
typename _Alloc>
1761 template<
typename _Iterator>
1763 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1764 _M_assign_equal(_Iterator __first, _Iterator __last)
1766 _Reuse_or_alloc_node __roan(*
this);
1768 for (; __first != __last; ++__first)
1769 _M_insert_equal_(
end(), *__first, __roan);
1773 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1774 typename _Compare,
typename _Alloc>
1775 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1776 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1777 operator=(
const _Rb_tree& __x)
1782#if __cplusplus >= 201103L
1783 if (_Alloc_traits::_S_propagate_on_copy_assign())
1785 auto& __this_alloc = this->_M_get_Node_allocator();
1786 auto& __that_alloc = __x._M_get_Node_allocator();
1787 if (!_Alloc_traits::_S_always_equal()
1788 && __this_alloc != __that_alloc)
1793 std::__alloc_on_copy(__this_alloc, __that_alloc);
1798 _Reuse_or_alloc_node __roan(*
this);
1800 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1801 if (__x._M_root() != 0)
1802 _M_root() = _M_copy<__as_lvalue>(__x, __roan);
1808 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1809 typename _Compare,
typename _Alloc>
1810#if __cplusplus >= 201103L
1811 template<
typename _Arg,
typename _NodeGen>
1813 template<
typename _NodeGen>
1815 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1816 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1817 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1818#
if __cplusplus >= 201103L
1823 _NodeGen& __node_gen)
1825 bool __insert_left = (__x != 0 || __p == _M_end()
1826 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1829 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1831 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1832 this->_M_impl._M_header);
1833 ++_M_impl._M_node_count;
1834 return iterator(__z);
1837 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1838 typename _Compare,
typename _Alloc>
1839#if __cplusplus >= 201103L
1840 template<
typename _Arg>
1842 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1843 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1844#if __cplusplus >= 201103L
1845 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1847 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1850 bool __insert_left = (__p == _M_end()
1851 || !_M_impl._M_key_compare(_S_key(__p),
1852 _KeyOfValue()(__v)));
1854 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1856 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1857 this->_M_impl._M_header);
1858 ++_M_impl._M_node_count;
1859 return iterator(__z);
1862 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1863 typename _Compare,
typename _Alloc>
1864#if __cplusplus >= 201103L
1865 template<
typename _Arg>
1867 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1868 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1869#if __cplusplus >= 201103L
1870 _M_insert_equal_lower(_Arg&& __v)
1872 _M_insert_equal_lower(
const _Val& __v)
1875 _Link_type __x = _M_begin();
1876 _Base_ptr __y = _M_end();
1880 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1881 _S_left(__x) : _S_right(__x);
1883 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1886 template<
typename _Key,
typename _Val,
typename _KoV,
1887 typename _Compare,
typename _Alloc>
1888 template<
bool _MoveValues,
typename _NodeGen>
1889 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1890 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1891 _M_copy(_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen)
1894 _Link_type __top = _M_clone_node<_MoveValues>(__x, __node_gen);
1895 __top->_M_parent = __p;
1901 _M_copy<_MoveValues>(_S_right(__x), __top, __node_gen);
1907 _Link_type __y = _M_clone_node<_MoveValues>(__x, __node_gen);
1909 __y->_M_parent = __p;
1911 __y->_M_right = _M_copy<_MoveValues>(_S_right(__x),
1920 __throw_exception_again;
1925 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1926 typename _Compare,
typename _Alloc>
1928 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1929 _M_erase(_Link_type __x)
1934 _M_erase(_S_right(__x));
1935 _Link_type __y = _S_left(__x);
1941 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1942 typename _Compare,
typename _Alloc>
1943 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1944 _Compare, _Alloc>::iterator
1945 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1946 _M_lower_bound(_Link_type __x, _Base_ptr __y,
1950 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1951 __y = __x, __x = _S_left(__x);
1953 __x = _S_right(__x);
1954 return iterator(__y);
1957 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1958 typename _Compare,
typename _Alloc>
1959 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1960 _Compare, _Alloc>::const_iterator
1961 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1962 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1963 const _Key& __k)
const
1966 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1967 __y = __x, __x = _S_left(__x);
1969 __x = _S_right(__x);
1970 return const_iterator(__y);
1973 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1974 typename _Compare,
typename _Alloc>
1975 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1976 _Compare, _Alloc>::iterator
1977 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1978 _M_upper_bound(_Link_type __x, _Base_ptr __y,
1982 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1983 __y = __x, __x = _S_left(__x);
1985 __x = _S_right(__x);
1986 return iterator(__y);
1989 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1990 typename _Compare,
typename _Alloc>
1991 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1992 _Compare, _Alloc>::const_iterator
1993 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1994 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1995 const _Key& __k)
const
1998 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1999 __y = __x, __x = _S_left(__x);
2001 __x = _S_right(__x);
2002 return const_iterator(__y);
2005 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2006 typename _Compare,
typename _Alloc>
2007 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2008 _Compare, _Alloc>::iterator,
2009 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2010 _Compare, _Alloc>::iterator>
2011 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2012 equal_range(
const _Key& __k)
2014 _Link_type __x = _M_begin();
2015 _Base_ptr __y = _M_end();
2018 if (_M_impl._M_key_compare(_S_key(__x), __k))
2019 __x = _S_right(__x);
2020 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
2021 __y = __x, __x = _S_left(__x);
2024 _Link_type __xu(__x);
2025 _Base_ptr __yu(__y);
2026 __y = __x, __x = _S_left(__x);
2027 __xu = _S_right(__xu);
2028 return pair<iterator,
2029 iterator>(_M_lower_bound(__x, __y, __k),
2030 _M_upper_bound(__xu, __yu, __k));
2033 return pair<iterator, iterator>(iterator(__y),
2037 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2038 typename _Compare,
typename _Alloc>
2039 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2040 _Compare, _Alloc>::const_iterator,
2041 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2042 _Compare, _Alloc>::const_iterator>
2043 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2044 equal_range(
const _Key& __k)
const
2046 _Const_Link_type __x = _M_begin();
2047 _Const_Base_ptr __y = _M_end();
2050 if (_M_impl._M_key_compare(_S_key(__x), __k))
2051 __x = _S_right(__x);
2052 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
2053 __y = __x, __x = _S_left(__x);
2056 _Const_Link_type __xu(__x);
2057 _Const_Base_ptr __yu(__y);
2058 __y = __x, __x = _S_left(__x);
2059 __xu = _S_right(__xu);
2060 return pair<const_iterator,
2061 const_iterator>(_M_lower_bound(__x, __y, __k),
2062 _M_upper_bound(__xu, __yu, __k));
2065 return pair<const_iterator, const_iterator>(const_iterator(__y),
2066 const_iterator(__y));
2069 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2070 typename _Compare,
typename _Alloc>
2072 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2074 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
2078 if (__t._M_root() != 0)
2079 _M_impl._M_move_data(__t._M_impl);
2081 else if (__t._M_root() == 0)
2082 __t._M_impl._M_move_data(_M_impl);
2085 std::swap(_M_root(),__t._M_root());
2086 std::swap(_M_leftmost(),__t._M_leftmost());
2087 std::swap(_M_rightmost(),__t._M_rightmost());
2089 _M_root()->_M_parent = _M_end();
2090 __t._M_root()->_M_parent = __t._M_end();
2091 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
2096 swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
2098 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
2099 __t._M_get_Node_allocator());
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_unique_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();
2118 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
2119 __x = __comp ? _S_left(__x) : _S_right(__x);
2121 iterator __j = iterator(__y);
2125 return _Res(__x, __y);
2129 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
2130 return _Res(__x, __y);
2131 return _Res(__j._M_node, 0);
2134 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2135 typename _Compare,
typename _Alloc>
2136 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2137 _Compare, _Alloc>::_Base_ptr,
2138 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2139 _Compare, _Alloc>::_Base_ptr>
2140 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2141 _M_get_insert_equal_pos(
const key_type& __k)
2143 typedef pair<_Base_ptr, _Base_ptr> _Res;
2144 _Link_type __x = _M_begin();
2145 _Base_ptr __y = _M_end();
2149 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
2150 _S_left(__x) : _S_right(__x);
2152 return _Res(__x, __y);
2155 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2156 typename _Compare,
typename _Alloc>
2157#if __cplusplus >= 201103L
2158 template<
typename _Arg>
2160 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2161 _Compare, _Alloc>::iterator,
bool>
2162 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2163#if __cplusplus >= 201103L
2164 _M_insert_unique(_Arg&& __v)
2166 _M_insert_unique(
const _Val& __v)
2169 typedef pair<iterator, bool> _Res;
2170 pair<_Base_ptr, _Base_ptr> __res
2171 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
2175 _Alloc_node __an(*
this);
2176 return _Res(_M_insert_(__res.first, __res.second,
2177 _GLIBCXX_FORWARD(_Arg, __v), __an),
2181 return _Res(iterator(__res.first),
false);
2184 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2185 typename _Compare,
typename _Alloc>
2186#if __cplusplus >= 201103L
2187 template<
typename _Arg>
2189 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2190 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2191#if __cplusplus >= 201103L
2192 _M_insert_equal(_Arg&& __v)
2194 _M_insert_equal(
const _Val& __v)
2197 pair<_Base_ptr, _Base_ptr> __res
2198 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
2199 _Alloc_node __an(*
this);
2200 return _M_insert_(__res.first, __res.second,
2201 _GLIBCXX_FORWARD(_Arg, __v), __an);
2204 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2205 typename _Compare,
typename _Alloc>
2206 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2207 _Compare, _Alloc>::_Base_ptr,
2208 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2209 _Compare, _Alloc>::_Base_ptr>
2210 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2211 _M_get_insert_hint_unique_pos(const_iterator __position,
2212 const key_type& __k)
2214 iterator __pos = __position._M_const_cast();
2215 typedef pair<_Base_ptr, _Base_ptr> _Res;
2218 if (__pos._M_node == _M_end())
2221 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
2222 return _Res(0, _M_rightmost());
2224 return _M_get_insert_unique_pos(__k);
2226 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
2229 iterator __before = __pos;
2230 if (__pos._M_node == _M_leftmost())
2231 return _Res(_M_leftmost(), _M_leftmost());
2232 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
2234 if (_S_right(__before._M_node) == 0)
2235 return _Res(0, __before._M_node);
2237 return _Res(__pos._M_node, __pos._M_node);
2240 return _M_get_insert_unique_pos(__k);
2242 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2245 iterator __after = __pos;
2246 if (__pos._M_node == _M_rightmost())
2247 return _Res(0, _M_rightmost());
2248 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
2250 if (_S_right(__pos._M_node) == 0)
2251 return _Res(0, __pos._M_node);
2253 return _Res(__after._M_node, __after._M_node);
2256 return _M_get_insert_unique_pos(__k);
2260 return _Res(__pos._M_node, 0);
2263 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2264 typename _Compare,
typename _Alloc>
2265#if __cplusplus >= 201103L
2266 template<
typename _Arg,
typename _NodeGen>
2268 template<
typename _NodeGen>
2270 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2271 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2272 _M_insert_unique_(const_iterator __position,
2273#
if __cplusplus >= 201103L
2278 _NodeGen& __node_gen)
2280 pair<_Base_ptr, _Base_ptr> __res
2281 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
2284 return _M_insert_(__res.first, __res.second,
2285 _GLIBCXX_FORWARD(_Arg, __v),
2287 return iterator(__res.first);
2290 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2291 typename _Compare,
typename _Alloc>
2292 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2293 _Compare, _Alloc>::_Base_ptr,
2294 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2295 _Compare, _Alloc>::_Base_ptr>
2296 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2297 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
2299 iterator __pos = __position._M_const_cast();
2300 typedef pair<_Base_ptr, _Base_ptr> _Res;
2303 if (__pos._M_node == _M_end())
2306 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
2307 return _Res(0, _M_rightmost());
2309 return _M_get_insert_equal_pos(__k);
2311 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2314 iterator __before = __pos;
2315 if (__pos._M_node == _M_leftmost())
2316 return _Res(_M_leftmost(), _M_leftmost());
2317 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2319 if (_S_right(__before._M_node) == 0)
2320 return _Res(0, __before._M_node);
2322 return _Res(__pos._M_node, __pos._M_node);
2325 return _M_get_insert_equal_pos(__k);
2330 iterator __after = __pos;
2331 if (__pos._M_node == _M_rightmost())
2332 return _Res(0, _M_rightmost());
2333 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2335 if (_S_right(__pos._M_node) == 0)
2336 return _Res(0, __pos._M_node);
2338 return _Res(__after._M_node, __after._M_node);
2345 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2346 typename _Compare,
typename _Alloc>
2347#if __cplusplus >= 201103L
2348 template<
typename _Arg,
typename _NodeGen>
2350 template<
typename _NodeGen>
2352 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2353 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2354 _M_insert_equal_(const_iterator __position,
2355#
if __cplusplus >= 201103L
2360 _NodeGen& __node_gen)
2362 pair<_Base_ptr, _Base_ptr> __res
2363 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2366 return _M_insert_(__res.first, __res.second,
2367 _GLIBCXX_FORWARD(_Arg, __v),
2370 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2373#if __cplusplus >= 201103L
2374 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2375 typename _Compare,
typename _Alloc>
2377 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2378 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2381 bool __insert_left = (__x != 0 || __p == _M_end()
2382 || _M_impl._M_key_compare(_S_key(__z),
2385 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2386 this->_M_impl._M_header);
2387 ++_M_impl._M_node_count;
2388 return iterator(__z);
2391 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2392 typename _Compare,
typename _Alloc>
2394 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2395 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2398 bool __insert_left = (__p == _M_end()
2399 || !_M_impl._M_key_compare(_S_key(__p),
2402 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2403 this->_M_impl._M_header);
2404 ++_M_impl._M_node_count;
2405 return iterator(__z);
2408 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2409 typename _Compare,
typename _Alloc>
2411 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2412 _M_insert_equal_lower_node(_Link_type __z)
2415 _Link_type __x = _M_begin();
2416 _Base_ptr __y = _M_end();
2420 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2421 _S_left(__x) : _S_right(__x);
2423 return _M_insert_lower_node(__y, __z);
2426 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2427 typename _Compare,
typename _Alloc>
2428 template<
typename... _Args>
2430 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2431 _M_emplace_unique(_Args&&... __args)
2432 -> pair<iterator, bool>
2434 _Auto_node __z(*
this, std::forward<_Args>(__args)...);
2435 auto __res = _M_get_insert_unique_pos(__z._M_key());
2437 return {__z._M_insert(__res),
true};
2438 return {iterator(__res.first),
false};
2441 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2442 typename _Compare,
typename _Alloc>
2443 template<
typename... _Args>
2445 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2446 _M_emplace_equal(_Args&&... __args)
2449 _Auto_node __z(*
this, std::forward<_Args>(__args)...);
2450 auto __res = _M_get_insert_equal_pos(__z._M_key());
2451 return __z._M_insert(__res);
2454 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2455 typename _Compare,
typename _Alloc>
2456 template<
typename... _Args>
2458 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2459 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
2462 _Auto_node __z(*
this, std::forward<_Args>(__args)...);
2463 auto __res = _M_get_insert_hint_unique_pos(__pos, __z._M_key());
2465 return __z._M_insert(__res);
2466 return iterator(__res.first);
2469 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2470 typename _Compare,
typename _Alloc>
2471 template<
typename... _Args>
2473 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2474 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2477 _Auto_node __z(*
this, std::forward<_Args>(__args)...);
2478 auto __res = _M_get_insert_hint_equal_pos(__pos, __z._M_key());
2480 return __z._M_insert(__res);
2481 return __z._M_insert_equal_lower();
2486 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2487 typename _Compare,
typename _Alloc>
2489 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2490 _M_erase_aux(const_iterator __position)
2493 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
2494 (
const_cast<_Base_ptr
>(__position._M_node),
2495 this->_M_impl._M_header));
2497 --_M_impl._M_node_count;
2500 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2501 typename _Compare,
typename _Alloc>
2503 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2504 _M_erase_aux(const_iterator __first, const_iterator __last)
2506 if (__first ==
begin() && __last ==
end())
2509 while (__first != __last)
2510 _M_erase_aux(__first++);
2513 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2514 typename _Compare,
typename _Alloc>
2515 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2516 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2517 erase(
const _Key& __x)
2519 pair<iterator, iterator> __p = equal_range(__x);
2520 const size_type __old_size =
size();
2521 _M_erase_aux(__p.first, __p.second);
2522 return __old_size -
size();
2525 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2526 typename _Compare,
typename _Alloc>
2527 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2528 _Compare, _Alloc>::iterator
2529 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2530 find(
const _Key& __k)
2532 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2533 return (__j ==
end()
2534 || _M_impl._M_key_compare(__k,
2535 _S_key(__j._M_node))) ?
end() : __j;
2538 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2539 typename _Compare,
typename _Alloc>
2540 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2541 _Compare, _Alloc>::const_iterator
2542 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2543 find(
const _Key& __k)
const
2545 const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
2546 return (__j ==
end()
2547 || _M_impl._M_key_compare(__k,
2548 _S_key(__j._M_node))) ?
end() : __j;
2551 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2552 typename _Compare,
typename _Alloc>
2553 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2554 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2555 count(
const _Key& __k)
const
2557 pair<const_iterator, const_iterator> __p = equal_range(__k);
2562 _GLIBCXX_PURE
unsigned int
2563 _Rb_tree_black_count(
const _Rb_tree_node_base* __node,
2564 const _Rb_tree_node_base* __root)
throw ();
2566 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2567 typename _Compare,
typename _Alloc>
2569 _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify()
const
2571 if (_M_impl._M_node_count == 0 ||
begin() ==
end())
2572 return _M_impl._M_node_count == 0 &&
begin() ==
end()
2573 && this->_M_impl._M_header._M_left == _M_end()
2574 && this->_M_impl._M_header._M_right == _M_end();
2576 unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root());
2577 for (const_iterator __it =
begin(); __it !=
end(); ++__it)
2579 _Const_Link_type __x =
static_cast<_Const_Link_type
>(__it._M_node);
2580 _Const_Link_type __L = _S_left(__x);
2581 _Const_Link_type __R = _S_right(__x);
2583 if (__x->_M_color == _S_red)
2584 if ((__L && __L->_M_color == _S_red)
2585 || (__R && __R->_M_color == _S_red))
2588 if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L)))
2590 if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x)))
2593 if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len)
2597 if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
2599 if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
2604#if __cplusplus > 201402L
2606 template<
typename _Key,
typename _Val,
typename _Sel,
typename _Cmp1,
2607 typename _Alloc,
typename _Cmp2>
2608 struct _Rb_tree_merge_helper<_Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>,
2612 friend class _Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>;
2615 _S_get_impl(_Rb_tree<_Key, _Val, _Sel, _Cmp2, _Alloc>& __tree)
2616 {
return __tree._M_impl; }
2620_GLIBCXX_END_NAMESPACE_VERSION
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
__bool_constant< 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.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
_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.
constexpr auto lexicographical_compare_three_way(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _Comp __comp) -> decltype(__comp(*__first1, *__first2))
Performs dictionary comparison on ranges.
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.
typename __detected_or_t< is_empty< _Alloc >, __equal, _Alloc >::type 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.