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;
54 typedef typename _Base::reference reference;
55 typedef typename _Base::const_reference const_reference;
62 typedef typename _Base::size_type size_type;
63 typedef typename _Base::difference_type difference_type;
65 typedef _Tp value_type;
66 typedef _Alloc allocator_type;
67 typedef typename _Base::pointer pointer;
68 typedef typename _Base::const_pointer const_pointer;
80 :
_Base(std::move(__list._M_base()), __al)
82 this->_M_swap(__list);
91 const _Alloc& __al = _Alloc())
92 :
_Base(__n, __value, __al)
95 template<
typename _InputIterator>
96 forward_list(_InputIterator __first, _InputIterator __last,
97 const _Alloc& __al = _Alloc())
108 :
_Base(std::move(__list._M_base()))
110 this->_M_swap(__list);
114 const _Alloc& __al = _Alloc())
124 static_cast<_Base&
>(*this) = __list;
125 this->_M_invalidate_all();
142 static_cast<_Base&
>(*this) = __il;
143 this->_M_invalidate_all();
147 template<
typename _InputIterator>
149 assign(_InputIterator __first, _InputIterator __last)
151 __glibcxx_check_valid_range(__first, __last);
154 this->_M_invalidate_all();
158 assign(size_type __n,
const _Tp& __val)
160 _Base::assign(__n, __val);
161 this->_M_invalidate_all();
168 this->_M_invalidate_all();
171 using _Base::get_allocator;
177 {
return iterator(_Base::before_begin(),
this); }
185 {
return iterator(_Base::begin(),
this); }
193 {
return iterator(_Base::end(),
this); }
204 cbefore_begin()
const
212 using _Base::max_size;
219 __glibcxx_check_nonempty();
220 return _Base::front();
226 __glibcxx_check_nonempty();
227 return _Base::front();
232 using _Base::emplace_front;
233 using _Base::push_front;
238 __glibcxx_check_nonempty();
240 {
return __it == this->_M_base().cbegin(); });
244 template<
typename... _Args>
250 std::forward<_Args>(__args)...),
258 return iterator(_Base::insert_after(__pos.
base(), __val),
this);
265 return iterator(_Base::insert_after(__pos.
base(), std::move(__val)),
270 insert_after(
const_iterator __pos, size_type __n,
const _Tp& __val)
273 return iterator(_Base::insert_after(__pos.
base(), __n, __val),
277 template<
typename _InputIterator>
280 _InputIterator __first, _InputIterator __last)
293 return iterator(_Base::insert_after(__pos.
base(), __il),
this);
302 {
return __it == __next; });
303 return _Base::erase_after(__pos);
318 __victim != __last.
base(); ++__victim)
321 _M_message(__gnu_debug::__msg_valid_range2)
322 ._M_sequence(*
this,
"this")
323 ._M_iterator(__pos,
"pos")
324 ._M_iterator(__last,
"last"));
326 {
return __it == __victim; });
335 this->_M_swap(__list);
339 resize(size_type __sz)
346 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
349 for (; __victim != __end; ++__victim)
352 {
return __it == __victim; });
362 __throw_exception_again;
367 resize(size_type __sz,
const value_type& __val)
374 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
377 for (; __victim != __end; ++__victim)
380 {
return __it == __victim; });
385 _Base::resize(__sz, __val);
390 __throw_exception_again;
398 this->_M_invalidate_all();
407 _M_message(__gnu_debug::__msg_self_splice)
408 ._M_sequence(*
this,
"this"));
411 return __it != __list._M_base().cbefore_begin()
412 && __it != __list._M_base().end();
414 _Base::splice_after(__pos.
base(), std::move(__list._M_base()));
423 _M_message(__gnu_debug::__msg_splice_bad)
424 ._M_iterator(__i,
"__i"));
426 _M_message(__gnu_debug::__msg_splice_other)
427 ._M_iterator(__i,
"__i")
428 ._M_sequence(__list,
"__list"));
434 {
return __it == __next; });
435 _Base::splice_after(__pos.
base(), std::move(__list._M_base()),
444 __glibcxx_check_valid_range(__before, __last);
446 _M_message(__gnu_debug::__msg_splice_other)
447 ._M_sequence(__list,
"list")
448 ._M_iterator(__before,
"before"));
451 _M_message(__gnu_debug::__msg_valid_range2)
452 ._M_sequence(__list,
"list")
453 ._M_iterator(__before,
"before")
454 ._M_iterator(__last,
"last"));
456 _M_message(__gnu_debug::__msg_valid_range2)
457 ._M_sequence(__list,
"list")
458 ._M_iterator(__before,
"before")
459 ._M_iterator(__last,
"last"));
462 __tmp != __last.
base(); ++__tmp)
465 _M_message(__gnu_debug::__msg_valid_range2)
467 ._M_iterator(__before,
"before")
468 ._M_iterator(__last,
"last"));
470 _M_message(__gnu_debug::__msg_splice_overlap)
471 ._M_iterator(__tmp,
"position")
472 ._M_iterator(__before,
"before")
473 ._M_iterator(__last,
"last"));
477 {
return __it == __tmp; });
480 _Base::splice_after(__pos.
base(), std::move(__list._M_base()),
485 remove(
const _Tp& __val)
489 while (__x != _Base::end())
492 __x = _M_erase_after(__old);
498 template<
typename _Pred>
500 remove_if(_Pred __pred)
504 while (__x != _Base::end())
507 __x = _M_erase_after(__old);
518 if (__first == __last)
521 while (__next != __last)
523 if (*__first == *__next)
524 __next = _M_erase_after(__first);
530 template<
typename _BinPred>
532 unique(_BinPred __binary_pred)
536 if (__first == __last)
539 while (__next != __last)
541 if (__binary_pred(*__first, *__next))
542 __next = _M_erase_after(__first);
553 __glibcxx_check_sorted(_Base::begin(), _Base::end());
554 __glibcxx_check_sorted(__list._M_base().begin(),
555 __list._M_base().end());
558 return __it != __list._M_base().cbefore_begin()
559 && __it != __list._M_base().cend();
561 _Base::merge(std::move(__list._M_base()));
565 template<
typename _Comp>
573 __list._M_base().end(), __comp);
577 return __it != __list._M_base().cbefore_begin()
578 && __it != __list._M_base().cend();
580 _Base::merge(std::move(__list._M_base()), __comp);
585 using _Base::reverse;
588 _M_base() {
return *
this; }
591 _M_base()
const {
return *
this; }
599 return __it != this->_M_base().cbefore_begin()
600 && __it != this->_M_base().cend();
612 template<
typename _Tp,
typename _Alloc>
621 _Safe_iterator_base* __bbegin_its = 0;
622 _Safe_iterator_base* __last_bbegin = 0;
623 for (_Safe_iterator_base* __iter = __lhs_iterators; __iter;)
626 const_iterator* __victim =
static_cast<const_iterator*
>(__iter);
628 if (__victim->base() == __rhs._M_base().cbefore_begin())
631 if (__lhs_iterators == __victim)
632 __lhs_iterators = __victim->
_M_next;
635 __victim->
_M_next = __bbegin_its;
639 __last_bbegin = __victim;
640 __bbegin_its = __victim;
650 __rhs_iterators->
_M_prior = __last_bbegin;
651 __last_bbegin->
_M_next = __rhs_iterators;
653 __rhs_iterators = __bbegin_its;
659 template<
typename _Tp,
typename _Alloc>
661 forward_list<_Tp, _Alloc>::
662 _M_swap(forward_list<_Tp, _Alloc>& __list)
665 std::swap(this->_M_iterators, __list._M_iterators);
666 std::swap(this->_M_const_iterators, __list._M_const_iterators);
669 _Safe_iterator_base* __this_its = this->_M_iterators;
670 _M_swap_aux(__list, __list._M_iterators, *
this, this->_M_iterators);
671 _Safe_iterator_base* __this_const_its = this->_M_const_iterators;
672 _M_swap_aux(__list, __list._M_const_iterators, *
this, this->_M_const_iterators);
673 _M_swap_aux(*
this, __this_its, __list, __list._M_iterators);
674 _M_swap_aux(*
this, __this_const_its, __list, __list._M_const_iterators);
677 template<
typename _Tp,
typename _Alloc>
679 operator==(
const forward_list<_Tp, _Alloc>& __lx,
680 const forward_list<_Tp, _Alloc>& __ly)
681 {
return __lx._M_base() == __ly._M_base(); }
683 template<
typename _Tp,
typename _Alloc>
685 operator<(const forward_list<_Tp, _Alloc>& __lx,
686 const forward_list<_Tp, _Alloc>& __ly)
687 {
return __lx._M_base() < __ly._M_base(); }
689 template<
typename _Tp,
typename _Alloc>
691 operator!=(
const forward_list<_Tp, _Alloc>& __lx,
692 const forward_list<_Tp, _Alloc>& __ly)
693 {
return !(__lx == __ly); }
696 template<
typename _Tp,
typename _Alloc>
700 {
return (__ly < __lx); }
703 template<
typename _Tp,
typename _Alloc>
707 {
return !(__lx < __ly); }
710 template<
typename _Tp,
typename _Alloc>
712 operator<=(const forward_list<_Tp, _Alloc>& __lx,
714 {
return !(__ly < __lx); }
717 template<
typename _Tp,
typename _Alloc>
726 namespace __gnu_debug
728 template<
class _Tp,
class _Alloc>
732 typedef typename _Sequence::const_iterator _It;
733 typedef typename _It::iterator_type _BaseIt;
736 _M_Is(_BaseIt __it,
const _Sequence* __seq)
737 {
return __it == __seq->_M_base().cbefore_begin(); }