29 #ifndef _GLIBCXX_DEBUG_FORWARD_LIST
30 #define _GLIBCXX_DEBUG_FORWARD_LIST 1
32 #pragma GCC system_header
38 namespace std _GLIBCXX_VISIBILITY(default)
43 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
45 :
public _GLIBCXX_STD_C::forward_list<_Tp, _Alloc>,
48 typedef _GLIBCXX_STD_C::forward_list<_Tp, _Alloc>
_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 _Alloc allocator_type;
66 typedef typename _Base::pointer pointer;
67 typedef typename _Base::const_pointer const_pointer;
79 :
_Base(std::move(__list._M_base()), __al)
81 this->_M_swap(__list);
90 const _Alloc& __al = _Alloc())
91 :
_Base(__n, __value, __al)
94 template<
typename _InputIterator>
95 forward_list(_InputIterator __first, _InputIterator __last,
96 const _Alloc& __al = _Alloc())
107 :
_Base(std::move(__list._M_base()))
109 this->_M_swap(__list);
113 const _Alloc& __al = _Alloc())
123 static_cast<_Base&
>(*this) = __list;
124 this->_M_invalidate_all();
141 static_cast<_Base&
>(*this) = __il;
142 this->_M_invalidate_all();
146 template<
typename _InputIterator>
148 assign(_InputIterator __first, _InputIterator __last)
150 __glibcxx_check_valid_range(__first, __last);
153 this->_M_invalidate_all();
157 assign(size_type __n,
const _Tp& __val)
159 _Base::assign(__n, __val);
160 this->_M_invalidate_all();
167 this->_M_invalidate_all();
170 using _Base::get_allocator;
175 before_begin() noexcept
176 {
return iterator(_Base::before_begin(),
this); }
179 before_begin()
const noexcept
184 {
return iterator(_Base::begin(),
this); }
187 begin()
const noexcept
192 {
return iterator(_Base::end(),
this); }
199 cbegin()
const noexcept
203 cbefore_begin()
const noexcept
207 cend()
const noexcept
211 using _Base::max_size;
218 __glibcxx_check_nonempty();
219 return _Base::front();
225 __glibcxx_check_nonempty();
226 return _Base::front();
231 using _Base::emplace_front;
232 using _Base::push_front;
237 __glibcxx_check_nonempty();
239 {
return __it == this->_M_base().cbegin(); });
243 template<
typename... _Args>
249 std::forward<_Args>(__args)...),
257 return iterator(_Base::insert_after(__pos.
base(), __val),
this);
264 return iterator(_Base::insert_after(__pos.
base(), std::move(__val)),
269 insert_after(
const_iterator __pos, size_type __n,
const _Tp& __val)
272 return iterator(_Base::insert_after(__pos.
base(), __n, __val),
276 template<
typename _InputIterator>
279 _InputIterator __first, _InputIterator __last)
292 return iterator(_Base::insert_after(__pos.
base(), __il),
this);
301 {
return __it == __next; });
302 return _Base::erase_after(__pos);
317 __victim != __last.
base(); ++__victim)
319 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
320 _M_message(__gnu_debug::__msg_valid_range2)
321 ._M_sequence(*
this,
"this")
322 ._M_iterator(__pos,
"pos")
323 ._M_iterator(__last,
"last"));
325 {
return __it == __victim; });
334 this->_M_swap(__list);
338 resize(size_type __sz)
345 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
348 for (; __victim != __end; ++__victim)
351 {
return __it == __victim; });
361 __throw_exception_again;
366 resize(size_type __sz,
const value_type& __val)
373 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
376 for (; __victim != __end; ++__victim)
379 {
return __it == __victim; });
384 _Base::resize(__sz, __val);
389 __throw_exception_again;
397 this->_M_invalidate_all();
405 _GLIBCXX_DEBUG_VERIFY(&__list !=
this,
406 _M_message(__gnu_debug::__msg_self_splice)
407 ._M_sequence(*
this,
"this"));
410 return __it != __list._M_base().cbefore_begin()
411 && __it != __list._M_base().end();
413 _Base::splice_after(__pos.
base(), std::move(__list._M_base()));
418 { splice_after(__pos, std::move(__list)); }
426 _M_message(__gnu_debug::__msg_splice_bad)
427 ._M_iterator(__i,
"__i"));
429 _M_message(__gnu_debug::__msg_splice_other)
430 ._M_iterator(__i,
"__i")
431 ._M_sequence(__list,
"__list"));
437 {
return __it == __next; });
438 _Base::splice_after(__pos.
base(), std::move(__list._M_base()),
445 { splice_after(__pos, std::move(__list), __i); }
452 __glibcxx_check_valid_range(__before, __last);
454 _M_message(__gnu_debug::__msg_splice_other)
455 ._M_sequence(__list,
"list")
456 ._M_iterator(__before,
"before"));
459 _M_message(__gnu_debug::__msg_valid_range2)
460 ._M_sequence(__list,
"list")
461 ._M_iterator(__before,
"before")
462 ._M_iterator(__last,
"last"));
463 _GLIBCXX_DEBUG_VERIFY(__before != __last,
464 _M_message(__gnu_debug::__msg_valid_range2)
465 ._M_sequence(__list,
"list")
466 ._M_iterator(__before,
"before")
467 ._M_iterator(__last,
"last"));
470 __tmp != __last.
base(); ++__tmp)
472 _GLIBCXX_DEBUG_VERIFY(__tmp != __list._M_base().end(),
473 _M_message(__gnu_debug::__msg_valid_range2)
475 ._M_iterator(__before,
"before")
476 ._M_iterator(__last,
"last"));
477 _GLIBCXX_DEBUG_VERIFY(&__list !=
this || __tmp != __pos.
base(),
478 _M_message(__gnu_debug::__msg_splice_overlap)
479 ._M_iterator(__tmp,
"position")
480 ._M_iterator(__before,
"before")
481 ._M_iterator(__last,
"last"));
485 {
return __it == __tmp; });
488 _Base::splice_after(__pos.
base(), std::move(__list._M_base()),
495 { splice_after(__pos, std::move(__list), __before, __last); }
498 remove(
const _Tp& __val)
502 while (__x != _Base::end())
505 __x = _M_erase_after(__old);
511 template<
typename _Pred>
513 remove_if(_Pred __pred)
517 while (__x != _Base::end())
520 __x = _M_erase_after(__old);
531 if (__first == __last)
534 while (__next != __last)
536 if (*__first == *__next)
537 __next = _M_erase_after(__first);
543 template<
typename _BinPred>
545 unique(_BinPred __binary_pred)
549 if (__first == __last)
552 while (__next != __last)
554 if (__binary_pred(*__first, *__next))
555 __next = _M_erase_after(__first);
566 __glibcxx_check_sorted(_Base::begin(), _Base::end());
567 __glibcxx_check_sorted(__list._M_base().begin(),
568 __list._M_base().end());
571 return __it != __list._M_base().cbefore_begin()
572 && __it != __list._M_base().cend();
574 _Base::merge(std::move(__list._M_base()));
580 { merge(std::move(__list)); }
582 template<
typename _Comp>
590 __list._M_base().end(), __comp);
594 return __it != __list._M_base().cbefore_begin()
595 && __it != __list._M_base().cend();
597 _Base::merge(std::move(__list._M_base()), __comp);
601 template<
typename _Comp>
604 { merge(std::move(__list), __comp); }
607 using _Base::reverse;
610 _M_base() noexcept {
return *
this; }
613 _M_base()
const noexcept {
return *
this; }
621 return __it != this->_M_base().cbefore_begin()
622 && __it != this->_M_base().cend();
634 template<
typename _Tp,
typename _Alloc>
643 _Safe_iterator_base* __bbegin_its = 0;
644 _Safe_iterator_base* __last_bbegin = 0;
645 for (_Safe_iterator_base* __iter = __lhs_iterators; __iter;)
648 const_iterator* __victim =
static_cast<const_iterator*
>(__iter);
650 if (__victim->base() == __rhs._M_base().cbefore_begin())
653 if (__lhs_iterators == __victim)
654 __lhs_iterators = __victim->
_M_next;
657 __victim->
_M_next = __bbegin_its;
661 __last_bbegin = __victim;
662 __bbegin_its = __victim;
672 __rhs_iterators->
_M_prior = __last_bbegin;
673 __last_bbegin->
_M_next = __rhs_iterators;
675 __rhs_iterators = __bbegin_its;
681 template<
typename _Tp,
typename _Alloc>
683 forward_list<_Tp, _Alloc>::
684 _M_swap(forward_list<_Tp, _Alloc>& __list)
687 std::swap(this->_M_iterators, __list._M_iterators);
688 std::swap(this->_M_const_iterators, __list._M_const_iterators);
691 _Safe_iterator_base* __this_its = this->_M_iterators;
692 _M_swap_aux(__list, __list._M_iterators, *
this, this->_M_iterators);
693 _Safe_iterator_base* __this_const_its = this->_M_const_iterators;
694 _M_swap_aux(__list, __list._M_const_iterators, *
this,
695 this->_M_const_iterators);
696 _M_swap_aux(*
this, __this_its, __list, __list._M_iterators);
697 _M_swap_aux(*
this, __this_const_its, __list, __list._M_const_iterators);
700 template<
typename _Tp,
typename _Alloc>
702 operator==(
const forward_list<_Tp, _Alloc>& __lx,
703 const forward_list<_Tp, _Alloc>& __ly)
704 {
return __lx._M_base() == __ly._M_base(); }
706 template<
typename _Tp,
typename _Alloc>
708 operator<(const forward_list<_Tp, _Alloc>& __lx,
709 const forward_list<_Tp, _Alloc>& __ly)
710 {
return __lx._M_base() < __ly._M_base(); }
712 template<
typename _Tp,
typename _Alloc>
714 operator!=(
const forward_list<_Tp, _Alloc>& __lx,
715 const forward_list<_Tp, _Alloc>& __ly)
716 {
return !(__lx == __ly); }
719 template<
typename _Tp,
typename _Alloc>
723 {
return (__ly < __lx); }
726 template<
typename _Tp,
typename _Alloc>
730 {
return !(__lx < __ly); }
733 template<
typename _Tp,
typename _Alloc>
735 operator<=(const forward_list<_Tp, _Alloc>& __lx,
737 {
return !(__ly < __lx); }
740 template<
typename _Tp,
typename _Alloc>
749 namespace __gnu_debug
751 template<
class _Tp,
class _Alloc>
752 struct _BeforeBeginHelper<std::__debug::forward_list<_Tp, _Alloc> >
755 typedef typename _Sequence::const_iterator _It;
756 typedef typename _It::iterator_type _BaseIt;
759 _S_Is(_BaseIt __it,
const _Sequence* __seq)
760 {
return __it == __seq->_M_base().cbefore_begin(); }
763 _S_Is_Beginnest(_BaseIt __it,
const _Sequence* __seq)
764 {
return _S_Is(__it, __seq); }
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
void _M_revalidate_singular()
bool _M_is_before_begin() const
Is this iterator equal to the sequence's before_begin() iterator if any?
void _M_invalidate_if(_Predicate __pred)
_Safe_iterator_base * _M_prior
_Iterator base() const
Return the underlying iterator.
#define __glibcxx_check_erase_range_after(_First, _Last)
void _M_detach_singular()
_Safe_iterator_base * _M_next
bool _M_before_dereferenceable() const
Is the iterator before a dereferenceable one?
#define __glibcxx_check_erase_after(_Position)
void _M_transfer_from_if(_Safe_sequence &__from, _Predicate __pred)
bool _M_attached_to(const _Safe_sequence_base *__seq) const
#define __glibcxx_check_insert_range_after(_Position, _First, _Last)
#define __glibcxx_check_insert_after(_Position)
Class std::forward_list with safety/checking/debug instrumentation.
_Safe_sequence_base * _M_sequence
Basic functionality for a safe iterator.
bool _M_dereferenceable() const
Is the iterator dereferenceable?
Base class for constructing a safe sequence type that tracks iterators that reference it...
#define __glibcxx_check_sorted_pred(_First, _Last, _Pred)