61 #pragma GCC system_header 68 #if __cplusplus >= 201103L 71 #if __cplusplus > 201402L 75 namespace std _GLIBCXX_VISIBILITY(default)
77 _GLIBCXX_BEGIN_NAMESPACE_VERSION
79 #if __cplusplus > 201103L 80 # define __cpp_lib_generic_associative_lookup 201304 99 enum _Rb_tree_color { _S_red =
false, _S_black =
true };
101 struct _Rb_tree_node_base
103 typedef _Rb_tree_node_base* _Base_ptr;
104 typedef const _Rb_tree_node_base* _Const_Base_ptr;
106 _Rb_tree_color _M_color;
112 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
114 while (__x->_M_left != 0) __x = __x->_M_left;
118 static _Const_Base_ptr
119 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
121 while (__x->_M_left != 0) __x = __x->_M_left;
126 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
128 while (__x->_M_right != 0) __x = __x->_M_right;
132 static _Const_Base_ptr
133 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
135 while (__x->_M_right != 0) __x = __x->_M_right;
141 template<
typename _Key_compare>
142 struct _Rb_tree_key_compare
144 _Key_compare _M_key_compare;
146 _Rb_tree_key_compare()
147 _GLIBCXX_NOEXCEPT_IF(
148 is_nothrow_default_constructible<_Key_compare>::value)
152 _Rb_tree_key_compare(
const _Key_compare& __comp)
153 : _M_key_compare(__comp)
156 #if __cplusplus >= 201103L 158 _Rb_tree_key_compare(
const _Rb_tree_key_compare&) =
default;
160 _Rb_tree_key_compare(_Rb_tree_key_compare&& __x)
161 noexcept(is_nothrow_copy_constructible<_Key_compare>::value)
162 : _M_key_compare(__x._M_key_compare)
168 struct _Rb_tree_header
170 _Rb_tree_node_base _M_header;
171 size_t _M_node_count;
173 _Rb_tree_header() _GLIBCXX_NOEXCEPT
175 _M_header._M_color = _S_red;
179 #if __cplusplus >= 201103L 180 _Rb_tree_header(_Rb_tree_header&& __x) noexcept
182 if (__x._M_header._M_parent !=
nullptr)
186 _M_header._M_color = _S_red;
193 _M_move_data(_Rb_tree_header& __from)
195 _M_header._M_color = __from._M_header._M_color;
196 _M_header._M_parent = __from._M_header._M_parent;
197 _M_header._M_left = __from._M_header._M_left;
198 _M_header._M_right = __from._M_header._M_right;
199 _M_header._M_parent->_M_parent = &_M_header;
200 _M_node_count = __from._M_node_count;
208 _M_header._M_parent = 0;
209 _M_header._M_left = &_M_header;
210 _M_header._M_right = &_M_header;
215 template<
typename _Val>
216 struct _Rb_tree_node :
public _Rb_tree_node_base
218 typedef _Rb_tree_node<_Val>* _Link_type;
220 #if __cplusplus < 201103L 231 __gnu_cxx::__aligned_membuf<_Val> _M_storage;
235 {
return _M_storage._M_ptr(); }
239 {
return _M_storage._M_ptr(); }
243 _GLIBCXX_PURE _Rb_tree_node_base*
244 _Rb_tree_increment(_Rb_tree_node_base* __x)
throw ();
246 _GLIBCXX_PURE
const _Rb_tree_node_base*
247 _Rb_tree_increment(
const _Rb_tree_node_base* __x)
throw ();
249 _GLIBCXX_PURE _Rb_tree_node_base*
250 _Rb_tree_decrement(_Rb_tree_node_base* __x)
throw ();
252 _GLIBCXX_PURE
const _Rb_tree_node_base*
253 _Rb_tree_decrement(
const _Rb_tree_node_base* __x)
throw ();
255 template<
typename _Tp>
256 struct _Rb_tree_iterator
258 typedef _Tp value_type;
259 typedef _Tp& reference;
260 typedef _Tp* pointer;
262 typedef bidirectional_iterator_tag iterator_category;
263 typedef ptrdiff_t difference_type;
265 typedef _Rb_tree_iterator<_Tp> _Self;
266 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
267 typedef _Rb_tree_node<_Tp>* _Link_type;
269 _Rb_tree_iterator() _GLIBCXX_NOEXCEPT
273 _Rb_tree_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
278 {
return *
static_cast<_Link_type
>(_M_node)->_M_valptr(); }
281 operator->() const _GLIBCXX_NOEXCEPT
282 {
return static_cast<_Link_type
> (_M_node)->_M_valptr(); }
285 operator++() _GLIBCXX_NOEXCEPT
287 _M_node = _Rb_tree_increment(_M_node);
292 operator++(
int) _GLIBCXX_NOEXCEPT
295 _M_node = _Rb_tree_increment(_M_node);
300 operator--() _GLIBCXX_NOEXCEPT
302 _M_node = _Rb_tree_decrement(_M_node);
307 operator--(
int) _GLIBCXX_NOEXCEPT
310 _M_node = _Rb_tree_decrement(_M_node);
315 operator==(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
316 {
return _M_node == __x._M_node; }
319 operator!=(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
320 {
return _M_node != __x._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 _GLIBCXX_NOEXCEPT
395 {
return _M_node == __x._M_node; }
398 operator!=(
const _Self& __x)
const _GLIBCXX_NOEXCEPT
399 {
return _M_node != __x._M_node; }
404 template<
typename _Val>
406 operator==(
const _Rb_tree_iterator<_Val>& __x,
407 const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
408 {
return __x._M_node == __y._M_node; }
410 template<
typename _Val>
412 operator!=(
const _Rb_tree_iterator<_Val>& __x,
413 const _Rb_tree_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
414 {
return __x._M_node != __y._M_node; }
417 _Rb_tree_insert_and_rebalance(
const bool __insert_left,
418 _Rb_tree_node_base* __x,
419 _Rb_tree_node_base* __p,
420 _Rb_tree_node_base& __header)
throw ();
423 _Rb_tree_rebalance_for_erase(_Rb_tree_node_base*
const __z,
424 _Rb_tree_node_base& __header)
throw ();
426 #if __cplusplus > 201103L 427 template<
typename _Cmp,
typename _SfinaeType,
typename = __
void_t<>>
428 struct __has_is_transparent
431 template<
typename _Cmp,
typename _SfinaeType>
432 struct __has_is_transparent<_Cmp, _SfinaeType,
433 __void_t<typename _Cmp::is_transparent>>
434 {
typedef void type; };
437 #if __cplusplus > 201402L 438 template<
typename _Tree1,
typename _Cmp2>
439 struct _Rb_tree_merge_helper { };
442 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
443 typename _Compare,
typename _Alloc = allocator<_Val> >
447 rebind<_Rb_tree_node<_Val> >::other _Node_allocator;
452 typedef _Rb_tree_node_base* _Base_ptr;
453 typedef const _Rb_tree_node_base* _Const_Base_ptr;
454 typedef _Rb_tree_node<_Val>* _Link_type;
455 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
460 struct _Reuse_or_alloc_node
462 _Reuse_or_alloc_node(_Rb_tree& __t)
463 : _M_root(__t._M_root()), _M_nodes(__t._M_rightmost()), _M_t(__t)
467 _M_root->_M_parent = 0;
469 if (_M_nodes->_M_left)
470 _M_nodes = _M_nodes->_M_left;
476 #if __cplusplus >= 201103L 477 _Reuse_or_alloc_node(
const _Reuse_or_alloc_node&) =
delete;
480 ~_Reuse_or_alloc_node()
481 { _M_t._M_erase(static_cast<_Link_type>(_M_root)); }
483 template<
typename _Arg>
485 #if __cplusplus < 201103L 486 operator()(
const _Arg& __arg)
488 operator()(_Arg&& __arg)
491 _Link_type __node =
static_cast<_Link_type
>(_M_extract());
494 _M_t._M_destroy_node(__node);
495 _M_t._M_construct_node(__node, _GLIBCXX_FORWARD(_Arg, __arg));
499 return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg));
509 _Base_ptr __node = _M_nodes;
510 _M_nodes = _M_nodes->_M_parent;
513 if (_M_nodes->_M_right == __node)
515 _M_nodes->_M_right = 0;
517 if (_M_nodes->_M_left)
519 _M_nodes = _M_nodes->_M_left;
521 while (_M_nodes->_M_right)
522 _M_nodes = _M_nodes->_M_right;
524 if (_M_nodes->_M_left)
525 _M_nodes = _M_nodes->_M_left;
529 _M_nodes->_M_left = 0;
546 _Alloc_node(_Rb_tree& __t)
549 template<
typename _Arg>
551 #if __cplusplus < 201103L 552 operator()(
const _Arg& __arg)
const 554 operator()(_Arg&& __arg)
const 556 {
return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg)); }
563 typedef _Key key_type;
564 typedef _Val value_type;
565 typedef value_type* pointer;
566 typedef const value_type* const_pointer;
567 typedef value_type& reference;
568 typedef const value_type& const_reference;
569 typedef size_t size_type;
570 typedef ptrdiff_t difference_type;
571 typedef _Alloc allocator_type;
574 _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
575 {
return *
static_cast<_Node_allocator*
>(&this->_M_impl); }
577 const _Node_allocator&
578 _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
579 {
return *
static_cast<const _Node_allocator*
>(&this->_M_impl); }
582 get_allocator() const _GLIBCXX_NOEXCEPT
583 {
return allocator_type(_M_get_Node_allocator()); }
588 {
return _Alloc_traits::allocate(_M_get_Node_allocator(), 1); }
591 _M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT
592 { _Alloc_traits::deallocate(_M_get_Node_allocator(), __p, 1); }
594 #if __cplusplus < 201103L 596 _M_construct_node(_Link_type __node,
const value_type& __x)
599 { get_allocator().construct(__node->_M_valptr(), __x); }
603 __throw_exception_again;
608 _M_create_node(
const value_type& __x)
610 _Link_type __tmp = _M_get_node();
611 _M_construct_node(__tmp, __x);
616 _M_destroy_node(_Link_type __p)
617 { get_allocator().destroy(__p->_M_valptr()); }
619 template<
typename... _Args>
621 _M_construct_node(_Link_type __node, _Args&&... __args)
625 ::new(__node) _Rb_tree_node<_Val>;
626 _Alloc_traits::construct(_M_get_Node_allocator(),
628 std::forward<_Args>(__args)...);
632 __node->~_Rb_tree_node<_Val>();
634 __throw_exception_again;
638 template<
typename... _Args>
640 _M_create_node(_Args&&... __args)
642 _Link_type __tmp = _M_get_node();
643 _M_construct_node(__tmp, std::forward<_Args>(__args)...);
648 _M_destroy_node(_Link_type __p) noexcept
650 _Alloc_traits::destroy(_M_get_Node_allocator(), __p->_M_valptr());
651 __p->~_Rb_tree_node<_Val>();
656 _M_drop_node(_Link_type __p) _GLIBCXX_NOEXCEPT
658 _M_destroy_node(__p);
662 template<
typename _NodeGen>
664 _M_clone_node(_Const_Link_type __x, _NodeGen& __node_gen)
666 _Link_type __tmp = __node_gen(*__x->_M_valptr());
667 __tmp->_M_color = __x->_M_color;
675 template<
typename _Key_compare,
676 bool = __is_pod(_Key_compare)>
678 :
public _Node_allocator
679 ,
public _Rb_tree_key_compare<_Key_compare>
680 ,
public _Rb_tree_header
682 typedef _Rb_tree_key_compare<_Key_compare> _Base_key_compare;
684 #if __cplusplus < 201103L 688 _Rb_tree_impl() =
default;
689 _Rb_tree_impl(_Rb_tree_impl&&) =
default;
692 _Rb_tree_impl(
const _Rb_tree_impl& __x)
693 : _Node_allocator(_Alloc_traits::_S_select_on_copy(__x))
694 , _Base_key_compare(__x._M_key_compare)
697 #if __cplusplus < 201103L 698 _Rb_tree_impl(
const _Key_compare& __comp,
const _Node_allocator& __a)
699 : _Node_allocator(__a), _Base_key_compare(__comp)
702 _Rb_tree_impl(
const _Key_compare& __comp, _Node_allocator&& __a)
703 : _Node_allocator(
std::move(__a)), _Base_key_compare(__comp)
708 _Rb_tree_impl<_Compare> _M_impl;
712 _M_root() _GLIBCXX_NOEXCEPT
713 {
return this->_M_impl._M_header._M_parent; }
716 _M_root() const _GLIBCXX_NOEXCEPT
717 {
return this->_M_impl._M_header._M_parent; }
720 _M_leftmost() _GLIBCXX_NOEXCEPT
721 {
return this->_M_impl._M_header._M_left; }
724 _M_leftmost() const _GLIBCXX_NOEXCEPT
725 {
return this->_M_impl._M_header._M_left; }
728 _M_rightmost() _GLIBCXX_NOEXCEPT
729 {
return this->_M_impl._M_header._M_right; }
732 _M_rightmost() const _GLIBCXX_NOEXCEPT
733 {
return this->_M_impl._M_header._M_right; }
736 _M_begin() _GLIBCXX_NOEXCEPT
737 {
return static_cast<_Link_type
>(this->_M_impl._M_header._M_parent); }
740 _M_begin() const _GLIBCXX_NOEXCEPT
742 return static_cast<_Const_Link_type
> 743 (this->_M_impl._M_header._M_parent);
747 _M_end() _GLIBCXX_NOEXCEPT
748 {
return &this->_M_impl._M_header; }
751 _M_end() const _GLIBCXX_NOEXCEPT
752 {
return &this->_M_impl._M_header; }
754 static const_reference
755 _S_value(_Const_Link_type __x)
756 {
return *__x->_M_valptr(); }
759 _S_key(_Const_Link_type __x)
760 {
return _KeyOfValue()(_S_value(__x)); }
763 _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
764 {
return static_cast<_Link_type
>(__x->_M_left); }
766 static _Const_Link_type
767 _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
768 {
return static_cast<_Const_Link_type
>(__x->_M_left); }
771 _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPT
772 {
return static_cast<_Link_type
>(__x->_M_right); }
774 static _Const_Link_type
775 _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
776 {
return static_cast<_Const_Link_type
>(__x->_M_right); }
778 static const_reference
779 _S_value(_Const_Base_ptr __x)
780 {
return *
static_cast<_Const_Link_type
>(__x)->_M_valptr(); }
783 _S_key(_Const_Base_ptr __x)
784 {
return _KeyOfValue()(_S_value(__x)); }
787 _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
788 {
return _Rb_tree_node_base::_S_minimum(__x); }
790 static _Const_Base_ptr
791 _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
792 {
return _Rb_tree_node_base::_S_minimum(__x); }
795 _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
796 {
return _Rb_tree_node_base::_S_maximum(__x); }
798 static _Const_Base_ptr
799 _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
800 {
return _Rb_tree_node_base::_S_maximum(__x); }
803 typedef _Rb_tree_iterator<value_type> iterator;
804 typedef _Rb_tree_const_iterator<value_type> const_iterator;
809 #if __cplusplus > 201402L 810 using node_type = _Node_handle<_Key, _Val, _Node_allocator>;
811 using insert_return_type = _Node_insert_return<
812 conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
816 pair<_Base_ptr, _Base_ptr>
817 _M_get_insert_unique_pos(
const key_type& __k);
819 pair<_Base_ptr, _Base_ptr>
820 _M_get_insert_equal_pos(
const key_type& __k);
822 pair<_Base_ptr, _Base_ptr>
823 _M_get_insert_hint_unique_pos(const_iterator __pos,
824 const key_type& __k);
826 pair<_Base_ptr, _Base_ptr>
827 _M_get_insert_hint_equal_pos(const_iterator __pos,
828 const key_type& __k);
831 #if __cplusplus >= 201103L 832 template<
typename _Arg,
typename _NodeGen>
834 _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&);
837 _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z);
839 template<
typename _Arg>
841 _M_insert_lower(_Base_ptr __y, _Arg&& __v);
843 template<
typename _Arg>
845 _M_insert_equal_lower(_Arg&& __x);
848 _M_insert_lower_node(_Base_ptr __p, _Link_type __z);
851 _M_insert_equal_lower_node(_Link_type __z);
853 template<
typename _NodeGen>
855 _M_insert_(_Base_ptr __x, _Base_ptr __y,
856 const value_type& __v, _NodeGen&);
861 _M_insert_lower(_Base_ptr __y,
const value_type& __v);
864 _M_insert_equal_lower(
const value_type& __x);
867 template<
typename _NodeGen>
869 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen&);
871 template<
typename _NodeGen>
873 _M_copy(
const _Rb_tree& __x, _NodeGen& __gen)
875 _Link_type __root = _M_copy(__x._M_begin(), _M_end(), __gen);
876 _M_leftmost() = _S_minimum(__root);
877 _M_rightmost() = _S_maximum(__root);
878 _M_impl._M_node_count = __x._M_impl._M_node_count;
883 _M_copy(
const _Rb_tree& __x)
885 _Alloc_node __an(*
this);
886 return _M_copy(__x, __an);
890 _M_erase(_Link_type __x);
893 _M_lower_bound(_Link_type __x, _Base_ptr __y,
897 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
898 const _Key& __k)
const;
901 _M_upper_bound(_Link_type __x, _Base_ptr __y,
905 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
906 const _Key& __k)
const;
910 #if __cplusplus < 201103L 913 _Rb_tree() =
default;
916 _Rb_tree(
const _Compare& __comp,
917 const allocator_type& __a = allocator_type())
918 : _M_impl(__comp, _Node_allocator(__a)) { }
920 _Rb_tree(
const _Rb_tree& __x)
921 : _M_impl(__x._M_impl)
923 if (__x._M_root() != 0)
924 _M_root() = _M_copy(__x);
927 #if __cplusplus >= 201103L 928 _Rb_tree(
const allocator_type& __a)
929 : _M_impl(_Compare(), _Node_allocator(__a))
932 _Rb_tree(
const _Rb_tree& __x,
const allocator_type& __a)
933 : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
935 if (__x._M_root() !=
nullptr)
936 _M_root() = _M_copy(__x);
939 _Rb_tree(_Rb_tree&&) =
default;
941 _Rb_tree(_Rb_tree&& __x,
const allocator_type& __a)
942 : _Rb_tree(
std::move(__x), _Node_allocator(__a))
945 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a);
948 ~_Rb_tree() _GLIBCXX_NOEXCEPT
949 { _M_erase(_M_begin()); }
952 operator=(
const _Rb_tree& __x);
957 {
return _M_impl._M_key_compare; }
960 begin() _GLIBCXX_NOEXCEPT
961 {
return iterator(this->_M_impl._M_header._M_left); }
964 begin() const _GLIBCXX_NOEXCEPT
965 {
return const_iterator(this->_M_impl._M_header._M_left); }
968 end() _GLIBCXX_NOEXCEPT
969 {
return iterator(&this->_M_impl._M_header); }
972 end() const _GLIBCXX_NOEXCEPT
973 {
return const_iterator(&this->_M_impl._M_header); }
976 rbegin() _GLIBCXX_NOEXCEPT
977 {
return reverse_iterator(
end()); }
979 const_reverse_iterator
980 rbegin() const _GLIBCXX_NOEXCEPT
981 {
return const_reverse_iterator(
end()); }
984 rend() _GLIBCXX_NOEXCEPT
985 {
return reverse_iterator(
begin()); }
987 const_reverse_iterator
988 rend() const _GLIBCXX_NOEXCEPT
989 {
return const_reverse_iterator(
begin()); }
992 empty() const _GLIBCXX_NOEXCEPT
993 {
return _M_impl._M_node_count == 0; }
996 size() const _GLIBCXX_NOEXCEPT
997 {
return _M_impl._M_node_count; }
1000 max_size() const _GLIBCXX_NOEXCEPT
1001 {
return _Alloc_traits::max_size(_M_get_Node_allocator()); }
1005 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value);
1008 #if __cplusplus >= 201103L 1009 template<
typename _Arg>
1010 pair<iterator, bool>
1011 _M_insert_unique(_Arg&& __x);
1013 template<
typename _Arg>
1015 _M_insert_equal(_Arg&& __x);
1017 template<
typename _Arg,
typename _NodeGen>
1019 _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1021 template<
typename _Arg>
1023 _M_insert_unique_(const_iterator __pos, _Arg&& __x)
1025 _Alloc_node __an(*
this);
1026 return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an);
1029 template<
typename _Arg,
typename _NodeGen>
1031 _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&);
1033 template<
typename _Arg>
1035 _M_insert_equal_(const_iterator __pos, _Arg&& __x)
1037 _Alloc_node __an(*
this);
1038 return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an);
1041 template<
typename... _Args>
1042 pair<iterator, bool>
1043 _M_emplace_unique(_Args&&... __args);
1045 template<
typename... _Args>
1047 _M_emplace_equal(_Args&&... __args);
1049 template<
typename... _Args>
1051 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args);
1053 template<
typename... _Args>
1055 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args);
1057 pair<iterator, bool>
1058 _M_insert_unique(
const value_type& __x);
1061 _M_insert_equal(
const value_type& __x);
1063 template<
typename _NodeGen>
1065 _M_insert_unique_(const_iterator __pos,
const value_type& __x,
1069 _M_insert_unique_(const_iterator __pos,
const value_type& __x)
1071 _Alloc_node __an(*
this);
1072 return _M_insert_unique_(__pos, __x, __an);
1075 template<
typename _NodeGen>
1077 _M_insert_equal_(const_iterator __pos,
const value_type& __x,
1080 _M_insert_equal_(const_iterator __pos,
const value_type& __x)
1082 _Alloc_node __an(*
this);
1083 return _M_insert_equal_(__pos, __x, __an);
1087 template<
typename _InputIterator>
1089 _M_insert_unique(_InputIterator __first, _InputIterator __last);
1091 template<
typename _InputIterator>
1093 _M_insert_equal(_InputIterator __first, _InputIterator __last);
1097 _M_erase_aux(const_iterator __position);
1100 _M_erase_aux(const_iterator __first, const_iterator __last);
1103 #if __cplusplus >= 201103L 1106 _GLIBCXX_ABI_TAG_CXX11
1108 erase(const_iterator __position)
1110 __glibcxx_assert(__position !=
end());
1111 const_iterator __result = __position;
1113 _M_erase_aux(__position);
1114 return __result._M_const_cast();
1118 _GLIBCXX_ABI_TAG_CXX11
1120 erase(iterator __position)
1122 __glibcxx_assert(__position !=
end());
1123 iterator __result = __position;
1125 _M_erase_aux(__position);
1130 erase(iterator __position)
1132 __glibcxx_assert(__position !=
end());
1133 _M_erase_aux(__position);
1137 erase(const_iterator __position)
1139 __glibcxx_assert(__position !=
end());
1140 _M_erase_aux(__position);
1144 erase(
const key_type& __x);
1146 #if __cplusplus >= 201103L 1149 _GLIBCXX_ABI_TAG_CXX11
1151 erase(const_iterator __first, const_iterator __last)
1153 _M_erase_aux(__first, __last);
1154 return __last._M_const_cast();
1158 erase(iterator __first, iterator __last)
1159 { _M_erase_aux(__first, __last); }
1162 erase(const_iterator __first, const_iterator __last)
1163 { _M_erase_aux(__first, __last); }
1166 erase(
const key_type* __first,
const key_type* __last);
1169 clear() _GLIBCXX_NOEXCEPT
1171 _M_erase(_M_begin());
1177 find(
const key_type& __k);
1180 find(
const key_type& __k)
const;
1183 count(
const key_type& __k)
const;
1186 lower_bound(
const key_type& __k)
1187 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1190 lower_bound(
const key_type& __k)
const 1191 {
return _M_lower_bound(_M_begin(), _M_end(), __k); }
1194 upper_bound(
const key_type& __k)
1195 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1198 upper_bound(
const key_type& __k)
const 1199 {
return _M_upper_bound(_M_begin(), _M_end(), __k); }
1201 pair<iterator, iterator>
1202 equal_range(
const key_type& __k);
1204 pair<const_iterator, const_iterator>
1205 equal_range(
const key_type& __k)
const;
1207 #if __cplusplus > 201103L 1208 template<
typename _Kt,
1210 typename __has_is_transparent<_Compare, _Kt>::type>
1212 _M_find_tr(
const _Kt& __k)
1214 const _Rb_tree* __const_this =
this;
1215 return __const_this->_M_find_tr(__k)._M_const_cast();
1218 template<
typename _Kt,
1220 typename __has_is_transparent<_Compare, _Kt>::type>
1222 _M_find_tr(
const _Kt& __k)
const 1224 auto __j = _M_lower_bound_tr(__k);
1225 if (__j !=
end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node)))
1230 template<
typename _Kt,
1232 typename __has_is_transparent<_Compare, _Kt>::type>
1234 _M_count_tr(
const _Kt& __k)
const 1236 auto __p = _M_equal_range_tr(__k);
1240 template<
typename _Kt,
1242 typename __has_is_transparent<_Compare, _Kt>::type>
1244 _M_lower_bound_tr(
const _Kt& __k)
1246 const _Rb_tree* __const_this =
this;
1247 return __const_this->_M_lower_bound_tr(__k)._M_const_cast();
1250 template<
typename _Kt,
1252 typename __has_is_transparent<_Compare, _Kt>::type>
1254 _M_lower_bound_tr(
const _Kt& __k)
const 1256 auto __x = _M_begin();
1257 auto __y = _M_end();
1259 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1265 __x = _S_right(__x);
1266 return const_iterator(__y);
1269 template<
typename _Kt,
1271 typename __has_is_transparent<_Compare, _Kt>::type>
1273 _M_upper_bound_tr(
const _Kt& __k)
1275 const _Rb_tree* __const_this =
this;
1276 return __const_this->_M_upper_bound_tr(__k)._M_const_cast();
1279 template<
typename _Kt,
1281 typename __has_is_transparent<_Compare, _Kt>::type>
1283 _M_upper_bound_tr(
const _Kt& __k)
const 1285 auto __x = _M_begin();
1286 auto __y = _M_end();
1288 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1294 __x = _S_right(__x);
1295 return const_iterator(__y);
1298 template<
typename _Kt,
1300 typename __has_is_transparent<_Compare, _Kt>::type>
1301 pair<iterator, iterator>
1302 _M_equal_range_tr(
const _Kt& __k)
1304 const _Rb_tree* __const_this =
this;
1305 auto __ret = __const_this->_M_equal_range_tr(__k);
1306 return { __ret.first._M_const_cast(), __ret.second._M_const_cast() };
1309 template<
typename _Kt,
1311 typename __has_is_transparent<_Compare, _Kt>::type>
1312 pair<const_iterator, const_iterator>
1313 _M_equal_range_tr(
const _Kt& __k)
const 1315 auto __low = _M_lower_bound_tr(__k);
1316 auto __high = __low;
1317 auto& __cmp = _M_impl._M_key_compare;
1318 while (__high !=
end() && !__cmp(__k, _S_key(__high._M_node)))
1320 return { __low, __high };
1326 __rb_verify()
const;
1328 #if __cplusplus >= 201103L 1330 operator=(_Rb_tree&&)
1331 noexcept(_Alloc_traits::_S_nothrow_move()
1332 && is_nothrow_move_assignable<_Compare>::value);
1334 template<typename _Iterator>
1336 _M_assign_unique(_Iterator, _Iterator);
1338 template<typename _Iterator>
1340 _M_assign_equal(_Iterator, _Iterator);
1346 { _M_impl._M_move_data(__x._M_impl); }
1363 #if __cplusplus > 201402L 1367 _M_reinsert_node_unique(node_type&& __nh)
1369 insert_return_type __ret;
1371 __ret.position =
end();
1374 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1376 auto __res = _M_get_insert_unique_pos(__nh._M_key());
1380 = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1381 __nh._M_ptr =
nullptr;
1382 __ret.inserted =
true;
1386 __ret.node = std::move(__nh);
1387 __ret.position = iterator(__res.first);
1388 __ret.inserted =
false;
1396 _M_reinsert_node_equal(node_type&& __nh)
1403 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1404 auto __res = _M_get_insert_equal_pos(__nh._M_key());
1406 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1408 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1409 __nh._M_ptr =
nullptr;
1416 _M_reinsert_node_hint_unique(const_iterator __hint, node_type&& __nh)
1423 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1424 auto __res = _M_get_insert_hint_unique_pos(__hint, __nh._M_key());
1427 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1428 __nh._M_ptr =
nullptr;
1431 __ret = iterator(__res.first);
1438 _M_reinsert_node_hint_equal(const_iterator __hint, node_type&& __nh)
1445 __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc);
1446 auto __res = _M_get_insert_hint_equal_pos(__hint, __nh._M_key());
1448 __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr);
1450 __ret = _M_insert_equal_lower_node(__nh._M_ptr);
1451 __nh._M_ptr =
nullptr;
1458 extract(const_iterator __pos)
1460 auto __ptr = _Rb_tree_rebalance_for_erase(
1461 __pos._M_const_cast()._M_node, _M_impl._M_header);
1462 --_M_impl._M_node_count;
1463 return {
static_cast<_Link_type
>(__ptr), _M_get_Node_allocator() };
1468 extract(
const key_type& __k)
1471 auto __pos = find(__k);
1473 __nh = extract(const_iterator(__pos));
1477 template<
typename _Compare2>
1478 using _Compatible_tree
1479 = _Rb_tree<_Key, _Val, _KeyOfValue, _Compare2, _Alloc>;
1481 template<
typename,
typename>
1482 friend class _Rb_tree_merge_helper;
1485 template<
typename _Compare2>
1487 _M_merge_unique(_Compatible_tree<_Compare2>& __src) noexcept
1489 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1490 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1493 auto __res = _M_get_insert_unique_pos(_KeyOfValue()(*__pos));
1496 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1497 auto __ptr = _Rb_tree_rebalance_for_erase(
1498 __pos._M_node, __src_impl._M_header);
1499 --__src_impl._M_node_count;
1500 _M_insert_node(__res.first, __res.second,
1501 static_cast<_Link_type>(__ptr));
1507 template<
typename _Compare2>
1509 _M_merge_equal(_Compatible_tree<_Compare2>& __src) noexcept
1511 using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>;
1512 for (
auto __i = __src.begin(), __end = __src.end(); __i != __end;)
1515 auto __res = _M_get_insert_equal_pos(_KeyOfValue()(*__pos));
1518 auto& __src_impl = _Merge_helper::_S_get_impl(__src);
1519 auto __ptr = _Rb_tree_rebalance_for_erase(
1520 __pos._M_node, __src_impl._M_header);
1521 --__src_impl._M_node_count;
1522 _M_insert_node(__res.first, __res.second,
1523 static_cast<_Link_type>(__ptr));
1530 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1531 typename _Compare,
typename _Alloc>
1533 operator==(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1534 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1536 return __x.size() == __y.size()
1537 &&
std::equal(__x.begin(), __x.end(), __y.begin());
1540 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1541 typename _Compare,
typename _Alloc>
1543 operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1544 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1547 __y.begin(), __y.end());
1550 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1551 typename _Compare,
typename _Alloc>
1553 operator!=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1554 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1555 {
return !(__x == __y); }
1557 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1558 typename _Compare,
typename _Alloc>
1560 operator>(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1561 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1562 {
return __y < __x; }
1564 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1565 typename _Compare,
typename _Alloc>
1567 operator<=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1568 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1569 {
return !(__y < __x); }
1571 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1572 typename _Compare,
typename _Alloc>
1574 operator>=(
const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1575 const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1576 {
return !(__x < __y); }
1578 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1579 typename _Compare,
typename _Alloc>
1581 swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
1582 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
1585 #if __cplusplus >= 201103L 1586 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1587 typename _Compare,
typename _Alloc>
1588 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1589 _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
1590 : _M_impl(__x._M_impl._M_key_compare,
std::move(__a))
1592 using __eq =
typename _Alloc_traits::is_always_equal;
1593 if (__x._M_root() !=
nullptr)
1594 _M_move_data(__x, __eq());
1597 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1598 typename _Compare,
typename _Alloc>
1600 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1603 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1607 _Alloc_node __an(*
this);
1609 [&__an](
const value_type& __cval)
1611 auto& __val =
const_cast<value_type&
>(__cval);
1614 _M_root() = _M_copy(__x, __lbd);
1618 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1619 typename _Compare,
typename _Alloc>
1621 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1622 _M_move_assign(_Rb_tree& __x, true_type)
1625 if (__x._M_root() !=
nullptr)
1627 std::__alloc_on_move(_M_get_Node_allocator(),
1628 __x._M_get_Node_allocator());
1631 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1632 typename _Compare,
typename _Alloc>
1634 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1637 if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1638 return _M_move_assign(__x, true_type{});
1642 _Reuse_or_alloc_node __roan(*
this);
1644 if (__x._M_root() !=
nullptr)
1647 [&__roan](
const value_type& __cval)
1649 auto& __val =
const_cast<value_type&
>(__cval);
1652 _M_root() = _M_copy(__x, __lbd);
1657 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1658 typename _Compare,
typename _Alloc>
1659 inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1660 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1661 operator=(_Rb_tree&& __x)
1662 noexcept(_Alloc_traits::_S_nothrow_move()
1663 && is_nothrow_move_assignable<_Compare>::value)
1665 _M_impl._M_key_compare = std::move(__x._M_impl._M_key_compare);
1666 _M_move_assign(__x, __bool_constant<_Alloc_traits::_S_nothrow_move()>());
1670 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1671 typename _Compare,
typename _Alloc>
1672 template<
typename _Iterator>
1674 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1675 _M_assign_unique(_Iterator __first, _Iterator __last)
1677 _Reuse_or_alloc_node __roan(*
this);
1679 for (; __first != __last; ++__first)
1680 _M_insert_unique_(
end(), *__first, __roan);
1683 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1684 typename _Compare,
typename _Alloc>
1685 template<
typename _Iterator>
1687 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1688 _M_assign_equal(_Iterator __first, _Iterator __last)
1690 _Reuse_or_alloc_node __roan(*
this);
1692 for (; __first != __last; ++__first)
1693 _M_insert_equal_(
end(), *__first, __roan);
1697 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1698 typename _Compare,
typename _Alloc>
1699 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
1700 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1701 operator=(
const _Rb_tree& __x)
1706 #if __cplusplus >= 201103L 1707 if (_Alloc_traits::_S_propagate_on_copy_assign())
1709 auto& __this_alloc = this->_M_get_Node_allocator();
1710 auto& __that_alloc = __x._M_get_Node_allocator();
1711 if (!_Alloc_traits::_S_always_equal()
1712 && __this_alloc != __that_alloc)
1717 std::__alloc_on_copy(__this_alloc, __that_alloc);
1722 _Reuse_or_alloc_node __roan(*
this);
1724 _M_impl._M_key_compare = __x._M_impl._M_key_compare;
1725 if (__x._M_root() != 0)
1726 _M_root() = _M_copy(__x, __roan);
1732 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1733 typename _Compare,
typename _Alloc>
1734 #if __cplusplus >= 201103L 1735 template<
typename _Arg,
typename _NodeGen>
1737 template<
typename _NodeGen>
1739 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1740 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1741 _M_insert_(_Base_ptr __x, _Base_ptr __p,
1742 #
if __cplusplus >= 201103L
1747 _NodeGen& __node_gen)
1749 bool __insert_left = (__x != 0 || __p == _M_end()
1750 || _M_impl._M_key_compare(_KeyOfValue()(__v),
1753 _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v));
1755 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1756 this->_M_impl._M_header);
1757 ++_M_impl._M_node_count;
1758 return iterator(__z);
1761 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1762 typename _Compare,
typename _Alloc>
1763 #if __cplusplus >= 201103L 1764 template<
typename _Arg>
1766 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1767 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1768 #if __cplusplus >= 201103L 1769 _M_insert_lower(_Base_ptr __p, _Arg&& __v)
1771 _M_insert_lower(_Base_ptr __p,
const _Val& __v)
1774 bool __insert_left = (__p == _M_end()
1775 || !_M_impl._M_key_compare(_S_key(__p),
1776 _KeyOfValue()(__v)));
1778 _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v));
1780 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
1781 this->_M_impl._M_header);
1782 ++_M_impl._M_node_count;
1783 return iterator(__z);
1786 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1787 typename _Compare,
typename _Alloc>
1788 #if __cplusplus >= 201103L 1789 template<
typename _Arg>
1791 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
1792 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1793 #if __cplusplus >= 201103L 1794 _M_insert_equal_lower(_Arg&& __v)
1796 _M_insert_equal_lower(
const _Val& __v)
1799 _Link_type __x = _M_begin();
1800 _Base_ptr __y = _M_end();
1804 __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ?
1805 _S_left(__x) : _S_right(__x);
1807 return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v));
1810 template<
typename _Key,
typename _Val,
typename _KoV,
1811 typename _Compare,
typename _Alloc>
1812 template<
typename _NodeGen>
1813 typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
1814 _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::
1815 _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen)
1818 _Link_type __top = _M_clone_node(__x, __node_gen);
1819 __top->_M_parent = __p;
1824 __top->_M_right = _M_copy(_S_right(__x), __top, __node_gen);
1830 _Link_type __y = _M_clone_node(__x, __node_gen);
1832 __y->_M_parent = __p;
1834 __y->_M_right = _M_copy(_S_right(__x), __y, __node_gen);
1842 __throw_exception_again;
1847 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1848 typename _Compare,
typename _Alloc>
1850 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1851 _M_erase(_Link_type __x)
1856 _M_erase(_S_right(__x));
1857 _Link_type __y = _S_left(__x);
1863 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1864 typename _Compare,
typename _Alloc>
1865 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1866 _Compare, _Alloc>::iterator
1867 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1868 _M_lower_bound(_Link_type __x, _Base_ptr __y,
1872 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1873 __y = __x, __x = _S_left(__x);
1875 __x = _S_right(__x);
1876 return iterator(__y);
1879 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1880 typename _Compare,
typename _Alloc>
1881 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1882 _Compare, _Alloc>::const_iterator
1883 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1884 _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1885 const _Key& __k)
const 1888 if (!_M_impl._M_key_compare(_S_key(__x), __k))
1889 __y = __x, __x = _S_left(__x);
1891 __x = _S_right(__x);
1892 return const_iterator(__y);
1895 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1896 typename _Compare,
typename _Alloc>
1897 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1898 _Compare, _Alloc>::iterator
1899 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1900 _M_upper_bound(_Link_type __x, _Base_ptr __y,
1904 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1905 __y = __x, __x = _S_left(__x);
1907 __x = _S_right(__x);
1908 return iterator(__y);
1911 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1912 typename _Compare,
typename _Alloc>
1913 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1914 _Compare, _Alloc>::const_iterator
1915 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1916 _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y,
1917 const _Key& __k)
const 1920 if (_M_impl._M_key_compare(__k, _S_key(__x)))
1921 __y = __x, __x = _S_left(__x);
1923 __x = _S_right(__x);
1924 return const_iterator(__y);
1927 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1928 typename _Compare,
typename _Alloc>
1929 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1930 _Compare, _Alloc>::iterator,
1931 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1932 _Compare, _Alloc>::iterator>
1933 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1934 equal_range(
const _Key& __k)
1936 _Link_type __x = _M_begin();
1937 _Base_ptr __y = _M_end();
1940 if (_M_impl._M_key_compare(_S_key(__x), __k))
1941 __x = _S_right(__x);
1942 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1943 __y = __x, __x = _S_left(__x);
1946 _Link_type __xu(__x);
1947 _Base_ptr __yu(__y);
1948 __y = __x, __x = _S_left(__x);
1949 __xu = _S_right(__xu);
1950 return pair<iterator,
1951 iterator>(_M_lower_bound(__x, __y, __k),
1952 _M_upper_bound(__xu, __yu, __k));
1955 return pair<iterator, iterator>(iterator(__y),
1959 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1960 typename _Compare,
typename _Alloc>
1961 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
1962 _Compare, _Alloc>::const_iterator,
1963 typename _Rb_tree<_Key, _Val, _KeyOfValue,
1964 _Compare, _Alloc>::const_iterator>
1965 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1966 equal_range(
const _Key& __k)
const 1968 _Const_Link_type __x = _M_begin();
1969 _Const_Base_ptr __y = _M_end();
1972 if (_M_impl._M_key_compare(_S_key(__x), __k))
1973 __x = _S_right(__x);
1974 else if (_M_impl._M_key_compare(__k, _S_key(__x)))
1975 __y = __x, __x = _S_left(__x);
1978 _Const_Link_type __xu(__x);
1979 _Const_Base_ptr __yu(__y);
1980 __y = __x, __x = _S_left(__x);
1981 __xu = _S_right(__xu);
1982 return pair<const_iterator,
1983 const_iterator>(_M_lower_bound(__x, __y, __k),
1984 _M_upper_bound(__xu, __yu, __k));
1987 return pair<const_iterator, const_iterator>(const_iterator(__y),
1988 const_iterator(__y));
1991 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
1992 typename _Compare,
typename _Alloc>
1994 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1996 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
2000 if (__t._M_root() != 0)
2001 _M_impl._M_move_data(__t._M_impl);
2003 else if (__t._M_root() == 0)
2004 __t._M_impl._M_move_data(_M_impl);
2007 std::swap(_M_root(),__t._M_root());
2008 std::swap(_M_leftmost(),__t._M_leftmost());
2009 std::swap(_M_rightmost(),__t._M_rightmost());
2011 _M_root()->_M_parent = _M_end();
2012 __t._M_root()->_M_parent = __t._M_end();
2013 std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
2016 std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
2018 _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
2019 __t._M_get_Node_allocator());
2022 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2023 typename _Compare,
typename _Alloc>
2024 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2025 _Compare, _Alloc>::_Base_ptr,
2026 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2027 _Compare, _Alloc>::_Base_ptr>
2028 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2029 _M_get_insert_unique_pos(
const key_type& __k)
2031 typedef pair<_Base_ptr, _Base_ptr> _Res;
2032 _Link_type __x = _M_begin();
2033 _Base_ptr __y = _M_end();
2038 __comp = _M_impl._M_key_compare(__k, _S_key(__x));
2039 __x = __comp ? _S_left(__x) : _S_right(__x);
2041 iterator __j = iterator(__y);
2045 return _Res(__x, __y);
2049 if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
2050 return _Res(__x, __y);
2051 return _Res(__j._M_node, 0);
2054 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2055 typename _Compare,
typename _Alloc>
2056 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2057 _Compare, _Alloc>::_Base_ptr,
2058 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2059 _Compare, _Alloc>::_Base_ptr>
2060 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2061 _M_get_insert_equal_pos(
const key_type& __k)
2063 typedef pair<_Base_ptr, _Base_ptr> _Res;
2064 _Link_type __x = _M_begin();
2065 _Base_ptr __y = _M_end();
2069 __x = _M_impl._M_key_compare(__k, _S_key(__x)) ?
2070 _S_left(__x) : _S_right(__x);
2072 return _Res(__x, __y);
2075 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2076 typename _Compare,
typename _Alloc>
2077 #if __cplusplus >= 201103L 2078 template<
typename _Arg>
2080 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2081 _Compare, _Alloc>::iterator,
bool>
2082 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2083 #if __cplusplus >= 201103L 2084 _M_insert_unique(_Arg&& __v)
2086 _M_insert_unique(
const _Val& __v)
2089 typedef pair<iterator, bool> _Res;
2090 pair<_Base_ptr, _Base_ptr> __res
2091 = _M_get_insert_unique_pos(_KeyOfValue()(__v));
2095 _Alloc_node __an(*
this);
2096 return _Res(_M_insert_(__res.first, __res.second,
2097 _GLIBCXX_FORWARD(_Arg, __v), __an),
2101 return _Res(iterator(__res.first),
false);
2104 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2105 typename _Compare,
typename _Alloc>
2106 #if __cplusplus >= 201103L 2107 template<
typename _Arg>
2109 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2110 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2111 #if __cplusplus >= 201103L 2112 _M_insert_equal(_Arg&& __v)
2114 _M_insert_equal(
const _Val& __v)
2117 pair<_Base_ptr, _Base_ptr> __res
2118 = _M_get_insert_equal_pos(_KeyOfValue()(__v));
2119 _Alloc_node __an(*
this);
2120 return _M_insert_(__res.first, __res.second,
2121 _GLIBCXX_FORWARD(_Arg, __v), __an);
2124 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2125 typename _Compare,
typename _Alloc>
2126 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2127 _Compare, _Alloc>::_Base_ptr,
2128 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2129 _Compare, _Alloc>::_Base_ptr>
2130 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2131 _M_get_insert_hint_unique_pos(const_iterator __position,
2132 const key_type& __k)
2134 iterator __pos = __position._M_const_cast();
2135 typedef pair<_Base_ptr, _Base_ptr> _Res;
2138 if (__pos._M_node == _M_end())
2141 && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k))
2142 return _Res(0, _M_rightmost());
2144 return _M_get_insert_unique_pos(__k);
2146 else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node)))
2149 iterator __before = __pos;
2150 if (__pos._M_node == _M_leftmost())
2151 return _Res(_M_leftmost(), _M_leftmost());
2152 else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k))
2154 if (_S_right(__before._M_node) == 0)
2155 return _Res(0, __before._M_node);
2157 return _Res(__pos._M_node, __pos._M_node);
2160 return _M_get_insert_unique_pos(__k);
2162 else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2165 iterator __after = __pos;
2166 if (__pos._M_node == _M_rightmost())
2167 return _Res(0, _M_rightmost());
2168 else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node)))
2170 if (_S_right(__pos._M_node) == 0)
2171 return _Res(0, __pos._M_node);
2173 return _Res(__after._M_node, __after._M_node);
2176 return _M_get_insert_unique_pos(__k);
2180 return _Res(__pos._M_node, 0);
2183 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2184 typename _Compare,
typename _Alloc>
2185 #if __cplusplus >= 201103L 2186 template<
typename _Arg,
typename _NodeGen>
2188 template<
typename _NodeGen>
2190 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2191 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2192 _M_insert_unique_(const_iterator __position,
2193 #
if __cplusplus >= 201103L
2198 _NodeGen& __node_gen)
2200 pair<_Base_ptr, _Base_ptr> __res
2201 = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v));
2204 return _M_insert_(__res.first, __res.second,
2205 _GLIBCXX_FORWARD(_Arg, __v),
2207 return iterator(__res.first);
2210 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2211 typename _Compare,
typename _Alloc>
2212 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2213 _Compare, _Alloc>::_Base_ptr,
2214 typename _Rb_tree<_Key, _Val, _KeyOfValue,
2215 _Compare, _Alloc>::_Base_ptr>
2216 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2217 _M_get_insert_hint_equal_pos(const_iterator __position,
const key_type& __k)
2219 iterator __pos = __position._M_const_cast();
2220 typedef pair<_Base_ptr, _Base_ptr> _Res;
2223 if (__pos._M_node == _M_end())
2226 && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost())))
2227 return _Res(0, _M_rightmost());
2229 return _M_get_insert_equal_pos(__k);
2231 else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k))
2234 iterator __before = __pos;
2235 if (__pos._M_node == _M_leftmost())
2236 return _Res(_M_leftmost(), _M_leftmost());
2237 else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node)))
2239 if (_S_right(__before._M_node) == 0)
2240 return _Res(0, __before._M_node);
2242 return _Res(__pos._M_node, __pos._M_node);
2245 return _M_get_insert_equal_pos(__k);
2250 iterator __after = __pos;
2251 if (__pos._M_node == _M_rightmost())
2252 return _Res(0, _M_rightmost());
2253 else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k))
2255 if (_S_right(__pos._M_node) == 0)
2256 return _Res(0, __pos._M_node);
2258 return _Res(__after._M_node, __after._M_node);
2265 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2266 typename _Compare,
typename _Alloc>
2267 #if __cplusplus >= 201103L 2268 template<
typename _Arg,
typename _NodeGen>
2270 template<
typename _NodeGen>
2272 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2273 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2274 _M_insert_equal_(const_iterator __position,
2275 #
if __cplusplus >= 201103L
2280 _NodeGen& __node_gen)
2282 pair<_Base_ptr, _Base_ptr> __res
2283 = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v));
2286 return _M_insert_(__res.first, __res.second,
2287 _GLIBCXX_FORWARD(_Arg, __v),
2290 return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v));
2293 #if __cplusplus >= 201103L 2294 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2295 typename _Compare,
typename _Alloc>
2296 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2297 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2298 _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z)
2300 bool __insert_left = (__x != 0 || __p == _M_end()
2301 || _M_impl._M_key_compare(_S_key(__z),
2304 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2305 this->_M_impl._M_header);
2306 ++_M_impl._M_node_count;
2307 return iterator(__z);
2310 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2311 typename _Compare,
typename _Alloc>
2312 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2313 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2314 _M_insert_lower_node(_Base_ptr __p, _Link_type __z)
2316 bool __insert_left = (__p == _M_end()
2317 || !_M_impl._M_key_compare(_S_key(__p),
2320 _Rb_tree_insert_and_rebalance(__insert_left, __z, __p,
2321 this->_M_impl._M_header);
2322 ++_M_impl._M_node_count;
2323 return iterator(__z);
2326 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2327 typename _Compare,
typename _Alloc>
2328 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2329 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2330 _M_insert_equal_lower_node(_Link_type __z)
2332 _Link_type __x = _M_begin();
2333 _Base_ptr __y = _M_end();
2337 __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ?
2338 _S_left(__x) : _S_right(__x);
2340 return _M_insert_lower_node(__y, __z);
2343 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2344 typename _Compare,
typename _Alloc>
2345 template<
typename... _Args>
2346 pair<
typename _Rb_tree<_Key, _Val, _KeyOfValue,
2347 _Compare, _Alloc>::iterator,
bool>
2348 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2349 _M_emplace_unique(_Args&&... __args)
2351 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2355 typedef pair<iterator, bool> _Res;
2356 auto __res = _M_get_insert_unique_pos(_S_key(__z));
2358 return _Res(_M_insert_node(__res.first, __res.second, __z),
true);
2361 return _Res(iterator(__res.first),
false);
2366 __throw_exception_again;
2370 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2371 typename _Compare,
typename _Alloc>
2372 template<
typename... _Args>
2373 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2374 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2375 _M_emplace_equal(_Args&&... __args)
2377 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2381 auto __res = _M_get_insert_equal_pos(_S_key(__z));
2382 return _M_insert_node(__res.first, __res.second, __z);
2387 __throw_exception_again;
2391 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2392 typename _Compare,
typename _Alloc>
2393 template<
typename... _Args>
2394 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2395 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2396 _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args)
2398 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2402 auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z));
2405 return _M_insert_node(__res.first, __res.second, __z);
2408 return iterator(__res.first);
2413 __throw_exception_again;
2417 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2418 typename _Compare,
typename _Alloc>
2419 template<
typename... _Args>
2420 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
2421 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2422 _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args)
2424 _Link_type __z = _M_create_node(std::forward<_Args>(__args)...);
2428 auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z));
2431 return _M_insert_node(__res.first, __res.second, __z);
2433 return _M_insert_equal_lower_node(__z);
2438 __throw_exception_again;
2443 template<
typename _Key,
typename _Val,
typename _KoV,
2444 typename _Cmp,
typename _Alloc>
2447 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
2448 _M_insert_unique(_II __first, _II __last)
2450 _Alloc_node __an(*
this);
2451 for (; __first != __last; ++__first)
2452 _M_insert_unique_(
end(), *__first, __an);
2455 template<
typename _Key,
typename _Val,
typename _KoV,
2456 typename _Cmp,
typename _Alloc>
2459 _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>::
2460 _M_insert_equal(_II __first, _II __last)
2462 _Alloc_node __an(*
this);
2463 for (; __first != __last; ++__first)
2464 _M_insert_equal_(
end(), *__first, __an);
2467 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2468 typename _Compare,
typename _Alloc>
2470 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2471 _M_erase_aux(const_iterator __position)
2474 static_cast<_Link_type
>(_Rb_tree_rebalance_for_erase
2475 (const_cast<_Base_ptr>(__position._M_node),
2476 this->_M_impl._M_header));
2478 --_M_impl._M_node_count;
2481 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2482 typename _Compare,
typename _Alloc>
2484 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2485 _M_erase_aux(const_iterator __first, const_iterator __last)
2487 if (__first ==
begin() && __last ==
end())
2490 while (__first != __last)
2491 _M_erase_aux(__first++);
2494 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2495 typename _Compare,
typename _Alloc>
2496 typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type
2497 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2498 erase(
const _Key& __x)
2500 pair<iterator, iterator> __p = equal_range(__x);
2501 const size_type __old_size =
size();
2502 _M_erase_aux(__p.first, __p.second);
2503 return __old_size -
size();
2506 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
2507 typename _Compare,
typename _Alloc>
2509 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
2510 erase(
const _Key* __first,
const _Key* __last)
2512 while (__first != __last)
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
Uniform interface to C++98 and C++11 allocators.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
ISO C++ entities toplevel namespace is std.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
iterator begin()
As per Table mumble.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
_GLIBCXX17_CONSTEXPR auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
_GLIBCXX17_CONSTEXPR auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
constexpr conditional< __move_if_noexcept_cond< _Tp >::value, const _Tp &, _Tp && >::type move_if_noexcept(_Tp &__x) noexcept
Conditionally convert a value to an rvalue.
iterator end()
As per Table mumble.
size_type size() const
As per Table mumble.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.