brintos

brintos / llvm-project-archived public Read only

0
0
Text · 58.8 KiB · 4961a5f Raw
1435 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___VECTOR_VECTOR_H10#define _LIBCPP___VECTOR_VECTOR_H11 12#include <__algorithm/copy.h>13#include <__algorithm/copy_n.h>14#include <__algorithm/fill_n.h>15#include <__algorithm/iterator_operations.h>16#include <__algorithm/max.h>17#include <__algorithm/min.h>18#include <__algorithm/move.h>19#include <__algorithm/move_backward.h>20#include <__algorithm/rotate.h>21#include <__assert>22#include <__config>23#include <__debug_utils/sanitizers.h>24#include <__format/enable_insertable.h>25#include <__fwd/vector.h>26#include <__iterator/bounded_iter.h>27#include <__iterator/concepts.h>28#include <__iterator/distance.h>29#include <__iterator/iterator_traits.h>30#include <__iterator/move_iterator.h>31#include <__iterator/next.h>32#include <__iterator/reverse_iterator.h>33#include <__iterator/wrap_iter.h>34#include <__memory/addressof.h>35#include <__memory/allocate_at_least.h>36#include <__memory/allocator.h>37#include <__memory/allocator_traits.h>38#include <__memory/compressed_pair.h>39#include <__memory/noexcept_move_assign_container.h>40#include <__memory/pointer_traits.h>41#include <__memory/swap_allocator.h>42#include <__memory/temp_value.h>43#include <__memory/uninitialized_algorithms.h>44#include <__ranges/access.h>45#include <__ranges/concepts.h>46#include <__ranges/container_compatible_range.h>47#include <__ranges/from_range.h>48#include <__split_buffer>49#include <__type_traits/conditional.h>50#include <__type_traits/enable_if.h>51#include <__type_traits/is_allocator.h>52#include <__type_traits/is_constant_evaluated.h>53#include <__type_traits/is_constructible.h>54#include <__type_traits/is_nothrow_assignable.h>55#include <__type_traits/is_nothrow_constructible.h>56#include <__type_traits/is_pointer.h>57#include <__type_traits/is_same.h>58#include <__type_traits/is_trivially_relocatable.h>59#include <__type_traits/type_identity.h>60#include <__utility/declval.h>61#include <__utility/exception_guard.h>62#include <__utility/forward.h>63#include <__utility/is_pointer_in_range.h>64#include <__utility/move.h>65#include <__utility/pair.h>66#include <__utility/swap.h>67#include <initializer_list>68#include <limits>69#include <stdexcept>70 71// These headers define parts of vectors definition, since they define ADL functions or class specializations.72#include <__vector/comparison.h>73#include <__vector/container_traits.h>74#include <__vector/swap.h>75 76#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)77#  pragma GCC system_header78#endif79 80_LIBCPP_PUSH_MACROS81#include <__undef_macros>82 83_LIBCPP_BEGIN_NAMESPACE_STD84 85template <class _Tp, class _Allocator /* = allocator<_Tp> */>86class vector {87  template <class _Up, class _Alloc>88  using __split_buffer _LIBCPP_NODEBUG = std::__split_buffer<_Up, _Alloc, __split_buffer_pointer_layout>;89 90public:91  //92  // Types93  //94  using __self _LIBCPP_NODEBUG         = vector;95  using value_type                     = _Tp;96  using allocator_type                 = _Allocator;97  using __alloc_traits _LIBCPP_NODEBUG = allocator_traits<allocator_type>;98  using reference                      = value_type&;99  using const_reference                = const value_type&;100  using size_type                      = typename __alloc_traits::size_type;101  using difference_type                = typename __alloc_traits::difference_type;102  using pointer                        = typename __alloc_traits::pointer;103  using const_pointer                  = typename __alloc_traits::const_pointer;104#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR105  // Users might provide custom allocators, and prior to C++20 we have no existing way to detect whether the allocator's106  // pointer type is contiguous (though it has to be by the Standard). Using the wrapper type ensures the iterator is107  // considered contiguous.108  using iterator       = __bounded_iter<__wrap_iter<pointer> >;109  using const_iterator = __bounded_iter<__wrap_iter<const_pointer> >;110#else111  using iterator       = __wrap_iter<pointer>;112  using const_iterator = __wrap_iter<const_pointer>;113#endif114  using reverse_iterator       = std::reverse_iterator<iterator>;115  using const_reverse_iterator = std::reverse_iterator<const_iterator>;116 117  // A vector containers the following members which may be trivially relocatable:118  // - pointer: may be trivially relocatable, so it's checked119  // - allocator_type: may be trivially relocatable, so it's checked120  // vector doesn't contain any self-references, so it's trivially relocatable if its members are.121  using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<122      __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<allocator_type>::value,123      vector,124      void>;125 126  static_assert(__check_valid_allocator<allocator_type>::value, "");127  static_assert(is_same<typename allocator_type::value_type, value_type>::value,128                "Allocator::value_type must be same type as value_type");129 130  //131  // [vector.cons], construct/copy/destroy132  //133  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector()134      _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) {}135  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a)136#if _LIBCPP_STD_VER <= 14137      _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)138#else139      noexcept140#endif141      : __alloc_(__a) {142  }143 144  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n) {145    auto __guard = std::__make_exception_guard(__destroy_vector(*this));146    if (__n > 0) {147      __vallocate(__n);148      __construct_at_end(__n);149    }150    __guard.__complete();151  }152 153#if _LIBCPP_STD_VER >= 14154  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a)155      : __alloc_(__a) {156    auto __guard = std::__make_exception_guard(__destroy_vector(*this));157    if (__n > 0) {158      __vallocate(__n);159      __construct_at_end(__n);160    }161    __guard.__complete();162  }163#endif164 165  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x) {166    auto __guard = std::__make_exception_guard(__destroy_vector(*this));167    if (__n > 0) {168      __vallocate(__n);169      __construct_at_end(__n, __x);170    }171    __guard.__complete();172  }173 174  template <__enable_if_t<__is_allocator_v<_Allocator>, int> = 0>175  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI176  vector(size_type __n, const value_type& __x, const allocator_type& __a)177      : __alloc_(__a) {178    auto __guard = std::__make_exception_guard(__destroy_vector(*this));179    if (__n > 0) {180      __vallocate(__n);181      __construct_at_end(__n, __x);182    }183    __guard.__complete();184  }185 186  template <class _InputIterator,187            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&188                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,189                          int> = 0>190  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last) {191    __init_with_sentinel(__first, __last);192  }193 194  template <class _InputIterator,195            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&196                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,197                          int> = 0>198  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI199  vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)200      : __alloc_(__a) {201    __init_with_sentinel(__first, __last);202  }203 204  template <205      class _ForwardIterator,206      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&207                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,208                    int> = 0>209  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last) {210    size_type __n = static_cast<size_type>(std::distance(__first, __last));211    __init_with_size(__first, __last, __n);212  }213 214  template <215      class _ForwardIterator,216      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&217                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,218                    int> = 0>219  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI220  vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)221      : __alloc_(__a) {222    size_type __n = static_cast<size_type>(std::distance(__first, __last));223    __init_with_size(__first, __last, __n);224  }225 226#if _LIBCPP_STD_VER >= 23227  template <_ContainerCompatibleRange<_Tp> _Range>228  _LIBCPP_HIDE_FROM_ABI constexpr vector(229      from_range_t, _Range&& __range, const allocator_type& __alloc = allocator_type())230      : __alloc_(__alloc) {231    if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {232      auto __n = static_cast<size_type>(ranges::distance(__range));233      __init_with_size(ranges::begin(__range), ranges::end(__range), __n);234 235    } else {236      __init_with_sentinel(ranges::begin(__range), ranges::end(__range));237    }238  }239#endif240 241private:242  class __destroy_vector {243  public:244    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}245 246    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {247      if (__vec_.__begin_ != nullptr) {248        __vec_.clear();249        __vec_.__annotate_delete();250        __alloc_traits::deallocate(__vec_.__alloc_, __vec_.__begin_, __vec_.capacity());251      }252    }253 254  private:255    vector& __vec_;256  };257 258public:259  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector (*this)(); }260 261  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x)262      : __alloc_(__alloc_traits::select_on_container_copy_construction(__x.__alloc_)) {263    __init_with_size(__x.__begin_, __x.__end_, __x.size());264  }265  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI266  vector(const vector& __x, const __type_identity_t<allocator_type>& __a)267      : __alloc_(__a) {268    __init_with_size(__x.__begin_, __x.__end_, __x.size());269  }270  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(const vector& __x);271 272#ifndef _LIBCPP_CXX03_LANG273  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(initializer_list<value_type> __il) {274    __init_with_size(__il.begin(), __il.end(), __il.size());275  }276 277  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI278  vector(initializer_list<value_type> __il, const allocator_type& __a)279      : __alloc_(__a) {280    __init_with_size(__il.begin(), __il.end(), __il.size());281  }282 283  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(initializer_list<value_type> __il) {284    assign(__il.begin(), __il.end());285    return *this;286  }287#endif // !_LIBCPP_CXX03_LANG288 289  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(vector&& __x)290#if _LIBCPP_STD_VER >= 17291      noexcept;292#else293      _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);294#endif295 296  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI297  vector(vector&& __x, const __type_identity_t<allocator_type>& __a);298  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(vector&& __x)299      _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value) {300    __move_assign(__x, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());301    return *this;302  }303 304  template <class _InputIterator,305            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&306                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,307                          int> = 0>308  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_InputIterator __first, _InputIterator __last) {309    __assign_with_sentinel(__first, __last);310  }311  template <312      class _ForwardIterator,313      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&314                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,315                    int> = 0>316  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_ForwardIterator __first, _ForwardIterator __last) {317    __assign_with_size<_ClassicAlgPolicy>(__first, __last, std::distance(__first, __last));318  }319 320#if _LIBCPP_STD_VER >= 23321  template <_ContainerCompatibleRange<_Tp> _Range>322  _LIBCPP_HIDE_FROM_ABI constexpr void assign_range(_Range&& __range) {323    if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {324      auto __n = static_cast<size_type>(ranges::distance(__range));325      __assign_with_size<_RangeAlgPolicy>(ranges::begin(__range), ranges::end(__range), __n);326 327    } else {328      __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));329    }330  }331#endif332 333  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const_reference __u);334 335#ifndef _LIBCPP_CXX03_LANG336  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) {337    assign(__il.begin(), __il.end());338  }339#endif340 341  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT {342    return this->__alloc_;343  }344 345  //346  // Iterators347  //348  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT {349    return __make_iter(__add_alignment_assumption(this->__begin_));350  }351  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT {352    return __make_iter(__add_alignment_assumption(this->__begin_));353  }354  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT {355    return __make_iter(__add_alignment_assumption(this->__end_));356  }357  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT {358    return __make_iter(__add_alignment_assumption(this->__end_));359  }360 361  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT {362    return reverse_iterator(end());363  }364  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator365  rbegin() const _NOEXCEPT {366    return const_reverse_iterator(end());367  }368  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT {369    return reverse_iterator(begin());370  }371  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT {372    return const_reverse_iterator(begin());373  }374 375  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT {376    return begin();377  }378  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT {379    return end();380  }381  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator382  crbegin() const _NOEXCEPT {383    return rbegin();384  }385  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT {386    return rend();387  }388 389  //390  // [vector.capacity], capacity391  //392  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT {393    return static_cast<size_type>(this->__end_ - this->__begin_);394  }395  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type capacity() const _NOEXCEPT {396    return static_cast<size_type>(this->__cap_ - this->__begin_);397  }398  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT {399    return this->__begin_ == this->__end_;400  }401  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {402    return std::min<size_type>(__alloc_traits::max_size(this->__alloc_), numeric_limits<difference_type>::max());403  }404  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n);405  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;406 407  //408  // element access409  //410  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference operator[](size_type __n) _NOEXCEPT {411    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");412    return this->__begin_[__n];413  }414  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference415  operator[](size_type __n) const _NOEXCEPT {416    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");417    return this->__begin_[__n];418  }419  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference at(size_type __n) {420    if (__n >= size())421      this->__throw_out_of_range();422    return this->__begin_[__n];423  }424  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const {425    if (__n >= size())426      this->__throw_out_of_range();427    return this->__begin_[__n];428  }429 430  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference front() _NOEXCEPT {431    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");432    return *this->__begin_;433  }434  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT {435    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");436    return *this->__begin_;437  }438  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference back() _NOEXCEPT {439    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");440    return *(this->__end_ - 1);441  }442  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT {443    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");444    return *(this->__end_ - 1);445  }446 447  //448  // [vector.data], data access449  //450  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI value_type* data() _NOEXCEPT {451    return std::__to_address(this->__begin_);452  }453 454  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const value_type* data() const _NOEXCEPT {455    return std::__to_address(this->__begin_);456  }457 458  //459  // [vector.modifiers], modifiers460  //461  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x) { emplace_back(__x); }462 463  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x) { emplace_back(std::move(__x)); }464 465  template <class... _Args>466  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI467#if _LIBCPP_STD_VER >= 17468  reference469  emplace_back(_Args&&... __args);470#else471  void472  emplace_back(_Args&&... __args);473#endif474 475  template <class... _Args>476  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __emplace_back_assume_capacity(_Args&&... __args) {477    _LIBCPP_ASSERT_INTERNAL(478        size() < capacity(), "We assume that we have enough space to insert an element at the end of the vector");479    _ConstructTransaction __tx(*this, 1);480    __alloc_traits::construct(this->__alloc_, std::__to_address(__tx.__pos_), std::forward<_Args>(__args)...);481    ++__tx.__pos_;482  }483 484#if _LIBCPP_STD_VER >= 23485  template <_ContainerCompatibleRange<_Tp> _Range>486  _LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) {487    insert_range(end(), std::forward<_Range>(__range));488  }489#endif490 491  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void pop_back() {492    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector::pop_back called on an empty vector");493    this->__destruct_at_end(this->__end_ - 1);494  }495 496  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x);497 498  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x);499  template <class... _Args>500  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args);501 502  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator503  insert(const_iterator __position, size_type __n, const_reference __x);504 505  template <class _InputIterator,506            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&507                              is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value,508                          int> = 0>509  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator510  insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {511    return __insert_with_sentinel(__position, __first, __last);512  }513 514  template <515      class _ForwardIterator,516      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&517                        is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value,518                    int> = 0>519  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator520  insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) {521    return __insert_with_size<_ClassicAlgPolicy>(__position, __first, __last, std::distance(__first, __last));522  }523 524#if _LIBCPP_STD_VER >= 23525  template <_ContainerCompatibleRange<_Tp> _Range>526  _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) {527    if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {528      auto __n = static_cast<size_type>(ranges::distance(__range));529      return __insert_with_size<_RangeAlgPolicy>(__position, ranges::begin(__range), ranges::end(__range), __n);530 531    } else {532      return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));533    }534  }535#endif536 537#ifndef _LIBCPP_CXX03_LANG538  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator539  insert(const_iterator __position, initializer_list<value_type> __il) {540    return insert(__position, __il.begin(), __il.end());541  }542#endif543 544  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position);545  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);546 547  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT {548    size_type __old_size = size();549    __base_destruct_at_end(this->__begin_);550    __annotate_shrink(__old_size);551  }552 553  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz);554  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const_reference __x);555 556  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void swap(vector&)557#if _LIBCPP_STD_VER >= 14558      _NOEXCEPT;559#else560      _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);561#endif562 563  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;564 565private:566  pointer __begin_ = nullptr;567  pointer __end_   = nullptr;568  _LIBCPP_COMPRESSED_PAIR(pointer, __cap_ = nullptr, allocator_type, __alloc_);569 570  //  Allocate space for __n objects571  //  throws length_error if __n > max_size()572  //  throws (probably bad_alloc) if memory run out573  //  Precondition:  __begin_ == __end_ == __cap_ == nullptr574  //  Precondition:  __n > 0575  //  Postcondition:  capacity() >= __n576  //  Postcondition:  size() == 0577  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {578    if (__n > max_size())579      this->__throw_length_error();580    auto __allocation = std::__allocate_at_least(this->__alloc_, __n);581    __begin_          = __allocation.ptr;582    __end_            = __allocation.ptr;583    __cap_            = __begin_ + __allocation.count;584    __annotate_new(0);585  }586 587  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vdeallocate() _NOEXCEPT;588  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __recommend(size_type __new_size) const;589  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n);590  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n, const_reference __x);591 592  template <class _InputIterator, class _Sentinel>593  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void594  __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {595    auto __guard = std::__make_exception_guard(__destroy_vector(*this));596 597    if (__n > 0) {598      __vallocate(__n);599      __construct_at_end(std::move(__first), std::move(__last), __n);600    }601 602    __guard.__complete();603  }604 605  template <class _InputIterator, class _Sentinel>606  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void607  __init_with_sentinel(_InputIterator __first, _Sentinel __last) {608    auto __guard = std::__make_exception_guard(__destroy_vector(*this));609 610    for (; __first != __last; ++__first)611      emplace_back(*__first);612 613    __guard.__complete();614  }615 616  template <class _Iterator, class _Sentinel>617  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last);618 619  // The `_Iterator` in `*_with_size` functions can be input-only only if called from `*_range` (since C++23).620  // Otherwise, `_Iterator` is a forward iterator.621 622  template <class _AlgPolicy, class _Iterator, class _Sentinel>623  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void624  __assign_with_size(_Iterator __first, _Sentinel __last, difference_type __n);625 626  template <class _AlgPolicy,627            class _Iterator,628            __enable_if_t<!is_same<__policy_value_type<_AlgPolicy, _Iterator>, value_type>::value, int> = 0>629  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void630  __insert_assign_n_unchecked(_Iterator __first, difference_type __n, pointer __position) {631    for (pointer __end_position = __position + __n; __position != __end_position; ++__position, (void)++__first) {632      __temp_value<value_type, _Allocator> __tmp(this->__alloc_, *__first);633      *__position = std::move(__tmp.get());634    }635  }636 637  template <class _AlgPolicy,638            class _Iterator,639            __enable_if_t<is_same<__policy_value_type<_AlgPolicy, _Iterator>, value_type>::value, int> = 0>640  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void641  __insert_assign_n_unchecked(_Iterator __first, difference_type __n, pointer __position) {642    std::__copy_n<_AlgPolicy>(std::move(__first), __n, __position);643  }644 645  template <class _InputIterator, class _Sentinel>646  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator647  __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);648 649  template <class _AlgPolicy, class _Iterator, class _Sentinel>650  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator651  __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);652 653  template <class _InputIterator, class _Sentinel>654  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void655  __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);656 657  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator __make_iter(pointer __p) _NOEXCEPT {658#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR659    // Bound the iterator according to the capacity, rather than the size.660    //661    // Vector guarantees that iterators stay valid as long as no reallocation occurs even if new elements are inserted662    // into the container; for these cases, we need to make sure that the newly-inserted elements can be accessed663    // through the bounded iterator without failing checks. The downside is that the bounded iterator won't catch664    // access that is logically out-of-bounds, i.e., goes beyond the size, but is still within the capacity. With the665    // current implementation, there is no connection between a bounded iterator and its associated container, so we666    // don't have a way to update existing valid iterators when the container is resized and thus have to go with667    // a laxer approach.668    return std::__make_bounded_iter(669        std::__wrap_iter<pointer>(__p),670        std::__wrap_iter<pointer>(this->__begin_),671        std::__wrap_iter<pointer>(this->__cap_));672#else673    return iterator(__p);674#endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR675  }676 677  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator __make_iter(const_pointer __p) const _NOEXCEPT {678#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR679    // Bound the iterator according to the capacity, rather than the size.680    return std::__make_bounded_iter(681        std::__wrap_iter<const_pointer>(__p),682        std::__wrap_iter<const_pointer>(this->__begin_),683        std::__wrap_iter<const_pointer>(this->__cap_));684#else685    return const_iterator(__p);686#endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR687  }688 689  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void690  __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);691  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer692  __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);693  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void694  __move_range(pointer __from_s, pointer __from_e, pointer __to);695  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, true_type)696      _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);697  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type)698      _NOEXCEPT_(__alloc_traits::is_always_equal::value);699  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_end(pointer __new_last) _NOEXCEPT {700    size_type __old_size = size();701    __base_destruct_at_end(__new_last);702    __annotate_shrink(__old_size);703  }704 705  template <class... _Args>706  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI inline pointer __emplace_back_slow_path(_Args&&... __args);707 708  // The following functions are no-ops outside of AddressSanitizer mode.709  // We call annotations for every allocator, unless explicitly disabled.710  //711  // To disable annotations for a particular allocator, change value of712  // __asan_annotate_container_with_allocator to false.713  // For more details, see the "Using libc++" documentation page or714  // the documentation for __sanitizer_annotate_contiguous_container.715 716  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void717  __annotate_contiguous_container(const void* __old_mid, const void* __new_mid) const {718    std::__annotate_contiguous_container<_Allocator>(data(), data() + capacity(), __old_mid, __new_mid);719  }720 721  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT {722    __annotate_contiguous_container(data() + capacity(), data() + __current_size);723  }724 725  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {726    __annotate_contiguous_container(data() + size(), data() + capacity());727  }728 729  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_increase(size_type __n) const _NOEXCEPT {730    __annotate_contiguous_container(data() + size(), data() + size() + __n);731  }732 733  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink(size_type __old_size) const _NOEXCEPT {734    __annotate_contiguous_container(data() + __old_size, data() + size());735  }736 737  struct _ConstructTransaction {738    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit _ConstructTransaction(vector& __v, size_type __n)739        : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {740      __v_.__annotate_increase(__n);741    }742 743    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() {744      __v_.__end_ = __pos_;745      if (__pos_ != __new_end_) {746        __v_.__annotate_shrink(__new_end_ - __v_.__begin_);747      }748    }749 750    vector& __v_;751    pointer __pos_;752    const_pointer const __new_end_;753 754    _ConstructTransaction(_ConstructTransaction const&)            = delete;755    _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;756  };757 758  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {759    pointer __soon_to_be_end = this->__end_;760    while (__new_last != __soon_to_be_end)761      __alloc_traits::destroy(this->__alloc_, std::__to_address(--__soon_to_be_end));762    this->__end_ = __new_last;763  }764 765  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c) {766    __copy_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_copy_assignment::value>());767  }768 769  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c)770      _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value ||771                 is_nothrow_move_assignable<allocator_type>::value) {772    __move_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());773  }774 775  [[__noreturn__]] _LIBCPP_HIDE_FROM_ABI static void __throw_length_error() { std::__throw_length_error("vector"); }776 777  [[__noreturn__]] _LIBCPP_HIDE_FROM_ABI static void __throw_out_of_range() { std::__throw_out_of_range("vector"); }778 779  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c, true_type) {780    if (this->__alloc_ != __c.__alloc_) {781      clear();782      __annotate_delete();783      __alloc_traits::deallocate(this->__alloc_, this->__begin_, capacity());784      this->__begin_ = this->__end_ = this->__cap_ = nullptr;785    }786    this->__alloc_ = __c.__alloc_;787  }788 789  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector&, false_type) {}790 791  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c, true_type)792      _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {793    this->__alloc_ = std::move(__c.__alloc_);794  }795 796  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}797 798  template <class _Ptr = pointer, __enable_if_t<is_pointer<_Ptr>::value, int> = 0>799  static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI pointer800  __add_alignment_assumption(_Ptr __p) _NOEXCEPT {801    if (!__libcpp_is_constant_evaluated()) {802      return static_cast<pointer>(__builtin_assume_aligned(__p, _LIBCPP_ALIGNOF(decltype(*__p))));803    }804    return __p;805  }806 807  template <class _Ptr = pointer, __enable_if_t<!is_pointer<_Ptr>::value, int> = 0>808  static _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI pointer809  __add_alignment_assumption(_Ptr __p) _NOEXCEPT {810    return __p;811  }812 813  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_layouts(__split_buffer<_Tp, allocator_type&>& __sb) {814    auto __vector_begin    = __begin_;815    auto __vector_sentinel = __end_;816    auto __vector_cap      = __cap_;817 818    auto __sb_begin    = __sb.begin();819    auto __sb_sentinel = __sb.__raw_sentinel();820    auto __sb_cap      = __sb.__raw_capacity();821 822    // TODO: replace with __set_valid_range and __set_capacity when vector supports it.823    __begin_ = __sb_begin;824    __end_   = __sb_sentinel;825    __cap_   = __sb_cap;826 827    __sb.__set_valid_range(__vector_begin, __vector_sentinel);828    __sb.__set_capacity(__vector_cap);829  }830};831 832#if _LIBCPP_STD_VER >= 17833template <class _InputIterator,834          class _Alloc = allocator<__iterator_value_type<_InputIterator>>,835          class        = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,836          class        = enable_if_t<__is_allocator_v<_Alloc>>>837vector(_InputIterator, _InputIterator) -> vector<__iterator_value_type<_InputIterator>, _Alloc>;838 839template <class _InputIterator,840          class _Alloc,841          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,842          class = enable_if_t<__is_allocator_v<_Alloc>>>843vector(_InputIterator, _InputIterator, _Alloc) -> vector<__iterator_value_type<_InputIterator>, _Alloc>;844#endif845 846#if _LIBCPP_STD_VER >= 23847template <ranges::input_range _Range,848          class _Alloc = allocator<ranges::range_value_t<_Range>>,849          class        = enable_if_t<__is_allocator_v<_Alloc>>>850vector(from_range_t, _Range&&, _Alloc = _Alloc()) -> vector<ranges::range_value_t<_Range>, _Alloc>;851#endif852 853// __swap_out_circular_buffer relocates the objects in [__begin_, __end_) into the front of __v and swaps the buffers of854// *this and __v. It is assumed that __v provides space for exactly (__end_ - __begin_) objects in the front. This855// function has a strong exception guarantee.856template <class _Tp, class _Allocator>857_LIBCPP_CONSTEXPR_SINCE_CXX20 void858vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) {859  __annotate_delete();860  auto __new_begin = __v.begin() - size();861  std::__uninitialized_allocator_relocate(862      this->__alloc_, std::__to_address(__begin_), std::__to_address(__end_), std::__to_address(__new_begin));863  __v.__set_valid_range(__new_begin, __v.end());864  __end_       = __begin_; // All the objects have been destroyed by relocating them.865 866  __swap_layouts(__v);867  __v.__set_data(__v.begin());868  __annotate_new(size());869}870 871// __swap_out_circular_buffer relocates the objects in [__begin_, __p) into the front of __v, the objects in872// [__p, __end_) into the back of __v and swaps the buffers of *this and __v. It is assumed that __v provides space for873// exactly (__p - __begin_) objects in the front and space for at least (__end_ - __p) objects in the back. This874// function has a strong exception guarantee if __begin_ == __p || __end_ == __p.875template <class _Tp, class _Allocator>876_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer877vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) {878  __annotate_delete();879  pointer __ret = __v.begin();880 881  // Relocate [__p, __end_) first to avoid having a hole in [__begin_, __end_)882  // in case something in [__begin_, __p) throws.883  std::__uninitialized_allocator_relocate(884      this->__alloc_, std::__to_address(__p), std::__to_address(__end_), std::__to_address(__v.end()));885  auto __relocated_so_far = __end_ - __p;886  __v.__set_sentinel(__v.end() + __relocated_so_far);887  __end_           = __p; // The objects in [__p, __end_) have been destroyed by relocating them.888  auto __new_begin = __v.begin() - (__p - __begin_);889 890  std::__uninitialized_allocator_relocate(891      this->__alloc_, std::__to_address(__begin_), std::__to_address(__p), std::__to_address(__new_begin));892  __v.__set_valid_range(__new_begin, __v.end());893  __end_ = __begin_; // All the objects have been destroyed by relocating them.894  __swap_layouts(__v);895  __v.__set_data(__v.begin());896  __annotate_new(size());897  return __ret;898}899 900template <class _Tp, class _Allocator>901_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT {902  if (this->__begin_ != nullptr) {903    clear();904    __annotate_delete();905    __alloc_traits::deallocate(this->__alloc_, this->__begin_, capacity());906    this->__begin_ = this->__end_ = this->__cap_ = nullptr;907  }908}909 910//  Precondition:  __new_size > capacity()911template <class _Tp, class _Allocator>912_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type913vector<_Tp, _Allocator>::__recommend(size_type __new_size) const {914  const size_type __ms = max_size();915  if (__new_size > __ms)916    this->__throw_length_error();917  const size_type __cap = capacity();918  if (__cap >= __ms / 2)919    return __ms;920  return std::max<size_type>(2 * __cap, __new_size);921}922 923//  Default constructs __n objects starting at __end_924//  throws if construction throws925//  Precondition:  __n > 0926//  Precondition:  size() + __n <= capacity()927//  Postcondition:  size() == size() + __n928template <class _Tp, class _Allocator>929_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__construct_at_end(size_type __n) {930  _ConstructTransaction __tx(*this, __n);931  const_pointer __new_end = __tx.__new_end_;932  for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {933    __alloc_traits::construct(this->__alloc_, std::__to_address(__pos));934  }935}936 937//  Copy constructs __n objects starting at __end_ from __x938//  throws if construction throws939//  Precondition:  __n > 0940//  Precondition:  size() + __n <= capacity()941//  Postcondition:  size() == old size() + __n942//  Postcondition:  [i] == __x for all i in [size() - __n, __n)943template <class _Tp, class _Allocator>944_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void945vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) {946  _ConstructTransaction __tx(*this, __n);947  const_pointer __new_end = __tx.__new_end_;948  for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {949    __alloc_traits::construct(this->__alloc_, std::__to_address(__pos), __x);950  }951}952 953template <class _Tp, class _Allocator>954template <class _InputIterator, class _Sentinel>955_LIBCPP_CONSTEXPR_SINCE_CXX20 void956vector<_Tp, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {957  _ConstructTransaction __tx(*this, __n);958  __tx.__pos_ = std::__uninitialized_allocator_copy(this->__alloc_, std::move(__first), std::move(__last), __tx.__pos_);959}960 961template <class _Tp, class _Allocator>962_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(vector&& __x)963#if _LIBCPP_STD_VER >= 17964    noexcept965#else966    _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)967#endif968    : __alloc_(std::move(__x.__alloc_)) {969  this->__begin_ = __x.__begin_;970  this->__end_   = __x.__end_;971  this->__cap_   = __x.__cap_;972  __x.__begin_ = __x.__end_ = __x.__cap_ = nullptr;973}974 975template <class _Tp, class _Allocator>976_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI977vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)978    : __alloc_(__a) {979  if (__a == __x.__alloc_) {980    this->__begin_ = __x.__begin_;981    this->__end_   = __x.__end_;982    this->__cap_   = __x.__cap_;983    __x.__begin_ = __x.__end_ = __x.__cap_ = nullptr;984  } else {985    typedef move_iterator<iterator> _Ip;986    __init_with_size(_Ip(__x.begin()), _Ip(__x.end()), __x.size());987  }988}989 990template <class _Tp, class _Allocator>991_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)992    _NOEXCEPT_(__alloc_traits::is_always_equal::value) {993  if (this->__alloc_ != __c.__alloc_) {994    typedef move_iterator<iterator> _Ip;995    assign(_Ip(__c.begin()), _Ip(__c.end()));996  } else997    __move_assign(__c, true_type());998}999 1000template <class _Tp, class _Allocator>1001_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)1002    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {1003  __vdeallocate();1004  __move_assign_alloc(__c); // this can throw1005  this->__begin_ = __c.__begin_;1006  this->__end_   = __c.__end_;1007  this->__cap_   = __c.__cap_;1008  __c.__begin_ = __c.__end_ = __c.__cap_ = nullptr;1009}1010 1011template <class _Tp, class _Allocator>1012_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>&1013vector<_Tp, _Allocator>::operator=(const vector& __x) {1014  if (this != std::addressof(__x)) {1015    __copy_assign_alloc(__x);1016    assign(__x.__begin_, __x.__end_);1017  }1018  return *this;1019}1020 1021template <class _Tp, class _Allocator>1022template <class _Iterator, class _Sentinel>1023_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void1024vector<_Tp, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {1025  pointer __cur = __begin_;1026  for (; __first != __last && __cur != __end_; ++__first, (void)++__cur)1027    *__cur = *__first;1028  if (__cur != __end_) {1029    __destruct_at_end(__cur);1030  } else {1031    for (; __first != __last; ++__first)1032      emplace_back(*__first);1033  }1034}1035 1036template <class _Tp, class _Allocator>1037template <class _AlgPolicy, class _Iterator, class _Sentinel>1038_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void1039vector<_Tp, _Allocator>::__assign_with_size(_Iterator __first, _Sentinel __last, difference_type __n) {1040  size_type __new_size = static_cast<size_type>(__n);1041  if (__new_size <= capacity()) {1042    if (__new_size > size()) {1043      auto __mid = std::__copy_n<_AlgPolicy>(std::move(__first), size(), this->__begin_).first;1044      __construct_at_end(std::move(__mid), std::move(__last), __new_size - size());1045    } else {1046      pointer __m = std::__copy(std::move(__first), __last, this->__begin_).second;1047      this->__destruct_at_end(__m);1048    }1049  } else {1050    __vdeallocate();1051    __vallocate(__recommend(__new_size));1052    __construct_at_end(std::move(__first), std::move(__last), __new_size);1053  }1054}1055 1056template <class _Tp, class _Allocator>1057_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) {1058  if (__n <= capacity()) {1059    size_type __s = size();1060    std::fill_n(this->__begin_, std::min(__n, __s), __u);1061    if (__n > __s)1062      __construct_at_end(__n - __s, __u);1063    else1064      this->__destruct_at_end(this->__begin_ + __n);1065  } else {1066    __vdeallocate();1067    __vallocate(__recommend(static_cast<size_type>(__n)));1068    __construct_at_end(__n, __u);1069  }1070}1071 1072template <class _Tp, class _Allocator>1073_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::reserve(size_type __n) {1074  if (__n > capacity()) {1075    if (__n > max_size())1076      this->__throw_length_error();1077    __split_buffer<value_type, allocator_type&> __v(__n, size(), this->__alloc_);1078    __swap_out_circular_buffer(__v);1079  }1080}1081 1082template <class _Tp, class _Allocator>1083_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT {1084  if (capacity() > size()) {1085#if _LIBCPP_HAS_EXCEPTIONS1086    try {1087#endif // _LIBCPP_HAS_EXCEPTIONS1088      __split_buffer<value_type, allocator_type&> __v(size(), size(), this->__alloc_);1089      // The Standard mandates shrink_to_fit() does not increase the capacity.1090      // With equal capacity keep the existing buffer. This avoids extra work1091      // due to swapping the elements.1092      if (__v.capacity() < capacity())1093        __swap_out_circular_buffer(__v);1094#if _LIBCPP_HAS_EXCEPTIONS1095    } catch (...) {1096    }1097#endif // _LIBCPP_HAS_EXCEPTIONS1098  }1099}1100 1101template <class _Tp, class _Allocator>1102template <class... _Args>1103_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer1104vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) {1105  __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), this->__alloc_);1106  //    __v.emplace_back(std::forward<_Args>(__args)...);1107  pointer __end = __v.end();1108  __alloc_traits::construct(this->__alloc_, std::__to_address(__end), std::forward<_Args>(__args)...);1109  __v.__set_sentinel(++__end);1110  __swap_out_circular_buffer(__v);1111  return this->__end_;1112}1113 1114// This makes the compiler inline `__else()` if `__cond` is known to be false. Currently LLVM doesn't do that without1115// the `__builtin_constant_p`, since it considers `__else` unlikely even through it's known to be run.1116// See https://llvm.org/PR1542921117template <class _If, class _Else>1118_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __if_likely_else(bool __cond, _If __if, _Else __else) {1119  if (__builtin_constant_p(__cond)) {1120    if (__cond)1121      __if();1122    else1123      __else();1124  } else {1125    if (__cond) [[__likely__]]1126      __if();1127    else1128      __else();1129  }1130}1131 1132template <class _Tp, class _Allocator>1133template <class... _Args>1134_LIBCPP_CONSTEXPR_SINCE_CXX20 inline1135#if _LIBCPP_STD_VER >= 171136    typename vector<_Tp, _Allocator>::reference1137#else1138    void1139#endif1140    vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) {1141  pointer __end = this->__end_;1142  std::__if_likely_else(1143      __end < this->__cap_,1144      [&] {1145        __emplace_back_assume_capacity(std::forward<_Args>(__args)...);1146        ++__end;1147      },1148      [&] { __end = __emplace_back_slow_path(std::forward<_Args>(__args)...); });1149 1150  this->__end_ = __end;1151#if _LIBCPP_STD_VER >= 171152  return *(__end - 1);1153#endif1154}1155 1156template <class _Tp, class _Allocator>1157_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator1158vector<_Tp, _Allocator>::erase(const_iterator __position) {1159  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(1160      __position != end(), "vector::erase(iterator) called with a non-dereferenceable iterator");1161  difference_type __ps = __position - cbegin();1162  pointer __p          = this->__begin_ + __ps;1163  this->__destruct_at_end(std::move(__p + 1, this->__end_, __p));1164  return __make_iter(__p);1165}1166 1167template <class _Tp, class _Allocator>1168_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator1169vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) {1170  _LIBCPP_ASSERT_VALID_INPUT_RANGE(__first <= __last, "vector::erase(first, last) called with invalid range");1171  pointer __p = this->__begin_ + (__first - begin());1172  if (__first != __last) {1173    this->__destruct_at_end(std::move(__p + (__last - __first), this->__end_, __p));1174  }1175  return __make_iter(__p);1176}1177 1178template <class _Tp, class _Allocator>1179_LIBCPP_CONSTEXPR_SINCE_CXX20 void1180vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) {1181  pointer __old_last  = this->__end_;1182  difference_type __n = __old_last - __to;1183  {1184    pointer __i = __from_s + __n;1185    _ConstructTransaction __tx(*this, __from_e - __i);1186    for (pointer __pos = __tx.__pos_; __i < __from_e; ++__i, (void)++__pos, __tx.__pos_ = __pos) {1187      __alloc_traits::construct(this->__alloc_, std::__to_address(__pos), std::move(*__i));1188    }1189  }1190  std::move_backward(__from_s, __from_s + __n, __old_last);1191}1192 1193template <class _Tp, class _Allocator>1194_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator1195vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) {1196  pointer __p = this->__begin_ + (__position - begin());1197  if (this->__end_ < this->__cap_) {1198    if (__p == this->__end_) {1199      __emplace_back_assume_capacity(__x);1200    } else {1201      __move_range(__p, this->__end_, __p + 1);1202      const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);1203      if (std::__is_pointer_in_range(std::__to_address(__p), std::__to_address(__end_), std::addressof(__x)))1204        ++__xr;1205      *__p = *__xr;1206    }1207  } else {1208    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, this->__alloc_);1209    __v.emplace_back(__x);1210    __p = __swap_out_circular_buffer(__v, __p);1211  }1212  return __make_iter(__p);1213}1214 1215template <class _Tp, class _Allocator>1216_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator1217vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) {1218  pointer __p = this->__begin_ + (__position - begin());1219  if (this->__end_ < this->__cap_) {1220    if (__p == this->__end_) {1221      __emplace_back_assume_capacity(std::move(__x));1222    } else {1223      __move_range(__p, this->__end_, __p + 1);1224      *__p = std::move(__x);1225    }1226  } else {1227    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, this->__alloc_);1228    __v.emplace_back(std::move(__x));1229    __p = __swap_out_circular_buffer(__v, __p);1230  }1231  return __make_iter(__p);1232}1233 1234template <class _Tp, class _Allocator>1235template <class... _Args>1236_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator1237vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) {1238  pointer __p = this->__begin_ + (__position - begin());1239  if (this->__end_ < this->__cap_) {1240    if (__p == this->__end_) {1241      __emplace_back_assume_capacity(std::forward<_Args>(__args)...);1242    } else {1243      __temp_value<value_type, _Allocator> __tmp(this->__alloc_, std::forward<_Args>(__args)...);1244      __move_range(__p, this->__end_, __p + 1);1245      *__p = std::move(__tmp.get());1246    }1247  } else {1248    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, this->__alloc_);1249    __v.emplace_back(std::forward<_Args>(__args)...);1250    __p = __swap_out_circular_buffer(__v, __p);1251  }1252  return __make_iter(__p);1253}1254 1255template <class _Tp, class _Allocator>1256_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator1257vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) {1258  pointer __p = this->__begin_ + (__position - begin());1259  if (__n > 0) {1260    if (__n <= static_cast<size_type>(this->__cap_ - this->__end_)) {1261      size_type __old_n  = __n;1262      pointer __old_last = this->__end_;1263      if (__n > static_cast<size_type>(this->__end_ - __p)) {1264        size_type __cx = __n - (this->__end_ - __p);1265        __construct_at_end(__cx, __x);1266        __n -= __cx;1267      }1268      if (__n > 0) {1269        __move_range(__p, __old_last, __p + __old_n);1270        const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);1271        if (std::__is_pointer_in_range(std::__to_address(__p), std::__to_address(__end_), std::addressof(__x)))1272          __xr += __old_n;1273        std::fill_n(__p, __n, *__xr);1274      }1275    } else {1276      __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, this->__alloc_);1277      __v.__construct_at_end(__n, __x);1278      __p = __swap_out_circular_buffer(__v, __p);1279    }1280  }1281  return __make_iter(__p);1282}1283 1284template <class _Tp, class _Allocator>1285template <class _InputIterator, class _Sentinel>1286_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator1287vector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {1288  difference_type __off = __position - begin();1289  pointer __p           = this->__begin_ + __off;1290  pointer __old_last    = this->__end_;1291  for (; this->__end_ != this->__cap_ && __first != __last; ++__first)1292    __emplace_back_assume_capacity(*__first);1293 1294  if (__first == __last)1295    (void)std::rotate(__p, __old_last, this->__end_);1296  else {1297    __split_buffer<value_type, allocator_type&> __v(__alloc_);1298    auto __guard = std::__make_exception_guard(1299        _AllocatorDestroyRangeReverse<allocator_type, pointer>(__alloc_, __old_last, this->__end_));1300    __v.__construct_at_end_with_sentinel(std::move(__first), std::move(__last));1301    __split_buffer<value_type, allocator_type&> __merged(1302        __recommend(size() + __v.size()), __off, __alloc_); // has `__off` positions available at the front1303    std::__uninitialized_allocator_relocate(1304        __alloc_, std::__to_address(__old_last), std::__to_address(this->__end_), std::__to_address(__merged.end()));1305    __guard.__complete(); // Release the guard once objects in [__old_last_, __end_) have been successfully relocated.1306    __merged.__set_sentinel(__merged.end() + (this->__end_ - __old_last));1307    this->__end_ = __old_last;1308    std::__uninitialized_allocator_relocate(1309        __alloc_, std::__to_address(__v.begin()), std::__to_address(__v.end()), std::__to_address(__merged.end()));1310    __merged.__set_sentinel(__merged.size() + __v.size());1311    __v.__set_sentinel(__v.begin());1312    __p        = __swap_out_circular_buffer(__merged, __p);1313  }1314  return __make_iter(__p);1315}1316 1317template <class _Tp, class _Allocator>1318template <class _AlgPolicy, class _Iterator, class _Sentinel>1319_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator1320vector<_Tp, _Allocator>::__insert_with_size(1321    const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n) {1322  pointer __p = this->__begin_ + (__position - begin());1323  if (__n > 0) {1324    if (__n <= this->__cap_ - this->__end_) {1325      pointer __old_last   = this->__end_;1326      difference_type __dx = this->__end_ - __p;1327      if (__n > __dx) {1328#if _LIBCPP_STD_VER >= 231329        if constexpr (!forward_iterator<_Iterator>) {1330          __construct_at_end(std::move(__first), std::move(__last), __n);1331          std::rotate(__p, __old_last, this->__end_);1332        } else1333#endif1334        {1335          _Iterator __m = std::next(__first, __dx);1336          __construct_at_end(__m, __last, __n - __dx);1337          if (__dx > 0) {1338            __move_range(__p, __old_last, __p + __n);1339            __insert_assign_n_unchecked<_AlgPolicy>(__first, __dx, __p);1340          }1341        }1342      } else {1343        __move_range(__p, __old_last, __p + __n);1344        __insert_assign_n_unchecked<_AlgPolicy>(std::move(__first), __n, __p);1345      }1346    } else {1347      __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, this->__alloc_);1348      __v.__construct_at_end_with_size(std::move(__first), __n);1349      __p = __swap_out_circular_buffer(__v, __p);1350    }1351  }1352  return __make_iter(__p);1353}1354 1355template <class _Tp, class _Allocator>1356_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize(size_type __new_size) {1357  size_type __current_size = size();1358  if (__current_size < __new_size) {1359    if (__new_size <= capacity()) {1360      __construct_at_end(__new_size - __current_size);1361    } else {1362      __split_buffer<value_type, allocator_type&> __v(__recommend(__new_size), __current_size, __alloc_);1363      __v.__construct_at_end(__new_size - __current_size);1364      __swap_out_circular_buffer(__v);1365    }1366  } else if (__current_size > __new_size) {1367    this->__destruct_at_end(this->__begin_ + __new_size);1368  }1369}1370 1371template <class _Tp, class _Allocator>1372_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize(size_type __new_size, const_reference __x) {1373  size_type __current_size = size();1374  if (__current_size < __new_size) {1375    if (__new_size <= capacity())1376      __construct_at_end(__new_size - __current_size, __x);1377    else {1378      __split_buffer<value_type, allocator_type&> __v(__recommend(__new_size), __current_size, __alloc_);1379      __v.__construct_at_end(__new_size - __current_size, __x);1380      __swap_out_circular_buffer(__v);1381    }1382  } else if (__current_size > __new_size) {1383    this->__destruct_at_end(this->__begin_ + __new_size);1384  }1385}1386 1387template <class _Tp, class _Allocator>1388_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::swap(vector& __x)1389#if _LIBCPP_STD_VER >= 141390    _NOEXCEPT1391#else1392    _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)1393#endif1394{1395  _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(1396      __alloc_traits::propagate_on_container_swap::value || this->__alloc_ == __x.__alloc_,1397      "vector::swap: Either propagate_on_container_swap must be true"1398      " or the allocators must compare equal");1399  std::swap(this->__begin_, __x.__begin_);1400  std::swap(this->__end_, __x.__end_);1401  std::swap(this->__cap_, __x.__cap_);1402  std::__swap_allocator(this->__alloc_, __x.__alloc_);1403}1404 1405template <class _Tp, class _Allocator>1406_LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<_Tp, _Allocator>::__invariants() const {1407  if (this->__begin_ == nullptr) {1408    if (this->__end_ != nullptr || this->__cap_ != nullptr)1409      return false;1410  } else {1411    if (this->__begin_ > this->__end_)1412      return false;1413    if (this->__begin_ == this->__cap_)1414      return false;1415    if (this->__end_ > this->__cap_)1416      return false;1417  }1418  return true;1419}1420 1421#if _LIBCPP_STD_VER >= 201422template <>1423inline constexpr bool __format::__enable_insertable<vector<char>> = true;1424#  if _LIBCPP_HAS_WIDE_CHARACTERS1425template <>1426inline constexpr bool __format::__enable_insertable<vector<wchar_t>> = true;1427#  endif1428#endif // _LIBCPP_STD_VER >= 201429 1430_LIBCPP_END_NAMESPACE_STD1431 1432_LIBCPP_POP_MACROS1433 1434#endif // _LIBCPP___VECTOR_VECTOR_H1435