1// Debugging vector implementation -*- C++ -*-
3// Copyright (C) 2003-2025 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_VECTOR
30#define _GLIBCXX_DEBUG_VECTOR 1
33#pragma GCC system_header
36#include <bits/c++config.h>
37namespace std _GLIBCXX_VISIBILITY(default) { namespace __debug {
38 template<typename _Tp, typename _Allocator> class vector;
39} } // namespace std::__debug
42#include <debug/safe_sequence.h>
43#include <debug/safe_container.h>
44#include <debug/safe_iterator.h>
48 /** @brief Base class for Debug Mode vector.
50 * Adds information about the guaranteed capacity, which is useful for
51 * detecting code which relies on non-portable implementation details of
52 * the libstdc++ reallocation policy.
54 template<typename _SafeSequence,
55 typename _BaseSequence>
58 typedef typename _BaseSequence::size_type size_type;
62 _M_seq() const { return *static_cast<const _SafeSequence*>(this); }
66 _Safe_vector() _GLIBCXX_NOEXCEPT
67 : _M_guaranteed_capacity(0)
68 { _M_update_guaranteed_capacity(); }
71 _Safe_vector(const _Safe_vector&) _GLIBCXX_NOEXCEPT
72 : _M_guaranteed_capacity(0)
73 { _M_update_guaranteed_capacity(); }
76 _Safe_vector(size_type __n) _GLIBCXX_NOEXCEPT
77 : _M_guaranteed_capacity(__n)
82 operator=(const _Safe_vector&) _GLIBCXX_NOEXCEPT
84 _M_update_guaranteed_capacity();
88#if __cplusplus >= 201103L
90 _Safe_vector(_Safe_vector&& __x) noexcept
92 { __x._M_guaranteed_capacity = 0; }
96 operator=(_Safe_vector&& __x) noexcept
98 _M_update_guaranteed_capacity();
99 __x._M_guaranteed_capacity = 0;
104 size_type _M_guaranteed_capacity;
107 _M_requires_reallocation(size_type __elements) const _GLIBCXX_NOEXCEPT
108 { return __elements > _M_seq().capacity(); }
112 _M_update_guaranteed_capacity() _GLIBCXX_NOEXCEPT
114 if (_M_seq().size() > _M_guaranteed_capacity)
115 _M_guaranteed_capacity = _M_seq().size();
120namespace std _GLIBCXX_VISIBILITY(default)
124 /// Class std::vector with safety/checking/debug instrumentation.
125 template<typename _Tp,
126 typename _Allocator = std::allocator<_Tp> >
128 : public __gnu_debug::_Safe_container<
129 vector<_Tp, _Allocator>, _Allocator, __gnu_debug::_Safe_sequence>,
130 public _GLIBCXX_STD_C::vector<_Tp, _Allocator>,
131 public __gnu_debug::_Safe_vector<
132 vector<_Tp, _Allocator>,
133 _GLIBCXX_STD_C::vector<_Tp, _Allocator> >
135 typedef _GLIBCXX_STD_C::vector<_Tp, _Allocator> _Base;
136 typedef __gnu_debug::_Safe_container<
137 vector, _Allocator, __gnu_debug::_Safe_sequence> _Safe;
138 typedef __gnu_debug::_Safe_vector<vector, _Base> _Safe_vector;
140 typedef typename _Base::iterator _Base_iterator;
141 typedef typename _Base::const_iterator _Base_const_iterator;
142 typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal;
144 template<typename _ItT, typename _SeqT, typename _CatT>
145 friend class ::__gnu_debug::_Safe_iterator;
147 // Reference wrapper for base class. Disambiguates vector(const _Base&)
148 // from copy constructor by requiring a user-defined conversion.
149 // See PR libstdc++/90102.
152 _Base_ref(const _Base& __r) : _M_ref(__r) { }
158 typedef typename _Base::reference reference;
159 typedef typename _Base::const_reference const_reference;
161 typedef __gnu_debug::_Safe_iterator<
162 _Base_iterator, vector> iterator;
163 typedef __gnu_debug::_Safe_iterator<
164 _Base_const_iterator, vector> const_iterator;
166 typedef typename _Base::size_type size_type;
167 typedef typename _Base::difference_type difference_type;
169 typedef _Tp value_type;
170 typedef _Allocator allocator_type;
171 typedef typename _Base::pointer pointer;
172 typedef typename _Base::const_pointer const_pointer;
173 typedef std::reverse_iterator<iterator> reverse_iterator;
174 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
176 // 23.2.4.1 construct/copy/destroy:
178#if __cplusplus < 201103L
179 vector() _GLIBCXX_NOEXCEPT
187 vector(const _Allocator& __a) _GLIBCXX_NOEXCEPT
190#if __cplusplus >= 201103L
193 vector(size_type __n, const _Allocator& __a = _Allocator())
194 : _Base(__n, __a), _Safe_vector(__n) { }
197 vector(size_type __n, const __type_identity_t<_Tp>& __value,
198 const _Allocator& __a = _Allocator())
199 : _Base(__n, __value, __a) { }
202 vector(size_type __n, const _Tp& __value = _Tp(),
203 const _Allocator& __a = _Allocator())
204 : _Base(__n, __value, __a) { }
207#if __cplusplus >= 201103L
208 template<class _InputIterator,
209 typename = std::_RequireInputIter<_InputIterator>>
211 template<class _InputIterator>
214 vector(_InputIterator __first, _InputIterator __last,
215 const _Allocator& __a = _Allocator())
216 : _Base(__gnu_debug::__base(std::__is_constant_evaluated() ? __first
217 : __glibcxx_check_valid_constructor_range(__first, __last)),
218 __gnu_debug::__base(__last), __a) { }
220#if __cplusplus < 201103L
221 vector(const vector& __x)
224 ~vector() _GLIBCXX_NOEXCEPT { }
226 vector(const vector&) = default;
227 vector(vector&&) = default;
230 vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
231 : _Base(__x, __a) { }
234 vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
236 std::is_nothrow_constructible<_Base,
237 _Base, const allocator_type&>::value )
238 : _Safe(std::move(__x), __a),
239 _Base(std::move(__x), __a),
240 _Safe_vector(std::move(__x)) { }
243 vector(initializer_list<value_type> __l,
244 const allocator_type& __a = allocator_type())
245 : _Base(__l, __a) { }
247#if __glibcxx_containers_ranges // C++ >= 23
249 * @brief Construct a vector from a range.
252 template<std::__detail::__container_compatible_range<_Tp> _Rg>
254 vector(std::from_range_t __t, _Rg&& __rg,
255 const allocator_type& __a = allocator_type())
256 : _Base(__t, std::forward<_Rg>(__rg), __a)
263 /// Construction from a normal-mode vector
265 vector(_Base_ref __x)
266 : _Base(__x._M_ref) { }
268#if __cplusplus >= 201103L
270 operator=(const vector&) = default;
273 operator=(vector&&) = default;
277 operator=(initializer_list<value_type> __l)
279 _Base::operator=(__l);
280 if (!std::__is_constant_evaluated())
282 this->_M_invalidate_all();
283 this->_M_update_guaranteed_capacity();
289#if __cplusplus >= 201103L
290 template<typename _InputIterator,
291 typename = std::_RequireInputIter<_InputIterator>>
293 template<typename _InputIterator>
297 assign(_InputIterator __first, _InputIterator __last)
299 if (std::__is_constant_evaluated())
300 return _Base::assign(__gnu_debug::__unsafe(__first),
301 __gnu_debug::__unsafe(__last));
303 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
304 __glibcxx_check_valid_range2(__first, __last, __dist);
306 if (__dist.second >= __gnu_debug::__dp_sign)
307 _Base::assign(__gnu_debug::__unsafe(__first),
308 __gnu_debug::__unsafe(__last));
310 _Base::assign(__first, __last);
312 this->_M_invalidate_all();
313 this->_M_update_guaranteed_capacity();
318 assign(size_type __n, const _Tp& __u)
320 _Base::assign(__n, __u);
321 if (!std::__is_constant_evaluated())
323 this->_M_invalidate_all();
324 this->_M_update_guaranteed_capacity();
328#if __cplusplus >= 201103L
331 assign(initializer_list<value_type> __l)
334 if (!std::__is_constant_evaluated())
336 this->_M_invalidate_all();
337 this->_M_update_guaranteed_capacity();
342 using _Base::get_allocator;
348 begin() _GLIBCXX_NOEXCEPT
349 { return iterator(_Base::begin(), this); }
354 begin() const _GLIBCXX_NOEXCEPT
355 { return const_iterator(_Base::begin(), this); }
360 end() _GLIBCXX_NOEXCEPT
361 { return iterator(_Base::end(), this); }
366 end() const _GLIBCXX_NOEXCEPT
367 { return const_iterator(_Base::end(), this); }
372 rbegin() _GLIBCXX_NOEXCEPT
373 { return reverse_iterator(end()); }
377 const_reverse_iterator
378 rbegin() const _GLIBCXX_NOEXCEPT
379 { return const_reverse_iterator(end()); }
384 rend() _GLIBCXX_NOEXCEPT
385 { return reverse_iterator(begin()); }
389 const_reverse_iterator
390 rend() const _GLIBCXX_NOEXCEPT
391 { return const_reverse_iterator(begin()); }
393#if __cplusplus >= 201103L
397 cbegin() const noexcept
398 { return const_iterator(_Base::begin(), this); }
403 cend() const noexcept
404 { return const_iterator(_Base::end(), this); }
408 const_reverse_iterator
409 crbegin() const noexcept
410 { return const_reverse_iterator(end()); }
414 const_reverse_iterator
415 crend() const noexcept
416 { return const_reverse_iterator(begin()); }
419 // 23.2.4.2 capacity:
421 using _Base::max_size;
423#if __cplusplus >= 201103L
426 resize(size_type __sz)
428 if (std::__is_constant_evaluated())
429 return _Base::resize(__sz);
431 bool __realloc = this->_M_requires_reallocation(__sz);
432 if (__sz < this->size())
433 this->_M_invalidate_after_nth(__sz);
436 this->_M_invalidate_all();
437 this->_M_update_guaranteed_capacity();
442 resize(size_type __sz, const _Tp& __c)
444 if (std::__is_constant_evaluated())
445 return _Base::resize(__sz, __c);
447 bool __realloc = this->_M_requires_reallocation(__sz);
448 if (__sz < this->size())
449 this->_M_invalidate_after_nth(__sz);
450 _Base::resize(__sz, __c);
452 this->_M_invalidate_all();
453 this->_M_update_guaranteed_capacity();
457 resize(size_type __sz, _Tp __c = _Tp())
459 bool __realloc = this->_M_requires_reallocation(__sz);
460 if (__sz < this->size())
461 this->_M_invalidate_after_nth(__sz);
462 _Base::resize(__sz, __c);
464 this->_M_invalidate_all();
465 this->_M_update_guaranteed_capacity();
469#if __cplusplus >= 201103L
474 if (std::__is_constant_evaluated())
475 return _Base::shrink_to_fit();
477 if (_Base::_M_shrink_to_fit())
479 this->_M_guaranteed_capacity = _Base::capacity();
480 this->_M_invalidate_all();
488 capacity() const _GLIBCXX_NOEXCEPT
490 if (std::__is_constant_evaluated())
491 return _Base::capacity();
493#ifdef _GLIBCXX_DEBUG_PEDANTIC
494 return this->_M_guaranteed_capacity;
496 return _Base::capacity();
504 reserve(size_type __n)
506 if (std::__is_constant_evaluated())
507 return _Base::reserve(__n);
509 bool __realloc = this->_M_requires_reallocation(__n);
511 if (__n > this->_M_guaranteed_capacity)
512 this->_M_guaranteed_capacity = __n;
514 this->_M_invalidate_all();
521 operator[](size_type __n) _GLIBCXX_NOEXCEPT
523 __glibcxx_check_subscript(__n);
524 return _Base::operator[](__n);
530 operator[](size_type __n) const _GLIBCXX_NOEXCEPT
532 __glibcxx_check_subscript(__n);
533 return _Base::operator[](__n);
541 front() _GLIBCXX_NOEXCEPT
543 __glibcxx_check_nonempty();
544 return _Base::front();
550 front() const _GLIBCXX_NOEXCEPT
552 __glibcxx_check_nonempty();
553 return _Base::front();
559 back() _GLIBCXX_NOEXCEPT
561 __glibcxx_check_nonempty();
562 return _Base::back();
568 back() const _GLIBCXX_NOEXCEPT
570 __glibcxx_check_nonempty();
571 return _Base::back();
574 // _GLIBCXX_RESOLVE_LIB_DEFECTS
575 // DR 464. Suggestion for new member functions in standard containers.
578 // 23.2.4.3 modifiers:
581 push_back(const _Tp& __x)
583 if (std::__is_constant_evaluated())
584 return _Base::push_back(__x);
586 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
587 _Base::push_back(__x);
589 this->_M_invalidate_all();
590 this->_M_update_guaranteed_capacity();
593#if __cplusplus >= 201103L
594 template<typename _Up = _Tp>
596 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
599 { emplace_back(std::move(__x)); }
601 template<typename... _Args>
603#if __cplusplus > 201402L
608 emplace_back(_Args&&... __args)
610 if (std::__is_constant_evaluated())
611 return _Base::emplace_back(std::forward<_Args>(__args)...);
613 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
614 _Base::emplace_back(std::forward<_Args>(__args)...);
616 this->_M_invalidate_all();
617 this->_M_update_guaranteed_capacity();
618#if __cplusplus > 201402L
626 pop_back() _GLIBCXX_NOEXCEPT
628 if (!std::__is_constant_evaluated())
630 __glibcxx_check_nonempty();
631 this->_M_invalidate_if(_Equal(--_Base::end()));
636#if __cplusplus >= 201103L
637 template<typename... _Args>
640 emplace(const_iterator __position, _Args&&... __args)
642 if (std::__is_constant_evaluated())
643 return iterator(_Base::emplace(__position.base(),
644 std::forward<_Args>(__args)...),
647 __glibcxx_check_insert(__position);
648 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
649 difference_type __offset = __position.base() - _Base::cbegin();
650 _Base_iterator __res = _Base::emplace(__position.base(),
651 std::forward<_Args>(__args)...);
653 this->_M_invalidate_all();
655 this->_M_invalidate_after_nth(__offset);
656 this->_M_update_guaranteed_capacity();
657 return { __res, this };
663#if __cplusplus >= 201103L
664 insert(const_iterator __position, const _Tp& __x)
666 insert(iterator __position, const _Tp& __x)
669 if (std::__is_constant_evaluated())
670 return iterator(_Base::insert(__position.base(), __x), this);
672 __glibcxx_check_insert(__position);
673 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
674 difference_type __offset = __position.base() - _Base::begin();
675 _Base_iterator __res = _Base::insert(__position.base(), __x);
677 this->_M_invalidate_all();
679 this->_M_invalidate_after_nth(__offset);
680 this->_M_update_guaranteed_capacity();
681 return iterator(__res, this);
684#if __cplusplus >= 201103L
685 template<typename _Up = _Tp>
687 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
689 insert(const_iterator __position, _Tp&& __x)
690 { return emplace(__position, std::move(__x)); }
694 insert(const_iterator __position, initializer_list<value_type> __l)
695 { return this->insert(__position, __l.begin(), __l.end()); }
698#if __cplusplus >= 201103L
701 insert(const_iterator __position, size_type __n, const _Tp& __x)
703 if (std::__is_constant_evaluated())
704 return iterator(_Base::insert(__position.base(), __n, __x), this);
706 __glibcxx_check_insert(__position);
707 bool __realloc = this->_M_requires_reallocation(this->size() + __n);
708 difference_type __offset = __position.base() - _Base::cbegin();
709 _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
711 this->_M_invalidate_all();
713 this->_M_invalidate_after_nth(__offset);
714 this->_M_update_guaranteed_capacity();
715 return { __res, this };
719 insert(iterator __position, size_type __n, const _Tp& __x)
721 __glibcxx_check_insert(__position);
722 bool __realloc = this->_M_requires_reallocation(this->size() + __n);
723 difference_type __offset = __position.base() - _Base::begin();
724 _Base::insert(__position.base(), __n, __x);
726 this->_M_invalidate_all();
728 this->_M_invalidate_after_nth(__offset);
729 this->_M_update_guaranteed_capacity();
733#if __cplusplus >= 201103L
734 template<class _InputIterator,
735 typename = std::_RequireInputIter<_InputIterator>>
738 insert(const_iterator __position,
739 _InputIterator __first, _InputIterator __last)
741 if (std::__is_constant_evaluated())
742 return iterator(_Base::insert(__position.base(),
743 __gnu_debug::__unsafe(__first),
744 __gnu_debug::__unsafe(__last)), this);
746 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
747 __glibcxx_check_insert_range(__position, __first, __last, __dist);
749 /* Hard to guess if invalidation will occur, because __last
750 - __first can't be calculated in all cases, so we just
751 punt here by checking if it did occur. */
752 _Base_iterator __old_begin = _M_base().begin();
753 difference_type __offset = __position.base() - _Base::cbegin();
754 _Base_iterator __res;
755 if (__dist.second >= __gnu_debug::__dp_sign)
756 __res = _Base::insert(__position.base(),
757 __gnu_debug::__unsafe(__first),
758 __gnu_debug::__unsafe(__last));
760 __res = _Base::insert(__position.base(), __first, __last);
762 if (_M_base().begin() != __old_begin)
763 this->_M_invalidate_all();
765 this->_M_invalidate_after_nth(__offset);
766 this->_M_update_guaranteed_capacity();
767 return { __res, this };
770 template<class _InputIterator>
772 insert(iterator __position,
773 _InputIterator __first, _InputIterator __last)
775 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
776 __glibcxx_check_insert_range(__position, __first, __last, __dist);
778 /* Hard to guess if invalidation will occur, because __last
779 - __first can't be calculated in all cases, so we just
780 punt here by checking if it did occur. */
781 _Base_iterator __old_begin = _M_base().begin();
782 difference_type __offset = __position.base() - _Base::begin();
783 if (__dist.second >= __gnu_debug::__dp_sign)
784 _Base::insert(__position.base(), __gnu_debug::__unsafe(__first),
785 __gnu_debug::__unsafe(__last));
787 _Base::insert(__position.base(), __first, __last);
789 if (_M_base().begin() != __old_begin)
790 this->_M_invalidate_all();
792 this->_M_invalidate_after_nth(__offset);
793 this->_M_update_guaranteed_capacity();
799#if __cplusplus >= 201103L
800 erase(const_iterator __position)
802 erase(iterator __position)
805 if (std::__is_constant_evaluated())
806 return iterator(_Base::erase(__position.base()), this);
808 __glibcxx_check_erase(__position);
809 difference_type __offset = __position.base() - _Base::begin();
810 _Base_iterator __res = _Base::erase(__position.base());
811 this->_M_invalidate_after_nth(__offset);
812 return iterator(__res, this);
817#if __cplusplus >= 201103L
818 erase(const_iterator __first, const_iterator __last)
820 erase(iterator __first, iterator __last)
823 if (std::__is_constant_evaluated())
824 return iterator(_Base::erase(__first.base(), __last.base()), this);
826 // _GLIBCXX_RESOLVE_LIB_DEFECTS
827 // 151. can't currently clear() empty container
828 __glibcxx_check_erase_range(__first, __last);
830 if (__first.base() != __last.base())
832 difference_type __offset = __first.base() - _Base::begin();
833 _Base_iterator __res = _Base::erase(__first.base(),
835 this->_M_invalidate_after_nth(__offset);
836 return iterator(__res, this);
839#if __cplusplus >= 201103L
840 return { _Base::begin() + (__first.base() - _Base::cbegin()), this };
849 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
851 if (!std::__is_constant_evaluated())
854 std::swap(this->_M_guaranteed_capacity, __x._M_guaranteed_capacity);
859 clear() _GLIBCXX_NOEXCEPT
862 if (!std::__is_constant_evaluated())
863 this->_M_invalidate_all();
868 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
872 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
874#if __glibcxx_containers_ranges // C++ >= 23
875 template<std::__detail::__container_compatible_range<_Tp> _Rg>
877 assign_range(_Rg&& __rg)
879 auto __old_capacity = _Base::capacity();
880 auto __old_size = _Base::size();
881 _Base::assign_range(__rg);
882 if (!std::__is_constant_evaluated())
884 if (_Base::capacity() != __old_capacity)
885 this->_M_invalidate_all();
886 else if (_Base::size() < __old_size)
887 this->_M_invalidate_after_nth(_Base::size());
888 this->_M_update_guaranteed_capacity();
892 template<__detail::__container_compatible_range<_Tp> _Rg>
894 insert_range(const_iterator __pos, _Rg&& __rg)
896 auto __old_capacity = _Base::capacity();
897 auto __res = _Base::insert_range(__pos.base(), __rg);
898 if (!std::__is_constant_evaluated())
900 if (_Base::capacity() != __old_capacity)
901 this->_M_invalidate_all();
902 this->_M_update_guaranteed_capacity();
904 return iterator(__res, this);
907 template<__detail::__container_compatible_range<_Tp> _Rg>
909 append_range(_Rg&& __rg)
911 auto __old_capacity = _Base::capacity();
912 _Base::append_range(__rg);
913 if (!std::__is_constant_evaluated())
915 if (_Base::capacity() != __old_capacity)
916 this->_M_invalidate_all();
917 this->_M_update_guaranteed_capacity();
924 _M_invalidate_after_nth(difference_type __n) _GLIBCXX_NOEXCEPT
926 typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth;
927 this->_M_invalidate_if(_After_nth(__n, _Base::begin()));
931 template<typename _Tp, typename _Alloc>
932 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
934 operator==(const vector<_Tp, _Alloc>& __lhs,
935 const vector<_Tp, _Alloc>& __rhs)
936 { return __lhs._M_base() == __rhs._M_base(); }
938#if __cpp_lib_three_way_comparison
939 template<typename _Tp, typename _Alloc>
941 constexpr __detail::__synth3way_t<_Tp>
942 operator<=>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
943 { return __x._M_base() <=> __y._M_base(); }
945 template<typename _Tp, typename _Alloc>
948 operator!=(const vector<_Tp, _Alloc>& __lhs,
949 const vector<_Tp, _Alloc>& __rhs)
950 { return __lhs._M_base() != __rhs._M_base(); }
952 template<typename _Tp, typename _Alloc>
955 operator<(const vector<_Tp, _Alloc>& __lhs,
956 const vector<_Tp, _Alloc>& __rhs)
957 { return __lhs._M_base() < __rhs._M_base(); }
959 template<typename _Tp, typename _Alloc>
962 operator<=(const vector<_Tp, _Alloc>& __lhs,
963 const vector<_Tp, _Alloc>& __rhs)
964 { return __lhs._M_base() <= __rhs._M_base(); }
966 template<typename _Tp, typename _Alloc>
969 operator>=(const vector<_Tp, _Alloc>& __lhs,
970 const vector<_Tp, _Alloc>& __rhs)
971 { return __lhs._M_base() >= __rhs._M_base(); }
973 template<typename _Tp, typename _Alloc>
976 operator>(const vector<_Tp, _Alloc>& __lhs,
977 const vector<_Tp, _Alloc>& __rhs)
978 { return __lhs._M_base() > __rhs._M_base(); }
979#endif // three-way comparison
981 template<typename _Tp, typename _Alloc>
984 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
985 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
986 { __lhs.swap(__rhs); }
988#if __cpp_deduction_guides >= 201606
989 template<typename _InputIterator, typename _ValT
990 = typename iterator_traits<_InputIterator>::value_type,
991 typename _Allocator = allocator<_ValT>,
992 typename = _RequireInputIter<_InputIterator>,
993 typename = _RequireAllocator<_Allocator>>
994 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
995 -> vector<_ValT, _Allocator>;
997 template<typename _Tp, typename _Allocator = allocator<_Tp>,
998 typename = _RequireAllocator<_Allocator>>
999 vector(size_t, _Tp, _Allocator = _Allocator())
1000 -> vector<_Tp, _Allocator>;
1002#if __glibcxx_containers_ranges // C++ >= 23
1003 template<ranges::input_range _Rg,
1004 typename _Alloc = allocator<ranges::range_value_t<_Rg>>>
1005 vector(from_range_t, _Rg&&, _Alloc = _Alloc())
1006 -> vector<ranges::range_value_t<_Rg>, _Alloc>;
1010} // namespace __debug
1012_GLIBCXX_BEGIN_NAMESPACE_VERSION
1014#if __cplusplus >= 201103L
1016 /// std::hash specialization for vector<bool>.
1017 template<typename _Alloc>
1018 struct hash<__debug::vector<bool, _Alloc>>
1019 : public __hash_base<size_t, __debug::vector<bool, _Alloc>>
1022 operator()(const __debug::vector<bool, _Alloc>& __b) const noexcept
1023 { return std::hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>()(__b); }
1027#if __cplusplus >= 201703L
1028 namespace __detail::__variant
1030 template<typename> struct _Never_valueless_alt; // see <variant>
1032 // Provide the strong exception-safety guarantee when emplacing a
1033 // vector into a variant, but only if move assignment cannot throw.
1034 template<typename _Tp, typename _Alloc>
1035 struct _Never_valueless_alt<__debug::vector<_Tp, _Alloc>>
1036 : std::is_nothrow_move_assignable<__debug::vector<_Tp, _Alloc>>
1038 } // namespace __detail::__variant
1041_GLIBCXX_END_NAMESPACE_VERSION
1044namespace __gnu_debug
1046 template<typename _Tp, typename _Alloc>
1047 struct _Is_contiguous_sequence<std::__debug::vector<_Tp, _Alloc> >
1051 template<typename _Alloc>
1052 struct _Is_contiguous_sequence<std::__debug::vector<bool, _Alloc> >