29 #ifndef _GLIBCXX_DEBUG_LIST
30 #define _GLIBCXX_DEBUG_LIST 1
32 #pragma GCC system_header
35 namespace std _GLIBCXX_VISIBILITY(default) {
namespace __debug {
36 template<
typename _Tp,
typename _Allocator>
class list;
44 namespace 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 allocator_type& __a)
119 :
_Base(__x, __a) { }
121 list(
list&& __x,
const allocator_type& __a)
126 list(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
129 #if __cplusplus >= 201103L
131 list(size_type __n,
const allocator_type& __a = allocator_type())
132 :
_Base(__n, __a) { }
134 list(size_type __n,
const _Tp& __value,
135 const _Allocator& __a = _Allocator())
136 :
_Base(__n, __value, __a) { }
139 list(size_type __n,
const _Tp& __value = _Tp(),
140 const _Allocator& __a = _Allocator())
141 :
_Base(__n, __value, __a) { }
144 #if __cplusplus >= 201103L
145 template<
class _InputIterator,
146 typename = std::_RequireInputIter<_InputIterator>>
148 template<
class _InputIterator>
150 list(_InputIterator __first, _InputIterator __last,
151 const _Allocator& __a = _Allocator())
153 __glibcxx_check_valid_constructor_range(__first, __last)),
158 :
_Base(__x._M_ref) { }
160 #if __cplusplus < 201103L
162 operator=(
const list& __x)
164 this->_M_safe() = __x;
170 operator=(
const list&) =
default;
173 operator=(
list&&) =
default;
178 this->_M_invalidate_all();
187 this->_M_invalidate_all();
191 #if __cplusplus >= 201103L
192 template<
class _InputIterator,
193 typename = std::_RequireInputIter<_InputIterator>>
195 template<
class _InputIterator>
198 assign(_InputIterator __first, _InputIterator __last)
201 __glibcxx_check_valid_range2(__first, __last, __dist);
203 if (__dist.
second >= __gnu_debug::__dp_sign)
204 _Base::assign(__gnu_debug::__unsafe(__first),
205 __gnu_debug::__unsafe(__last));
207 _Base::assign(__first, __last);
209 this->_M_invalidate_all();
213 assign(size_type __n,
const _Tp& __t)
215 _Base::assign(__n, __t);
216 this->_M_invalidate_all();
219 using _Base::get_allocator;
223 begin() _GLIBCXX_NOEXCEPT
224 {
return iterator(_Base::begin(),
this); }
227 begin()
const _GLIBCXX_NOEXCEPT
231 end() _GLIBCXX_NOEXCEPT
232 {
return iterator(_Base::end(),
this); }
235 end()
const _GLIBCXX_NOEXCEPT
239 rbegin() _GLIBCXX_NOEXCEPT
243 rbegin()
const _GLIBCXX_NOEXCEPT
247 rend() _GLIBCXX_NOEXCEPT
251 rend()
const _GLIBCXX_NOEXCEPT
254 #if __cplusplus >= 201103L
256 cbegin()
const noexcept
260 cend()
const noexcept
264 crbegin()
const noexcept
268 crend()
const noexcept
275 using _Base::max_size;
277 #if __cplusplus >= 201103L
279 resize(size_type __sz)
284 _Base_iterator __victim = _Base::begin();
286 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
289 for (; __victim != __end; ++__victim)
299 __throw_exception_again;
304 resize(size_type __sz,
const _Tp& __c)
309 _Base_iterator __victim = _Base::begin();
311 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
314 for (; __victim != __end; ++__victim)
319 _Base::resize(__sz, __c);
324 __throw_exception_again;
329 resize(size_type __sz, _Tp __c = _Tp())
334 _Base_iterator __victim = _Base::begin();
336 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
339 for (; __victim != __end; ++__victim)
344 _Base::resize(__sz, __c);
349 __throw_exception_again;
356 front() _GLIBCXX_NOEXCEPT
358 __glibcxx_check_nonempty();
359 return _Base::front();
363 front()
const _GLIBCXX_NOEXCEPT
365 __glibcxx_check_nonempty();
366 return _Base::front();
370 back() _GLIBCXX_NOEXCEPT
372 __glibcxx_check_nonempty();
373 return _Base::back();
377 back()
const _GLIBCXX_NOEXCEPT
379 __glibcxx_check_nonempty();
380 return _Base::back();
384 using _Base::push_front;
386 #if __cplusplus >= 201103L
387 using _Base::emplace_front;
391 pop_front() _GLIBCXX_NOEXCEPT
393 __glibcxx_check_nonempty();
398 using _Base::push_back;
400 #if __cplusplus >= 201103L
401 using _Base::emplace_back;
405 pop_back() _GLIBCXX_NOEXCEPT
407 __glibcxx_check_nonempty();
412 #if __cplusplus >= 201103L
413 template<
typename... _Args>
418 return { _Base::emplace(__position.
base(),
419 std::forward<_Args>(__args)...),
this };
424 #if __cplusplus >= 201103L
427 insert(
iterator __position,
const _Tp& __x)
431 return iterator(_Base::insert(__position.
base(), __x),
this);
434 #if __cplusplus >= 201103L
437 {
return emplace(__position,
std::move(__x)); }
443 return { _Base::insert(__p.
base(), __l),
this };
447 #if __cplusplus >= 201103L
452 return { _Base::insert(__position.
base(), __n, __x),
this };
456 insert(
iterator __position, size_type __n,
const _Tp& __x)
459 _Base::insert(__position.
base(), __n, __x);
463 #if __cplusplus >= 201103L
464 template<
class _InputIterator,
465 typename = std::_RequireInputIter<_InputIterator>>
468 _InputIterator __last)
472 if (__dist.
second >= __gnu_debug::__dp_sign)
475 _Base::insert(__position.
base(),
476 __gnu_debug::__unsafe(__first),
477 __gnu_debug::__unsafe(__last)),
481 return { _Base::insert(__position.
base(), __first, __last),
this };
484 template<
class _InputIterator>
486 insert(
iterator __position, _InputIterator __first,
487 _InputIterator __last)
492 if (__dist.
second >= __gnu_debug::__dp_sign)
493 _Base::insert(__position.
base(), __gnu_debug::__unsafe(__first),
494 __gnu_debug::__unsafe(__last));
496 _Base::insert(__position.
base(), __first, __last);
502 #if __cplusplus >= 201103L
509 return _Base::erase(__position);
514 #if __cplusplus >= 201103L
525 #if __cplusplus >= 201103L
535 __victim != __last.base(); ++__victim)
537 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
538 _M_message(__gnu_debug::__msg_valid_range)
539 ._M_iterator(__first,
"position")
540 ._M_iterator(__last,
"last"));
544 return iterator(_Base::erase(__first.base(), __last.base()),
this);
549 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
556 clear() _GLIBCXX_NOEXCEPT
559 this->_M_invalidate_all();
564 #if __cplusplus >= 201103L
571 _M_message(__gnu_debug::__msg_self_splice)
572 ._M_sequence(*
this,
"this"));
574 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()));
577 #if __cplusplus >= 201103L
584 #if __cplusplus >= 201103L
596 _M_message(__gnu_debug::__msg_splice_bad)
597 ._M_iterator(__i,
"__i"));
599 _M_message(__gnu_debug::__msg_splice_other)
600 ._M_iterator(__i,
"__i")._M_sequence(__x,
"__x"));
605 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()),
609 #if __cplusplus >= 201103L
612 { splice(__position,
std::move(__x), __i); }
616 #if __cplusplus >= 201103L
625 __glibcxx_check_valid_range(__first, __last);
627 _M_message(__gnu_debug::__msg_splice_other)
628 ._M_sequence(__x,
"x")
629 ._M_iterator(__first,
"first"));
635 __tmp != __last.base(); ++__tmp)
637 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
638 _M_message(__gnu_debug::__msg_valid_range)
639 ._M_iterator(__first,
"first")
640 ._M_iterator(__last,
"last"));
642 || __tmp != __position.
base(),
643 _M_message(__gnu_debug::__msg_splice_overlap)
644 ._M_iterator(__tmp,
"position")
645 ._M_iterator(__first,
"first")
646 ._M_iterator(__last,
"last"));
653 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()),
654 __first.base(), __last.base());
657 #if __cplusplus >= 201103L
661 { splice(__position,
std::move(__x), __first, __last); }
665 #if __cplusplus > 201703L
666 typedef size_type __remove_return_type;
667 # define _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG \
668 __attribute__((__abi_tag__("__cxx20")))
669 # define _GLIBCXX20_ONLY(__expr) __expr
671 typedef void __remove_return_type;
672 # define _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
673 # define _GLIBCXX20_ONLY(__expr)
677 _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
679 remove(
const _Tp& __value)
682 return _Base::remove(__value);
684 #if !_GLIBCXX_USE_CXX11_ABI
685 size_type __removed __attribute__((__unused__)) = 0;
687 _Base __to_destroy(get_allocator());
690 while (__first != __last)
694 if (*__first == __value)
700 __to_destroy.splice(__to_destroy.begin(), _M_base(), __first);
701 #if !_GLIBCXX_USE_CXX11_ABI
702 _GLIBCXX20_ONLY( __removed++ );
709 #if !_GLIBCXX_USE_CXX11_ABI
710 return _GLIBCXX20_ONLY( __removed );
712 return _GLIBCXX20_ONLY( __to_destroy.size() );
716 template<
class _Predicate>
718 remove_if(_Predicate __pred)
721 return _Base::remove_if(__pred);
723 #if !_GLIBCXX_USE_CXX11_ABI
724 size_type __removed __attribute__((__unused__)) = 0;
726 _Base __to_destroy(get_allocator());
734 __to_destroy.splice(__to_destroy.begin(), _M_base(), __x);
735 #if !_GLIBCXX_USE_CXX11_ABI
736 _GLIBCXX20_ONLY( __removed++ );
743 #if !_GLIBCXX_USE_CXX11_ABI
744 return _GLIBCXX20_ONLY( __removed );
746 return _GLIBCXX20_ONLY( __to_destroy.size() );
750 _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
755 return _Base::unique();
758 return _GLIBCXX20_ONLY(0);
760 #if !_GLIBCXX_USE_CXX11_ABI
761 size_type __removed __attribute__((__unused__)) = 0;
763 _Base __to_destroy(get_allocator());
767 while (++__next != __last)
768 if (*__first == *__next)
771 __to_destroy.splice(__to_destroy.begin(), _M_base(), __next);
773 #if !_GLIBCXX_USE_CXX11_ABI
774 _GLIBCXX20_ONLY( __removed++ );
780 #if !_GLIBCXX_USE_CXX11_ABI
781 return _GLIBCXX20_ONLY( __removed );
783 return _GLIBCXX20_ONLY( __to_destroy.size() );
787 template<
class _BinaryPredicate>
789 unique(_BinaryPredicate __binary_pred)
792 return _Base::unique(__binary_pred);
795 return _GLIBCXX20_ONLY(0);
798 #if !_GLIBCXX_USE_CXX11_ABI
799 size_type __removed __attribute__((__unused__)) = 0;
801 _Base __to_destroy(get_allocator());
805 while (++__next != __last)
806 if (__binary_pred(*__first, *__next))
809 __to_destroy.splice(__to_destroy.begin(), _M_base(), __next);
811 #if !_GLIBCXX_USE_CXX11_ABI
812 _GLIBCXX20_ONLY( __removed++ );
818 #if !_GLIBCXX_USE_CXX11_ABI
819 return _GLIBCXX20_ONLY( __removed );
821 return _GLIBCXX20_ONLY( __to_destroy.size() );
825 #undef _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
826 #undef _GLIBCXX20_ONLY
829 #if __cplusplus >= 201103L
839 __glibcxx_check_sorted(_Base::begin(), _Base::end());
840 __glibcxx_check_sorted(__x.begin().
base(), __x.end().
base());
842 _Base::merge(_GLIBCXX_MOVE(__x._M_base()));
846 #if __cplusplus >= 201103L
852 template<
class _Compare>
854 #if __cplusplus >= 201103L
855 merge(
list&& __x, _Compare __comp)
857 merge(
list& __x, _Compare __comp)
869 _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp);
873 #if __cplusplus >= 201103L
874 template<
typename _Compare>
876 merge(
list& __x, _Compare __comp)
881 sort() { _Base::sort(); }
883 template<
typename _StrictWeakOrdering>
885 sort(_StrictWeakOrdering __pred) { _Base::sort(__pred); }
887 using _Base::reverse;
890 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
893 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
896 #if __cpp_deduction_guides >= 201606
897 template<
typename _InputIterator,
typename _ValT
900 typename = _RequireInputIter<_InputIterator>,
901 typename = _RequireAllocator<_Allocator>>
902 list(_InputIterator, _InputIterator, _Allocator = _Allocator())
906 template<
typename _Tp,
typename _Alloc>
910 {
return __lhs._M_base() == __rhs._M_base(); }
912 #if __cpp_lib_three_way_comparison
913 template<
typename _Tp,
typename _Alloc>
914 constexpr __detail::__synth3way_t<_Tp>
916 {
return __x._M_base() <=> __y._M_base(); }
918 template<
typename _Tp,
typename _Alloc>
920 operator!=(
const list<_Tp, _Alloc>& __lhs,
921 const list<_Tp, _Alloc>& __rhs)
922 {
return __lhs._M_base() != __rhs._M_base(); }
924 template<
typename _Tp,
typename _Alloc>
926 operator<(
const list<_Tp, _Alloc>& __lhs,
927 const list<_Tp, _Alloc>& __rhs)
928 {
return __lhs._M_base() < __rhs._M_base(); }
930 template<
typename _Tp,
typename _Alloc>
932 operator<=(
const list<_Tp, _Alloc>& __lhs,
933 const list<_Tp, _Alloc>& __rhs)
934 {
return __lhs._M_base() <= __rhs._M_base(); }
936 template<
typename _Tp,
typename _Alloc>
938 operator>=(
const list<_Tp, _Alloc>& __lhs,
939 const list<_Tp, _Alloc>& __rhs)
940 {
return __lhs._M_base() >= __rhs._M_base(); }
942 template<
typename _Tp,
typename _Alloc>
944 operator>(
const list<_Tp, _Alloc>& __lhs,
945 const list<_Tp, _Alloc>& __rhs)
946 {
return __lhs._M_base() > __rhs._M_base(); }
949 template<
typename _Tp,
typename _Alloc>
951 swap(list<_Tp, _Alloc>& __lhs, list<_Tp, _Alloc>& __rhs)
952 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
953 { __lhs.swap(__rhs); }
960 #ifndef _GLIBCXX_USE_CXX11_ABI
962 template<
typename _Tp,
typename _Alloc>
963 struct _Sequence_traits<
std::__debug::list<_Tp, _Alloc> >
967 static typename _Distance_traits<_It>::__type
971 ? std::make_pair(0, __dp_exact) :
std::make_pair(1, __dp_sign);
976 #ifndef _GLIBCXX_DEBUG_PEDANTIC
977 template<
class _Tp,
class _Alloc>
978 struct _Insert_range_from_self_is_safe<
std::__debug::list<_Tp, _Alloc> >
979 {
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 _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
_T2 second
The second member.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
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.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
GNU debug classes for public use.
constexpr _Iterator __base(_Iterator __it)
The standard allocator, as per [20.4].
Traits class for iterators.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
Struct holding two objects of arbitrary type.
bool _M_dereferenceable() const
Is the iterator dereferenceable?
_Iterator & base() noexcept
Return the underlying iterator.
void _M_invalidate_if(_Predicate __pred)
void _M_transfer_from_if(_Safe_sequence &__from, _Predicate __pred)
bool _M_attached_to(const _Safe_sequence_base *__seq) const
_Safe_iterator_base * _M_const_iterators
The list of constant iterators that reference this container.
void _M_revalidate_singular()
_Safe_iterator_base * _M_iterators
The list of mutable iterators that reference this container.
void _M_detach_singular()
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.