1 // <forward_list> -*- C++ -*-
3 // Copyright (C) 2010-2021 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file debug/forward_list
26 * This file is a GNU debug extension to the Standard C++ Library.
29 #ifndef _GLIBCXX_DEBUG_FORWARD_LIST
30 #define _GLIBCXX_DEBUG_FORWARD_LIST 1
32 #pragma GCC system_header
34 #include <bits/c++config.h>
35 namespace std _GLIBCXX_VISIBILITY(default) { namespace __debug {
36 template<typename _Tp, typename _Allocator> class forward_list;
37 } } // namespace std::__debug
39 #include <forward_list>
40 #include <debug/safe_sequence.h>
41 #include <debug/safe_container.h>
42 #include <debug/safe_iterator.h>
44 // Special validity check for forward_list ranges.
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))
53 /// Special iterators swap and invalidation for forward_list because of the
54 /// before_begin iterator.
55 template<typename _SafeSequence>
56 class _Safe_forward_list
57 : public _Safe_sequence<_SafeSequence>
61 { return *static_cast<_SafeSequence*>(this); }
64 _M_swap_aux(_Safe_sequence_base& __lhs,
65 _Safe_iterator_base*& __lhs_iterators,
66 _Safe_sequence_base& __rhs,
67 _Safe_iterator_base*& __rhs_iterators);
69 void _M_swap_single(_Safe_sequence_base&) noexcept;
75 using _Base_const_iterator = __decltype(_M_this()._M_base().cend());
76 this->_M_invalidate_if([this](_Base_const_iterator __it)
78 return __it != _M_this()._M_base().cbefore_begin()
79 && __it != _M_this()._M_base().cend(); });
82 void _M_swap(_Safe_sequence_base&) noexcept;
85 template<typename _SafeSequence>
87 _Safe_forward_list<_SafeSequence>::
88 _M_swap_aux(_Safe_sequence_base& __lhs,
89 _Safe_iterator_base*& __lhs_iterators,
90 _Safe_sequence_base& __rhs,
91 _Safe_iterator_base*& __rhs_iterators)
93 using const_iterator = typename _SafeSequence::const_iterator;
94 _Safe_iterator_base* __bbegin_its = 0;
95 _Safe_iterator_base* __last_bbegin = 0;
96 _SafeSequence& __rseq = static_cast<_SafeSequence&>(__rhs);
98 for (_Safe_iterator_base* __iter = __lhs_iterators; __iter;)
100 // Even iterator is cast to const_iterator, not a problem.
101 _Safe_iterator_base* __victim_base = __iter;
102 const_iterator* __victim =
103 static_cast<const_iterator*>(__victim_base);
104 __iter = __iter->_M_next;
105 if (__victim->base() == __rseq._M_base().cbefore_begin())
107 __victim->_M_unlink();
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;
120 __victim_base->_M_sequence = std::__addressof(__lhs);
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);
141 // Useless, always 1 on forward_list
142 //std::swap(_M_this()_M_version, __other._M_version);
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);
155 /* Special forward_list _M_swap version that does not swap the
156 * before-begin ownership.*/
157 template<typename _SafeSequence>
159 _Safe_forward_list<_SafeSequence>::
160 _M_swap(_Safe_sequence_base& __other) noexcept
162 // We need to lock both sequences to swap
163 using namespace __gnu_cxx;
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)
169 __scoped_lock __lock(*__this_mutex);
170 _M_swap_single(__other);
174 __scoped_lock __l1(__this_mutex < __other_mutex
175 ? *__this_mutex : *__other_mutex);
176 __scoped_lock __l2(__this_mutex < __other_mutex
177 ? *__other_mutex : *__this_mutex);
178 _M_swap_single(__other);
183 namespace std _GLIBCXX_VISIBILITY(default)
187 /// Class std::forward_list with safety/checking/debug instrumentation.
188 template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
190 : public __gnu_debug::_Safe_container<
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;
195 typedef __gnu_debug::_Safe_container<
196 forward_list, _Alloc, __gnu_debug::_Safe_forward_list> _Safe;
198 typedef typename _Base::iterator _Base_iterator;
199 typedef typename _Base::const_iterator _Base_const_iterator;
201 template<typename _ItT, typename _SeqT, typename _CatT>
202 friend class ::__gnu_debug::_Safe_iterator;
204 // Reference wrapper for base class. See PR libstdc++/90102.
207 _Base_ref(const _Base& __r) : _M_ref(__r) { }
213 typedef typename _Base::reference reference;
214 typedef typename _Base::const_reference const_reference;
216 typedef __gnu_debug::_Safe_iterator<
217 _Base_iterator, forward_list> iterator;
218 typedef __gnu_debug::_Safe_iterator<
219 _Base_const_iterator, forward_list> const_iterator;
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;
229 // 23.2.3.1 construct/copy/destroy:
231 forward_list() = default;
234 forward_list(const allocator_type& __al) noexcept
237 forward_list(const forward_list& __list, const allocator_type& __al)
238 : _Base(__list, __al)
241 forward_list(forward_list&& __list, const allocator_type& __al)
242 : _Safe(std::move(__list._M_safe()), __al),
243 _Base(std::move(__list._M_base()), __al)
247 forward_list(size_type __n, const allocator_type& __al = allocator_type())
251 forward_list(size_type __n, const _Tp& __value,
252 const allocator_type& __al = allocator_type())
253 : _Base(__n, __value, __al)
256 template<typename _InputIterator,
257 typename = std::_RequireInputIter<_InputIterator>>
258 forward_list(_InputIterator __first, _InputIterator __last,
259 const allocator_type& __al = allocator_type())
260 : _Base(__gnu_debug::__base(
261 __glibcxx_check_valid_constructor_range(__first, __last)),
262 __gnu_debug::__base(__last), __al)
265 forward_list(const forward_list&) = default;
267 forward_list(forward_list&&) = default;
269 forward_list(std::initializer_list<_Tp> __il,
270 const allocator_type& __al = allocator_type())
274 ~forward_list() = default;
276 forward_list(_Base_ref __x) : _Base(__x._M_ref) { }
279 operator=(const forward_list&) = default;
282 operator=(forward_list&&) = default;
285 operator=(std::initializer_list<_Tp> __il)
288 this->_M_invalidate_all();
292 template<typename _InputIterator,
293 typename = std::_RequireInputIter<_InputIterator>>
295 assign(_InputIterator __first, _InputIterator __last)
297 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
298 __glibcxx_check_valid_range2(__first, __last, __dist);
300 if (__dist.second >= __gnu_debug::__dp_sign)
301 _Base::assign(__gnu_debug::__unsafe(__first),
302 __gnu_debug::__unsafe(__last));
304 _Base::assign(__first, __last);
306 this->_M_invalidate_all();
310 assign(size_type __n, const _Tp& __val)
312 _Base::assign(__n, __val);
313 this->_M_invalidate_all();
317 assign(std::initializer_list<_Tp> __il)
320 this->_M_invalidate_all();
323 using _Base::get_allocator;
328 before_begin() noexcept
329 { return { _Base::before_begin(), this }; }
332 before_begin() const noexcept
333 { return { _Base::before_begin(), this }; }
337 { return { _Base::begin(), this }; }
340 begin() const noexcept
341 { return { _Base::begin(), this }; }
345 { return { _Base::end(), this }; }
349 { return { _Base::end(), this }; }
352 cbegin() const noexcept
353 { return { _Base::cbegin(), this }; }
356 cbefore_begin() const noexcept
357 { return { _Base::cbefore_begin(), this }; }
360 cend() const noexcept
361 { return { _Base::cend(), this }; }
364 using _Base::max_size;
371 __glibcxx_check_nonempty();
372 return _Base::front();
378 __glibcxx_check_nonempty();
379 return _Base::front();
384 using _Base::emplace_front;
385 using _Base::push_front;
390 __glibcxx_check_nonempty();
391 this->_M_invalidate_if([this](_Base_const_iterator __it)
392 { return __it == this->_M_base().cbegin(); });
396 template<typename... _Args>
398 emplace_after(const_iterator __pos, _Args&&... __args)
400 __glibcxx_check_insert_after(__pos);
401 return { _Base::emplace_after(__pos.base(),
402 std::forward<_Args>(__args)...),
407 insert_after(const_iterator __pos, const _Tp& __val)
409 __glibcxx_check_insert_after(__pos);
410 return { _Base::insert_after(__pos.base(), __val), this };
414 insert_after(const_iterator __pos, _Tp&& __val)
416 __glibcxx_check_insert_after(__pos);
417 return { _Base::insert_after(__pos.base(), std::move(__val)), this };
421 insert_after(const_iterator __pos, size_type __n, const _Tp& __val)
423 __glibcxx_check_insert_after(__pos);
424 return { _Base::insert_after(__pos.base(), __n, __val), this };
427 template<typename _InputIterator,
428 typename = std::_RequireInputIter<_InputIterator>>
430 insert_after(const_iterator __pos,
431 _InputIterator __first, _InputIterator __last)
433 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
434 __glibcxx_check_insert_range_after(__pos, __first, __last, __dist);
436 if (__dist.second >= __gnu_debug::__dp_sign)
439 _Base::insert_after(__pos.base(),
440 __gnu_debug::__unsafe(__first),
441 __gnu_debug::__unsafe(__last)),
445 return { _Base::insert_after(__pos.base(), __first, __last), this };
449 insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
451 __glibcxx_check_insert_after(__pos);
452 return { _Base::insert_after(__pos.base(), __il), this };
456 erase_after(const_iterator __pos)
458 __glibcxx_check_erase_after(__pos);
460 _Base_const_iterator __next = std::next(__pos.base());
461 this->_M_invalidate_if([__next](_Base_const_iterator __it)
462 { return __it == __next; });
463 return { _Base::erase_after(__pos.base()), this };
467 erase_after(const_iterator __pos, const_iterator __last)
469 __glibcxx_check_erase_range_after(__pos, __last);
470 for (_Base_const_iterator __victim = std::next(__pos.base());
471 __victim != __last.base(); ++__victim)
473 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::cend(),
474 _M_message(__gnu_debug::__msg_valid_range2)
475 ._M_sequence(*this, "this")
476 ._M_iterator(__pos, "pos")
477 ._M_iterator(__last, "last"));
478 this->_M_invalidate_if([__victim](_Base_const_iterator __it)
479 { return __it == __victim; });
482 return { _Base::erase_after(__pos.base(), __last.base()), this };
486 swap(forward_list& __list)
487 noexcept( noexcept(declval<_Base&>().swap(__list)) )
489 _Safe::_M_swap(__list);
494 resize(size_type __sz)
496 this->_M_detach_singular();
498 // if __sz < size(), invalidate all iterators in [begin+__sz, end()
499 _Base_iterator __victim = _Base::begin();
500 _Base_iterator __end = _Base::end();
501 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
504 for (; __victim != __end; ++__victim)
506 this->_M_invalidate_if([__victim](_Base_const_iterator __it)
507 { return __it == __victim; });
516 this->_M_revalidate_singular();
517 __throw_exception_again;
522 resize(size_type __sz, const value_type& __val)
524 this->_M_detach_singular();
526 // if __sz < size(), invalidate all iterators in [begin+__sz, end())
527 _Base_iterator __victim = _Base::begin();
528 _Base_iterator __end = _Base::end();
529 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
532 for (; __victim != __end; ++__victim)
534 this->_M_invalidate_if([__victim](_Base_const_iterator __it)
535 { return __it == __victim; });
540 _Base::resize(__sz, __val);
544 this->_M_revalidate_singular();
545 __throw_exception_again;
553 this->_M_invalidate_all();
556 // 23.2.3.5 forward_list operations:
558 splice_after(const_iterator __pos, forward_list&& __list)
560 __glibcxx_check_insert_after(__pos);
561 _GLIBCXX_DEBUG_VERIFY(std::__addressof(__list) != this,
562 _M_message(__gnu_debug::__msg_self_splice)
563 ._M_sequence(*this, "this"));
564 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
565 _M_message(__gnu_debug::__msg_splice_alloc)
567 ._M_sequence(__list, "__list"));
568 this->_M_transfer_from_if(__list, [&__list](_Base_const_iterator __it)
570 return __it != __list._M_base().cbefore_begin()
571 && __it != __list._M_base().end();
573 _Base::splice_after(__pos.base(), std::move(__list._M_base()));
577 splice_after(const_iterator __pos, forward_list& __list)
578 { splice_after(__pos, std::move(__list)); }
581 splice_after(const_iterator __pos, forward_list&& __list,
584 __glibcxx_check_insert_after(__pos);
585 _GLIBCXX_DEBUG_VERIFY(__i._M_before_dereferenceable(),
586 _M_message(__gnu_debug::__msg_splice_bad)
587 ._M_iterator(__i, "__i"));
588 _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(std::__addressof(__list)),
589 _M_message(__gnu_debug::__msg_splice_other)
590 ._M_iterator(__i, "__i")
591 ._M_sequence(__list, "__list"));
592 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
593 _M_message(__gnu_debug::__msg_splice_alloc)
595 ._M_sequence(__list, "__list"));
597 // _GLIBCXX_RESOLVE_LIB_DEFECTS
598 // 250. splicing invalidates iterators
599 _Base_const_iterator __next = std::next(__i.base());
600 this->_M_transfer_from_if(__list, [__next](_Base_const_iterator __it)
601 { return __it == __next; });
602 _Base::splice_after(__pos.base(), std::move(__list._M_base()),
607 splice_after(const_iterator __pos, forward_list& __list,
609 { splice_after(__pos, std::move(__list), __i); }
612 splice_after(const_iterator __pos, forward_list&& __list,
613 const_iterator __before, const_iterator __last)
615 typename __gnu_debug::_Distance_traits<const_iterator>::__type __dist;
616 auto __listptr = std::__addressof(__list);
617 __glibcxx_check_insert_after(__pos);
618 __glibcxx_check_valid_fl_range(__before, __last, __dist);
619 _GLIBCXX_DEBUG_VERIFY(__before._M_attached_to(__listptr),
620 _M_message(__gnu_debug::__msg_splice_other)
621 ._M_sequence(__list, "list")
622 ._M_iterator(__before, "before"));
623 _GLIBCXX_DEBUG_VERIFY(__before._M_dereferenceable()
624 || __before._M_is_before_begin(),
625 _M_message(__gnu_debug::__msg_valid_range2)
626 ._M_sequence(__list, "list")
627 ._M_iterator(__before, "before")
628 ._M_iterator(__last, "last"));
629 _GLIBCXX_DEBUG_VERIFY(__before != __last,
630 _M_message(__gnu_debug::__msg_valid_range2)
631 ._M_sequence(__list, "list")
632 ._M_iterator(__before, "before")
633 ._M_iterator(__last, "last"));
634 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
635 _M_message(__gnu_debug::__msg_splice_alloc)
637 ._M_sequence(__list, "__list"));
639 for (_Base_const_iterator __tmp = std::next(__before.base());
640 __tmp != __last.base(); ++__tmp)
642 _GLIBCXX_DEBUG_VERIFY(__tmp != __list._M_base().end(),
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(__listptr != this || __tmp != __pos.base(),
648 _M_message(__gnu_debug::__msg_splice_overlap)
649 ._M_iterator(__tmp, "position")
650 ._M_iterator(__before, "before")
651 ._M_iterator(__last, "last"));
652 // _GLIBCXX_RESOLVE_LIB_DEFECTS
653 // 250. splicing invalidates iterators
654 this->_M_transfer_from_if(__list, [__tmp](_Base_const_iterator __it)
655 { return __it == __tmp; });
658 _Base::splice_after(__pos.base(), std::move(__list._M_base()),
659 __before.base(), __last.base());
663 splice_after(const_iterator __pos, forward_list& __list,
664 const_iterator __before, const_iterator __last)
665 { splice_after(__pos, std::move(__list), __before, __last); }
668 #if __cplusplus > 201703L
669 using __remove_return_type = size_type;
670 # define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG \
671 __attribute__((__abi_tag__("__cxx20")))
672 # define _GLIBCXX20_ONLY(__expr) __expr
674 using __remove_return_type = void;
675 # define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
676 # define _GLIBCXX20_ONLY(__expr)
680 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
682 remove(const _Tp& __val)
684 if (!this->_M_iterators && !this->_M_const_iterators)
685 return _Base::remove(__val);
687 size_type __removed __attribute__((__unused__)) = 0;
688 _Base __to_destroy(get_allocator());
689 _Base_const_iterator __x = _Base::cbefore_begin();
690 _Base_const_iterator __old = __x++;
691 while (__x != _Base::cend())
695 _Base_const_iterator __next = std::next(__old);
696 this->_M_invalidate_if([__next](_Base_const_iterator __it)
697 { return __it == __next; });
698 __to_destroy.splice_after(__to_destroy.cbefore_begin(),
701 _GLIBCXX20_ONLY( __removed++ );
707 return _GLIBCXX20_ONLY( __removed );
710 template<typename _Pred>
712 remove_if(_Pred __pred)
714 if (!this->_M_iterators && !this->_M_const_iterators)
715 return _Base::remove_if(__pred);
717 size_type __removed __attribute__((__unused__)) = 0;
718 _Base __to_destroy(get_allocator());
719 _Base_iterator __x = _Base::before_begin();
720 _Base_iterator __old = __x++;
721 while (__x != _Base::end())
725 this->_M_invalidate_if([__x](_Base_const_iterator __it)
726 { return __it == __x; });
727 __to_destroy.splice_after(__to_destroy.cbefore_begin(),
730 _GLIBCXX20_ONLY( __removed++ );
736 return _GLIBCXX20_ONLY( __removed );
739 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
742 { return unique(std::equal_to<_Tp>()); }
744 template<typename _BinPred>
746 unique(_BinPred __binary_pred)
748 if (!this->_M_iterators && !this->_M_const_iterators)
749 return _Base::unique(__binary_pred);
751 _Base_const_iterator __first = _Base::cbegin();
752 _Base_const_iterator __last = _Base::cend();
753 if (__first == __last)
754 return _GLIBCXX20_ONLY(0);
756 size_type __removed __attribute__((__unused__)) = 0;
757 _Base __to_destroy(get_allocator());
758 _Base_const_iterator __next = std::next(__first);
759 while (__next != __last)
761 if (__binary_pred(*__first, *__next))
763 this->_M_invalidate_if([__next](_Base_const_iterator __it)
764 { return __it == __next; });
765 __to_destroy.splice_after(__to_destroy.cbefore_begin(),
768 _GLIBCXX20_ONLY( __removed++ );
774 return _GLIBCXX20_ONLY( __removed );
777 #undef _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
778 #undef _GLIBCXX20_ONLY
781 merge(forward_list&& __list)
783 if (this != std::__addressof(__list))
785 __glibcxx_check_sorted(_Base::begin(), _Base::end());
786 __glibcxx_check_sorted(__list._M_base().begin(),
787 __list._M_base().end());
788 this->_M_transfer_from_if(__list, [&__list](_Base_const_iterator __it)
790 return __it != __list._M_base().cbefore_begin()
791 && __it != __list._M_base().cend();
793 _Base::merge(std::move(__list._M_base()));
798 merge(forward_list& __list)
799 { merge(std::move(__list)); }
801 template<typename _Comp>
803 merge(forward_list&& __list, _Comp __comp)
805 if (this != std::__addressof(__list))
807 __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(), __comp);
808 __glibcxx_check_sorted_pred(__list._M_base().begin(),
809 __list._M_base().end(), __comp);
810 this->_M_transfer_from_if(__list,
811 [&__list](_Base_const_iterator __it)
813 return __it != __list._M_base().cbefore_begin()
814 && __it != __list._M_base().cend();
816 _Base::merge(std::move(__list._M_base()), __comp);
820 template<typename _Comp>
822 merge(forward_list& __list, _Comp __comp)
823 { merge(std::move(__list), __comp); }
826 using _Base::reverse;
829 _M_base() noexcept { return *this; }
832 _M_base() const noexcept { return *this; }
835 #if __cpp_deduction_guides >= 201606
836 template<typename _InputIterator, typename _ValT
837 = typename iterator_traits<_InputIterator>::value_type,
838 typename _Allocator = allocator<_ValT>,
839 typename = _RequireInputIter<_InputIterator>,
840 typename = _RequireAllocator<_Allocator>>
841 forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
842 -> forward_list<_ValT, _Allocator>;
845 template<typename _Tp, typename _Alloc>
847 operator==(const forward_list<_Tp, _Alloc>& __lx,
848 const forward_list<_Tp, _Alloc>& __ly)
849 { return __lx._M_base() == __ly._M_base(); }
851 #if __cpp_lib_three_way_comparison
852 template<typename _Tp, typename _Alloc>
853 constexpr __detail::__synth3way_t<_Tp>
854 operator<=>(const forward_list<_Tp, _Alloc>& __x,
855 const forward_list<_Tp, _Alloc>& __y)
856 { return __x._M_base() <=> __y._M_base(); }
858 template<typename _Tp, typename _Alloc>
860 operator<(const forward_list<_Tp, _Alloc>& __lx,
861 const forward_list<_Tp, _Alloc>& __ly)
862 { return __lx._M_base() < __ly._M_base(); }
864 template<typename _Tp, typename _Alloc>
866 operator!=(const forward_list<_Tp, _Alloc>& __lx,
867 const forward_list<_Tp, _Alloc>& __ly)
868 { return !(__lx == __ly); }
870 /// Based on operator<
871 template<typename _Tp, typename _Alloc>
873 operator>(const forward_list<_Tp, _Alloc>& __lx,
874 const forward_list<_Tp, _Alloc>& __ly)
875 { return (__ly < __lx); }
877 /// Based on operator<
878 template<typename _Tp, typename _Alloc>
880 operator>=(const forward_list<_Tp, _Alloc>& __lx,
881 const forward_list<_Tp, _Alloc>& __ly)
882 { return !(__lx < __ly); }
884 /// Based on operator<
885 template<typename _Tp, typename _Alloc>
887 operator<=(const forward_list<_Tp, _Alloc>& __lx,
888 const forward_list<_Tp, _Alloc>& __ly)
889 { return !(__ly < __lx); }
890 #endif // three-way comparison
892 /// See std::forward_list::swap().
893 template<typename _Tp, typename _Alloc>
895 swap(forward_list<_Tp, _Alloc>& __lx, forward_list<_Tp, _Alloc>& __ly)
896 noexcept(noexcept(__lx.swap(__ly)))
899 } // namespace __debug
902 namespace __gnu_debug
904 template<typename _Tp, typename _Alloc>
905 struct _BeforeBeginHelper<std::__debug::forward_list<_Tp, _Alloc> >
907 typedef std::__debug::forward_list<_Tp, _Alloc> _Sequence;
909 template<typename _Iterator>
911 _S_Is(const _Safe_iterator<_Iterator, _Sequence>& __it)
914 __it.base() == __it._M_get_sequence()->_M_base().before_begin();
917 template<typename _Iterator>
919 _S_Is_Beginnest(const _Safe_iterator<_Iterator, _Sequence>& __it)
920 { return _S_Is(__it); }
923 template<typename _Tp, typename _Alloc>
924 struct _Sequence_traits<std::__debug::forward_list<_Tp, _Alloc> >
926 typedef typename std::__debug::forward_list<_Tp, _Alloc>::iterator _It;
928 static typename _Distance_traits<_It>::__type
929 _S_size(const std::__debug::forward_list<_Tp, _Alloc>& __seq)
932 ? std::make_pair(0, __dp_exact) : std::make_pair(1, __dp_sign);
936 #ifndef _GLIBCXX_DEBUG_PEDANTIC
937 template<class _Tp, class _Alloc>
938 struct _Insert_range_from_self_is_safe<
939 std::__debug::forward_list<_Tp, _Alloc> >
940 { enum { __value = 1 }; };