29 #ifndef _GLIBCXX_DEBUG_LIST
30 #define _GLIBCXX_DEBUG_LIST 1
32 #pragma GCC system_header
39 namespace std _GLIBCXX_VISIBILITY(default)
44 template<
typename _Tp,
typename _Allocator = std::allocator<_Tp> >
47 list<_Tp, _Allocator>, _Allocator,
48 __gnu_debug::_Safe_node_sequence>,
49 public _GLIBCXX_STD_C::list<_Tp, _Allocator>
51 typedef _GLIBCXX_STD_C::list<_Tp, _Allocator>
_Base;
61 typedef typename _Base::reference reference;
62 typedef typename _Base::const_reference const_reference;
69 typedef typename _Base::size_type size_type;
70 typedef typename _Base::difference_type difference_type;
72 typedef _Tp value_type;
73 typedef _Allocator allocator_type;
74 typedef typename _Base::pointer pointer;
75 typedef typename _Base::const_pointer const_pointer;
81 #if __cplusplus < 201103L
95 const allocator_type& __a = allocator_type())
100 list(
const list& __x,
const allocator_type& __a)
101 :
_Base(__x, __a) { }
103 list(
list&& __x,
const allocator_type& __a)
104 :
_Base(std::move(__x), __a) { }
108 list(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
111 #if __cplusplus >= 201103L
113 list(size_type __n,
const allocator_type& __a = allocator_type())
114 :
_Base(__n, __a) { }
116 list(size_type __n,
const _Tp& __value,
117 const _Allocator& __a = _Allocator())
118 :
_Base(__n, __value, __a) { }
121 list(size_type __n,
const _Tp& __value = _Tp(),
122 const _Allocator& __a = _Allocator())
123 :
_Base(__n, __value, __a) { }
126 #if __cplusplus >= 201103L
127 template<
class _InputIterator,
128 typename = std::_RequireInputIter<_InputIterator>>
130 template<
class _InputIterator>
132 list(_InputIterator __first, _InputIterator __last,
133 const _Allocator& __a = _Allocator())
134 :
_Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
136 __gnu_debug::__base(__last), __a)
139 list(
const _Base& __x)
142 #if __cplusplus < 201103L
144 operator=(
const list& __x)
146 this->_M_safe() = __x;
152 operator=(
const list&) =
default;
155 operator=(list&&) =
default;
160 this->_M_invalidate_all();
169 this->_M_invalidate_all();
173 #if __cplusplus >= 201103L
174 template<
class _InputIterator,
175 typename = std::_RequireInputIter<_InputIterator>>
177 template<
class _InputIterator>
180 assign(_InputIterator __first, _InputIterator __last)
183 __glibcxx_check_valid_range2(__first, __last, __dist);
185 if (__dist.
second >= __gnu_debug::__dp_sign)
186 _Base::assign(__gnu_debug::__unsafe(__first),
187 __gnu_debug::__unsafe(__last));
189 _Base::assign(__first, __last);
191 this->_M_invalidate_all();
195 assign(size_type __n,
const _Tp& __t)
197 _Base::assign(__n, __t);
198 this->_M_invalidate_all();
201 using _Base::get_allocator;
205 begin() _GLIBCXX_NOEXCEPT
206 {
return iterator(_Base::begin(),
this); }
209 begin()
const _GLIBCXX_NOEXCEPT
213 end() _GLIBCXX_NOEXCEPT
214 {
return iterator(_Base::end(),
this); }
217 end()
const _GLIBCXX_NOEXCEPT
221 rbegin() _GLIBCXX_NOEXCEPT
225 rbegin()
const _GLIBCXX_NOEXCEPT
229 rend() _GLIBCXX_NOEXCEPT
233 rend()
const _GLIBCXX_NOEXCEPT
236 #if __cplusplus >= 201103L
238 cbegin()
const noexcept
242 cend()
const noexcept
246 crbegin()
const noexcept
250 crend()
const noexcept
257 using _Base::max_size;
259 #if __cplusplus >= 201103L
261 resize(size_type __sz)
268 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
271 for (; __victim != __end; ++__victim)
281 __throw_exception_again;
286 resize(size_type __sz,
const _Tp& __c)
293 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
296 for (; __victim != __end; ++__victim)
301 _Base::resize(__sz, __c);
306 __throw_exception_again;
311 resize(size_type __sz, _Tp __c = _Tp())
318 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
321 for (; __victim != __end; ++__victim)
326 _Base::resize(__sz, __c);
331 __throw_exception_again;
338 front() _GLIBCXX_NOEXCEPT
340 __glibcxx_check_nonempty();
341 return _Base::front();
345 front()
const _GLIBCXX_NOEXCEPT
347 __glibcxx_check_nonempty();
348 return _Base::front();
352 back() _GLIBCXX_NOEXCEPT
354 __glibcxx_check_nonempty();
355 return _Base::back();
359 back()
const _GLIBCXX_NOEXCEPT
361 __glibcxx_check_nonempty();
362 return _Base::back();
366 using _Base::push_front;
368 #if __cplusplus >= 201103L
369 using _Base::emplace_front;
373 pop_front() _GLIBCXX_NOEXCEPT
375 __glibcxx_check_nonempty();
380 using _Base::push_back;
382 #if __cplusplus >= 201103L
383 using _Base::emplace_back;
387 pop_back() _GLIBCXX_NOEXCEPT
389 __glibcxx_check_nonempty();
394 #if __cplusplus >= 201103L
395 template<
typename... _Args>
401 std::forward<_Args>(__args)...),
this);
406 #if __cplusplus >= 201103L
409 insert(
iterator __position,
const _Tp& __x)
413 return iterator(_Base::insert(__position.
base(), __x),
this);
416 #if __cplusplus >= 201103L
419 {
return emplace(__position, std::move(__x)); }
429 #if __cplusplus >= 201103L
434 return iterator(_Base::insert(__position.
base(), __n, __x),
this);
438 insert(
iterator __position, size_type __n,
const _Tp& __x)
441 _Base::insert(__position.
base(), __n, __x);
445 #if __cplusplus >= 201103L
446 template<
class _InputIterator,
447 typename = std::_RequireInputIter<_InputIterator>>
450 _InputIterator __last)
454 if (__dist.
second >= __gnu_debug::__dp_sign)
457 _Base::insert(__position.
base(),
458 __gnu_debug::__unsafe(__first),
459 __gnu_debug::__unsafe(__last)),
463 return { _Base::insert(__position.
base(), __first, __last),
this };
466 template<
class _InputIterator>
468 insert(
iterator __position, _InputIterator __first,
469 _InputIterator __last)
474 if (__dist.
second >= __gnu_debug::__dp_sign)
475 _Base::insert(__position.
base(), __gnu_debug::__unsafe(__first),
476 __gnu_debug::__unsafe(__last));
478 _Base::insert(__position.
base(), __first, __last);
484 #if __cplusplus >= 201103L
491 return _Base::erase(__position);
496 #if __cplusplus >= 201103L
507 #if __cplusplus >= 201103L
517 __victim != __last.
base(); ++__victim)
519 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
520 _M_message(__gnu_debug::__msg_valid_range)
521 ._M_iterator(__first,
"position")
522 ._M_iterator(__last,
"last"));
530 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
537 clear() _GLIBCXX_NOEXCEPT
540 this->_M_invalidate_all();
545 #if __cplusplus >= 201103L
548 splice(
iterator __position, list& __x)
552 _M_message(__gnu_debug::__msg_self_splice)
553 ._M_sequence(*
this,
"this"));
555 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()));
558 #if __cplusplus >= 201103L
561 { splice(__position, std::move(__x)); }
565 #if __cplusplus >= 201103L
577 _M_message(__gnu_debug::__msg_splice_bad)
578 ._M_iterator(__i,
"__i"));
580 _M_message(__gnu_debug::__msg_splice_other)
581 ._M_iterator(__i,
"__i")._M_sequence(__x,
"__x"));
586 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()),
590 #if __cplusplus >= 201103L
593 { splice(__position, std::move(__x), __i); }
597 #if __cplusplus >= 201103L
606 __glibcxx_check_valid_range(__first, __last);
608 _M_message(__gnu_debug::__msg_splice_other)
609 ._M_sequence(__x,
"x")
610 ._M_iterator(__first,
"first"));
616 __tmp != __last.
base(); ++__tmp)
618 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
619 _M_message(__gnu_debug::__msg_valid_range)
620 ._M_iterator(__first,
"first")
621 ._M_iterator(__last,
"last"));
623 || __tmp != __position.
base(),
624 _M_message(__gnu_debug::__msg_splice_overlap)
625 ._M_iterator(__tmp,
"position")
626 ._M_iterator(__first,
"first")
627 ._M_iterator(__last,
"last"));
633 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()),
637 #if __cplusplus >= 201103L
641 { splice(__position, std::move(__x), __first, __last); }
645 remove(
const _Tp& __value)
656 template<
class _Predicate>
658 remove_if(_Predicate __pred)
674 if (__first == __last)
677 while (__next != __last)
679 if (*__first == *__next)
680 __next = _M_erase(__next);
686 template<
class _BinaryPredicate>
688 unique(_BinaryPredicate __binary_pred)
692 if (__first == __last)
695 while (__next != __last)
697 if (__binary_pred(*__first, *__next))
698 __next = _M_erase(__next);
705 #if __cplusplus >= 201103L
715 __glibcxx_check_sorted(_Base::begin(), _Base::end());
716 __glibcxx_check_sorted(__x.begin().
base(), __x.end().
base());
718 _Base::merge(_GLIBCXX_MOVE(__x._M_base()));
722 #if __cplusplus >= 201103L
725 { merge(std::move(__x)); }
728 template<
class _Compare>
730 #if __cplusplus >= 201103L
731 merge(list&& __x, _Compare __comp)
733 merge(list& __x, _Compare __comp)
745 _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp);
749 #if __cplusplus >= 201103L
750 template<
typename _Compare>
752 merge(list& __x, _Compare __comp)
753 { merge(std::move(__x), __comp); }
757 sort() { _Base::sort(); }
759 template<
typename _StrictWeakOrdering>
761 sort(_StrictWeakOrdering __pred) { _Base::sort(__pred); }
763 using _Base::reverse;
766 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
769 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
772 #if __cpp_deduction_guides >= 201606
773 template<
typename _InputIterator,
typename _ValT
774 =
typename iterator_traits<_InputIterator>::value_type,
776 typename = _RequireInputIter<_InputIterator>,
777 typename = _RequireAllocator<_Allocator>>
778 list(_InputIterator, _InputIterator, _Allocator = _Allocator())
782 template<
typename _Tp,
typename _Alloc>
786 {
return __lhs._M_base() == __rhs._M_base(); }
788 template<
typename _Tp,
typename _Alloc>
792 {
return __lhs._M_base() != __rhs._M_base(); }
794 template<
typename _Tp,
typename _Alloc>
796 operator<(const list<_Tp, _Alloc>& __lhs,
798 {
return __lhs._M_base() < __rhs._M_base(); }
800 template<
typename _Tp,
typename _Alloc>
802 operator<=(const list<_Tp, _Alloc>& __lhs,
804 {
return __lhs._M_base() <= __rhs._M_base(); }
806 template<
typename _Tp,
typename _Alloc>
810 {
return __lhs._M_base() >= __rhs._M_base(); }
812 template<
typename _Tp,
typename _Alloc>
816 {
return __lhs._M_base() > __rhs._M_base(); }
818 template<
typename _Tp,
typename _Alloc>
821 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
822 { __lhs.swap(__rhs); }
827 namespace __gnu_debug
829 #ifndef _GLIBCXX_USE_CXX11_ABI
831 template<
typename _Tp,
typename _Alloc>
836 static typename _Distance_traits<_It>::__type
845 #ifndef _GLIBCXX_DEBUG_PEDANTIC
846 template<
class _Tp,
class _Alloc>
847 struct _Insert_range_from_self_is_safe<std::__debug::list<_Tp, _Alloc> >
848 {
enum { __value = 1 }; };
bool _M_dereferenceable() const
Is the iterator dereferenceable?
void _M_invalidate_if(_Predicate __pred)
Class std::list with safety/checking/debug instrumentation.
Safe class dealing with some allocator dependent operations.
_Iterator & base() noexcept
Return the underlying iterator.
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
void _M_transfer_from_if(_Safe_sequence &__from, _Predicate __pred)
Struct holding two objects of arbitrary type.
The standard allocator, as per [20.4].
#define __glibcxx_check_sorted_pred(_First, _Last, _Pred)
_T2 second
first is a copy of the first object
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
void _M_detach_singular()
#define __glibcxx_check_erase_range(_First, _Last)
bool _M_attached_to(const _Safe_sequence_base *__seq) const
#define __glibcxx_check_insert(_Position)
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
#define __glibcxx_check_erase(_Position)
void _M_revalidate_singular()