29 #ifndef _GLIBCXX_DEBUG_FORWARD_LIST
30 #define _GLIBCXX_DEBUG_FORWARD_LIST 1
32 #ifdef _GLIBCXX_SYSHDR
33 #pragma GCC system_header
37 namespace std _GLIBCXX_VISIBILITY(default) {
namespace __debug {
38 template<
typename _Tp,
typename _Allocator>
class forward_list;
47 #define __glibcxx_check_valid_fl_range(_First,_Last,_Dist) \
48 _GLIBCXX_DEBUG_VERIFY(_First._M_valid_range(_Last, _Dist, false), \
49 _M_message(__gnu_debug::__msg_valid_range) \
50 ._M_iterator(_First, #_First) \
51 ._M_iterator(_Last, #_Last))
57 template<
typename _SafeSequence>
62 _M_this()
const noexcept
63 {
return static_cast<const _SafeSequence*
>(
this); }
75 _M_invalidate_all()
const
77 using _Base_const_iterator = __decltype(_M_this()->_M_base().cend());
80 return __it != _M_this()->_M_base().cbefore_begin()
81 && __it != _M_this()->_M_base().cend(); });
88 template<
typename _SafeSequence>
96 using const_iterator =
typename _SafeSequence::const_iterator;
104 const_iterator* __victim =
105 static_cast<const_iterator*
>(__victim_base);
107 if (__victim->base() == __rhs._M_this()->_M_base().cbefore_begin())
110 if (__lhs_iterators == __victim_base)
111 __lhs_iterators = __victim_base->
_M_next;
114 __victim_base->
_M_next = __bbegin_its;
115 __bbegin_its->
_M_prior = __victim_base;
118 __last_bbegin = __victim_base;
119 __bbegin_its = __victim_base;
129 __rhs_iterators->
_M_prior = __last_bbegin;
130 __last_bbegin->
_M_next = __rhs_iterators;
132 __rhs_iterators = __bbegin_its;
136 template<
typename _SafeSequence>
138 _Safe_forward_list<_SafeSequence>::
139 _M_swap_single(
const _Safe_forward_list& __other)
const noexcept
141 std::swap(_M_this()->_M_iterators, __other._M_iterators);
142 std::swap(_M_this()->_M_const_iterators, __other._M_const_iterators);
145 _Safe_iterator_base* __this_its = _M_this()->_M_iterators;
146 _S_swap_aux(__other, __other._M_iterators,
147 *_M_this(), _M_this()->_M_iterators);
148 _Safe_iterator_base* __this_const_its = _M_this()->_M_const_iterators;
149 _S_swap_aux(__other, __other._M_const_iterators,
150 *_M_this(), _M_this()->_M_const_iterators);
151 _S_swap_aux(*_M_this(), __this_its,
152 __other, __other._M_iterators);
153 _S_swap_aux(*_M_this(), __this_const_its,
154 __other, __other._M_const_iterators);
159 template<
typename _SafeSequence>
161 _Safe_forward_list<_SafeSequence>::
162 _M_swap(
const _Safe_forward_list& __other)
const noexcept
166 __mutex *__this_mutex = &_M_this()->_M_get_mutex();
167 __mutex *__other_mutex = &__other._M_get_mutex();
168 if (__this_mutex == __other_mutex)
171 _M_swap_single(__other);
176 ? *__this_mutex : *__other_mutex);
178 ? *__other_mutex : *__this_mutex);
179 _M_swap_single(__other);
184 namespace std _GLIBCXX_VISIBILITY(default)
189 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
192 forward_list<_Tp, _Alloc>, _Alloc, __gnu_debug::_Safe_forward_list>,
193 public _GLIBCXX_STD_C::forward_list<_Tp, _Alloc>
195 typedef _GLIBCXX_STD_C::forward_list<_Tp, _Alloc>
_Base;
202 template<
typename _ItT,
typename _SeqT,
typename _CatT>
203 friend class ::__gnu_debug::_Safe_iterator;
208 _Base_ref(
const _Base& __r) : _M_ref(__r) { }
214 typedef typename _Base::reference reference;
215 typedef typename _Base::const_reference const_reference;
222 typedef typename _Base::size_type size_type;
223 typedef typename _Base::difference_type difference_type;
225 typedef _Tp value_type;
226 typedef typename _Base::allocator_type allocator_type;
227 typedef typename _Base::pointer pointer;
228 typedef typename _Base::const_pointer const_pointer;
239 :
_Base(__list, __al)
245 _Base,
const allocator_type&>::value )
251 forward_list(size_type __n,
const allocator_type& __al = allocator_type())
255 forward_list(size_type __n,
const __type_identity_t<_Tp>& __value,
256 const allocator_type& __al = allocator_type())
257 :
_Base(__n, __value, __al)
260 template<
typename _InputIterator,
261 typename = std::_RequireInputIter<_InputIterator>>
262 forward_list(_InputIterator __first, _InputIterator __last,
263 const allocator_type& __al = allocator_type())
265 __glibcxx_check_valid_constructor_range(__first, __last)),
269 #if __glibcxx_containers_ranges
270 template<__detail::__container_compatible_range<_Tp> _Rg>
271 forward_list(from_range_t, _Rg&& __rg,
const _Alloc& __a = _Alloc())
272 :
_Base(std::from_range, std::forward<_Rg>(__rg), __a)
281 const allocator_type& __al = allocator_type())
298 _Base::operator=(__il);
299 this->_M_invalidate_all();
303 template<
typename _InputIterator,
304 typename = std::_RequireInputIter<_InputIterator>>
306 assign(_InputIterator __first, _InputIterator __last)
309 __glibcxx_check_valid_range2(__first, __last, __dist);
311 if (__dist.
second >= __gnu_debug::__dp_sign)
312 _Base::assign(__gnu_debug::__unsafe(__first),
313 __gnu_debug::__unsafe(__last));
315 _Base::assign(__first, __last);
317 this->_M_invalidate_all();
320 #if __glibcxx_containers_ranges
321 template<__detail::__container_compatible_range<_Tp> _Rg>
323 assign_range(_Rg&& __rg)
330 auto __first = ranges::begin(__rg);
331 const auto __last = ranges::end(__rg);
332 auto __prev = _Base::before_begin();
333 auto __curr = _Base::begin();
334 const auto __end = _Base::end();
336 while (__curr != __end && __first != __last)
347 _Base::insert_range_after(__prev,
354 assign(size_type __n,
const _Tp& __val)
356 _Base::assign(__n, __val);
357 this->_M_invalidate_all();
364 this->_M_invalidate_all();
367 using _Base::get_allocator;
373 before_begin() noexcept
374 {
return { _Base::before_begin(),
this }; }
378 before_begin()
const noexcept
379 {
return { _Base::before_begin(),
this }; }
384 {
return { _Base::begin(),
this }; }
388 begin()
const noexcept
389 {
return { _Base::begin(),
this }; }
394 {
return { _Base::end(),
this }; }
399 {
return { _Base::end(),
this }; }
403 cbegin()
const noexcept
404 {
return { _Base::cbegin(),
this }; }
408 cbefore_begin()
const noexcept
409 {
return { _Base::cbefore_begin(),
this }; }
413 cend()
const noexcept
414 {
return { _Base::cend(),
this }; }
417 using _Base::max_size;
425 __glibcxx_check_nonempty();
426 return _Base::front();
433 __glibcxx_check_nonempty();
434 return _Base::front();
439 using _Base::emplace_front;
440 using _Base::push_front;
442 #if __glibcxx_containers_ranges
443 using _Base::prepend_range;
449 __glibcxx_check_nonempty();
451 {
return __it == this->_M_base().cbegin(); });
455 template<
typename... _Args>
460 return { _Base::emplace_after(__pos.
base(),
461 std::forward<_Args>(__args)...),
469 return { _Base::insert_after(__pos.
base(), __val),
this };
476 return { _Base::insert_after(__pos.
base(),
std::move(__val)),
this };
480 insert_after(
const_iterator __pos, size_type __n,
const _Tp& __val)
483 return { _Base::insert_after(__pos.
base(), __n, __val),
this };
486 template<
typename _InputIterator,
487 typename = std::_RequireInputIter<_InputIterator>>
490 _InputIterator __first, _InputIterator __last)
495 if (__dist.
second >= __gnu_debug::__dp_sign)
498 _Base::insert_after(__pos.
base(),
499 __gnu_debug::__unsafe(__first),
500 __gnu_debug::__unsafe(__last)),
504 return { _Base::insert_after(__pos.
base(), __first, __last),
this };
511 return { _Base::insert_after(__pos.
base(), __il),
this };
514 #if __glibcxx_containers_ranges
515 template<__detail::__container_compatible_range<_Tp> _Rg>
520 = _Base::insert_range_after(__position.
base(),
521 std::forward<_Rg>(__rg));
522 return { __ret,
this };
533 {
return __it == __next; });
534 return { _Base::erase_after(__pos.
base()),
this };
542 __victim != __last.
base(); ++__victim)
544 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::cend(),
545 _M_message(__gnu_debug::__msg_valid_range2)
546 ._M_sequence(*
this,
"this")
547 ._M_iterator(__pos,
"pos")
548 ._M_iterator(__last,
"last"));
550 {
return __it == __victim; });
553 return { _Base::erase_after(__pos.
base(), __last.
base()),
this };
558 noexcept( noexcept(declval<_Base&>().swap(__list)) )
560 _Safe::_M_swap(__list);
565 resize(size_type __sz)
573 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
576 for (; __victim != __end; ++__victim)
579 {
return __it == __victim; });
589 __throw_exception_again;
594 resize(size_type __sz,
const value_type& __val)
602 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
605 for (; __victim != __end; ++__victim)
608 {
return __it == __victim; });
613 _Base::resize(__sz, __val);
618 __throw_exception_again;
626 this->_M_invalidate_all();
635 _M_message(__gnu_debug::__msg_self_splice)
636 ._M_sequence(*
this,
"this"));
637 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
638 _M_message(__gnu_debug::__msg_splice_alloc)
640 ._M_sequence(__list,
"__list"));
643 return __it != __list._M_base().cbefore_begin()
644 && __it != __list._M_base().end();
651 { splice_after(__pos,
std::move(__list)); }
659 _M_message(__gnu_debug::__msg_splice_bad)
660 ._M_iterator(__i,
"__i"));
662 _M_message(__gnu_debug::__msg_splice_other)
663 ._M_iterator(__i,
"__i")
664 ._M_sequence(__list,
"__list"));
665 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
666 _M_message(__gnu_debug::__msg_splice_alloc)
668 ._M_sequence(__list,
"__list"));
674 {
return __it == __next; });
681 { splice_after(__pos,
std::move(__list), __i); }
690 __glibcxx_check_valid_fl_range(__before, __last, __dist);
692 _M_message(__gnu_debug::__msg_splice_other)
693 ._M_sequence(__list,
"list")
694 ._M_iterator(__before,
"before"));
697 _M_message(__gnu_debug::__msg_valid_range2)
698 ._M_sequence(__list,
"list")
699 ._M_iterator(__before,
"before")
700 ._M_iterator(__last,
"last"));
701 _GLIBCXX_DEBUG_VERIFY(__before != __last,
702 _M_message(__gnu_debug::__msg_valid_range2)
703 ._M_sequence(__list,
"list")
704 ._M_iterator(__before,
"before")
705 ._M_iterator(__last,
"last"));
706 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
707 _M_message(__gnu_debug::__msg_splice_alloc)
709 ._M_sequence(__list,
"__list"));
712 __tmp != __last.
base(); ++__tmp)
714 _GLIBCXX_DEBUG_VERIFY(__tmp != __list._M_base().end(),
715 _M_message(__gnu_debug::__msg_valid_range2)
716 ._M_sequence(__list,
"list")
717 ._M_iterator(__before,
"before")
718 ._M_iterator(__last,
"last"));
719 _GLIBCXX_DEBUG_VERIFY(__listptr !=
this || __tmp != __pos.
base(),
720 _M_message(__gnu_debug::__msg_splice_overlap)
721 ._M_iterator(__tmp,
"position")
722 ._M_iterator(__before,
"before")
723 ._M_iterator(__last,
"last"));
727 {
return __it == __tmp; });
737 { splice_after(__pos,
std::move(__list), __before, __last); }
740 #if __cplusplus > 201703L
741 using __remove_return_type = size_type;
742 # define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG \
743 __attribute__((__abi_tag__("__cxx20")))
744 # define _GLIBCXX20_ONLY(__expr) __expr
746 using __remove_return_type = void;
747 # define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
748 # define _GLIBCXX20_ONLY(__expr)
752 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
754 remove(
const _Tp& __val)
756 if (!this->_M_iterators && !this->_M_const_iterators)
757 return _Base::remove(__val);
759 size_type __removed __attribute__((__unused__)) = 0;
760 _Base __to_destroy(get_allocator());
763 while (__x != _Base::cend())
769 {
return __it == __next; });
770 __to_destroy.splice_after(__to_destroy.cbefore_begin(),
773 _GLIBCXX20_ONLY( __removed++ );
779 return _GLIBCXX20_ONLY( __removed );
782 template<
typename _Pred>
784 remove_if(_Pred __pred)
786 if (!this->_M_iterators && !this->_M_const_iterators)
787 return _Base::remove_if(__pred);
789 size_type __removed __attribute__((__unused__)) = 0;
790 _Base __to_destroy(get_allocator());
793 while (__x != _Base::end())
798 {
return __it == __x; });
799 __to_destroy.splice_after(__to_destroy.cbefore_begin(),
802 _GLIBCXX20_ONLY( __removed++ );
808 return _GLIBCXX20_ONLY( __removed );
811 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
816 template<
typename _BinPred>
818 unique(_BinPred __binary_pred)
820 if (!this->_M_iterators && !this->_M_const_iterators)
821 return _Base::unique(__binary_pred);
825 if (__first == __last)
826 return _GLIBCXX20_ONLY(0);
828 size_type __removed __attribute__((__unused__)) = 0;
829 _Base __to_destroy(get_allocator());
831 while (__next != __last)
833 if (__binary_pred(*__first, *__next))
836 {
return __it == __next; });
837 __to_destroy.splice_after(__to_destroy.cbefore_begin(),
840 _GLIBCXX20_ONLY( __removed++ );
846 return _GLIBCXX20_ONLY( __removed );
849 #undef _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
850 #undef _GLIBCXX20_ONLY
857 __glibcxx_check_sorted(_Base::begin(), _Base::end());
858 __glibcxx_check_sorted(__list._M_base().begin(),
859 __list._M_base().end());
862 return __it != __list._M_base().cbefore_begin()
863 && __it != __list._M_base().cend();
873 template<
typename _Comp>
881 __list._M_base().end(), __comp);
882 this->_M_transfer_from_if(__list,
885 return __it != __list._M_base().cbefore_begin()
886 && __it != __list._M_base().cend();
892 template<
typename _Comp>
898 using _Base::reverse;
901 _M_base() noexcept {
return *
this; }
904 _M_base()
const noexcept {
return *
this; }
907 #if __cpp_deduction_guides >= 201606
908 template<
typename _InputIterator,
typename _ValT
911 typename = _RequireInputIter<_InputIterator>,
912 typename = _RequireAllocator<_Allocator>>
913 forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
916 template<
typename _Tp,
typename _Allocator = allocator<_Tp>,
917 typename = _RequireAllocator<_Allocator>>
921 #if __glibcxx_containers_ranges
922 template<ranges::input_range _Rg,
924 forward_list(from_range_t, _Rg&&, _Allocator = _Allocator())
929 template<
typename _Tp,
typename _Alloc>
933 {
return __lx._M_base() == __ly._M_base(); }
935 #if __cpp_lib_three_way_comparison
936 template<
typename _Tp,
typename _Alloc>
937 constexpr __detail::__synth3way_t<_Tp>
940 {
return __x._M_base() <=> __y._M_base(); }
942 template<
typename _Tp,
typename _Alloc>
944 operator<(
const forward_list<_Tp, _Alloc>& __lx,
945 const forward_list<_Tp, _Alloc>& __ly)
946 {
return __lx._M_base() < __ly._M_base(); }
948 template<
typename _Tp,
typename _Alloc>
950 operator!=(
const forward_list<_Tp, _Alloc>& __lx,
951 const forward_list<_Tp, _Alloc>& __ly)
952 {
return !(__lx == __ly); }
955 template<
typename _Tp,
typename _Alloc>
957 operator>(
const forward_list<_Tp, _Alloc>& __lx,
958 const forward_list<_Tp, _Alloc>& __ly)
959 {
return (__ly < __lx); }
962 template<
typename _Tp,
typename _Alloc>
964 operator>=(
const forward_list<_Tp, _Alloc>& __lx,
965 const forward_list<_Tp, _Alloc>& __ly)
966 {
return !(__lx < __ly); }
969 template<
typename _Tp,
typename _Alloc>
971 operator<=(
const forward_list<_Tp, _Alloc>& __lx,
972 const forward_list<_Tp, _Alloc>& __ly)
973 {
return !(__ly < __lx); }
977 template<
typename _Tp,
typename _Alloc>
980 noexcept(noexcept(__lx.swap(__ly)))
985 #ifdef __glibcxx_erase_if
986 _GLIBCXX_BEGIN_NAMESPACE_VERSION
987 template<
typename _Tp,
typename _Alloc,
typename _Predicate>
988 inline typename __debug::forward_list<_Tp, _Alloc>::size_type
989 erase_if(__debug::forward_list<_Tp, _Alloc>&
__cont, _Predicate __pred)
990 {
return __cont.remove_if(__pred); }
992 template<
typename _Tp,
typename _Alloc,
993 typename _Up _GLIBCXX26_DEF_VAL_T(_Tp)>
994 inline typename __debug::forward_list<_Tp, _Alloc>::size_type
995 erase(__debug::forward_list<_Tp, _Alloc>&
__cont,
const _Up& __value)
999 return std::erase_if(
__cont, [&](
const auto& __elem) ->
bool {
1000 return __elem == __value;
1003 _GLIBCXX_END_NAMESPACE_VERSION
1009 template<
typename _Tp,
typename _Alloc>
1010 struct _BeforeBeginHelper<
std::__debug::forward_list<_Tp, _Alloc> >
1014 template<
typename _Iterator>
1016 _S_Is(
const _Safe_iterator<_Iterator, _Sequence>& __it)
1019 __it.base() == __it._M_get_sequence()->_M_base().before_begin();
1022 template<
typename _Iterator>
1024 _S_Is_Beginnest(
const _Safe_iterator<_Iterator, _Sequence>& __it)
1025 {
return _S_Is(__it); }
1028 template<
typename _Tp,
typename _Alloc>
1029 struct _Sequence_traits<
std::__debug::forward_list<_Tp, _Alloc> >
1033 static typename _Distance_traits<_It>::__type
1036 return __seq.empty()
1037 ? std::make_pair(0, __dp_exact) :
std::make_pair(1, __dp_sign);
1041 #ifndef _GLIBCXX_DEBUG_PEDANTIC
1042 template<
class _Tp,
class _Alloc>
1043 struct _Insert_range_from_self_is_safe<
1044 std::__debug::forward_list<_Tp, _Alloc> >
1045 {
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 bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
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.
ISO C++ entities toplevel namespace is std.
concept assignable_from
[concept.assignable], concept assignable_from
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?
constexpr _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?
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
Traits class for iterators.
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.
constexpr void _M_invalidate_if(_Predicate __pred) const
Basic functionality for a safe iterator.
void _M_unlink() noexcept
bool _M_attached_to(const _Safe_sequence_base *__seq) const
const _Safe_sequence_base * _M_sequence
_Safe_iterator_base * _M_prior
_Safe_iterator_base * _M_next
void _M_detach_singular() const
void _M_revalidate_singular() const
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.