1 // Debugging list implementation -*- C++ -*-
3 // Copyright (C) 2003-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/>.
26 * This file is a GNU debug extension to the Standard C++ Library.
29 #ifndef _GLIBCXX_DEBUG_LIST
30 #define _GLIBCXX_DEBUG_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 list;
37 } } // namespace std::__debug
40 #include <debug/safe_sequence.h>
41 #include <debug/safe_container.h>
42 #include <debug/safe_iterator.h>
44 namespace std _GLIBCXX_VISIBILITY(default)
48 /// Class std::list with safety/checking/debug instrumentation.
49 template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
51 : public __gnu_debug::_Safe_container<
52 list<_Tp, _Allocator>, _Allocator,
53 __gnu_debug::_Safe_node_sequence>,
54 public _GLIBCXX_STD_C::list<_Tp, _Allocator>
56 typedef _GLIBCXX_STD_C::list<_Tp, _Allocator> _Base;
57 typedef __gnu_debug::_Safe_container<
58 list, _Allocator, __gnu_debug::_Safe_node_sequence> _Safe;
60 typedef typename _Base::iterator _Base_iterator;
61 typedef typename _Base::const_iterator _Base_const_iterator;
62 typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal;
63 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
65 template<typename _ItT, typename _SeqT, typename _CatT>
66 friend class ::__gnu_debug::_Safe_iterator;
68 // Reference wrapper for base class. Disambiguates list(const _Base&)
69 // from copy constructor by requiring a user-defined conversion.
70 // See PR libstdc++/90102.
73 _Base_ref(const _Base& __r) : _M_ref(__r) { }
79 typedef typename _Base::reference reference;
80 typedef typename _Base::const_reference const_reference;
82 typedef __gnu_debug::_Safe_iterator<_Base_iterator, list>
84 typedef __gnu_debug::_Safe_iterator<_Base_const_iterator, list>
87 typedef typename _Base::size_type size_type;
88 typedef typename _Base::difference_type difference_type;
90 typedef _Tp value_type;
91 typedef _Allocator allocator_type;
92 typedef typename _Base::pointer pointer;
93 typedef typename _Base::const_pointer const_pointer;
94 typedef std::reverse_iterator<iterator> reverse_iterator;
95 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
97 // 23.2.2.1 construct/copy/destroy:
99 #if __cplusplus < 201103L
103 list(const list& __x)
109 list(const list&) = default;
110 list(list&&) = default;
112 list(initializer_list<value_type> __l,
113 const allocator_type& __a = allocator_type())
114 : _Base(__l, __a) { }
118 list(const list& __x, const allocator_type& __a)
119 : _Base(__x, __a) { }
121 list(list&& __x, const allocator_type& __a)
122 : _Base(std::move(__x), __a) { }
126 list(const _Allocator& __a) _GLIBCXX_NOEXCEPT
129 #if __cplusplus >= 201103L
131 list(size_type __n, const allocator_type& __a = allocator_type())
132 : _Base(__n, __a) { }
134 list(size_type __n, const _Tp& __value,
135 const _Allocator& __a = _Allocator())
136 : _Base(__n, __value, __a) { }
139 list(size_type __n, const _Tp& __value = _Tp(),
140 const _Allocator& __a = _Allocator())
141 : _Base(__n, __value, __a) { }
144 #if __cplusplus >= 201103L
145 template<class _InputIterator,
146 typename = std::_RequireInputIter<_InputIterator>>
148 template<class _InputIterator>
150 list(_InputIterator __first, _InputIterator __last,
151 const _Allocator& __a = _Allocator())
152 : _Base(__gnu_debug::__base(
153 __glibcxx_check_valid_constructor_range(__first, __last)),
154 __gnu_debug::__base(__last), __a)
158 : _Base(__x._M_ref) { }
160 #if __cplusplus < 201103L
162 operator=(const list& __x)
164 this->_M_safe() = __x;
170 operator=(const list&) = default;
173 operator=(list&&) = default;
176 operator=(initializer_list<value_type> __l)
178 this->_M_invalidate_all();
184 assign(initializer_list<value_type> __l)
187 this->_M_invalidate_all();
191 #if __cplusplus >= 201103L
192 template<class _InputIterator,
193 typename = std::_RequireInputIter<_InputIterator>>
195 template<class _InputIterator>
198 assign(_InputIterator __first, _InputIterator __last)
200 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
201 __glibcxx_check_valid_range2(__first, __last, __dist);
203 if (__dist.second >= __gnu_debug::__dp_sign)
204 _Base::assign(__gnu_debug::__unsafe(__first),
205 __gnu_debug::__unsafe(__last));
207 _Base::assign(__first, __last);
209 this->_M_invalidate_all();
213 assign(size_type __n, const _Tp& __t)
215 _Base::assign(__n, __t);
216 this->_M_invalidate_all();
219 using _Base::get_allocator;
223 begin() _GLIBCXX_NOEXCEPT
224 { return iterator(_Base::begin(), this); }
227 begin() const _GLIBCXX_NOEXCEPT
228 { return const_iterator(_Base::begin(), this); }
231 end() _GLIBCXX_NOEXCEPT
232 { return iterator(_Base::end(), this); }
235 end() const _GLIBCXX_NOEXCEPT
236 { return const_iterator(_Base::end(), this); }
239 rbegin() _GLIBCXX_NOEXCEPT
240 { return reverse_iterator(end()); }
242 const_reverse_iterator
243 rbegin() const _GLIBCXX_NOEXCEPT
244 { return const_reverse_iterator(end()); }
247 rend() _GLIBCXX_NOEXCEPT
248 { return reverse_iterator(begin()); }
250 const_reverse_iterator
251 rend() const _GLIBCXX_NOEXCEPT
252 { return const_reverse_iterator(begin()); }
254 #if __cplusplus >= 201103L
256 cbegin() const noexcept
257 { return const_iterator(_Base::begin(), this); }
260 cend() const noexcept
261 { return const_iterator(_Base::end(), this); }
263 const_reverse_iterator
264 crbegin() const noexcept
265 { return const_reverse_iterator(end()); }
267 const_reverse_iterator
268 crend() const noexcept
269 { return const_reverse_iterator(begin()); }
272 // 23.2.2.2 capacity:
275 using _Base::max_size;
277 #if __cplusplus >= 201103L
279 resize(size_type __sz)
281 this->_M_detach_singular();
283 // if __sz < size(), invalidate all iterators in [begin + __sz, end())
284 _Base_iterator __victim = _Base::begin();
285 _Base_iterator __end = _Base::end();
286 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
289 for (; __victim != __end; ++__victim)
290 this->_M_invalidate_if(_Equal(__victim));
298 this->_M_revalidate_singular();
299 __throw_exception_again;
304 resize(size_type __sz, const _Tp& __c)
306 this->_M_detach_singular();
308 // if __sz < size(), invalidate all iterators in [begin + __sz, end())
309 _Base_iterator __victim = _Base::begin();
310 _Base_iterator __end = _Base::end();
311 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
314 for (; __victim != __end; ++__victim)
315 this->_M_invalidate_if(_Equal(__victim));
319 _Base::resize(__sz, __c);
323 this->_M_revalidate_singular();
324 __throw_exception_again;
329 resize(size_type __sz, _Tp __c = _Tp())
331 this->_M_detach_singular();
333 // if __sz < size(), invalidate all iterators in [begin + __sz, end())
334 _Base_iterator __victim = _Base::begin();
335 _Base_iterator __end = _Base::end();
336 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
339 for (; __victim != __end; ++__victim)
340 this->_M_invalidate_if(_Equal(__victim));
344 _Base::resize(__sz, __c);
348 this->_M_revalidate_singular();
349 __throw_exception_again;
356 front() _GLIBCXX_NOEXCEPT
358 __glibcxx_check_nonempty();
359 return _Base::front();
363 front() const _GLIBCXX_NOEXCEPT
365 __glibcxx_check_nonempty();
366 return _Base::front();
370 back() _GLIBCXX_NOEXCEPT
372 __glibcxx_check_nonempty();
373 return _Base::back();
377 back() const _GLIBCXX_NOEXCEPT
379 __glibcxx_check_nonempty();
380 return _Base::back();
383 // 23.2.2.3 modifiers:
384 using _Base::push_front;
386 #if __cplusplus >= 201103L
387 using _Base::emplace_front;
391 pop_front() _GLIBCXX_NOEXCEPT
393 __glibcxx_check_nonempty();
394 this->_M_invalidate_if(_Equal(_Base::begin()));
398 using _Base::push_back;
400 #if __cplusplus >= 201103L
401 using _Base::emplace_back;
405 pop_back() _GLIBCXX_NOEXCEPT
407 __glibcxx_check_nonempty();
408 this->_M_invalidate_if(_Equal(--_Base::end()));
412 #if __cplusplus >= 201103L
413 template<typename... _Args>
415 emplace(const_iterator __position, _Args&&... __args)
417 __glibcxx_check_insert(__position);
418 return { _Base::emplace(__position.base(),
419 std::forward<_Args>(__args)...), this };
424 #if __cplusplus >= 201103L
425 insert(const_iterator __position, const _Tp& __x)
427 insert(iterator __position, const _Tp& __x)
430 __glibcxx_check_insert(__position);
431 return iterator(_Base::insert(__position.base(), __x), this);
434 #if __cplusplus >= 201103L
436 insert(const_iterator __position, _Tp&& __x)
437 { return emplace(__position, std::move(__x)); }
440 insert(const_iterator __p, initializer_list<value_type> __l)
442 __glibcxx_check_insert(__p);
443 return { _Base::insert(__p.base(), __l), this };
447 #if __cplusplus >= 201103L
449 insert(const_iterator __position, size_type __n, const _Tp& __x)
451 __glibcxx_check_insert(__position);
452 return { _Base::insert(__position.base(), __n, __x), this };
456 insert(iterator __position, size_type __n, const _Tp& __x)
458 __glibcxx_check_insert(__position);
459 _Base::insert(__position.base(), __n, __x);
463 #if __cplusplus >= 201103L
464 template<class _InputIterator,
465 typename = std::_RequireInputIter<_InputIterator>>
467 insert(const_iterator __position, _InputIterator __first,
468 _InputIterator __last)
470 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
471 __glibcxx_check_insert_range(__position, __first, __last, __dist);
472 if (__dist.second >= __gnu_debug::__dp_sign)
475 _Base::insert(__position.base(),
476 __gnu_debug::__unsafe(__first),
477 __gnu_debug::__unsafe(__last)),
481 return { _Base::insert(__position.base(), __first, __last), this };
484 template<class _InputIterator>
486 insert(iterator __position, _InputIterator __first,
487 _InputIterator __last)
489 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
490 __glibcxx_check_insert_range(__position, __first, __last, __dist);
492 if (__dist.second >= __gnu_debug::__dp_sign)
493 _Base::insert(__position.base(), __gnu_debug::__unsafe(__first),
494 __gnu_debug::__unsafe(__last));
496 _Base::insert(__position.base(), __first, __last);
502 #if __cplusplus >= 201103L
503 _M_erase(_Base_const_iterator __position) noexcept
505 _M_erase(_Base_iterator __position)
508 this->_M_invalidate_if(_Equal(__position));
509 return _Base::erase(__position);
514 #if __cplusplus >= 201103L
515 erase(const_iterator __position) noexcept
517 erase(iterator __position)
520 __glibcxx_check_erase(__position);
521 return iterator(_M_erase(__position.base()), this);
525 #if __cplusplus >= 201103L
526 erase(const_iterator __first, const_iterator __last) noexcept
528 erase(iterator __first, iterator __last)
531 // _GLIBCXX_RESOLVE_LIB_DEFECTS
532 // 151. can't currently clear() empty container
533 __glibcxx_check_erase_range(__first, __last);
534 for (_Base_const_iterator __victim = __first.base();
535 __victim != __last.base(); ++__victim)
537 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
538 _M_message(__gnu_debug::__msg_valid_range)
539 ._M_iterator(__first, "position")
540 ._M_iterator(__last, "last"));
541 this->_M_invalidate_if(_Equal(__victim));
544 return iterator(_Base::erase(__first.base(), __last.base()), this);
549 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
556 clear() _GLIBCXX_NOEXCEPT
559 this->_M_invalidate_all();
562 // 23.2.2.4 list operations:
564 #if __cplusplus >= 201103L
565 splice(const_iterator __position, list&& __x) noexcept
567 splice(iterator __position, list& __x)
570 _GLIBCXX_DEBUG_VERIFY(std::__addressof(__x) != this,
571 _M_message(__gnu_debug::__msg_self_splice)
572 ._M_sequence(*this, "this"));
573 this->_M_transfer_from_if(__x, _Not_equal(__x._M_base().end()));
574 _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()));
577 #if __cplusplus >= 201103L
579 splice(const_iterator __position, list& __x) noexcept
580 { splice(__position, std::move(__x)); }
584 #if __cplusplus >= 201103L
585 splice(const_iterator __position, list&& __x, const_iterator __i) noexcept
587 splice(iterator __position, list& __x, iterator __i)
590 __glibcxx_check_insert(__position);
592 // We used to perform the splice_alloc check: not anymore, redundant
593 // after implementing the relevant bits of N1599.
595 _GLIBCXX_DEBUG_VERIFY(__i._M_dereferenceable(),
596 _M_message(__gnu_debug::__msg_splice_bad)
597 ._M_iterator(__i, "__i"));
598 _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(std::__addressof(__x)),
599 _M_message(__gnu_debug::__msg_splice_other)
600 ._M_iterator(__i, "__i")._M_sequence(__x, "__x"));
602 // _GLIBCXX_RESOLVE_LIB_DEFECTS
603 // 250. splicing invalidates iterators
604 this->_M_transfer_from_if(__x, _Equal(__i.base()));
605 _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()),
609 #if __cplusplus >= 201103L
611 splice(const_iterator __position, list& __x, const_iterator __i) noexcept
612 { splice(__position, std::move(__x), __i); }
616 #if __cplusplus >= 201103L
617 splice(const_iterator __position, list&& __x, const_iterator __first,
618 const_iterator __last) noexcept
620 splice(iterator __position, list& __x, iterator __first,
624 __glibcxx_check_insert(__position);
625 __glibcxx_check_valid_range(__first, __last);
626 _GLIBCXX_DEBUG_VERIFY(__first._M_attached_to(std::__addressof(__x)),
627 _M_message(__gnu_debug::__msg_splice_other)
628 ._M_sequence(__x, "x")
629 ._M_iterator(__first, "first"));
631 // We used to perform the splice_alloc check: not anymore, redundant
632 // after implementing the relevant bits of N1599.
634 for (_Base_const_iterator __tmp = __first.base();
635 __tmp != __last.base(); ++__tmp)
637 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
638 _M_message(__gnu_debug::__msg_valid_range)
639 ._M_iterator(__first, "first")
640 ._M_iterator(__last, "last"));
641 _GLIBCXX_DEBUG_VERIFY(std::__addressof(__x) != this
642 || __tmp != __position.base(),
643 _M_message(__gnu_debug::__msg_splice_overlap)
644 ._M_iterator(__tmp, "position")
645 ._M_iterator(__first, "first")
646 ._M_iterator(__last, "last"));
648 // _GLIBCXX_RESOLVE_LIB_DEFECTS
649 // 250. splicing invalidates iterators
650 this->_M_transfer_from_if(__x, _Equal(__tmp));
653 _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()),
654 __first.base(), __last.base());
657 #if __cplusplus >= 201103L
659 splice(const_iterator __position, list& __x,
660 const_iterator __first, const_iterator __last) noexcept
661 { splice(__position, std::move(__x), __first, __last); }
665 #if __cplusplus > 201703L
666 typedef size_type __remove_return_type;
667 # define _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG \
668 __attribute__((__abi_tag__("__cxx20")))
669 # define _GLIBCXX20_ONLY(__expr) __expr
671 typedef void __remove_return_type;
672 # define _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
673 # define _GLIBCXX20_ONLY(__expr)
677 _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
679 remove(const _Tp& __value)
681 if (!this->_M_iterators && !this->_M_const_iterators)
682 return _Base::remove(__value);
684 #if !_GLIBCXX_USE_CXX11_ABI
685 size_type __removed __attribute__((__unused__)) = 0;
687 _Base __to_destroy(get_allocator());
688 _Base_iterator __first = _Base::begin();
689 _Base_iterator __last = _Base::end();
690 while (__first != __last)
692 _Base_iterator __next = __first;
694 if (*__first == __value)
696 // _GLIBCXX_RESOLVE_LIB_DEFECTS
697 // 526. Is it undefined if a function in the standard changes
699 this->_M_invalidate_if(_Equal(__first));
700 __to_destroy.splice(__to_destroy.begin(), _M_base(), __first);
701 #if !_GLIBCXX_USE_CXX11_ABI
702 _GLIBCXX20_ONLY( __removed++ );
709 #if !_GLIBCXX_USE_CXX11_ABI
710 return _GLIBCXX20_ONLY( __removed );
712 return _GLIBCXX20_ONLY( __to_destroy.size() );
716 template<class _Predicate>
718 remove_if(_Predicate __pred)
720 if (!this->_M_iterators && !this->_M_const_iterators)
721 return _Base::remove_if(__pred);
723 #if !_GLIBCXX_USE_CXX11_ABI
724 size_type __removed __attribute__((__unused__)) = 0;
726 _Base __to_destroy(get_allocator());
727 for (_Base_iterator __x = _Base::begin(); __x != _Base::end(); )
729 _Base_iterator __next = __x;
733 this->_M_invalidate_if(_Equal(__x));
734 __to_destroy.splice(__to_destroy.begin(), _M_base(), __x);
735 #if !_GLIBCXX_USE_CXX11_ABI
736 _GLIBCXX20_ONLY( __removed++ );
743 #if !_GLIBCXX_USE_CXX11_ABI
744 return _GLIBCXX20_ONLY( __removed );
746 return _GLIBCXX20_ONLY( __to_destroy.size() );
750 _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
754 if (!this->_M_iterators && !this->_M_const_iterators)
755 return _Base::unique();
758 return _GLIBCXX20_ONLY(0);
760 #if !_GLIBCXX_USE_CXX11_ABI
761 size_type __removed __attribute__((__unused__)) = 0;
763 _Base __to_destroy(get_allocator());
764 _Base_iterator __first = _Base::begin();
765 _Base_iterator __last = _Base::end();
766 _Base_iterator __next = __first;
767 while (++__next != __last)
768 if (*__first == *__next)
770 this->_M_invalidate_if(_Equal(__next));
771 __to_destroy.splice(__to_destroy.begin(), _M_base(), __next);
773 #if !_GLIBCXX_USE_CXX11_ABI
774 _GLIBCXX20_ONLY( __removed++ );
780 #if !_GLIBCXX_USE_CXX11_ABI
781 return _GLIBCXX20_ONLY( __removed );
783 return _GLIBCXX20_ONLY( __to_destroy.size() );
787 template<class _BinaryPredicate>
789 unique(_BinaryPredicate __binary_pred)
791 if (!this->_M_iterators && !this->_M_const_iterators)
792 return _Base::unique(__binary_pred);
795 return _GLIBCXX20_ONLY(0);
798 #if !_GLIBCXX_USE_CXX11_ABI
799 size_type __removed __attribute__((__unused__)) = 0;
801 _Base __to_destroy(get_allocator());
802 _Base_iterator __first = _Base::begin();
803 _Base_iterator __last = _Base::end();
804 _Base_iterator __next = __first;
805 while (++__next != __last)
806 if (__binary_pred(*__first, *__next))
808 this->_M_invalidate_if(_Equal(__next));
809 __to_destroy.splice(__to_destroy.begin(), _M_base(), __next);
811 #if !_GLIBCXX_USE_CXX11_ABI
812 _GLIBCXX20_ONLY( __removed++ );
818 #if !_GLIBCXX_USE_CXX11_ABI
819 return _GLIBCXX20_ONLY( __removed );
821 return _GLIBCXX20_ONLY( __to_destroy.size() );
825 #undef _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
826 #undef _GLIBCXX20_ONLY
829 #if __cplusplus >= 201103L
835 // _GLIBCXX_RESOLVE_LIB_DEFECTS
836 // 300. list::merge() specification incomplete
837 if (this != std::__addressof(__x))
839 __glibcxx_check_sorted(_Base::begin(), _Base::end());
840 __glibcxx_check_sorted(__x.begin().base(), __x.end().base());
841 this->_M_transfer_from_if(__x, _Not_equal(__x._M_base().end()));
842 _Base::merge(_GLIBCXX_MOVE(__x._M_base()));
846 #if __cplusplus >= 201103L
849 { merge(std::move(__x)); }
852 template<class _Compare>
854 #if __cplusplus >= 201103L
855 merge(list&& __x, _Compare __comp)
857 merge(list& __x, _Compare __comp)
860 // _GLIBCXX_RESOLVE_LIB_DEFECTS
861 // 300. list::merge() specification incomplete
862 if (this != std::__addressof(__x))
864 __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(),
866 __glibcxx_check_sorted_pred(__x.begin().base(), __x.end().base(),
868 this->_M_transfer_from_if(__x, _Not_equal(__x._M_base().end()));
869 _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp);
873 #if __cplusplus >= 201103L
874 template<typename _Compare>
876 merge(list& __x, _Compare __comp)
877 { merge(std::move(__x), __comp); }
881 sort() { _Base::sort(); }
883 template<typename _StrictWeakOrdering>
885 sort(_StrictWeakOrdering __pred) { _Base::sort(__pred); }
887 using _Base::reverse;
890 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
893 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
896 #if __cpp_deduction_guides >= 201606
897 template<typename _InputIterator, typename _ValT
898 = typename iterator_traits<_InputIterator>::value_type,
899 typename _Allocator = allocator<_ValT>,
900 typename = _RequireInputIter<_InputIterator>,
901 typename = _RequireAllocator<_Allocator>>
902 list(_InputIterator, _InputIterator, _Allocator = _Allocator())
903 -> list<_ValT, _Allocator>;
906 template<typename _Tp, typename _Alloc>
908 operator==(const list<_Tp, _Alloc>& __lhs,
909 const list<_Tp, _Alloc>& __rhs)
910 { return __lhs._M_base() == __rhs._M_base(); }
912 #if __cpp_lib_three_way_comparison
913 template<typename _Tp, typename _Alloc>
914 constexpr __detail::__synth3way_t<_Tp>
915 operator<=>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
916 { return __x._M_base() <=> __y._M_base(); }
918 template<typename _Tp, typename _Alloc>
920 operator!=(const list<_Tp, _Alloc>& __lhs,
921 const list<_Tp, _Alloc>& __rhs)
922 { return __lhs._M_base() != __rhs._M_base(); }
924 template<typename _Tp, typename _Alloc>
926 operator<(const list<_Tp, _Alloc>& __lhs,
927 const list<_Tp, _Alloc>& __rhs)
928 { return __lhs._M_base() < __rhs._M_base(); }
930 template<typename _Tp, typename _Alloc>
932 operator<=(const list<_Tp, _Alloc>& __lhs,
933 const list<_Tp, _Alloc>& __rhs)
934 { return __lhs._M_base() <= __rhs._M_base(); }
936 template<typename _Tp, typename _Alloc>
938 operator>=(const list<_Tp, _Alloc>& __lhs,
939 const list<_Tp, _Alloc>& __rhs)
940 { return __lhs._M_base() >= __rhs._M_base(); }
942 template<typename _Tp, typename _Alloc>
944 operator>(const list<_Tp, _Alloc>& __lhs,
945 const list<_Tp, _Alloc>& __rhs)
946 { return __lhs._M_base() > __rhs._M_base(); }
947 #endif // three-way comparison
949 template<typename _Tp, typename _Alloc>
951 swap(list<_Tp, _Alloc>& __lhs, list<_Tp, _Alloc>& __rhs)
952 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
953 { __lhs.swap(__rhs); }
955 } // namespace __debug
958 namespace __gnu_debug
960 #ifndef _GLIBCXX_USE_CXX11_ABI
961 // If not using C++11 list::size() is not in O(1) so we do not use it.
962 template<typename _Tp, typename _Alloc>
963 struct _Sequence_traits<std::__debug::list<_Tp, _Alloc> >
965 typedef typename std::__debug::list<_Tp, _Alloc>::iterator _It;
967 static typename _Distance_traits<_It>::__type
968 _S_size(const std::__debug::list<_Tp, _Alloc>& __seq)
971 ? std::make_pair(0, __dp_exact) : std::make_pair(1, __dp_sign);
976 #ifndef _GLIBCXX_DEBUG_PEDANTIC
977 template<class _Tp, class _Alloc>
978 struct _Insert_range_from_self_is_safe<std::__debug::list<_Tp, _Alloc> >
979 { enum { __value = 1 }; };