Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:07

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___VECTOR_VECTOR_BOOL_H
0010 #define _LIBCPP___VECTOR_VECTOR_BOOL_H
0011 
0012 #include <__algorithm/copy.h>
0013 #include <__algorithm/fill_n.h>
0014 #include <__algorithm/iterator_operations.h>
0015 #include <__algorithm/max.h>
0016 #include <__assert>
0017 #include <__bit_reference>
0018 #include <__config>
0019 #include <__functional/unary_function.h>
0020 #include <__fwd/bit_reference.h>
0021 #include <__fwd/functional.h>
0022 #include <__fwd/vector.h>
0023 #include <__iterator/distance.h>
0024 #include <__iterator/iterator_traits.h>
0025 #include <__iterator/reverse_iterator.h>
0026 #include <__memory/addressof.h>
0027 #include <__memory/allocate_at_least.h>
0028 #include <__memory/allocator.h>
0029 #include <__memory/allocator_traits.h>
0030 #include <__memory/compressed_pair.h>
0031 #include <__memory/construct_at.h>
0032 #include <__memory/noexcept_move_assign_container.h>
0033 #include <__memory/pointer_traits.h>
0034 #include <__memory/swap_allocator.h>
0035 #include <__ranges/access.h>
0036 #include <__ranges/concepts.h>
0037 #include <__ranges/container_compatible_range.h>
0038 #include <__ranges/from_range.h>
0039 #include <__type_traits/enable_if.h>
0040 #include <__type_traits/is_constant_evaluated.h>
0041 #include <__type_traits/is_nothrow_assignable.h>
0042 #include <__type_traits/is_nothrow_constructible.h>
0043 #include <__type_traits/type_identity.h>
0044 #include <__utility/exception_guard.h>
0045 #include <__utility/forward.h>
0046 #include <__utility/move.h>
0047 #include <__utility/swap.h>
0048 #include <climits>
0049 #include <initializer_list>
0050 #include <limits>
0051 #include <stdexcept>
0052 
0053 // These headers define parts of vectors definition, since they define ADL functions or class specializations.
0054 #include <__vector/comparison.h>
0055 #include <__vector/container_traits.h>
0056 #include <__vector/swap.h>
0057 
0058 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0059 #  pragma GCC system_header
0060 #endif
0061 
0062 _LIBCPP_PUSH_MACROS
0063 #include <__undef_macros>
0064 
0065 _LIBCPP_BEGIN_NAMESPACE_STD
0066 
0067 template <class _Allocator>
0068 struct hash<vector<bool, _Allocator> >;
0069 
0070 template <class _Allocator>
0071 struct __has_storage_type<vector<bool, _Allocator> > {
0072   static const bool value = true;
0073 };
0074 
0075 template <class _Allocator>
0076 class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
0077 public:
0078   typedef vector __self;
0079   typedef bool value_type;
0080   typedef _Allocator allocator_type;
0081   typedef allocator_traits<allocator_type> __alloc_traits;
0082   typedef typename __alloc_traits::size_type size_type;
0083   typedef typename __alloc_traits::difference_type difference_type;
0084   typedef size_type __storage_type;
0085   typedef __bit_iterator<vector, false> pointer;
0086   typedef __bit_iterator<vector, true> const_pointer;
0087   typedef pointer iterator;
0088   typedef const_pointer const_iterator;
0089   typedef std::reverse_iterator<iterator> reverse_iterator;
0090   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
0091 
0092 private:
0093   typedef __rebind_alloc<__alloc_traits, __storage_type> __storage_allocator;
0094   typedef allocator_traits<__storage_allocator> __storage_traits;
0095   typedef typename __storage_traits::pointer __storage_pointer;
0096   typedef typename __storage_traits::const_pointer __const_storage_pointer;
0097 
0098   __storage_pointer __begin_;
0099   size_type __size_;
0100   _LIBCPP_COMPRESSED_PAIR(size_type, __cap_, __storage_allocator, __alloc_);
0101 
0102 public:
0103   typedef __bit_reference<vector> reference;
0104 #ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
0105   using const_reference = bool;
0106 #else
0107   typedef __bit_const_reference<vector> const_reference;
0108 #endif
0109 
0110 private:
0111   static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
0112 
0113   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type
0114   __internal_cap_to_external(size_type __n) _NOEXCEPT {
0115     return __n * __bits_per_word;
0116   }
0117   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type
0118   __external_cap_to_internal(size_type __n) _NOEXCEPT {
0119     return __n > 0 ? (__n - 1) / __bits_per_word + 1 : size_type(0);
0120   }
0121 
0122 public:
0123   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector()
0124       _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
0125 
0126   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(const allocator_type& __a)
0127 #if _LIBCPP_STD_VER <= 14
0128       _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
0129 #else
0130       _NOEXCEPT;
0131 #endif
0132 
0133 private:
0134   class __destroy_vector {
0135   public:
0136     _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}
0137 
0138     _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {
0139       if (__vec_.__begin_ != nullptr)
0140         __storage_traits::deallocate(__vec_.__alloc_, __vec_.__begin_, __vec_.__cap_);
0141     }
0142 
0143   private:
0144     vector& __vec_;
0145   };
0146 
0147 public:
0148   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector (*this)(); }
0149 
0150   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n);
0151 #if _LIBCPP_STD_VER >= 14
0152   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a);
0153 #endif
0154   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v);
0155   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0156   vector(size_type __n, const value_type& __v, const allocator_type& __a);
0157   template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
0158   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last);
0159   template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
0160   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0161   vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
0162   template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
0163   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last);
0164   template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
0165   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0166   vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a);
0167 
0168 #if _LIBCPP_STD_VER >= 23
0169   template <_ContainerCompatibleRange<bool> _Range>
0170   _LIBCPP_HIDE_FROM_ABI constexpr vector(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
0171       : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
0172     if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
0173       auto __n = static_cast<size_type>(ranges::distance(__range));
0174       __init_with_size(ranges::begin(__range), ranges::end(__range), __n);
0175 
0176     } else {
0177       __init_with_sentinel(ranges::begin(__range), ranges::end(__range));
0178     }
0179   }
0180 #endif
0181 
0182   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v);
0183   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v, const allocator_type& __a);
0184   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(const vector& __v);
0185 
0186 #ifndef _LIBCPP_CXX03_LANG
0187   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il);
0188   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0189   vector(initializer_list<value_type> __il, const allocator_type& __a);
0190 
0191   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(initializer_list<value_type> __il) {
0192     assign(__il.begin(), __il.end());
0193     return *this;
0194   }
0195 
0196 #endif // !_LIBCPP_CXX03_LANG
0197 
0198   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(vector&& __v)
0199 #if _LIBCPP_STD_VER >= 17
0200       noexcept;
0201 #else
0202       _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
0203 #endif
0204   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0205   vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
0206   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(vector&& __v)
0207       _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value);
0208 
0209   template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
0210   void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_InputIterator __first, _InputIterator __last);
0211   template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
0212   void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_ForwardIterator __first, _ForwardIterator __last);
0213 
0214 #if _LIBCPP_STD_VER >= 23
0215   template <_ContainerCompatibleRange<bool> _Range>
0216   _LIBCPP_HIDE_FROM_ABI constexpr void assign_range(_Range&& __range) {
0217     if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
0218       auto __n = static_cast<size_type>(ranges::distance(__range));
0219       __assign_with_size(ranges::begin(__range), ranges::end(__range), __n);
0220 
0221     } else {
0222       __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
0223     }
0224   }
0225 #endif
0226 
0227   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(size_type __n, const value_type& __x);
0228 
0229 #ifndef _LIBCPP_CXX03_LANG
0230   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(initializer_list<value_type> __il) {
0231     assign(__il.begin(), __il.end());
0232   }
0233 #endif
0234 
0235   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator_type get_allocator() const _NOEXCEPT {
0236     return allocator_type(this->__alloc_);
0237   }
0238 
0239   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT;
0240   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type capacity() const _NOEXCEPT {
0241     return __internal_cap_to_external(__cap_);
0242   }
0243   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type size() const _NOEXCEPT { return __size_; }
0244   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool empty() const _NOEXCEPT {
0245     return __size_ == 0;
0246   }
0247   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __n);
0248   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT;
0249 
0250   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() _NOEXCEPT { return __make_iter(0); }
0251   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator begin() const _NOEXCEPT { return __make_iter(0); }
0252   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator end() _NOEXCEPT { return __make_iter(__size_); }
0253   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator end() const _NOEXCEPT {
0254     return __make_iter(__size_);
0255   }
0256 
0257   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rbegin() _NOEXCEPT {
0258     return reverse_iterator(end());
0259   }
0260   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rbegin() const _NOEXCEPT {
0261     return const_reverse_iterator(end());
0262   }
0263   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rend() _NOEXCEPT {
0264     return reverse_iterator(begin());
0265   }
0266   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rend() const _NOEXCEPT {
0267     return const_reverse_iterator(begin());
0268   }
0269 
0270   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cbegin() const _NOEXCEPT { return __make_iter(0); }
0271   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cend() const _NOEXCEPT {
0272     return __make_iter(__size_);
0273   }
0274   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crbegin() const _NOEXCEPT {
0275     return rbegin();
0276   }
0277   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
0278 
0279   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __n) {
0280     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector<bool>::operator[] index out of bounds");
0281     return __make_ref(__n);
0282   }
0283   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __n) const {
0284     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector<bool>::operator[] index out of bounds");
0285     return __make_ref(__n);
0286   }
0287   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference at(size_type __n);
0288   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference at(size_type __n) const;
0289 
0290   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() {
0291     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector<bool>::front() called on an empty vector");
0292     return __make_ref(0);
0293   }
0294   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const {
0295     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector<bool>::front() called on an empty vector");
0296     return __make_ref(0);
0297   }
0298   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() {
0299     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector<bool>::back() called on an empty vector");
0300     return __make_ref(__size_ - 1);
0301   }
0302   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const {
0303     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector<bool>::back() called on an empty vector");
0304     return __make_ref(__size_ - 1);
0305   }
0306 
0307   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(const value_type& __x);
0308 #if _LIBCPP_STD_VER >= 14
0309   template <class... _Args>
0310 #  if _LIBCPP_STD_VER >= 17
0311   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference emplace_back(_Args&&... __args)
0312 #  else
0313   _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args)
0314 #  endif
0315   {
0316     push_back(value_type(std::forward<_Args>(__args)...));
0317 #  if _LIBCPP_STD_VER >= 17
0318     return this->back();
0319 #  endif
0320   }
0321 #endif
0322 
0323 #if _LIBCPP_STD_VER >= 23
0324   template <_ContainerCompatibleRange<bool> _Range>
0325   _LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) {
0326     insert_range(end(), std::forward<_Range>(__range));
0327   }
0328 #endif
0329 
0330   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back() {
0331     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector<bool>::pop_back called on an empty vector");
0332     --__size_;
0333   }
0334 
0335 #if _LIBCPP_STD_VER >= 14
0336   template <class... _Args>
0337   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args) {
0338     return insert(__position, value_type(std::forward<_Args>(__args)...));
0339   }
0340 #endif
0341 
0342   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x);
0343   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
0344   insert(const_iterator __position, size_type __n, const value_type& __x);
0345   template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
0346   iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0347   insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
0348   template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
0349   iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0350   insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
0351 
0352 #if _LIBCPP_STD_VER >= 23
0353   template <_ContainerCompatibleRange<bool> _Range>
0354   _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) {
0355     if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
0356       auto __n = static_cast<size_type>(ranges::distance(__range));
0357       return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
0358 
0359     } else {
0360       return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
0361     }
0362   }
0363 #endif
0364 
0365 #ifndef _LIBCPP_CXX03_LANG
0366   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
0367   insert(const_iterator __position, initializer_list<value_type> __il) {
0368     return insert(__position, __il.begin(), __il.end());
0369   }
0370 #endif
0371 
0372   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __position);
0373   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last);
0374 
0375   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT { __size_ = 0; }
0376 
0377   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(vector&)
0378 #if _LIBCPP_STD_VER >= 14
0379       _NOEXCEPT;
0380 #else
0381       _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
0382 #endif
0383   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void swap(reference __x, reference __y) _NOEXCEPT {
0384     std::swap(__x, __y);
0385   }
0386 
0387   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __sz, value_type __x = false);
0388   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT;
0389 
0390   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const;
0391 
0392 private:
0393   [[__noreturn__]] _LIBCPP_HIDE_FROM_ABI static void __throw_length_error() { std::__throw_length_error("vector"); }
0394 
0395   [[__noreturn__]] _LIBCPP_HIDE_FROM_ABI static void __throw_out_of_range() { std::__throw_out_of_range("vector"); }
0396 
0397   template <class _InputIterator, class _Sentinel>
0398   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0399   __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {
0400     auto __guard = std::__make_exception_guard(__destroy_vector(*this));
0401 
0402     if (__n > 0) {
0403       __vallocate(__n);
0404       __construct_at_end(std::move(__first), std::move(__last), __n);
0405     }
0406 
0407     __guard.__complete();
0408   }
0409 
0410   template <class _InputIterator, class _Sentinel>
0411   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0412   __init_with_sentinel(_InputIterator __first, _Sentinel __last) {
0413     auto __guard = std::__make_exception_guard(__destroy_vector(*this));
0414 
0415     for (; __first != __last; ++__first)
0416       push_back(*__first);
0417 
0418     __guard.__complete();
0419   }
0420 
0421   template <class _Iterator, class _Sentinel>
0422   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last);
0423 
0424   // The `_Iterator` in `*_with_size` functions can be input-only only if called from `*_range` (since C++23).
0425   // Otherwise, `_Iterator` is a forward iterator.
0426 
0427   template <class _Iterator, class _Sentinel>
0428   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
0429   __assign_with_size(_Iterator __first, _Sentinel __last, difference_type __ns);
0430 
0431   template <class _InputIterator, class _Sentinel>
0432   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
0433   __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
0434 
0435   template <class _Iterator, class _Sentinel>
0436   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
0437   __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
0438 
0439   //  Allocate space for __n objects
0440   //  throws length_error if __n > max_size()
0441   //  throws (probably bad_alloc) if memory run out
0442   //  Precondition:  __begin_ == __end_ == __cap_ == nullptr
0443   //  Precondition:  __n > 0
0444   //  Postcondition:  capacity() >= __n
0445   //  Postcondition:  size() == 0
0446   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vallocate(size_type __n) {
0447     if (__n > max_size())
0448       __throw_length_error();
0449     auto __allocation = std::__allocate_at_least(__alloc_, __external_cap_to_internal(__n));
0450     __begin_          = __allocation.ptr;
0451     __size_           = 0;
0452     __cap_            = __allocation.count;
0453     if (__libcpp_is_constant_evaluated()) {
0454       for (size_type __i = 0; __i != __cap_; ++__i)
0455         std::__construct_at(std::__to_address(__begin_) + __i);
0456     }
0457   }
0458 
0459   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vdeallocate() _NOEXCEPT;
0460   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type __align_it(size_type __new_size) _NOEXCEPT {
0461     return (__new_size + (__bits_per_word - 1)) & ~((size_type)__bits_per_word - 1);
0462   }
0463   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend(size_type __new_size) const;
0464   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct_at_end(size_type __n, bool __x);
0465   template <class _InputIterator, class _Sentinel>
0466   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0467   __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
0468   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference __make_ref(size_type __pos) _NOEXCEPT {
0469     return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
0470   }
0471   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference __make_ref(size_type __pos) const _NOEXCEPT {
0472     return __bit_const_reference<vector>(
0473         __begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
0474   }
0475   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __make_iter(size_type __pos) _NOEXCEPT {
0476     return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));
0477   }
0478   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator __make_iter(size_type __pos) const _NOEXCEPT {
0479     return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));
0480   }
0481   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT {
0482     return begin() + (__p - cbegin());
0483   }
0484 
0485   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector& __v) {
0486     __copy_assign_alloc(
0487         __v, integral_constant<bool, __storage_traits::propagate_on_container_copy_assignment::value>());
0488   }
0489   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector& __c, true_type) {
0490     if (__alloc_ != __c.__alloc_)
0491       __vdeallocate();
0492     __alloc_ = __c.__alloc_;
0493   }
0494 
0495   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector&, false_type) {}
0496 
0497   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, false_type);
0498   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, true_type)
0499       _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
0500   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector& __c)
0501       _NOEXCEPT_(!__storage_traits::propagate_on_container_move_assignment::value ||
0502                  is_nothrow_move_assignable<allocator_type>::value) {
0503     __move_assign_alloc(
0504         __c, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>());
0505   }
0506   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector& __c, true_type)
0507       _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
0508     __alloc_ = std::move(__c.__alloc_);
0509   }
0510 
0511   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
0512 
0513   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t __hash_code() const _NOEXCEPT;
0514 
0515   friend class __bit_reference<vector>;
0516   friend class __bit_const_reference<vector>;
0517   friend class __bit_iterator<vector, false>;
0518   friend class __bit_iterator<vector, true>;
0519   friend struct __bit_array<vector>;
0520   friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
0521 };
0522 
0523 template <class _Allocator>
0524 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT {
0525   if (this->__begin_ != nullptr) {
0526     __storage_traits::deallocate(this->__alloc_, this->__begin_, __cap_);
0527     this->__begin_ = nullptr;
0528     this->__size_ = this->__cap_ = 0;
0529   }
0530 }
0531 
0532 template <class _Allocator>
0533 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::size_type
0534 vector<bool, _Allocator>::max_size() const _NOEXCEPT {
0535   size_type __amax = __storage_traits::max_size(__alloc_);
0536   size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
0537   if (__nmax / __bits_per_word <= __amax)
0538     return __nmax;
0539   return __internal_cap_to_external(__amax);
0540 }
0541 
0542 //  Precondition:  __new_size > capacity()
0543 template <class _Allocator>
0544 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::size_type
0545 vector<bool, _Allocator>::__recommend(size_type __new_size) const {
0546   const size_type __ms = max_size();
0547   if (__new_size > __ms)
0548     this->__throw_length_error();
0549   const size_type __cap = capacity();
0550   if (__cap >= __ms / 2)
0551     return __ms;
0552   return std::max(2 * __cap, __align_it(__new_size));
0553 }
0554 
0555 //  Default constructs __n objects starting at __end_
0556 //  Precondition:  __n > 0
0557 //  Precondition:  size() + __n <= capacity()
0558 //  Postcondition:  size() == size() + __n
0559 template <class _Allocator>
0560 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0561 vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) {
0562   size_type __old_size = this->__size_;
0563   this->__size_ += __n;
0564   if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
0565     if (this->__size_ <= __bits_per_word)
0566       this->__begin_[0] = __storage_type(0);
0567     else
0568       this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
0569   }
0570   std::fill_n(__make_iter(__old_size), __n, __x);
0571 }
0572 
0573 template <class _Allocator>
0574 template <class _InputIterator, class _Sentinel>
0575 _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0576 vector<bool, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
0577   size_type __old_size = this->__size_;
0578   this->__size_ += __n;
0579   if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
0580     if (this->__size_ <= __bits_per_word)
0581       this->__begin_[0] = __storage_type(0);
0582     else
0583       this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
0584   }
0585   std::__copy(std::move(__first), std::move(__last), __make_iter(__old_size));
0586 }
0587 
0588 template <class _Allocator>
0589 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector()
0590     _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
0591     : __begin_(nullptr), __size_(0), __cap_(0) {}
0592 
0593 template <class _Allocator>
0594 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const allocator_type& __a)
0595 #if _LIBCPP_STD_VER <= 14
0596     _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
0597 #else
0598         _NOEXCEPT
0599 #endif
0600     : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
0601 }
0602 
0603 template <class _Allocator>
0604 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n)
0605     : __begin_(nullptr), __size_(0), __cap_(0) {
0606   if (__n > 0) {
0607     __vallocate(__n);
0608     __construct_at_end(__n, false);
0609   }
0610 }
0611 
0612 #if _LIBCPP_STD_VER >= 14
0613 template <class _Allocator>
0614 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
0615     : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
0616   if (__n > 0) {
0617     __vallocate(__n);
0618     __construct_at_end(__n, false);
0619   }
0620 }
0621 #endif
0622 
0623 template <class _Allocator>
0624 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
0625     : __begin_(nullptr), __size_(0), __cap_(0) {
0626   if (__n > 0) {
0627     __vallocate(__n);
0628     __construct_at_end(__n, __x);
0629   }
0630 }
0631 
0632 template <class _Allocator>
0633 _LIBCPP_CONSTEXPR_SINCE_CXX20
0634 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
0635     : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
0636   if (__n > 0) {
0637     __vallocate(__n);
0638     __construct_at_end(__n, __x);
0639   }
0640 }
0641 
0642 template <class _Allocator>
0643 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
0644 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last)
0645     : __begin_(nullptr), __size_(0), __cap_(0) {
0646   __init_with_sentinel(__first, __last);
0647 }
0648 
0649 template <class _Allocator>
0650 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
0651 _LIBCPP_CONSTEXPR_SINCE_CXX20
0652 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
0653     : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
0654   __init_with_sentinel(__first, __last);
0655 }
0656 
0657 template <class _Allocator>
0658 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
0659 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last)
0660     : __begin_(nullptr), __size_(0), __cap_(0) {
0661   auto __n = static_cast<size_type>(std::distance(__first, __last));
0662   __init_with_size(__first, __last, __n);
0663 }
0664 
0665 template <class _Allocator>
0666 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
0667 _LIBCPP_CONSTEXPR_SINCE_CXX20
0668 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
0669     : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
0670   auto __n = static_cast<size_type>(std::distance(__first, __last));
0671   __init_with_size(__first, __last, __n);
0672 }
0673 
0674 #ifndef _LIBCPP_CXX03_LANG
0675 
0676 template <class _Allocator>
0677 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
0678     : __begin_(nullptr), __size_(0), __cap_(0) {
0679   size_type __n = static_cast<size_type>(__il.size());
0680   if (__n > 0) {
0681     __vallocate(__n);
0682     __construct_at_end(__il.begin(), __il.end(), __n);
0683   }
0684 }
0685 
0686 template <class _Allocator>
0687 _LIBCPP_CONSTEXPR_SINCE_CXX20
0688 vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
0689     : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator>(__a)) {
0690   size_type __n = static_cast<size_type>(__il.size());
0691   if (__n > 0) {
0692     __vallocate(__n);
0693     __construct_at_end(__il.begin(), __il.end(), __n);
0694   }
0695 }
0696 
0697 #endif // _LIBCPP_CXX03_LANG
0698 
0699 template <class _Allocator>
0700 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const vector& __v)
0701     : __begin_(nullptr),
0702       __size_(0),
0703       __cap_(0),
0704       __alloc_(__storage_traits::select_on_container_copy_construction(__v.__alloc_)) {
0705   if (__v.size() > 0) {
0706     __vallocate(__v.size());
0707     __construct_at_end(__v.begin(), __v.end(), __v.size());
0708   }
0709 }
0710 
0711 template <class _Allocator>
0712 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
0713     : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(__a) {
0714   if (__v.size() > 0) {
0715     __vallocate(__v.size());
0716     __construct_at_end(__v.begin(), __v.end(), __v.size());
0717   }
0718 }
0719 
0720 template <class _Allocator>
0721 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>& vector<bool, _Allocator>::operator=(const vector& __v) {
0722   if (this != std::addressof(__v)) {
0723     __copy_assign_alloc(__v);
0724     if (__v.__size_) {
0725       if (__v.__size_ > capacity()) {
0726         __vdeallocate();
0727         __vallocate(__v.__size_);
0728       }
0729       std::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
0730     }
0731     __size_ = __v.__size_;
0732   }
0733   return *this;
0734 }
0735 
0736 template <class _Allocator>
0737 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(vector&& __v)
0738 #if _LIBCPP_STD_VER >= 17
0739     _NOEXCEPT
0740 #else
0741     _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
0742 #endif
0743     : __begin_(__v.__begin_),
0744       __size_(__v.__size_),
0745       __cap_(__v.__cap_),
0746       __alloc_(std::move(__v.__alloc_)) {
0747   __v.__begin_ = nullptr;
0748   __v.__size_  = 0;
0749   __v.__cap_   = 0;
0750 }
0751 
0752 template <class _Allocator>
0753 _LIBCPP_CONSTEXPR_SINCE_CXX20
0754 vector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
0755     : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(__a) {
0756   if (__a == allocator_type(__v.__alloc_)) {
0757     this->__begin_ = __v.__begin_;
0758     this->__size_  = __v.__size_;
0759     this->__cap_   = __v.__cap_;
0760     __v.__begin_   = nullptr;
0761     __v.__cap_ = __v.__size_ = 0;
0762   } else if (__v.size() > 0) {
0763     __vallocate(__v.size());
0764     __construct_at_end(__v.begin(), __v.end(), __v.size());
0765   }
0766 }
0767 
0768 template <class _Allocator>
0769 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>&
0770 vector<bool, _Allocator>::operator=(vector&& __v)
0771     _NOEXCEPT_(__noexcept_move_assign_container<_Allocator, __alloc_traits>::value) {
0772   __move_assign(__v, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>());
0773   return *this;
0774 }
0775 
0776 template <class _Allocator>
0777 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vector& __c, false_type) {
0778   if (__alloc_ != __c.__alloc_)
0779     assign(__c.begin(), __c.end());
0780   else
0781     __move_assign(__c, true_type());
0782 }
0783 
0784 template <class _Allocator>
0785 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
0786     _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
0787   __vdeallocate();
0788   __move_assign_alloc(__c);
0789   this->__begin_ = __c.__begin_;
0790   this->__size_  = __c.__size_;
0791   this->__cap_   = __c.__cap_;
0792   __c.__begin_   = nullptr;
0793   __c.__cap_ = __c.__size_ = 0;
0794 }
0795 
0796 template <class _Allocator>
0797 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) {
0798   __size_ = 0;
0799   if (__n > 0) {
0800     size_type __c = capacity();
0801     if (__n <= __c)
0802       __size_ = __n;
0803     else {
0804       vector __v(get_allocator());
0805       __v.reserve(__recommend(__n));
0806       __v.__size_ = __n;
0807       swap(__v);
0808     }
0809     std::fill_n(begin(), __n, __x);
0810   }
0811 }
0812 
0813 template <class _Allocator>
0814 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
0815 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) {
0816   __assign_with_sentinel(__first, __last);
0817 }
0818 
0819 template <class _Allocator>
0820 template <class _Iterator, class _Sentinel>
0821 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
0822 vector<bool, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {
0823   clear();
0824   for (; __first != __last; ++__first)
0825     push_back(*__first);
0826 }
0827 
0828 template <class _Allocator>
0829 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
0830 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) {
0831   __assign_with_size(__first, __last, std::distance(__first, __last));
0832 }
0833 
0834 template <class _Allocator>
0835 template <class _Iterator, class _Sentinel>
0836 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
0837 vector<bool, _Allocator>::__assign_with_size(_Iterator __first, _Sentinel __last, difference_type __ns) {
0838   _LIBCPP_ASSERT_VALID_INPUT_RANGE(__ns >= 0, "invalid range specified");
0839 
0840   clear();
0841 
0842   const size_t __n = static_cast<size_type>(__ns);
0843   if (__n) {
0844     if (__n > capacity()) {
0845       __vdeallocate();
0846       __vallocate(__n);
0847     }
0848     __construct_at_end(std::move(__first), std::move(__last), __n);
0849   }
0850 }
0851 
0852 template <class _Allocator>
0853 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type __n) {
0854   if (__n > capacity()) {
0855     if (__n > max_size())
0856       this->__throw_length_error();
0857     vector __v(this->get_allocator());
0858     __v.__vallocate(__n);
0859     __v.__construct_at_end(this->begin(), this->end(), this->size());
0860     swap(__v);
0861   }
0862 }
0863 
0864 template <class _Allocator>
0865 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT {
0866   if (__external_cap_to_internal(size()) < __cap_) {
0867 #if _LIBCPP_HAS_EXCEPTIONS
0868     try {
0869 #endif // _LIBCPP_HAS_EXCEPTIONS
0870       vector __v(*this, allocator_type(__alloc_));
0871       if (__v.__cap_ < __cap_)
0872         __v.swap(*this);
0873 #if _LIBCPP_HAS_EXCEPTIONS
0874     } catch (...) {
0875     }
0876 #endif // _LIBCPP_HAS_EXCEPTIONS
0877   }
0878 }
0879 
0880 template <class _Allocator>
0881 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::reference vector<bool, _Allocator>::at(size_type __n) {
0882   if (__n >= size())
0883     this->__throw_out_of_range();
0884   return (*this)[__n];
0885 }
0886 
0887 template <class _Allocator>
0888 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::const_reference
0889 vector<bool, _Allocator>::at(size_type __n) const {
0890   if (__n >= size())
0891     this->__throw_out_of_range();
0892   return (*this)[__n];
0893 }
0894 
0895 template <class _Allocator>
0896 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::push_back(const value_type& __x) {
0897   if (this->__size_ == this->capacity())
0898     reserve(__recommend(this->__size_ + 1));
0899   ++this->__size_;
0900   back() = __x;
0901 }
0902 
0903 template <class _Allocator>
0904 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
0905 vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) {
0906   iterator __r;
0907   if (size() < capacity()) {
0908     const_iterator __old_end = end();
0909     ++__size_;
0910     std::copy_backward(__position, __old_end, end());
0911     __r = __const_iterator_cast(__position);
0912   } else {
0913     vector __v(get_allocator());
0914     __v.reserve(__recommend(__size_ + 1));
0915     __v.__size_ = __size_ + 1;
0916     __r         = std::copy(cbegin(), __position, __v.begin());
0917     std::copy_backward(__position, cend(), __v.end());
0918     swap(__v);
0919   }
0920   *__r = __x;
0921   return __r;
0922 }
0923 
0924 template <class _Allocator>
0925 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
0926 vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) {
0927   iterator __r;
0928   size_type __c = capacity();
0929   if (__n <= __c && size() <= __c - __n) {
0930     const_iterator __old_end = end();
0931     __size_ += __n;
0932     std::copy_backward(__position, __old_end, end());
0933     __r = __const_iterator_cast(__position);
0934   } else {
0935     vector __v(get_allocator());
0936     __v.reserve(__recommend(__size_ + __n));
0937     __v.__size_ = __size_ + __n;
0938     __r         = std::copy(cbegin(), __position, __v.begin());
0939     std::copy_backward(__position, cend(), __v.end());
0940     swap(__v);
0941   }
0942   std::fill_n(__r, __n, __x);
0943   return __r;
0944 }
0945 
0946 template <class _Allocator>
0947 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
0948 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
0949 vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {
0950   return __insert_with_sentinel(__position, __first, __last);
0951 }
0952 
0953 template <class _Allocator>
0954 template <class _InputIterator, class _Sentinel>
0955 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator
0956 vector<bool, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {
0957   difference_type __off = __position - begin();
0958   iterator __p          = __const_iterator_cast(__position);
0959   iterator __old_end    = end();
0960   for (; size() != capacity() && __first != __last; ++__first) {
0961     ++this->__size_;
0962     back() = *__first;
0963   }
0964   vector __v(get_allocator());
0965   if (__first != __last) {
0966 #if _LIBCPP_HAS_EXCEPTIONS
0967     try {
0968 #endif // _LIBCPP_HAS_EXCEPTIONS
0969       __v.__assign_with_sentinel(std::move(__first), std::move(__last));
0970       difference_type __old_size = static_cast<difference_type>(__old_end - begin());
0971       difference_type __old_p    = __p - begin();
0972       reserve(__recommend(size() + __v.size()));
0973       __p       = begin() + __old_p;
0974       __old_end = begin() + __old_size;
0975 #if _LIBCPP_HAS_EXCEPTIONS
0976     } catch (...) {
0977       erase(__old_end, end());
0978       throw;
0979     }
0980 #endif // _LIBCPP_HAS_EXCEPTIONS
0981   }
0982   __p = std::rotate(__p, __old_end, end());
0983   insert(__p, __v.begin(), __v.end());
0984   return begin() + __off;
0985 }
0986 
0987 template <class _Allocator>
0988 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
0989 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
0990 vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) {
0991   return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
0992 }
0993 
0994 template <class _Allocator>
0995 template <class _Iterator, class _Sentinel>
0996 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator
0997 vector<bool, _Allocator>::__insert_with_size(
0998     const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n_signed) {
0999   _LIBCPP_ASSERT_VALID_INPUT_RANGE(__n_signed >= 0, "invalid range specified");
1000   const size_type __n = static_cast<size_type>(__n_signed);
1001   iterator __r;
1002   size_type __c = capacity();
1003   if (__n <= __c && size() <= __c - __n) {
1004     const_iterator __old_end = end();
1005     __size_ += __n;
1006     std::copy_backward(__position, __old_end, end());
1007     __r = __const_iterator_cast(__position);
1008   } else {
1009     vector __v(get_allocator());
1010     __v.reserve(__recommend(__size_ + __n));
1011     __v.__size_ = __size_ + __n;
1012     __r         = std::copy(cbegin(), __position, __v.begin());
1013     std::copy_backward(__position, cend(), __v.end());
1014     swap(__v);
1015   }
1016   std::__copy(std::move(__first), std::move(__last), __r);
1017   return __r;
1018 }
1019 
1020 template <class _Allocator>
1021 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
1022 vector<bool, _Allocator>::erase(const_iterator __position) {
1023   _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
1024       __position != end(), "vector<bool>::erase(iterator) called with a non-dereferenceable iterator");
1025   iterator __r = __const_iterator_cast(__position);
1026   std::copy(__position + 1, this->cend(), __r);
1027   --__size_;
1028   return __r;
1029 }
1030 
1031 template <class _Allocator>
1032 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
1033 vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) {
1034   _LIBCPP_ASSERT_VALID_INPUT_RANGE(
1035       __first <= __last, "vector<bool>::erase(iterator, iterator) called with an invalid range");
1036   iterator __r        = __const_iterator_cast(__first);
1037   difference_type __d = __last - __first;
1038   std::copy(__last, this->cend(), __r);
1039   __size_ -= __d;
1040   return __r;
1041 }
1042 
1043 template <class _Allocator>
1044 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::swap(vector& __x)
1045 #if _LIBCPP_STD_VER >= 14
1046     _NOEXCEPT
1047 #else
1048     _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
1049 #endif
1050 {
1051   std::swap(this->__begin_, __x.__begin_);
1052   std::swap(this->__size_, __x.__size_);
1053   std::swap(this->__cap_, __x.__cap_);
1054   std::__swap_allocator(this->__alloc_, __x.__alloc_);
1055 }
1056 
1057 template <class _Allocator>
1058 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::resize(size_type __sz, value_type __x) {
1059   size_type __cs = size();
1060   if (__cs < __sz) {
1061     iterator __r;
1062     size_type __c = capacity();
1063     size_type __n = __sz - __cs;
1064     if (__n <= __c && __cs <= __c - __n) {
1065       __r = end();
1066       __size_ += __n;
1067     } else {
1068       vector __v(get_allocator());
1069       __v.reserve(__recommend(__size_ + __n));
1070       __v.__size_ = __size_ + __n;
1071       __r         = std::copy(cbegin(), cend(), __v.begin());
1072       swap(__v);
1073     }
1074     std::fill_n(__r, __n, __x);
1075   } else
1076     __size_ = __sz;
1077 }
1078 
1079 template <class _Allocator>
1080 _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::flip() _NOEXCEPT {
1081   // Flip each storage word entirely, including the last potentially partial word.
1082   // The unused bits in the last word are safe to flip as they won't be accessed.
1083   __storage_pointer __p = __begin_;
1084   for (size_type __n = __external_cap_to_internal(size()); __n != 0; ++__p, --__n)
1085     *__p = ~*__p;
1086 }
1087 
1088 template <class _Allocator>
1089 _LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<bool, _Allocator>::__invariants() const {
1090   if (this->__begin_ == nullptr) {
1091     if (this->__size_ != 0 || this->__cap_ != 0)
1092       return false;
1093   } else {
1094     if (this->__cap_ == 0)
1095       return false;
1096     if (this->__size_ > this->capacity())
1097       return false;
1098   }
1099   return true;
1100 }
1101 
1102 template <class _Allocator>
1103 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t vector<bool, _Allocator>::__hash_code() const _NOEXCEPT {
1104   size_t __h = 0;
1105   // do middle whole words
1106   size_type __n         = __size_;
1107   __storage_pointer __p = __begin_;
1108   for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
1109     __h ^= *__p;
1110   // do last partial word
1111   if (__n > 0) {
1112     const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
1113     __h ^= *__p & __m;
1114   }
1115   return __h;
1116 }
1117 
1118 template <class _Allocator>
1119 struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
1120     : public __unary_function<vector<bool, _Allocator>, size_t> {
1121   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t
1122   operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT {
1123     return __vec.__hash_code();
1124   }
1125 };
1126 
1127 _LIBCPP_END_NAMESPACE_STD
1128 
1129 _LIBCPP_POP_MACROS
1130 
1131 #endif // _LIBCPP___VECTOR_VECTOR_BOOL_H