29 #ifndef _GLIBCXX_DEBUG_LIST
30 #define _GLIBCXX_DEBUG_LIST 1
37 namespace std _GLIBCXX_VISIBILITY(default)
42 template<
typename _Tp,
typename _Allocator = std::allocator<_Tp> >
45 list<_Tp, _Allocator>, _Allocator,
46 __gnu_debug::_Safe_node_sequence>,
47 public _GLIBCXX_STD_C::list<_Tp, _Allocator>
49 typedef _GLIBCXX_STD_C::list<_Tp, _Allocator>
_Base;
59 typedef typename _Base::reference reference;
60 typedef typename _Base::const_reference const_reference;
67 typedef typename _Base::size_type size_type;
68 typedef typename _Base::difference_type difference_type;
70 typedef _Tp value_type;
71 typedef _Allocator allocator_type;
72 typedef typename _Base::pointer pointer;
73 typedef typename _Base::const_pointer const_pointer;
79 #if __cplusplus < 201103L
93 const allocator_type& __a = allocator_type())
98 list(
const list& __x,
const allocator_type& __a)
101 list(
list&& __x,
const allocator_type& __a)
102 :
_Base(std::move(__x), __a) { }
106 list(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
109 #if __cplusplus >= 201103L
111 list(size_type __n,
const allocator_type& __a = allocator_type())
112 :
_Base(__n, __a) { }
114 list(size_type __n,
const _Tp& __value,
115 const _Allocator& __a = _Allocator())
116 :
_Base(__n, __value, __a) { }
119 list(size_type __n,
const _Tp& __value = _Tp(),
120 const _Allocator& __a = _Allocator())
121 :
_Base(__n, __value, __a) { }
124 #if __cplusplus >= 201103L
125 template<
class _InputIterator,
126 typename = std::_RequireInputIter<_InputIterator>>
128 template<
class _InputIterator>
130 list(_InputIterator __first, _InputIterator __last,
131 const _Allocator& __a = _Allocator())
132 :
_Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
134 __gnu_debug::__base(__last), __a)
137 list(
const _Base& __x)
140 #if __cplusplus < 201103L
142 operator=(
const list& __x)
144 this->_M_safe() = __x;
150 operator=(
const list&) =
default;
153 operator=(list&&) =
default;
158 this->_M_invalidate_all();
167 this->_M_invalidate_all();
171 #if __cplusplus >= 201103L
172 template<
class _InputIterator,
173 typename = std::_RequireInputIter<_InputIterator>>
175 template<
class _InputIterator>
178 assign(_InputIterator __first, _InputIterator __last)
181 __glibcxx_check_valid_range2(__first, __last, __dist);
183 if (__dist.
second >= __gnu_debug::__dp_sign)
184 _Base::assign(__gnu_debug::__unsafe(__first),
185 __gnu_debug::__unsafe(__last));
187 _Base::assign(__first, __last);
189 this->_M_invalidate_all();
193 assign(size_type __n,
const _Tp& __t)
195 _Base::assign(__n, __t);
196 this->_M_invalidate_all();
199 using _Base::get_allocator;
203 begin() _GLIBCXX_NOEXCEPT
204 {
return iterator(_Base::begin(),
this); }
207 begin()
const _GLIBCXX_NOEXCEPT
211 end() _GLIBCXX_NOEXCEPT
212 {
return iterator(_Base::end(),
this); }
215 end()
const _GLIBCXX_NOEXCEPT
219 rbegin() _GLIBCXX_NOEXCEPT
223 rbegin()
const _GLIBCXX_NOEXCEPT
227 rend() _GLIBCXX_NOEXCEPT
231 rend()
const _GLIBCXX_NOEXCEPT
234 #if __cplusplus >= 201103L
236 cbegin()
const noexcept
240 cend()
const noexcept
244 crbegin()
const noexcept
248 crend()
const noexcept
255 using _Base::max_size;
257 #if __cplusplus >= 201103L
259 resize(size_type __sz)
266 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
269 for (; __victim != __end; ++__victim)
279 __throw_exception_again;
284 resize(size_type __sz,
const _Tp& __c)
291 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
294 for (; __victim != __end; ++__victim)
299 _Base::resize(__sz, __c);
304 __throw_exception_again;
309 resize(size_type __sz, _Tp __c = _Tp())
316 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
319 for (; __victim != __end; ++__victim)
324 _Base::resize(__sz, __c);
329 __throw_exception_again;
336 front() _GLIBCXX_NOEXCEPT
338 __glibcxx_check_nonempty();
339 return _Base::front();
343 front()
const _GLIBCXX_NOEXCEPT
345 __glibcxx_check_nonempty();
346 return _Base::front();
350 back() _GLIBCXX_NOEXCEPT
352 __glibcxx_check_nonempty();
353 return _Base::back();
357 back()
const _GLIBCXX_NOEXCEPT
359 __glibcxx_check_nonempty();
360 return _Base::back();
364 using _Base::push_front;
366 #if __cplusplus >= 201103L
367 using _Base::emplace_front;
371 pop_front() _GLIBCXX_NOEXCEPT
373 __glibcxx_check_nonempty();
378 using _Base::push_back;
380 #if __cplusplus >= 201103L
381 using _Base::emplace_back;
385 pop_back() _GLIBCXX_NOEXCEPT
387 __glibcxx_check_nonempty();
392 #if __cplusplus >= 201103L
393 template<
typename... _Args>
399 std::forward<_Args>(__args)...),
this);
404 #if __cplusplus >= 201103L
407 insert(
iterator __position,
const _Tp& __x)
411 return iterator(_Base::insert(__position.
base(), __x),
this);
414 #if __cplusplus >= 201103L
417 {
return emplace(__position, std::move(__x)); }
427 #if __cplusplus >= 201103L
432 return iterator(_Base::insert(__position.
base(), __n, __x),
this);
436 insert(
iterator __position, size_type __n,
const _Tp& __x)
439 _Base::insert(__position.
base(), __n, __x);
443 #if __cplusplus >= 201103L
444 template<
class _InputIterator,
445 typename = std::_RequireInputIter<_InputIterator>>
448 _InputIterator __last)
452 if (__dist.
second >= __gnu_debug::__dp_sign)
455 _Base::insert(__position.
base(),
456 __gnu_debug::__unsafe(__first),
457 __gnu_debug::__unsafe(__last)),
461 return { _Base::insert(__position.
base(), __first, __last),
this };
464 template<
class _InputIterator>
466 insert(
iterator __position, _InputIterator __first,
467 _InputIterator __last)
472 if (__dist.
second >= __gnu_debug::__dp_sign)
473 _Base::insert(__position.
base(), __gnu_debug::__unsafe(__first),
474 __gnu_debug::__unsafe(__last));
476 _Base::insert(__position.
base(), __first, __last);
482 #if __cplusplus >= 201103L
489 return _Base::erase(__position);
494 #if __cplusplus >= 201103L
505 #if __cplusplus >= 201103L
515 __victim != __last.
base(); ++__victim)
517 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
518 _M_message(__gnu_debug::__msg_valid_range)
519 ._M_iterator(__first,
"position")
520 ._M_iterator(__last,
"last"));
528 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
535 clear() _GLIBCXX_NOEXCEPT
538 this->_M_invalidate_all();
543 #if __cplusplus >= 201103L
546 splice(
iterator __position, list& __x)
550 _M_message(__gnu_debug::__msg_self_splice)
551 ._M_sequence(*
this,
"this"));
553 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()));
556 #if __cplusplus >= 201103L
559 { splice(__position, std::move(__x)); }
563 #if __cplusplus >= 201103L
575 _M_message(__gnu_debug::__msg_splice_bad)
576 ._M_iterator(__i,
"__i"));
578 _M_message(__gnu_debug::__msg_splice_other)
579 ._M_iterator(__i,
"__i")._M_sequence(__x,
"__x"));
584 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()),
588 #if __cplusplus >= 201103L
591 { splice(__position, std::move(__x), __i); }
595 #if __cplusplus >= 201103L
604 __glibcxx_check_valid_range(__first, __last);
606 _M_message(__gnu_debug::__msg_splice_other)
607 ._M_sequence(__x,
"x")
608 ._M_iterator(__first,
"first"));
614 __tmp != __last.
base(); ++__tmp)
616 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
617 _M_message(__gnu_debug::__msg_valid_range)
618 ._M_iterator(__first,
"first")
619 ._M_iterator(__last,
"last"));
621 || __tmp != __position.
base(),
622 _M_message(__gnu_debug::__msg_splice_overlap)
623 ._M_iterator(__tmp,
"position")
624 ._M_iterator(__first,
"first")
625 ._M_iterator(__last,
"last"));
631 _Base::splice(__position.
base(), _GLIBCXX_MOVE(__x._M_base()),
635 #if __cplusplus >= 201103L
639 { splice(__position, std::move(__x), __first, __last); }
643 remove(
const _Tp& __value)
654 template<
class _Predicate>
656 remove_if(_Predicate __pred)
672 if (__first == __last)
675 while (__next != __last)
677 if (*__first == *__next)
678 __next = _M_erase(__next);
684 template<
class _BinaryPredicate>
686 unique(_BinaryPredicate __binary_pred)
690 if (__first == __last)
693 while (__next != __last)
695 if (__binary_pred(*__first, *__next))
696 __next = _M_erase(__next);
703 #if __cplusplus >= 201103L
713 __glibcxx_check_sorted(_Base::begin(), _Base::end());
714 __glibcxx_check_sorted(__x.begin().
base(), __x.end().
base());
716 _Base::merge(_GLIBCXX_MOVE(__x._M_base()));
720 #if __cplusplus >= 201103L
723 { merge(std::move(__x)); }
726 template<
class _Compare>
728 #if __cplusplus >= 201103L
729 merge(list&& __x, _Compare __comp)
731 merge(list& __x, _Compare __comp)
743 _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp);
747 #if __cplusplus >= 201103L
748 template<
typename _Compare>
750 merge(list& __x, _Compare __comp)
751 { merge(std::move(__x), __comp); }
755 sort() { _Base::sort(); }
757 template<
typename _StrictWeakOrdering>
759 sort(_StrictWeakOrdering __pred) { _Base::sort(__pred); }
761 using _Base::reverse;
764 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
767 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
770 template<
typename _Tp,
typename _Alloc>
774 {
return __lhs._M_base() == __rhs._M_base(); }
776 template<
typename _Tp,
typename _Alloc>
780 {
return __lhs._M_base() != __rhs._M_base(); }
782 template<
typename _Tp,
typename _Alloc>
784 operator<(const list<_Tp, _Alloc>& __lhs,
786 {
return __lhs._M_base() < __rhs._M_base(); }
788 template<
typename _Tp,
typename _Alloc>
790 operator<=(const list<_Tp, _Alloc>& __lhs,
792 {
return __lhs._M_base() <= __rhs._M_base(); }
794 template<
typename _Tp,
typename _Alloc>
798 {
return __lhs._M_base() >= __rhs._M_base(); }
800 template<
typename _Tp,
typename _Alloc>
804 {
return __lhs._M_base() > __rhs._M_base(); }
806 template<
typename _Tp,
typename _Alloc>
809 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
810 { __lhs.swap(__rhs); }
815 namespace __gnu_debug
817 #ifndef _GLIBCXX_USE_CXX11_ABI
819 template<
typename _Tp,
typename _Alloc>
824 static typename _Distance_traits<_It>::__type
833 #ifndef _GLIBCXX_DEBUG_PEDANTIC
834 template<
class _Tp,
class _Alloc>
835 struct _Insert_range_from_self_is_safe<std::__debug::list<_Tp, _Alloc> >
836 {
enum { __value = 1 }; };
Class std::list with safety/checking/debug instrumentation.
#define __glibcxx_check_erase(_Position)
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
#define __glibcxx_check_insert(_Position)
Struct holding two objects of arbitrary type.
bool _M_dereferenceable() const
Is the iterator dereferenceable?
void _M_revalidate_singular()
_Iterator & base() noexcept
Return the underlying iterator.
bool _M_attached_to(const _Safe_sequence_base *__seq) const
void _M_invalidate_if(_Predicate __pred)
void _M_detach_singular()
void _M_transfer_from_if(_Safe_sequence &__from, _Predicate __pred)
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
#define __glibcxx_check_erase_range(_First, _Last)
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.
Safe class dealing with some allocator dependent operations.
_T2 second
first is a copy of the first object
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
#define __glibcxx_check_sorted_pred(_First, _Last, _Pred)