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>
35namespace 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>
44namespace 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)
123 std::is_nothrow_constructible<_Base,
124 _Base, const allocator_type&>::value )
125 : _Safe(std::move(__x._M_safe()), __a),
126 _Base(std::move(__x._M_base()), __a) { }
130 list(const _Allocator& __a) _GLIBCXX_NOEXCEPT
133#if __cplusplus >= 201103L
135 list(size_type __n, const allocator_type& __a = allocator_type())
136 : _Base(__n, __a) { }
138 list(size_type __n, const __type_identity_t<_Tp>& __value,
139 const _Allocator& __a = _Allocator())
140 : _Base(__n, __value, __a) { }
143 list(size_type __n, const _Tp& __value = _Tp(),
144 const _Allocator& __a = _Allocator())
145 : _Base(__n, __value, __a) { }
148#if __cplusplus >= 201103L
149 template<class _InputIterator,
150 typename = std::_RequireInputIter<_InputIterator>>
152 template<class _InputIterator>
154 list(_InputIterator __first, _InputIterator __last,
155 const _Allocator& __a = _Allocator())
156 : _Base(__gnu_debug::__base(
157 __glibcxx_check_valid_constructor_range(__first, __last)),
158 __gnu_debug::__base(__last), __a)
162 : _Base(__x._M_ref) { }
164#if __cplusplus < 201103L
166 operator=(const list& __x)
168 this->_M_safe() = __x;
174 operator=(const list&) = default;
177 operator=(list&&) = default;
180 operator=(initializer_list<value_type> __l)
182 this->_M_invalidate_all();
188 assign(initializer_list<value_type> __l)
191 this->_M_invalidate_all();
195#if __cplusplus >= 201103L
196 template<class _InputIterator,
197 typename = std::_RequireInputIter<_InputIterator>>
199 template<class _InputIterator>
202 assign(_InputIterator __first, _InputIterator __last)
204 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
205 __glibcxx_check_valid_range2(__first, __last, __dist);
207 if (__dist.second >= __gnu_debug::__dp_sign)
208 _Base::assign(__gnu_debug::__unsafe(__first),
209 __gnu_debug::__unsafe(__last));
211 _Base::assign(__first, __last);
213 this->_M_invalidate_all();
217 assign(size_type __n, const _Tp& __t)
219 _Base::assign(__n, __t);
220 this->_M_invalidate_all();
223 using _Base::get_allocator;
227 begin() _GLIBCXX_NOEXCEPT
228 { return iterator(_Base::begin(), this); }
231 begin() const _GLIBCXX_NOEXCEPT
232 { return const_iterator(_Base::begin(), this); }
235 end() _GLIBCXX_NOEXCEPT
236 { return iterator(_Base::end(), this); }
239 end() const _GLIBCXX_NOEXCEPT
240 { return const_iterator(_Base::end(), this); }
243 rbegin() _GLIBCXX_NOEXCEPT
244 { return reverse_iterator(end()); }
246 const_reverse_iterator
247 rbegin() const _GLIBCXX_NOEXCEPT
248 { return const_reverse_iterator(end()); }
251 rend() _GLIBCXX_NOEXCEPT
252 { return reverse_iterator(begin()); }
254 const_reverse_iterator
255 rend() const _GLIBCXX_NOEXCEPT
256 { return const_reverse_iterator(begin()); }
258#if __cplusplus >= 201103L
260 cbegin() const noexcept
261 { return const_iterator(_Base::begin(), this); }
264 cend() const noexcept
265 { return const_iterator(_Base::end(), this); }
267 const_reverse_iterator
268 crbegin() const noexcept
269 { return const_reverse_iterator(end()); }
271 const_reverse_iterator
272 crend() const noexcept
273 { return const_reverse_iterator(begin()); }
276 // 23.2.2.2 capacity:
279 using _Base::max_size;
281#if __cplusplus >= 201103L
283 resize(size_type __sz)
285 this->_M_detach_singular();
287 // if __sz < size(), invalidate all iterators in [begin + __sz, end())
288 _Base_iterator __victim = _Base::begin();
289 _Base_iterator __end = _Base::end();
290 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
293 for (; __victim != __end; ++__victim)
294 this->_M_invalidate_if(_Equal(__victim));
302 this->_M_revalidate_singular();
303 __throw_exception_again;
308 resize(size_type __sz, const _Tp& __c)
310 this->_M_detach_singular();
312 // if __sz < size(), invalidate all iterators in [begin + __sz, end())
313 _Base_iterator __victim = _Base::begin();
314 _Base_iterator __end = _Base::end();
315 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
318 for (; __victim != __end; ++__victim)
319 this->_M_invalidate_if(_Equal(__victim));
323 _Base::resize(__sz, __c);
327 this->_M_revalidate_singular();
328 __throw_exception_again;
333 resize(size_type __sz, _Tp __c = _Tp())
335 this->_M_detach_singular();
337 // if __sz < size(), invalidate all iterators in [begin + __sz, end())
338 _Base_iterator __victim = _Base::begin();
339 _Base_iterator __end = _Base::end();
340 for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
343 for (; __victim != __end; ++__victim)
344 this->_M_invalidate_if(_Equal(__victim));
348 _Base::resize(__sz, __c);
352 this->_M_revalidate_singular();
353 __throw_exception_again;
360 front() _GLIBCXX_NOEXCEPT
362 __glibcxx_check_nonempty();
363 return _Base::front();
367 front() const _GLIBCXX_NOEXCEPT
369 __glibcxx_check_nonempty();
370 return _Base::front();
374 back() _GLIBCXX_NOEXCEPT
376 __glibcxx_check_nonempty();
377 return _Base::back();
381 back() const _GLIBCXX_NOEXCEPT
383 __glibcxx_check_nonempty();
384 return _Base::back();
387 // 23.2.2.3 modifiers:
388 using _Base::push_front;
390#if __cplusplus >= 201103L
391 using _Base::emplace_front;
395 pop_front() _GLIBCXX_NOEXCEPT
397 __glibcxx_check_nonempty();
398 this->_M_invalidate_if(_Equal(_Base::begin()));
402 using _Base::push_back;
404#if __cplusplus >= 201103L
405 using _Base::emplace_back;
409 pop_back() _GLIBCXX_NOEXCEPT
411 __glibcxx_check_nonempty();
412 this->_M_invalidate_if(_Equal(--_Base::end()));
416#if __cplusplus >= 201103L
417 template<typename... _Args>
419 emplace(const_iterator __position, _Args&&... __args)
421 __glibcxx_check_insert(__position);
422 return { _Base::emplace(__position.base(),
423 std::forward<_Args>(__args)...), this };
428#if __cplusplus >= 201103L
429 insert(const_iterator __position, const _Tp& __x)
431 insert(iterator __position, const _Tp& __x)
434 __glibcxx_check_insert(__position);
435 return iterator(_Base::insert(__position.base(), __x), this);
438#if __cplusplus >= 201103L
440 insert(const_iterator __position, _Tp&& __x)
441 { return emplace(__position, std::move(__x)); }
444 insert(const_iterator __p, initializer_list<value_type> __l)
446 __glibcxx_check_insert(__p);
447 return { _Base::insert(__p.base(), __l), this };
451#if __cplusplus >= 201103L
453 insert(const_iterator __position, size_type __n, const _Tp& __x)
455 __glibcxx_check_insert(__position);
456 return { _Base::insert(__position.base(), __n, __x), this };
460 insert(iterator __position, size_type __n, const _Tp& __x)
462 __glibcxx_check_insert(__position);
463 _Base::insert(__position.base(), __n, __x);
467#if __cplusplus >= 201103L
468 template<class _InputIterator,
469 typename = std::_RequireInputIter<_InputIterator>>
471 insert(const_iterator __position, _InputIterator __first,
472 _InputIterator __last)
474 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
475 __glibcxx_check_insert_range(__position, __first, __last, __dist);
476 if (__dist.second >= __gnu_debug::__dp_sign)
479 _Base::insert(__position.base(),
480 __gnu_debug::__unsafe(__first),
481 __gnu_debug::__unsafe(__last)),
485 return { _Base::insert(__position.base(), __first, __last), this };
488 template<class _InputIterator>
490 insert(iterator __position, _InputIterator __first,
491 _InputIterator __last)
493 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
494 __glibcxx_check_insert_range(__position, __first, __last, __dist);
496 if (__dist.second >= __gnu_debug::__dp_sign)
497 _Base::insert(__position.base(), __gnu_debug::__unsafe(__first),
498 __gnu_debug::__unsafe(__last));
500 _Base::insert(__position.base(), __first, __last);
506#if __cplusplus >= 201103L
507 _M_erase(_Base_const_iterator __position) noexcept
509 _M_erase(_Base_iterator __position)
512 this->_M_invalidate_if(_Equal(__position));
513 return _Base::erase(__position);
518#if __cplusplus >= 201103L
519 erase(const_iterator __position) noexcept
521 erase(iterator __position)
524 __glibcxx_check_erase(__position);
525 return iterator(_M_erase(__position.base()), this);
529#if __cplusplus >= 201103L
530 erase(const_iterator __first, const_iterator __last) noexcept
532 erase(iterator __first, iterator __last)
535 // _GLIBCXX_RESOLVE_LIB_DEFECTS
536 // 151. can't currently clear() empty container
537 __glibcxx_check_erase_range(__first, __last);
538 for (_Base_const_iterator __victim = __first.base();
539 __victim != __last.base(); ++__victim)
541 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
542 _M_message(__gnu_debug::__msg_valid_range)
543 ._M_iterator(__first, "position")
544 ._M_iterator(__last, "last"));
545 this->_M_invalidate_if(_Equal(__victim));
548 return iterator(_Base::erase(__first.base(), __last.base()), this);
553 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
560 clear() _GLIBCXX_NOEXCEPT
563 this->_M_invalidate_all();
566 // 23.2.2.4 list operations:
568#if __cplusplus >= 201103L
569 splice(const_iterator __position, list&& __x) noexcept
571 splice(iterator __position, list& __x)
574 _GLIBCXX_DEBUG_VERIFY(std::__addressof(__x) != this,
575 _M_message(__gnu_debug::__msg_self_splice)
576 ._M_sequence(*this, "this"));
577 this->_M_transfer_from_if(__x, _Not_equal(__x._M_base().end()));
578 _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()));
581#if __cplusplus >= 201103L
583 splice(const_iterator __position, list& __x) noexcept
584 { splice(__position, std::move(__x)); }
588#if __cplusplus >= 201103L
589 splice(const_iterator __position, list&& __x, const_iterator __i) noexcept
591 splice(iterator __position, list& __x, iterator __i)
594 __glibcxx_check_insert(__position);
596 // We used to perform the splice_alloc check: not anymore, redundant
597 // after implementing the relevant bits of N1599.
599 _GLIBCXX_DEBUG_VERIFY(__i._M_dereferenceable(),
600 _M_message(__gnu_debug::__msg_splice_bad)
601 ._M_iterator(__i, "__i"));
602 _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(std::__addressof(__x)),
603 _M_message(__gnu_debug::__msg_splice_other)
604 ._M_iterator(__i, "__i")._M_sequence(__x, "__x"));
606 // _GLIBCXX_RESOLVE_LIB_DEFECTS
607 // 250. splicing invalidates iterators
608 this->_M_transfer_from_if(__x, _Equal(__i.base()));
609 _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()),
613#if __cplusplus >= 201103L
615 splice(const_iterator __position, list& __x, const_iterator __i) noexcept
616 { splice(__position, std::move(__x), __i); }
620#if __cplusplus >= 201103L
621 splice(const_iterator __position, list&& __x, const_iterator __first,
622 const_iterator __last) noexcept
624 splice(iterator __position, list& __x, iterator __first,
628 __glibcxx_check_insert(__position);
629 __glibcxx_check_valid_range(__first, __last);
630 _GLIBCXX_DEBUG_VERIFY(__first._M_attached_to(std::__addressof(__x)),
631 _M_message(__gnu_debug::__msg_splice_other)
632 ._M_sequence(__x, "x")
633 ._M_iterator(__first, "first"));
635 // We used to perform the splice_alloc check: not anymore, redundant
636 // after implementing the relevant bits of N1599.
638 for (_Base_const_iterator __tmp = __first.base();
639 __tmp != __last.base(); ++__tmp)
641 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
642 _M_message(__gnu_debug::__msg_valid_range)
643 ._M_iterator(__first, "first")
644 ._M_iterator(__last, "last"));
645 _GLIBCXX_DEBUG_VERIFY(std::__addressof(__x) != this
646 || __tmp != __position.base(),
647 _M_message(__gnu_debug::__msg_splice_overlap)
648 ._M_iterator(__tmp, "position")
649 ._M_iterator(__first, "first")
650 ._M_iterator(__last, "last"));
652 // _GLIBCXX_RESOLVE_LIB_DEFECTS
653 // 250. splicing invalidates iterators
654 this->_M_transfer_from_if(__x, _Equal(__tmp));
657 _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()),
658 __first.base(), __last.base());
661#if __cplusplus >= 201103L
663 splice(const_iterator __position, list& __x,
664 const_iterator __first, const_iterator __last) noexcept
665 { splice(__position, std::move(__x), __first, __last); }
669#if __cplusplus > 201703L
670 typedef size_type __remove_return_type;
671# define _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG \
672 __attribute__((__abi_tag__("__cxx20")))
673# define _GLIBCXX20_ONLY(__expr) __expr
675 typedef void __remove_return_type;
676# define _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
677# define _GLIBCXX20_ONLY(__expr)
681 _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
683 remove(const _Tp& __value)
685 if (!this->_M_iterators && !this->_M_const_iterators)
686 return _Base::remove(__value);
688#if !_GLIBCXX_USE_CXX11_ABI
689 size_type __removed __attribute__((__unused__)) = 0;
691 _Base __to_destroy(get_allocator());
692 _Base_iterator __first = _Base::begin();
693 _Base_iterator __last = _Base::end();
694 while (__first != __last)
696 _Base_iterator __next = __first;
698 if (*__first == __value)
700 // _GLIBCXX_RESOLVE_LIB_DEFECTS
701 // 526. Is it undefined if a function in the standard changes
703 this->_M_invalidate_if(_Equal(__first));
704 __to_destroy.splice(__to_destroy.begin(), _M_base(), __first);
705#if !_GLIBCXX_USE_CXX11_ABI
706 _GLIBCXX20_ONLY( __removed++ );
713#if !_GLIBCXX_USE_CXX11_ABI
714 return _GLIBCXX20_ONLY( __removed );
716 return _GLIBCXX20_ONLY( __to_destroy.size() );
720 template<class _Predicate>
722 remove_if(_Predicate __pred)
724 if (!this->_M_iterators && !this->_M_const_iterators)
725 return _Base::remove_if(__pred);
727#if !_GLIBCXX_USE_CXX11_ABI
728 size_type __removed __attribute__((__unused__)) = 0;
730 _Base __to_destroy(get_allocator());
731 for (_Base_iterator __x = _Base::begin(); __x != _Base::end(); )
733 _Base_iterator __next = __x;
737 this->_M_invalidate_if(_Equal(__x));
738 __to_destroy.splice(__to_destroy.begin(), _M_base(), __x);
739#if !_GLIBCXX_USE_CXX11_ABI
740 _GLIBCXX20_ONLY( __removed++ );
747#if !_GLIBCXX_USE_CXX11_ABI
748 return _GLIBCXX20_ONLY( __removed );
750 return _GLIBCXX20_ONLY( __to_destroy.size() );
754 _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
758 if (!this->_M_iterators && !this->_M_const_iterators)
759 return _Base::unique();
762 return _GLIBCXX20_ONLY(0);
764#if !_GLIBCXX_USE_CXX11_ABI
765 size_type __removed __attribute__((__unused__)) = 0;
767 _Base __to_destroy(get_allocator());
768 _Base_iterator __first = _Base::begin();
769 _Base_iterator __last = _Base::end();
770 _Base_iterator __next = __first;
771 while (++__next != __last)
772 if (*__first == *__next)
774 this->_M_invalidate_if(_Equal(__next));
775 __to_destroy.splice(__to_destroy.begin(), _M_base(), __next);
777#if !_GLIBCXX_USE_CXX11_ABI
778 _GLIBCXX20_ONLY( __removed++ );
784#if !_GLIBCXX_USE_CXX11_ABI
785 return _GLIBCXX20_ONLY( __removed );
787 return _GLIBCXX20_ONLY( __to_destroy.size() );
791 template<class _BinaryPredicate>
793 unique(_BinaryPredicate __binary_pred)
795 if (!this->_M_iterators && !this->_M_const_iterators)
796 return _Base::unique(__binary_pred);
799 return _GLIBCXX20_ONLY(0);
802#if !_GLIBCXX_USE_CXX11_ABI
803 size_type __removed __attribute__((__unused__)) = 0;
805 _Base __to_destroy(get_allocator());
806 _Base_iterator __first = _Base::begin();
807 _Base_iterator __last = _Base::end();
808 _Base_iterator __next = __first;
809 while (++__next != __last)
810 if (__binary_pred(*__first, *__next))
812 this->_M_invalidate_if(_Equal(__next));
813 __to_destroy.splice(__to_destroy.begin(), _M_base(), __next);
815#if !_GLIBCXX_USE_CXX11_ABI
816 _GLIBCXX20_ONLY( __removed++ );
822#if !_GLIBCXX_USE_CXX11_ABI
823 return _GLIBCXX20_ONLY( __removed );
825 return _GLIBCXX20_ONLY( __to_destroy.size() );
829#undef _GLIBCXX_LIST_REMOVE_RETURN_TYPE_TAG
830#undef _GLIBCXX20_ONLY
833#if __cplusplus >= 201103L
839 // _GLIBCXX_RESOLVE_LIB_DEFECTS
840 // 300. list::merge() specification incomplete
841 if (this != std::__addressof(__x))
843 __glibcxx_check_sorted(_Base::begin(), _Base::end());
844 __glibcxx_check_sorted(__x.begin().base(), __x.end().base());
845 this->_M_transfer_from_if(__x, _Not_equal(__x._M_base().end()));
846 _Base::merge(_GLIBCXX_MOVE(__x._M_base()));
850#if __cplusplus >= 201103L
853 { merge(std::move(__x)); }
856 template<class _Compare>
858#if __cplusplus >= 201103L
859 merge(list&& __x, _Compare __comp)
861 merge(list& __x, _Compare __comp)
864 // _GLIBCXX_RESOLVE_LIB_DEFECTS
865 // 300. list::merge() specification incomplete
866 if (this != std::__addressof(__x))
868 __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(),
870 __glibcxx_check_sorted_pred(__x.begin().base(), __x.end().base(),
872 this->_M_transfer_from_if(__x, _Not_equal(__x._M_base().end()));
873 _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp);
877#if __cplusplus >= 201103L
878 template<typename _Compare>
880 merge(list& __x, _Compare __comp)
881 { merge(std::move(__x), __comp); }
885 sort() { _Base::sort(); }
887 template<typename _StrictWeakOrdering>
889 sort(_StrictWeakOrdering __pred) { _Base::sort(__pred); }
891 using _Base::reverse;
894 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
897 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
900#if __cpp_deduction_guides >= 201606
901 template<typename _InputIterator, typename _ValT
902 = typename iterator_traits<_InputIterator>::value_type,
903 typename _Allocator = allocator<_ValT>,
904 typename = _RequireInputIter<_InputIterator>,
905 typename = _RequireAllocator<_Allocator>>
906 list(_InputIterator, _InputIterator, _Allocator = _Allocator())
907 -> list<_ValT, _Allocator>;
909 template<typename _Tp, typename _Allocator = allocator<_Tp>,
910 typename = _RequireAllocator<_Allocator>>
911 list(size_t, _Tp, _Allocator = _Allocator())
912 -> list<_Tp, _Allocator>;
915 template<typename _Tp, typename _Alloc>
917 operator==(const list<_Tp, _Alloc>& __lhs,
918 const list<_Tp, _Alloc>& __rhs)
919 { return __lhs._M_base() == __rhs._M_base(); }
921#if __cpp_lib_three_way_comparison
922 template<typename _Tp, typename _Alloc>
923 constexpr __detail::__synth3way_t<_Tp>
924 operator<=>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
925 { return __x._M_base() <=> __y._M_base(); }
927 template<typename _Tp, typename _Alloc>
929 operator!=(const list<_Tp, _Alloc>& __lhs,
930 const list<_Tp, _Alloc>& __rhs)
931 { return __lhs._M_base() != __rhs._M_base(); }
933 template<typename _Tp, typename _Alloc>
935 operator<(const list<_Tp, _Alloc>& __lhs,
936 const list<_Tp, _Alloc>& __rhs)
937 { return __lhs._M_base() < __rhs._M_base(); }
939 template<typename _Tp, typename _Alloc>
941 operator<=(const list<_Tp, _Alloc>& __lhs,
942 const list<_Tp, _Alloc>& __rhs)
943 { return __lhs._M_base() <= __rhs._M_base(); }
945 template<typename _Tp, typename _Alloc>
947 operator>=(const list<_Tp, _Alloc>& __lhs,
948 const list<_Tp, _Alloc>& __rhs)
949 { return __lhs._M_base() >= __rhs._M_base(); }
951 template<typename _Tp, typename _Alloc>
953 operator>(const list<_Tp, _Alloc>& __lhs,
954 const list<_Tp, _Alloc>& __rhs)
955 { return __lhs._M_base() > __rhs._M_base(); }
956#endif // three-way comparison
958 template<typename _Tp, typename _Alloc>
960 swap(list<_Tp, _Alloc>& __lhs, list<_Tp, _Alloc>& __rhs)
961 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
962 { __lhs.swap(__rhs); }
964} // namespace __debug
969#ifndef _GLIBCXX_USE_CXX11_ABI
970 // If not using C++11 list::size() is not in O(1) so we do not use it.
971 template<typename _Tp, typename _Alloc>
972 struct _Sequence_traits<std::__debug::list<_Tp, _Alloc> >
974 typedef typename std::__debug::list<_Tp, _Alloc>::iterator _It;
976 static typename _Distance_traits<_It>::__type
977 _S_size(const std::__debug::list<_Tp, _Alloc>& __seq)
980 ? std::make_pair(0, __dp_exact) : std::make_pair(1, __dp_sign);
985#ifndef _GLIBCXX_DEBUG_PEDANTIC
986 template<class _Tp, class _Alloc>
987 struct _Insert_range_from_self_is_safe<std::__debug::list<_Tp, _Alloc> >
988 { enum { __value = 1 }; };