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 91 list(
const list&) =
default;
92 list(list&&) =
default;
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
210 {
return const_iterator(_Base::begin(),
this); }
213 end() _GLIBCXX_NOEXCEPT
214 {
return iterator(_Base::end(),
this); }
217 end()
const _GLIBCXX_NOEXCEPT
218 {
return const_iterator(_Base::end(),
this); }
221 rbegin() _GLIBCXX_NOEXCEPT
222 {
return reverse_iterator(end()); }
224 const_reverse_iterator
225 rbegin()
const _GLIBCXX_NOEXCEPT
226 {
return const_reverse_iterator(end()); }
229 rend() _GLIBCXX_NOEXCEPT
230 {
return reverse_iterator(begin()); }
232 const_reverse_iterator
233 rend()
const _GLIBCXX_NOEXCEPT
234 {
return const_reverse_iterator(begin()); }
236 #if __cplusplus >= 201103L 238 cbegin()
const noexcept
239 {
return const_iterator(_Base::begin(),
this); }
242 cend()
const noexcept
243 {
return const_iterator(_Base::end(),
this); }
245 const_reverse_iterator
246 crbegin()
const noexcept
247 {
return const_reverse_iterator(end()); }
249 const_reverse_iterator
250 crend()
const noexcept
251 {
return const_reverse_iterator(begin()); }
257 using _Base::max_size;
259 #if __cplusplus >= 201103L 261 resize(size_type __sz)
266 _Base_iterator __victim = _Base::begin();
267 _Base_iterator __end = _Base::end();
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)
291 _Base_iterator __victim = _Base::begin();
292 _Base_iterator __end = _Base::end();
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())
316 _Base_iterator __victim = _Base::begin();
317 _Base_iterator __end = _Base::end();
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>
397 emplace(const_iterator __position, _Args&&... __args)
400 return iterator(_Base::emplace(__position.
base(),
401 std::forward<_Args>(__args)...),
this);
406 #if __cplusplus >= 201103L 407 insert(const_iterator __position,
const _Tp& __x)
409 insert(iterator __position,
const _Tp& __x)
413 return iterator(_Base::insert(__position.
base(), __x),
this);
416 #if __cplusplus >= 201103L 418 insert(const_iterator __position, _Tp&& __x)
419 {
return emplace(__position, std::move(__x)); }
425 return iterator(_Base::insert(__p.
base(), __l),
this);
429 #if __cplusplus >= 201103L 431 insert(const_iterator __position, size_type __n,
const _Tp& __x)
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>>
449 insert(const_iterator __position, _InputIterator __first,
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 485 _M_erase(_Base_const_iterator __position) noexcept
487 _M_erase(_Base_iterator __position)
491 return _Base::erase(__position);
496 #if __cplusplus >= 201103L 497 erase(const_iterator __position) noexcept
499 erase(iterator __position)
503 return iterator(_M_erase(__position.
base()),
this);
507 #if __cplusplus >= 201103L 508 erase(const_iterator __first, const_iterator __last) noexcept
510 erase(iterator __first, iterator __last)
516 for (_Base_const_iterator __victim = __first.
base();
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"));
525 return iterator(_Base::erase(__first.
base(), __last.
base()),
this);
530 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
537 clear() _GLIBCXX_NOEXCEPT
540 this->_M_invalidate_all();
545 #if __cplusplus >= 201103L 546 splice(const_iterator __position, list&& __x) noexcept
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 560 splice(const_iterator __position, list& __x) noexcept
561 { splice(__position, std::move(__x)); }
565 #if __cplusplus >= 201103L 566 splice(const_iterator __position, list&& __x, const_iterator __i) noexcept
568 splice(iterator __position, list& __x, iterator __i)
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 592 splice(const_iterator __position, list& __x, const_iterator __i) noexcept
593 { splice(__position, std::move(__x), __i); }
597 #if __cplusplus >= 201103L 598 splice(const_iterator __position, list&& __x, const_iterator __first,
599 const_iterator __last) noexcept
601 splice(iterator __position, list& __x, iterator __first,
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"));
615 for (_Base_const_iterator __tmp = __first.
base();
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 639 splice(const_iterator __position, list& __x,
640 const_iterator __first, const_iterator __last) noexcept
641 { splice(__position, std::move(__x), __first, __last); }
645 remove(
const _Tp& __value)
647 for (_Base_iterator __x = _Base::begin(); __x != _Base::end(); )
656 template<
class _Predicate>
658 remove_if(_Predicate __pred)
660 for (_Base_iterator __x = _Base::begin(); __x != _Base::end(); )
672 _Base_iterator __first = _Base::begin();
673 _Base_iterator __last = _Base::end();
674 if (__first == __last)
676 _Base_iterator __next = __first; ++__next;
677 while (__next != __last)
679 if (*__first == *__next)
680 __next = _M_erase(__next);
686 template<
class _BinaryPredicate>
688 unique(_BinaryPredicate __binary_pred)
690 _Base_iterator __first = _Base::begin();
691 _Base_iterator __last = _Base::end();
692 if (__first == __last)
694 _Base_iterator __next = __first; ++__next;
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 template<
typename _Tp,
typename _Alloc>
776 {
return __lhs._M_base() == __rhs._M_base(); }
778 template<
typename _Tp,
typename _Alloc>
782 {
return __lhs._M_base() != __rhs._M_base(); }
784 template<
typename _Tp,
typename _Alloc>
786 operator<(const list<_Tp, _Alloc>& __lhs,
788 {
return __lhs._M_base() < __rhs._M_base(); }
790 template<
typename _Tp,
typename _Alloc>
792 operator<=(const list<_Tp, _Alloc>& __lhs,
794 {
return __lhs._M_base() <= __rhs._M_base(); }
796 template<
typename _Tp,
typename _Alloc>
800 {
return __lhs._M_base() >= __rhs._M_base(); }
802 template<
typename _Tp,
typename _Alloc>
806 {
return __lhs._M_base() > __rhs._M_base(); }
808 template<
typename _Tp,
typename _Alloc>
811 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
812 { __lhs.swap(__rhs); }
819 #ifndef _GLIBCXX_USE_CXX11_ABI 821 template<
typename _Tp,
typename _Alloc>
826 static typename _Distance_traits<_It>::__type
835 #ifndef _GLIBCXX_DEBUG_PEDANTIC 836 template<
class _Tp,
class _Alloc>
837 struct _Insert_range_from_self_is_safe<std::
__debug::list<_Tp, _Alloc> >
838 {
enum { __value = 1 }; };
_T2 second
first is a copy of the first object
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.
#define __glibcxx_check_insert(_Position)
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.
bool _M_dereferenceable() const
Is the iterator dereferenceable?
bool _M_attached_to(const _Safe_sequence_base *__seq) const
void _M_detach_singular()
Safe class dealing with some allocator dependent operations.
void _M_transfer_from_if(_Safe_sequence &__from, _Predicate __pred)
Like _Safe_sequence but with a special _M_invalidate_all implementation not invalidating past-the-end...
_Iterator & base() noexcept
Return the underlying iterator.
#define __glibcxx_check_sorted_pred(_First, _Last, _Pred)
void _M_revalidate_singular()
Class std::list with safety/checking/debug instrumentation.
Struct holding two objects of arbitrary type.
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
GNU debug classes for public use.
void _M_invalidate_if(_Predicate __pred)
#define __glibcxx_check_erase(_Position)
#define __glibcxx_check_erase_range(_First, _Last)