29 #ifndef _GLIBCXX_DEBUG_LIST
30 #define _GLIBCXX_DEBUG_LIST 1
36 namespace std _GLIBCXX_VISIBILITY(default)
41 template<
typename _Tp,
typename _Allocator = std::allocator<_Tp> >
43 :
public _GLIBCXX_STD_C::list<_Tp, _Allocator>,
46 typedef _GLIBCXX_STD_C::list<_Tp, _Allocator>
_Base;
53 typedef typename _Base::reference reference;
54 typedef typename _Base::const_reference const_reference;
61 typedef typename _Base::size_type size_type;
62 typedef typename _Base::difference_type difference_type;
64 typedef _Tp value_type;
65 typedef _Allocator allocator_type;
66 typedef typename _Base::pointer pointer;
67 typedef typename _Base::const_pointer const_pointer;
73 list() _GLIBCXX_NOEXCEPT
77 list(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
80 #if __cplusplus >= 201103L
85 list(size_type __n,
const _Tp& __value,
86 const _Allocator& __a = _Allocator())
87 :
_Base(__n, __value, __a) { }
90 list(size_type __n,
const _Tp& __value = _Tp(),
91 const _Allocator& __a = _Allocator())
92 :
_Base(__n, __value, __a) { }
95 #if __cplusplus >= 201103L
96 template<
class _InputIterator,
97 typename = std::_RequireInputIter<_InputIterator>>
99 template<
class _InputIterator>
101 list(_InputIterator __first, _InputIterator __last,
102 const _Allocator& __a = _Allocator())
108 list(
const list& __x)
111 list(
const _Base& __x)
114 #if __cplusplus >= 201103L
115 list(list&& __x) noexcept
116 :
_Base(std::move(__x))
120 const allocator_type& __a = allocator_type())
121 :
_Base(__l, __a) { }
124 ~list() _GLIBCXX_NOEXCEPT { }
127 operator=(
const list& __x)
129 static_cast<_Base&
>(*this) = __x;
130 this->_M_invalidate_all();
134 #if __cplusplus >= 201103L
136 operator=(list&& __x)
140 __glibcxx_check_self_move_assign(__x);
149 static_cast<_Base&
>(*this) = __l;
150 this->_M_invalidate_all();
158 this->_M_invalidate_all();
162 #if __cplusplus >= 201103L
163 template<
class _InputIterator,
164 typename = std::_RequireInputIter<_InputIterator>>
166 template<
class _InputIterator>
169 assign(_InputIterator __first, _InputIterator __last)
171 __glibcxx_check_valid_range(__first, __last);
174 this->_M_invalidate_all();
178 assign(size_type __n,
const _Tp& __t)
180 _Base::assign(__n, __t);
181 this->_M_invalidate_all();
184 using _Base::get_allocator;
188 begin() _GLIBCXX_NOEXCEPT
189 {
return iterator(_Base::begin(),
this); }
192 begin()
const _GLIBCXX_NOEXCEPT
196 end() _GLIBCXX_NOEXCEPT
197 {
return iterator(_Base::end(),
this); }
200 end()
const _GLIBCXX_NOEXCEPT
204 rbegin() _GLIBCXX_NOEXCEPT
208 rbegin()
const _GLIBCXX_NOEXCEPT
212 rend() _GLIBCXX_NOEXCEPT
216 rend()
const _GLIBCXX_NOEXCEPT
219 #if __cplusplus >= 201103L
221 cbegin()
const noexcept
225 cend()
const noexcept
229 crbegin()
const noexcept
233 crend()
const noexcept
240 using _Base::max_size;
242 #if __cplusplus >= 201103L
244 resize(size_type __sz)
251 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
254 for (; __victim != __end; ++__victim)
266 __throw_exception_again;
271 resize(size_type __sz,
const _Tp& __c)
278 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
281 for (; __victim != __end; ++__victim)
288 _Base::resize(__sz, __c);
293 __throw_exception_again;
298 resize(size_type __sz, _Tp __c = _Tp())
305 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
308 for (; __victim != __end; ++__victim)
315 _Base::resize(__sz, __c);
320 __throw_exception_again;
327 front() _GLIBCXX_NOEXCEPT
329 __glibcxx_check_nonempty();
330 return _Base::front();
334 front()
const _GLIBCXX_NOEXCEPT
336 __glibcxx_check_nonempty();
337 return _Base::front();
341 back() _GLIBCXX_NOEXCEPT
343 __glibcxx_check_nonempty();
344 return _Base::back();
348 back()
const _GLIBCXX_NOEXCEPT
350 __glibcxx_check_nonempty();
351 return _Base::back();
355 using _Base::push_front;
357 #if __cplusplus >= 201103L
358 using _Base::emplace_front;
362 pop_front() _GLIBCXX_NOEXCEPT
364 __glibcxx_check_nonempty();
369 using _Base::push_back;
371 #if __cplusplus >= 201103L
372 using _Base::emplace_back;
376 pop_back() _GLIBCXX_NOEXCEPT
378 __glibcxx_check_nonempty();
383 #if __cplusplus >= 201103L
384 template<
typename... _Args>
390 std::forward<_Args>(__args)...),
this);
395 #if __cplusplus >= 201103L
398 insert(
iterator __position,
const _Tp& __x)
402 return iterator(_Base::insert(__position.
base(), __x),
this);
405 #if __cplusplus >= 201103L
408 {
return emplace(__position, std::move(__x)); }
418 #if __cplusplus >= 201103L
423 return iterator(_Base::insert(__position.
base(), __n, __x),
this);
427 insert(
iterator __position, size_type __n,
const _Tp& __x)
430 _Base::insert(__position.
base(), __n, __x);
434 #if __cplusplus >= 201103L
435 template<
class _InputIterator,
436 typename = std::_RequireInputIter<_InputIterator>>
439 _InputIterator __last)
448 template<
class _InputIterator>
450 insert(
iterator __position, _InputIterator __first,
451 _InputIterator __last)
461 #if __cplusplus >= 201103L
468 return _Base::erase(__position);
473 #if __cplusplus >= 201103L
484 #if __cplusplus >= 201103L
494 __victim != __last.
base(); ++__victim)
496 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
497 _M_message(__gnu_debug::__msg_valid_range)
498 ._M_iterator(__first,
"position")
499 ._M_iterator(__last,
"last"));
513 clear() _GLIBCXX_NOEXCEPT
516 this->_M_invalidate_all();
521 #if __cplusplus >= 201103L
524 splice(
iterator __position, list& __x)
527 _GLIBCXX_DEBUG_VERIFY(&__x !=
this,
528 _M_message(__gnu_debug::__msg_self_splice)
529 ._M_sequence(*
this,
"this"));
531 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()));
534 #if __cplusplus >= 201103L
537 { splice(__position, std::move(__x)); }
541 #if __cplusplus >= 201103L
553 _M_message(__gnu_debug::__msg_splice_bad)
554 ._M_iterator(__i,
"__i"));
556 _M_message(__gnu_debug::__msg_splice_other)
557 ._M_iterator(__i,
"__i")._M_sequence(__x,
"__x"));
562 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()),
566 #if __cplusplus >= 201103L
569 { splice(__position, std::move(__x), __i); }
573 #if __cplusplus >= 201103L
582 __glibcxx_check_valid_range(__first, __last);
584 _M_message(__gnu_debug::__msg_splice_other)
585 ._M_sequence(__x,
"x")
586 ._M_iterator(__first,
"first"));
592 __tmp != __last.
base(); ++__tmp)
594 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
595 _M_message(__gnu_debug::__msg_valid_range)
596 ._M_iterator(__first,
"first")
597 ._M_iterator(__last,
"last"));
598 _GLIBCXX_DEBUG_VERIFY(&__x !=
this || __tmp != __position.
base(),
599 _M_message(__gnu_debug::__msg_splice_overlap)
600 ._M_iterator(__tmp,
"position")
601 ._M_iterator(__first,
"first")
602 ._M_iterator(__last,
"last"));
608 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()),
612 #if __cplusplus >= 201103L
616 { splice(__position, std::move(__x), __first, __last); }
620 remove(
const _Tp& __value)
631 template<
class _Predicate>
633 remove_if(_Predicate __pred)
649 if (__first == __last)
652 while (__next != __last)
654 if (*__first == *__next)
655 __next = _M_erase(__next);
661 template<
class _BinaryPredicate>
663 unique(_BinaryPredicate __binary_pred)
667 if (__first == __last)
670 while (__next != __last)
672 if (__binary_pred(*__first, *__next))
673 __next = _M_erase(__next);
680 #if __cplusplus >= 201103L
690 __glibcxx_check_sorted(_Base::begin(), _Base::end());
691 __glibcxx_check_sorted(__x.begin().
base(), __x.end().
base());
693 _Base::merge(_GLIBCXX_MOVE(__x._M_base()));
697 #if __cplusplus >= 201103L
700 { merge(std::move(__x)); }
703 template<
class _Compare>
705 #if __cplusplus >= 201103L
706 merge(list&& __x, _Compare __comp)
708 merge(list& __x, _Compare __comp)
720 _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp);
724 #if __cplusplus >= 201103L
725 template<
typename _Compare>
727 merge(list& __x, _Compare __comp)
728 { merge(std::move(__x), __comp); }
732 sort() { _Base::sort(); }
734 template<
typename _StrictWeakOrdering>
736 sort(_StrictWeakOrdering __pred) { _Base::sort(__pred); }
738 using _Base::reverse;
741 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
744 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
754 template<
typename _Tp,
typename _Alloc>
758 {
return __lhs._M_base() == __rhs._M_base(); }
760 template<
typename _Tp,
typename _Alloc>
764 {
return __lhs._M_base() != __rhs._M_base(); }
766 template<
typename _Tp,
typename _Alloc>
768 operator<(const list<_Tp, _Alloc>& __lhs,
769 const list<_Tp, _Alloc>& __rhs)
770 {
return __lhs._M_base() < __rhs._M_base(); }
772 template<
typename _Tp,
typename _Alloc>
774 operator<=(const list<_Tp, _Alloc>& __lhs,
775 const list<_Tp, _Alloc>& __rhs)
776 {
return __lhs._M_base() <= __rhs._M_base(); }
778 template<
typename _Tp,
typename _Alloc>
780 operator>=(
const list<_Tp, _Alloc>& __lhs,
781 const list<_Tp, _Alloc>& __rhs)
782 {
return __lhs._M_base() >= __rhs._M_base(); }
784 template<
typename _Tp,
typename _Alloc>
786 operator>(
const list<_Tp, _Alloc>& __lhs,
787 const list<_Tp, _Alloc>& __rhs)
788 {
return __lhs._M_base() > __rhs._M_base(); }
790 template<
typename _Tp,
typename _Alloc>
792 swap(list<_Tp, _Alloc>& __lhs, list<_Tp, _Alloc>& __rhs)
793 { __lhs.swap(__rhs); }
798 #ifndef _GLIBCXX_DEBUG_PEDANTIC
799 namespace __gnu_debug
801 template<
class _Tp,
class _Alloc>
802 struct _Insert_range_from_self_is_safe<std::__debug::list<_Tp, _Alloc> >
803 {
enum { __value = 1 }; };
void _M_revalidate_singular()
#define __glibcxx_check_insert_range(_Position, _First, _Last)
void _M_swap(_Safe_sequence_base &__x)
void _M_invalidate_if(_Predicate __pred)
#define __glibcxx_check_insert(_Position)
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
void _M_detach_singular()
constexpr size_t size() const noexcept
Returns the total number of bits.
Class std::list with safety/checking/debug instrumentation.
void _M_transfer_from_if(_Safe_sequence &__from, _Predicate __pred)
bool _M_attached_to(const _Safe_sequence_base *__seq) const
_Iterator base() const noexcept
Return the underlying iterator.
#define __glibcxx_check_erase(_Position)
#define __glibcxx_check_sorted_pred(_First, _Last, _Pred)
bool _M_dereferenceable() const
Is the iterator dereferenceable?
Base class for constructing a safe sequence type that tracks iterators that reference it...
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
#define __glibcxx_check_erase_range(_First, _Last)