29 #ifndef _GLIBCXX_DEBUG_FORWARD_LIST
30 #define _GLIBCXX_DEBUG_FORWARD_LIST 1
32 #pragma GCC system_header
35 namespace std _GLIBCXX_VISIBILITY(default) {
namespace __debug {
36 template<
typename _Tp,
typename _Allocator>
class forward_list;
45 #define __glibcxx_check_valid_fl_range(_First,_Last,_Dist) \
46 _GLIBCXX_DEBUG_VERIFY(_First._M_valid_range(_Last, _Dist, false), \
47 _M_message(__gnu_debug::__msg_valid_range) \
48 ._M_iterator(_First, #_First) \
49 ._M_iterator(_Last, #_Last))
55 template<
typename _SafeSequence>
61 {
return *
static_cast<_SafeSequence*
>(
this); }
75 using _Base_const_iterator = __decltype(_M_this()._M_base().cend());
78 return __it != _M_this()._M_base().cbefore_begin()
79 && __it != _M_this()._M_base().cend(); });
85 template<
typename _SafeSequence>
93 using const_iterator =
typename _SafeSequence::const_iterator;
96 _SafeSequence& __rseq =
static_cast<_SafeSequence&
>(__rhs);
102 const_iterator* __victim =
103 static_cast<const_iterator*
>(__victim_base);
105 if (__victim->base() == __rseq._M_base().cbefore_begin())
108 if (__lhs_iterators == __victim_base)
109 __lhs_iterators = __victim_base->
_M_next;
112 __victim_base->
_M_next = __bbegin_its;
113 __bbegin_its->
_M_prior = __victim_base;
116 __last_bbegin = __victim_base;
117 __bbegin_its = __victim_base;
127 __rhs_iterators->
_M_prior = __last_bbegin;
128 __last_bbegin->
_M_next = __rhs_iterators;
130 __rhs_iterators = __bbegin_its;
134 template<
typename _SafeSequence>
136 _Safe_forward_list<_SafeSequence>::
137 _M_swap_single(_Safe_sequence_base& __other) noexcept
139 std::swap(_M_this()._M_iterators, __other._M_iterators);
140 std::swap(_M_this()._M_const_iterators, __other._M_const_iterators);
143 _Safe_iterator_base* __this_its = _M_this()._M_iterators;
144 _M_swap_aux(__other, __other._M_iterators,
145 _M_this(), _M_this()._M_iterators);
146 _Safe_iterator_base* __this_const_its = _M_this()._M_const_iterators;
147 _M_swap_aux(__other, __other._M_const_iterators,
148 _M_this(), _M_this()._M_const_iterators);
149 _M_swap_aux(_M_this(), __this_its,
150 __other, __other._M_iterators);
151 _M_swap_aux(_M_this(), __this_const_its,
152 __other, __other._M_const_iterators);
157 template<
typename _SafeSequence>
159 _Safe_forward_list<_SafeSequence>::
160 _M_swap(_Safe_sequence_base& __other) noexcept
164 __mutex *__this_mutex = &_M_this()._M_get_mutex();
165 __mutex *__other_mutex =
166 &
static_cast<_SafeSequence&
>(__other)._M_get_mutex();
167 if (__this_mutex == __other_mutex)
170 _M_swap_single(__other);
175 ? *__this_mutex : *__other_mutex);
177 ? *__other_mutex : *__this_mutex);
178 _M_swap_single(__other);
183 namespace std _GLIBCXX_VISIBILITY(default)
188 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
191 forward_list<_Tp, _Alloc>, _Alloc, __gnu_debug::_Safe_forward_list>,
192 public _GLIBCXX_STD_C::forward_list<_Tp, _Alloc>
194 typedef _GLIBCXX_STD_C::forward_list<_Tp, _Alloc>
_Base;
201 template<
typename _ItT,
typename _SeqT,
typename _CatT>
202 friend class ::__gnu_debug::_Safe_iterator;
207 _Base_ref(
const _Base& __r) : _M_ref(__r) { }
213 typedef typename _Base::reference reference;
214 typedef typename _Base::const_reference const_reference;
221 typedef typename _Base::size_type size_type;
222 typedef typename _Base::difference_type difference_type;
224 typedef _Tp value_type;
225 typedef typename _Base::allocator_type allocator_type;
226 typedef typename _Base::pointer pointer;
227 typedef typename _Base::const_pointer const_pointer;
238 :
_Base(__list, __al)
244 _Base,
const allocator_type&>::value )
250 forward_list(size_type __n,
const allocator_type& __al = allocator_type())
254 forward_list(size_type __n,
const __type_identity_t<_Tp>& __value,
255 const allocator_type& __al = allocator_type())
256 :
_Base(__n, __value, __al)
259 template<
typename _InputIterator,
260 typename = std::_RequireInputIter<_InputIterator>>
261 forward_list(_InputIterator __first, _InputIterator __last,
262 const allocator_type& __al = allocator_type())
264 __glibcxx_check_valid_constructor_range(__first, __last)),
273 const allocator_type& __al = allocator_type())
290 _Base::operator=(__il);
291 this->_M_invalidate_all();
295 template<
typename _InputIterator,
296 typename = std::_RequireInputIter<_InputIterator>>
298 assign(_InputIterator __first, _InputIterator __last)
301 __glibcxx_check_valid_range2(__first, __last, __dist);
303 if (__dist.
second >= __gnu_debug::__dp_sign)
304 _Base::assign(__gnu_debug::__unsafe(__first),
305 __gnu_debug::__unsafe(__last));
307 _Base::assign(__first, __last);
309 this->_M_invalidate_all();
313 assign(size_type __n,
const _Tp& __val)
315 _Base::assign(__n, __val);
316 this->_M_invalidate_all();
323 this->_M_invalidate_all();
326 using _Base::get_allocator;
332 before_begin() noexcept
333 {
return { _Base::before_begin(),
this }; }
337 before_begin()
const noexcept
338 {
return { _Base::before_begin(),
this }; }
343 {
return { _Base::begin(),
this }; }
347 begin()
const noexcept
348 {
return { _Base::begin(),
this }; }
353 {
return { _Base::end(),
this }; }
358 {
return { _Base::end(),
this }; }
362 cbegin()
const noexcept
363 {
return { _Base::cbegin(),
this }; }
367 cbefore_begin()
const noexcept
368 {
return { _Base::cbefore_begin(),
this }; }
372 cend()
const noexcept
373 {
return { _Base::cend(),
this }; }
376 using _Base::max_size;
384 __glibcxx_check_nonempty();
385 return _Base::front();
392 __glibcxx_check_nonempty();
393 return _Base::front();
398 using _Base::emplace_front;
399 using _Base::push_front;
404 __glibcxx_check_nonempty();
406 {
return __it == this->_M_base().cbegin(); });
410 template<
typename... _Args>
415 return { _Base::emplace_after(__pos.
base(),
416 std::forward<_Args>(__args)...),
424 return { _Base::insert_after(__pos.
base(), __val),
this };
431 return { _Base::insert_after(__pos.
base(),
std::move(__val)),
this };
435 insert_after(
const_iterator __pos, size_type __n,
const _Tp& __val)
438 return { _Base::insert_after(__pos.
base(), __n, __val),
this };
441 template<
typename _InputIterator,
442 typename = std::_RequireInputIter<_InputIterator>>
445 _InputIterator __first, _InputIterator __last)
450 if (__dist.
second >= __gnu_debug::__dp_sign)
453 _Base::insert_after(__pos.
base(),
454 __gnu_debug::__unsafe(__first),
455 __gnu_debug::__unsafe(__last)),
459 return { _Base::insert_after(__pos.
base(), __first, __last),
this };
466 return { _Base::insert_after(__pos.
base(), __il),
this };
476 {
return __it == __next; });
477 return { _Base::erase_after(__pos.
base()),
this };
485 __victim != __last.
base(); ++__victim)
487 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::cend(),
488 _M_message(__gnu_debug::__msg_valid_range2)
489 ._M_sequence(*
this,
"this")
490 ._M_iterator(__pos,
"pos")
491 ._M_iterator(__last,
"last"));
493 {
return __it == __victim; });
496 return { _Base::erase_after(__pos.
base(), __last.
base()),
this };
501 noexcept( noexcept(declval<_Base&>().swap(__list)) )
503 _Safe::_M_swap(__list);
508 resize(size_type __sz)
510 this->_M_detach_singular();
515 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
518 for (; __victim != __end; ++__victim)
521 {
return __it == __victim; });
530 this->_M_revalidate_singular();
531 __throw_exception_again;
536 resize(size_type __sz,
const value_type& __val)
538 this->_M_detach_singular();
543 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
546 for (; __victim != __end; ++__victim)
549 {
return __it == __victim; });
554 _Base::resize(__sz, __val);
558 this->_M_revalidate_singular();
559 __throw_exception_again;
567 this->_M_invalidate_all();
576 _M_message(__gnu_debug::__msg_self_splice)
577 ._M_sequence(*
this,
"this"));
578 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
579 _M_message(__gnu_debug::__msg_splice_alloc)
581 ._M_sequence(__list,
"__list"));
584 return __it != __list._M_base().cbefore_begin()
585 && __it != __list._M_base().end();
592 { splice_after(__pos,
std::move(__list)); }
600 _M_message(__gnu_debug::__msg_splice_bad)
601 ._M_iterator(__i,
"__i"));
603 _M_message(__gnu_debug::__msg_splice_other)
604 ._M_iterator(__i,
"__i")
605 ._M_sequence(__list,
"__list"));
606 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
607 _M_message(__gnu_debug::__msg_splice_alloc)
609 ._M_sequence(__list,
"__list"));
615 {
return __it == __next; });
622 { splice_after(__pos,
std::move(__list), __i); }
631 __glibcxx_check_valid_fl_range(__before, __last, __dist);
633 _M_message(__gnu_debug::__msg_splice_other)
634 ._M_sequence(__list,
"list")
635 ._M_iterator(__before,
"before"));
638 _M_message(__gnu_debug::__msg_valid_range2)
639 ._M_sequence(__list,
"list")
640 ._M_iterator(__before,
"before")
641 ._M_iterator(__last,
"last"));
642 _GLIBCXX_DEBUG_VERIFY(__before != __last,
643 _M_message(__gnu_debug::__msg_valid_range2)
644 ._M_sequence(__list,
"list")
645 ._M_iterator(__before,
"before")
646 ._M_iterator(__last,
"last"));
647 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
648 _M_message(__gnu_debug::__msg_splice_alloc)
650 ._M_sequence(__list,
"__list"));
653 __tmp != __last.
base(); ++__tmp)
655 _GLIBCXX_DEBUG_VERIFY(__tmp != __list._M_base().end(),
656 _M_message(__gnu_debug::__msg_valid_range2)
657 ._M_sequence(__list,
"list")
658 ._M_iterator(__before,
"before")
659 ._M_iterator(__last,
"last"));
660 _GLIBCXX_DEBUG_VERIFY(__listptr !=
this || __tmp != __pos.
base(),
661 _M_message(__gnu_debug::__msg_splice_overlap)
662 ._M_iterator(__tmp,
"position")
663 ._M_iterator(__before,
"before")
664 ._M_iterator(__last,
"last"));
668 {
return __it == __tmp; });
678 { splice_after(__pos,
std::move(__list), __before, __last); }
681 #if __cplusplus > 201703L
682 using __remove_return_type = size_type;
683 # define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG \
684 __attribute__((__abi_tag__("__cxx20")))
685 # define _GLIBCXX20_ONLY(__expr) __expr
687 using __remove_return_type = void;
688 # define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
689 # define _GLIBCXX20_ONLY(__expr)
693 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
695 remove(
const _Tp& __val)
697 if (!this->_M_iterators && !this->_M_const_iterators)
698 return _Base::remove(__val);
700 size_type __removed __attribute__((__unused__)) = 0;
701 _Base __to_destroy(get_allocator());
704 while (__x != _Base::cend())
710 {
return __it == __next; });
711 __to_destroy.splice_after(__to_destroy.cbefore_begin(),
714 _GLIBCXX20_ONLY( __removed++ );
720 return _GLIBCXX20_ONLY( __removed );
723 template<
typename _Pred>
725 remove_if(_Pred __pred)
727 if (!this->_M_iterators && !this->_M_const_iterators)
728 return _Base::remove_if(__pred);
730 size_type __removed __attribute__((__unused__)) = 0;
731 _Base __to_destroy(get_allocator());
734 while (__x != _Base::end())
739 {
return __it == __x; });
740 __to_destroy.splice_after(__to_destroy.cbefore_begin(),
743 _GLIBCXX20_ONLY( __removed++ );
749 return _GLIBCXX20_ONLY( __removed );
752 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
757 template<
typename _BinPred>
759 unique(_BinPred __binary_pred)
761 if (!this->_M_iterators && !this->_M_const_iterators)
762 return _Base::unique(__binary_pred);
766 if (__first == __last)
767 return _GLIBCXX20_ONLY(0);
769 size_type __removed __attribute__((__unused__)) = 0;
770 _Base __to_destroy(get_allocator());
772 while (__next != __last)
774 if (__binary_pred(*__first, *__next))
777 {
return __it == __next; });
778 __to_destroy.splice_after(__to_destroy.cbefore_begin(),
781 _GLIBCXX20_ONLY( __removed++ );
787 return _GLIBCXX20_ONLY( __removed );
790 #undef _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
791 #undef _GLIBCXX20_ONLY
798 __glibcxx_check_sorted(_Base::begin(), _Base::end());
799 __glibcxx_check_sorted(__list._M_base().begin(),
800 __list._M_base().end());
803 return __it != __list._M_base().cbefore_begin()
804 && __it != __list._M_base().cend();
814 template<
typename _Comp>
822 __list._M_base().end(), __comp);
823 this->_M_transfer_from_if(__list,
826 return __it != __list._M_base().cbefore_begin()
827 && __it != __list._M_base().cend();
833 template<
typename _Comp>
839 using _Base::reverse;
842 _M_base() noexcept {
return *
this; }
845 _M_base()
const noexcept {
return *
this; }
848 #if __cpp_deduction_guides >= 201606
849 template<
typename _InputIterator,
typename _ValT
852 typename = _RequireInputIter<_InputIterator>,
853 typename = _RequireAllocator<_Allocator>>
854 forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
857 template<
typename _Tp,
typename _Allocator = allocator<_Tp>,
858 typename = _RequireAllocator<_Allocator>>
863 template<
typename _Tp,
typename _Alloc>
867 {
return __lx._M_base() == __ly._M_base(); }
869 #if __cpp_lib_three_way_comparison
870 template<
typename _Tp,
typename _Alloc>
871 constexpr __detail::__synth3way_t<_Tp>
874 {
return __x._M_base() <=> __y._M_base(); }
876 template<
typename _Tp,
typename _Alloc>
878 operator<(
const forward_list<_Tp, _Alloc>& __lx,
879 const forward_list<_Tp, _Alloc>& __ly)
880 {
return __lx._M_base() < __ly._M_base(); }
882 template<
typename _Tp,
typename _Alloc>
884 operator!=(
const forward_list<_Tp, _Alloc>& __lx,
885 const forward_list<_Tp, _Alloc>& __ly)
886 {
return !(__lx == __ly); }
889 template<
typename _Tp,
typename _Alloc>
893 {
return (__ly < __lx); }
896 template<
typename _Tp,
typename _Alloc>
900 {
return !(__lx < __ly); }
903 template<
typename _Tp,
typename _Alloc>
907 {
return !(__ly < __lx); }
911 template<
typename _Tp,
typename _Alloc>
914 noexcept(noexcept(__lx.swap(__ly)))
922 template<
typename _Tp,
typename _Alloc>
923 struct _BeforeBeginHelper<
std::__debug::forward_list<_Tp, _Alloc> >
927 template<
typename _Iterator>
929 _S_Is(
const _Safe_iterator<_Iterator, _Sequence>& __it)
932 __it.base() == __it._M_get_sequence()->_M_base().before_begin();
935 template<
typename _Iterator>
937 _S_Is_Beginnest(
const _Safe_iterator<_Iterator, _Sequence>& __it)
938 {
return _S_Is(__it); }
941 template<
typename _Tp,
typename _Alloc>
942 struct _Sequence_traits<
std::__debug::forward_list<_Tp, _Alloc> >
946 static typename _Distance_traits<_It>::__type
950 ? std::make_pair(0, __dp_exact) :
std::make_pair(1, __dp_sign);
954 #ifndef _GLIBCXX_DEBUG_PEDANTIC
955 template<
class _Tp,
class _Alloc>
956 struct _Insert_range_from_self_is_safe<
957 std::__debug::forward_list<_Tp, _Alloc> >
958 {
enum { __value = 1 }; };
#define __glibcxx_check_insert_after(_Position)
#define __glibcxx_check_erase_after(_Position)
#define __glibcxx_check_sorted_pred(_First, _Last, _Pred)
#define __glibcxx_check_insert_range_after(_Position, _First, _Last, _Dist)
#define __glibcxx_check_erase_range_after(_First, _Last)
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
ISO C++ entities toplevel namespace is std.
GNU extensions for public use.
GNU debug classes for public use.
constexpr _Iterator __base(_Iterator __it)
void swap(forward_list< _Tp, _Alloc > &__lx, forward_list< _Tp, _Alloc > &__ly) noexcept(noexcept(__lx.swap(__ly)))
See std::forward_list::swap().
The standard allocator, as per C++03 [20.4.1].
bool _M_dereferenceable() const
Is the iterator dereferenceable?
_Iterator & base() noexcept
Return the underlying iterator.
bool _M_before_dereferenceable() const
Is the iterator before a dereferenceable one?
bool _M_is_before_begin() const
Is this iterator equal to the sequence's before_begin() iterator if any?
Traits class for iterators.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
One of the comparison functors.
Struct holding two objects of arbitrary type.
_T2 second
The second member.
Base class for constructing a safe sequence type that tracks iterators that reference it.
void _M_invalidate_if(_Predicate __pred)
Basic functionality for a safe iterator.
_Safe_sequence_base * _M_sequence
bool _M_attached_to(const _Safe_sequence_base *__seq) const
_Safe_iterator_base * _M_prior
_Safe_iterator_base * _M_next
Base class that supports tracking of iterators that reference a sequence.
Safe class dealing with some allocator dependent operations.
Class std::forward_list with safety/checking/debug instrumentation.
Special iterators swap and invalidation for forward_list because of the before_begin iterator.