29#ifndef _GLIBCXX_DEBUG_LIST
30#define _GLIBCXX_DEBUG_LIST 1
32#pragma GCC system_header
35namespace std _GLIBCXX_VISIBILITY(default) {
namespace __debug {
36 template<
typename _Tp,
typename _Allocator>
class list;
44namespace std _GLIBCXX_VISIBILITY(default)
49 template<
typename _Tp,
typename _Allocator = std::allocator<_Tp> >
52 list<_Tp, _Allocator>, _Allocator,
53 __gnu_debug::_Safe_node_sequence>,
54 public _GLIBCXX_STD_C::list<_Tp, _Allocator>
56 typedef _GLIBCXX_STD_C::list<_Tp, _Allocator>
_Base;
65 template<
typename _ItT,
typename _SeqT,
typename _CatT>
66 friend class ::__gnu_debug::_Safe_iterator;
73 _Base_ref(
const _Base& __r) : _M_ref(__r) { }
79 typedef typename _Base::reference reference;
80 typedef typename _Base::const_reference const_reference;
87 typedef typename _Base::size_type size_type;
88 typedef typename _Base::difference_type difference_type;
90 typedef _Tp value_type;
91 typedef _Allocator allocator_type;
92 typedef typename _Base::pointer pointer;
93 typedef typename _Base::const_pointer const_pointer;
99#if __cplusplus < 201103L
113 const allocator_type& __a = allocator_type())
114 :
_Base(__l, __a) { }
118 list(
const list& __x,
const __type_identity_t<allocator_type>& __a)
119 :
_Base(__x, __a) { }
121 list(
list&& __x,
const __type_identity_t<allocator_type>& __a)
124 _Base,
const allocator_type&>::value )
130 list(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
133#if __cplusplus >= 201103L
135 list(size_type __n,
const allocator_type& __a = allocator_type())
136 :
_Base(__n, __a) { }
138 list(size_type __n,
const __type_identity_t<_Tp>& __value,
139 const _Allocator& __a = _Allocator())
140 :
_Base(__n, __value, __a) { }
143 list(size_type __n,
const _Tp& __value = _Tp(),
144 const _Allocator& __a = _Allocator())
145 :
_Base(__n, __value, __a) { }
148#if __cplusplus >= 201103L
149 template<
class _InputIterator,
150 typename = std::_RequireInputIter<_InputIterator>>
152 template<
class _InputIterator>
154 list(_InputIterator __first, _InputIterator __last,
155 const _Allocator& __a = _Allocator())
157 __glibcxx_check_valid_constructor_range(__first, __last)),
162 :
_Base(__x._M_ref) { }
164#if __cplusplus >= 201103L
166 operator=(
const list&) =
default;
169 operator=(
list&&) =
default;
174 this->_M_invalidate_all();
175 _Base::operator=(__l);
183 this->_M_invalidate_all();
187#if __cplusplus >= 201103L
188 template<
class _InputIterator,
189 typename = std::_RequireInputIter<_InputIterator>>
191 template<
class _InputIterator>
194 assign(_InputIterator __first, _InputIterator __last)
197 __glibcxx_check_valid_range2(__first, __last, __dist);
199 if (__dist.
second >= __gnu_debug::__dp_sign)
200 _Base::assign(__gnu_debug::__unsafe(__first),
201 __gnu_debug::__unsafe(__last));
203 _Base::assign(__first, __last);
205 this->_M_invalidate_all();
209 assign(size_type __n,
const _Tp& __t)
211 _Base::assign(__n, __t);
212 this->_M_invalidate_all();
215 using _Base::get_allocator;
220 begin() _GLIBCXX_NOEXCEPT
221 {
return iterator(_Base::begin(),
this); }
225 begin()
const _GLIBCXX_NOEXCEPT
230 end() _GLIBCXX_NOEXCEPT
231 {
return iterator(_Base::end(),
this); }
235 end()
const _GLIBCXX_NOEXCEPT
240 rbegin() _GLIBCXX_NOEXCEPT
245 rbegin()
const _GLIBCXX_NOEXCEPT
250 rend() _GLIBCXX_NOEXCEPT
255 rend()
const _GLIBCXX_NOEXCEPT
258#if __cplusplus >= 201103L
261 cbegin()
const noexcept
266 cend()
const noexcept
271 crbegin()
const noexcept
276 crend()
const noexcept
283 using _Base::max_size;
285#if __cplusplus >= 201103L
287 resize(size_type __sz)
289 this->_M_detach_singular();
294 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
297 for (; __victim != __end; ++__victim)
298 this->_M_invalidate_if(
_Equal(__victim));
306 this->_M_revalidate_singular();
307 __throw_exception_again;
312 resize(size_type __sz,
const _Tp& __c)
314 this->_M_detach_singular();
319 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
322 for (; __victim != __end; ++__victim)
323 this->_M_invalidate_if(
_Equal(__victim));
327 _Base::resize(__sz, __c);
331 this->_M_revalidate_singular();
332 __throw_exception_again;
337 resize(size_type __sz, _Tp __c = _Tp())
339 this->_M_detach_singular();
344 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
347 for (; __victim != __end; ++__victim)
348 this->_M_invalidate_if(
_Equal(__victim));
352 _Base::resize(__sz, __c);
356 this->_M_revalidate_singular();
357 __throw_exception_again;
365 front() _GLIBCXX_NOEXCEPT
367 __glibcxx_check_nonempty();
368 return _Base::front();
373 front()
const _GLIBCXX_NOEXCEPT
375 __glibcxx_check_nonempty();
376 return _Base::front();
381 back() _GLIBCXX_NOEXCEPT
383 __glibcxx_check_nonempty();
384 return _Base::back();
389 back()
const _GLIBCXX_NOEXCEPT
391 __glibcxx_check_nonempty();
392 return _Base::back();
396 using _Base::push_front;
398#if __cplusplus >= 201103L
399 using _Base::emplace_front;
403 pop_front() _GLIBCXX_NOEXCEPT
405 __glibcxx_check_nonempty();
406 this->_M_invalidate_if(
_Equal(_Base::begin()));
410 using _Base::push_back;
412#if __cplusplus >= 201103L
413 using _Base::emplace_back;
417 pop_back() _GLIBCXX_NOEXCEPT
419 __glibcxx_check_nonempty();
420 this->_M_invalidate_if(
_Equal(--_Base::end()));
424#if __cplusplus >= 201103L
425 template<
typename... _Args>
430 return { _Base::emplace(__position.
base(),
431 std::forward<_Args>(__args)...),
this };
436#if __cplusplus >= 201103L
439 insert(
iterator __position,
const _Tp& __x)
443 return iterator(_Base::insert(__position.
base(), __x),
this);
446#if __cplusplus >= 201103L
449 {
return emplace(__position,
std::move(__x)); }
455 return { _Base::insert(__p.
base(), __l),
this };
459#if __cplusplus >= 201103L
464 return { _Base::insert(__position.
base(), __n, __x),
this };
468 insert(
iterator __position, size_type __n,
const _Tp& __x)
471 _Base::insert(__position.
base(), __n, __x);
475#if __cplusplus >= 201103L
476 template<
class _InputIterator,
477 typename = std::_RequireInputIter<_InputIterator>>
480 _InputIterator __last)
484 if (__dist.
second >= __gnu_debug::__dp_sign)
487 _Base::insert(__position.
base(),
488 __gnu_debug::__unsafe(__first),
489 __gnu_debug::__unsafe(__last)),
493 return { _Base::insert(__position.
base(), __first, __last),
this };
496 template<
class _InputIterator>
498 insert(
iterator __position, _InputIterator __first,
499 _InputIterator __last)
504 if (__dist.
second >= __gnu_debug::__dp_sign)
505 _Base::insert(__position.
base(), __gnu_debug::__unsafe(__first),
506 __gnu_debug::__unsafe(__last));
508 _Base::insert(__position.
base(), __first, __last);
514#if __cplusplus >= 201103L
520 this->_M_invalidate_if(
_Equal(__position));
521 return _Base::erase(__position);
526#if __cplusplus >= 201103L
537#if __cplusplus >= 201103L
547 __victim != __last.base(); ++__victim)
549 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
550 _M_message(__gnu_debug::__msg_valid_range)
551 ._M_iterator(__first,
"position")
552 ._M_iterator(__last,
"last"));
553 this->_M_invalidate_if(
_Equal(__victim));
556 return iterator(_Base::erase(__first.base(), __last.base()),
this);
561 _GLIBCXX_NOEXCEPT_IF(
noexcept(declval<_Base&>().swap(__x)) )
568 clear() _GLIBCXX_NOEXCEPT
571 this->_M_invalidate_all();
576#if __cplusplus >= 201103L
583 _M_message(__gnu_debug::__msg_self_splice)
584 ._M_sequence(*
this,
"this"));
585 this->_M_transfer_from_if(__x,
_Not_equal(__x._M_base().end()));
586 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x));
589#if __cplusplus >= 201103L
596#if __cplusplus >= 201103L
608 _M_message(__gnu_debug::__msg_splice_bad)
609 ._M_iterator(__i,
"__i"));
611 _M_message(__gnu_debug::__msg_splice_other)
612 ._M_iterator(__i,
"__i")._M_sequence(__x,
"__x"));
616 this->_M_transfer_from_if(__x,
_Equal(__i.
base()));
617 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x),
621#if __cplusplus >= 201103L
624 { splice(__position,
std::move(__x), __i); }
628#if __cplusplus >= 201103L
637 __glibcxx_check_valid_range(__first, __last);
639 _M_message(__gnu_debug::__msg_splice_other)
640 ._M_sequence(__x,
"x")
641 ._M_iterator(__first,
"first"));
647 __tmp != __last.base(); ++__tmp)
649 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
650 _M_message(__gnu_debug::__msg_valid_range)
651 ._M_iterator(__first,
"first")
652 ._M_iterator(__last,
"last"));
654 || __tmp != __position.
base(),
655 _M_message(__gnu_debug::__msg_splice_overlap)
656 ._M_iterator(__tmp,
"position")
657 ._M_iterator(__first,
"first")
658 ._M_iterator(__last,
"last"));
662 this->_M_transfer_from_if(__x,
_Equal(__tmp));
665 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x),
666 __first.base(), __last.base());
669#if __cplusplus >= 201103L
673 { splice(__position,
std::move(__x), __first, __last); }
677#if __cplusplus > 201703L
678 typedef size_type __remove_return_type;
679# define _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG \
680 __attribute__((__abi_tag__("__cxx20")))
681# define _GLIBCXX20_ONLY(__expr) __expr
683 typedef void __remove_return_type;
684# define _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
685# define _GLIBCXX20_ONLY(__expr)
689 _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
691 remove(
const _Tp& __value)
693 if (!this->_M_iterators && !this->_M_const_iterators)
694 return _Base::remove(__value);
696#if !_GLIBCXX_USE_CXX11_ABI
697 size_type __removed __attribute__((__unused__)) = 0;
699 _Base __to_destroy(get_allocator());
702 while (__first != __last)
706 if (*__first == __value)
711 this->_M_invalidate_if(
_Equal(__first));
712 __to_destroy.splice(__to_destroy.begin(), *
this, __first);
713#if !_GLIBCXX_USE_CXX11_ABI
714 _GLIBCXX20_ONLY( __removed++ );
721#if !_GLIBCXX_USE_CXX11_ABI
722 return _GLIBCXX20_ONLY( __removed );
724 return _GLIBCXX20_ONLY( __to_destroy.size() );
728 template<
class _Predicate>
730 remove_if(_Predicate __pred)
732 if (!this->_M_iterators && !this->_M_const_iterators)
733 return _Base::remove_if(__pred);
735#if !_GLIBCXX_USE_CXX11_ABI
736 size_type __removed __attribute__((__unused__)) = 0;
738 _Base __to_destroy(get_allocator());
745 this->_M_invalidate_if(
_Equal(__x));
746 __to_destroy.splice(__to_destroy.begin(), *
this, __x);
747#if !_GLIBCXX_USE_CXX11_ABI
748 _GLIBCXX20_ONLY( __removed++ );
755#if !_GLIBCXX_USE_CXX11_ABI
756 return _GLIBCXX20_ONLY( __removed );
758 return _GLIBCXX20_ONLY( __to_destroy.size() );
762 _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
766 if (!this->_M_iterators && !this->_M_const_iterators)
767 return _Base::unique();
770 return _GLIBCXX20_ONLY(0);
772#if !_GLIBCXX_USE_CXX11_ABI
773 size_type __removed __attribute__((__unused__)) = 0;
775 _Base __to_destroy(get_allocator());
779 while (++__next != __last)
780 if (*__first == *__next)
782 this->_M_invalidate_if(
_Equal(__next));
783 __to_destroy.splice(__to_destroy.begin(), *
this, __next);
785#if !_GLIBCXX_USE_CXX11_ABI
786 _GLIBCXX20_ONLY( __removed++ );
792#if !_GLIBCXX_USE_CXX11_ABI
793 return _GLIBCXX20_ONLY( __removed );
795 return _GLIBCXX20_ONLY( __to_destroy.size() );
799 template<
class _BinaryPredicate>
801 unique(_BinaryPredicate __binary_pred)
803 if (!this->_M_iterators && !this->_M_const_iterators)
804 return _Base::unique(__binary_pred);
807 return _GLIBCXX20_ONLY(0);
810#if !_GLIBCXX_USE_CXX11_ABI
811 size_type __removed __attribute__((__unused__)) = 0;
813 _Base __to_destroy(get_allocator());
817 while (++__next != __last)
818 if (__binary_pred(*__first, *__next))
820 this->_M_invalidate_if(
_Equal(__next));
821 __to_destroy.splice(__to_destroy.begin(), *
this, __next);
823#if !_GLIBCXX_USE_CXX11_ABI
824 _GLIBCXX20_ONLY( __removed++ );
830#if !_GLIBCXX_USE_CXX11_ABI
831 return _GLIBCXX20_ONLY( __removed );
833 return _GLIBCXX20_ONLY( __to_destroy.size() );
837#undef _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
838#undef _GLIBCXX20_ONLY
841#if __cplusplus >= 201103L
851 __glibcxx_check_sorted(_Base::begin(), _Base::end());
852 __glibcxx_check_sorted(__x.begin().
base(), __x.end().
base());
853 this->_M_transfer_from_if(__x,
_Not_equal(__x._M_base().end()));
854 _Base::merge(_GLIBCXX_MOVE(__x));
858#if __cplusplus >= 201103L
864 template<
class _Compare>
866#if __cplusplus >= 201103L
867 merge(
list&& __x, _Compare __comp)
869 merge(
list& __x, _Compare __comp)
880 this->_M_transfer_from_if(__x,
_Not_equal(__x._M_base().end()));
881 _Base::merge(_GLIBCXX_MOVE(__x), __comp);
885#if __cplusplus >= 201103L
886 template<
typename _Compare>
888 merge(
list& __x, _Compare __comp)
893 sort() { _Base::sort(); }
895 template<
typename _StrictWeakOrdering>
897 sort(_StrictWeakOrdering __pred) { _Base::sort(__pred); }
899 using _Base::reverse;
902 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
905 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
908#if __cpp_deduction_guides >= 201606
909 template<
typename _InputIterator,
typename _ValT
912 typename = _RequireInputIter<_InputIterator>,
913 typename = _RequireAllocator<_Allocator>>
914 list(_InputIterator, _InputIterator, _Allocator = _Allocator())
917 template<
typename _Tp,
typename _Allocator = allocator<_Tp>,
918 typename = _RequireAllocator<_Allocator>>
919 list(
size_t, _Tp, _Allocator = _Allocator())
923 template<
typename _Tp,
typename _Alloc>
927 {
return __lhs._M_base() == __rhs._M_base(); }
929#if __cpp_lib_three_way_comparison
930 template<
typename _Tp,
typename _Alloc>
931 constexpr __detail::__synth3way_t<_Tp>
933 {
return __x._M_base() <=> __y._M_base(); }
935 template<
typename _Tp,
typename _Alloc>
937 operator!=(
const list<_Tp, _Alloc>& __lhs,
938 const list<_Tp, _Alloc>& __rhs)
939 {
return __lhs._M_base() != __rhs._M_base(); }
941 template<
typename _Tp,
typename _Alloc>
943 operator<(
const list<_Tp, _Alloc>& __lhs,
944 const list<_Tp, _Alloc>& __rhs)
945 {
return __lhs._M_base() < __rhs._M_base(); }
947 template<
typename _Tp,
typename _Alloc>
950 const list<_Tp, _Alloc>& __rhs)
951 {
return __lhs._M_base() <= __rhs._M_base(); }
953 template<
typename _Tp,
typename _Alloc>
956 const list<_Tp, _Alloc>& __rhs)
957 {
return __lhs._M_base() >= __rhs._M_base(); }
959 template<
typename _Tp,
typename _Alloc>
961 operator>(
const list<_Tp, _Alloc>& __lhs,
962 const list<_Tp, _Alloc>& __rhs)
963 {
return __lhs._M_base() > __rhs._M_base(); }
966 template<
typename _Tp,
typename _Alloc>
968 swap(list<_Tp, _Alloc>& __lhs, list<_Tp, _Alloc>& __rhs)
969 _GLIBCXX_NOEXCEPT_IF(
noexcept(__lhs.swap(__rhs)))
970 { __lhs.swap(__rhs); }
977#ifndef _GLIBCXX_USE_CXX11_ABI
979 template<
typename _Tp,
typename _Alloc>
980 struct _Sequence_traits<
std::__debug::list<_Tp, _Alloc> >
984 static typename _Distance_traits<_It>::__type
988 ? std::make_pair(0, __dp_exact) :
std::make_pair(1, __dp_sign);
993#ifndef _GLIBCXX_DEBUG_PEDANTIC
994 template<
class _Tp,
class _Alloc>
995 struct _Insert_range_from_self_is_safe<
std::__debug::list<_Tp, _Alloc> >
996 {
enum { __value = 1 }; };
#define __glibcxx_check_insert(_Position)
#define __glibcxx_check_sorted_pred(_First, _Last, _Pred)
#define __glibcxx_check_erase_range(_First, _Last)
#define __glibcxx_check_erase(_Position)
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
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.
ISO C++ entities toplevel namespace is std.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
GNU debug classes for public use.
constexpr _Iterator __base(_Iterator __it)
The standard allocator, as per C++03 [20.4.1].
constexpr _Iterator & base() noexcept
Return the underlying iterator.
bool _M_dereferenceable() const
Is the iterator dereferenceable?
Traits class for iterators.
Struct holding two objects of arbitrary type.
_T2 second
The second member.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
bool _M_attached_to(const _Safe_sequence_base *__seq) const
Safe class dealing with some allocator dependent operations.
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
Class std::list with safety/checking/debug instrumentation.