1 //===----------------------------------------------------------------------===//
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-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___VECTOR_VECTOR_BOOL_H
10 #define _LIBCPP___VECTOR_VECTOR_BOOL_H
12 #include <__algorithm/copy.h>
13 #include <__algorithm/fill_n.h>
14 #include <__algorithm/iterator_operations.h>
15 #include <__algorithm/max.h>
17 #include <__bit_reference>
19 #include <__functional/unary_function.h>
20 #include <__fwd/functional.h>
21 #include <__fwd/vector.h>
22 #include <__iterator/distance.h>
23 #include <__iterator/iterator_traits.h>
24 #include <__iterator/reverse_iterator.h>
25 #include <__memory/addressof.h>
26 #include <__memory/allocate_at_least.h>
27 #include <__memory/allocator.h>
28 #include <__memory/allocator_traits.h>
29 #include <__memory/compressed_pair.h>
30 #include <__memory/construct_at.h>
31 #include <__memory/noexcept_move_assign_container.h>
32 #include <__memory/pointer_traits.h>
33 #include <__memory/swap_allocator.h>
34 #include <__ranges/access.h>
35 #include <__ranges/concepts.h>
36 #include <__ranges/container_compatible_range.h>
37 #include <__ranges/from_range.h>
38 #include <__type_traits/enable_if.h>
39 #include <__type_traits/is_constant_evaluated.h>
40 #include <__type_traits/is_nothrow_assignable.h>
41 #include <__type_traits/is_nothrow_constructible.h>
42 #include <__type_traits/type_identity.h>
43 #include <__utility/exception_guard.h>
44 #include <__utility/forward.h>
45 #include <__utility/move.h>
46 #include <__utility/swap.h>
48 #include <initializer_list>
52 // These headers define parts of vectors definition, since they define ADL functions or class specializations.
53 #include <__vector/comparison.h>
54 #include <__vector/container_traits.h>
55 #include <__vector/swap.h>
57 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
58 # pragma GCC system_header
62 #include <__undef_macros>
64 _LIBCPP_BEGIN_NAMESPACE_STD
66 template <class _Allocator
>
67 struct hash
<vector
<bool, _Allocator
> >;
69 template <class _Allocator
>
70 struct __has_storage_type
<vector
<bool, _Allocator
> > {
71 static const bool value
= true;
74 template <class _Allocator
>
75 class _LIBCPP_TEMPLATE_VIS vector
<bool, _Allocator
> {
77 typedef vector __self
;
78 typedef bool value_type
;
79 typedef _Allocator allocator_type
;
80 typedef allocator_traits
<allocator_type
> __alloc_traits
;
81 typedef typename
__alloc_traits::size_type size_type
;
82 typedef typename
__alloc_traits::difference_type difference_type
;
83 typedef size_type __storage_type
;
84 typedef __bit_iterator
<vector
, false> pointer
;
85 typedef __bit_iterator
<vector
, true> const_pointer
;
86 typedef pointer iterator
;
87 typedef const_pointer const_iterator
;
88 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
89 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
92 typedef __rebind_alloc
<__alloc_traits
, __storage_type
> __storage_allocator
;
93 typedef allocator_traits
<__storage_allocator
> __storage_traits
;
94 typedef typename
__storage_traits::pointer __storage_pointer
;
95 typedef typename
__storage_traits::const_pointer __const_storage_pointer
;
97 __storage_pointer __begin_
;
99 _LIBCPP_COMPRESSED_PAIR(size_type
, __cap_
, __storage_allocator
, __alloc_
);
102 typedef __bit_reference
<vector
> reference
;
103 #ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
104 using const_reference
= bool;
106 typedef __bit_const_reference
<vector
> const_reference
;
110 static const unsigned __bits_per_word
= static_cast<unsigned>(sizeof(__storage_type
) * CHAR_BIT
);
112 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
static size_type
113 __internal_cap_to_external(size_type __n
) _NOEXCEPT
{
114 return __n
* __bits_per_word
;
116 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
static size_type
117 __external_cap_to_internal(size_type __n
) _NOEXCEPT
{
118 return (__n
- 1) / __bits_per_word
+ 1;
122 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
vector()
123 _NOEXCEPT_(is_nothrow_default_constructible
<allocator_type
>::value
);
125 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
explicit vector(const allocator_type
& __a
)
126 #if _LIBCPP_STD_VER <= 14
127 _NOEXCEPT_(is_nothrow_copy_constructible
<allocator_type
>::value
);
133 class __destroy_vector
{
135 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
__destroy_vector(vector
& __vec
) : __vec_(__vec
) {}
137 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
void operator()() {
138 if (__vec_
.__begin_
!= nullptr)
139 __storage_traits::deallocate(__vec_
.__alloc_
, __vec_
.__begin_
, __vec_
.__cap_
);
147 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
~vector() { __destroy_vector (*this)(); }
149 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
explicit vector(size_type __n
);
150 #if _LIBCPP_STD_VER >= 14
151 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
explicit vector(size_type __n
, const allocator_type
& __a
);
153 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
vector(size_type __n
, const value_type
& __v
);
154 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
155 vector(size_type __n
, const value_type
& __v
, const allocator_type
& __a
);
156 template <class _InputIterator
, __enable_if_t
<__has_exactly_input_iterator_category
<_InputIterator
>::value
, int> = 0>
157 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
vector(_InputIterator __first
, _InputIterator __last
);
158 template <class _InputIterator
, __enable_if_t
<__has_exactly_input_iterator_category
<_InputIterator
>::value
, int> = 0>
159 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
160 vector(_InputIterator __first
, _InputIterator __last
, const allocator_type
& __a
);
161 template <class _ForwardIterator
, __enable_if_t
<__has_forward_iterator_category
<_ForwardIterator
>::value
, int> = 0>
162 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
vector(_ForwardIterator __first
, _ForwardIterator __last
);
163 template <class _ForwardIterator
, __enable_if_t
<__has_forward_iterator_category
<_ForwardIterator
>::value
, int> = 0>
164 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
165 vector(_ForwardIterator __first
, _ForwardIterator __last
, const allocator_type
& __a
);
167 #if _LIBCPP_STD_VER >= 23
168 template <_ContainerCompatibleRange
<bool> _Range
>
169 _LIBCPP_HIDE_FROM_ABI
constexpr vector(from_range_t
, _Range
&& __range
, const allocator_type
& __a
= allocator_type())
170 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator
>(__a
)) {
171 if constexpr (ranges::forward_range
<_Range
> || ranges::sized_range
<_Range
>) {
172 auto __n
= static_cast<size_type
>(ranges::distance(__range
));
173 __init_with_size(ranges::begin(__range
), ranges::end(__range
), __n
);
176 __init_with_sentinel(ranges::begin(__range
), ranges::end(__range
));
181 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
vector(const vector
& __v
);
182 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
vector(const vector
& __v
, const allocator_type
& __a
);
183 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
& operator=(const vector
& __v
);
185 #ifndef _LIBCPP_CXX03_LANG
186 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
vector(initializer_list
<value_type
> __il
);
187 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
188 vector(initializer_list
<value_type
> __il
, const allocator_type
& __a
);
190 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
& operator=(initializer_list
<value_type
> __il
) {
191 assign(__il
.begin(), __il
.end());
195 #endif // !_LIBCPP_CXX03_LANG
197 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
vector(vector
&& __v
)
198 #if _LIBCPP_STD_VER >= 17
201 _NOEXCEPT_(is_nothrow_move_constructible
<allocator_type
>::value
);
203 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
204 vector(vector
&& __v
, const __type_identity_t
<allocator_type
>& __a
);
205 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
& operator=(vector
&& __v
)
206 _NOEXCEPT_(__noexcept_move_assign_container
<_Allocator
, __alloc_traits
>::value
);
208 template <class _InputIterator
, __enable_if_t
<__has_exactly_input_iterator_category
<_InputIterator
>::value
, int> = 0>
209 void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
assign(_InputIterator __first
, _InputIterator __last
);
210 template <class _ForwardIterator
, __enable_if_t
<__has_forward_iterator_category
<_ForwardIterator
>::value
, int> = 0>
211 void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
assign(_ForwardIterator __first
, _ForwardIterator __last
);
213 #if _LIBCPP_STD_VER >= 23
214 template <_ContainerCompatibleRange
<bool> _Range
>
215 _LIBCPP_HIDE_FROM_ABI
constexpr void assign_range(_Range
&& __range
) {
216 if constexpr (ranges::forward_range
<_Range
> || ranges::sized_range
<_Range
>) {
217 auto __n
= static_cast<size_type
>(ranges::distance(__range
));
218 __assign_with_size(ranges::begin(__range
), ranges::end(__range
), __n
);
221 __assign_with_sentinel(ranges::begin(__range
), ranges::end(__range
));
226 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void assign(size_type __n
, const value_type
& __x
);
228 #ifndef _LIBCPP_CXX03_LANG
229 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void assign(initializer_list
<value_type
> __il
) {
230 assign(__il
.begin(), __il
.end());
234 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator_type
get_allocator() const _NOEXCEPT
{
235 return allocator_type(this->__alloc_
);
238 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
max_size() const _NOEXCEPT
;
239 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
capacity() const _NOEXCEPT
{
240 return __internal_cap_to_external(__cap_
);
242 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
size() const _NOEXCEPT
{ return __size_
; }
243 [[__nodiscard__
]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
bool empty() const _NOEXCEPT
{
246 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void reserve(size_type __n
);
247 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void shrink_to_fit() _NOEXCEPT
;
249 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
begin() _NOEXCEPT
{ return __make_iter(0); }
250 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator
begin() const _NOEXCEPT
{ return __make_iter(0); }
251 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
end() _NOEXCEPT
{ return __make_iter(__size_
); }
252 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator
end() const _NOEXCEPT
{
253 return __make_iter(__size_
);
256 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator
rbegin() _NOEXCEPT
{
257 return reverse_iterator(end());
259 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
rbegin() const _NOEXCEPT
{
260 return const_reverse_iterator(end());
262 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator
rend() _NOEXCEPT
{
263 return reverse_iterator(begin());
265 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
rend() const _NOEXCEPT
{
266 return const_reverse_iterator(begin());
269 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator
cbegin() const _NOEXCEPT
{ return __make_iter(0); }
270 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator
cend() const _NOEXCEPT
{
271 return __make_iter(__size_
);
273 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
crbegin() const _NOEXCEPT
{
276 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
crend() const _NOEXCEPT
{ return rend(); }
278 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference
operator[](size_type __n
) { return __make_ref(__n
); }
279 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference
operator[](size_type __n
) const {
280 return __make_ref(__n
);
282 _LIBCPP_HIDE_FROM_ABI reference
at(size_type __n
);
283 _LIBCPP_HIDE_FROM_ABI const_reference
at(size_type __n
) const;
285 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference
front() { return __make_ref(0); }
286 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference
front() const { return __make_ref(0); }
287 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference
back() { return __make_ref(__size_
- 1); }
288 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference
back() const { return __make_ref(__size_
- 1); }
290 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void push_back(const value_type
& __x
);
291 #if _LIBCPP_STD_VER >= 14
292 template <class... _Args
>
293 # if _LIBCPP_STD_VER >= 17
294 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference
emplace_back(_Args
&&... __args
)
296 _LIBCPP_HIDE_FROM_ABI
void emplace_back(_Args
&&... __args
)
299 push_back(value_type(std::forward
<_Args
>(__args
)...));
300 # if _LIBCPP_STD_VER >= 17
306 #if _LIBCPP_STD_VER >= 23
307 template <_ContainerCompatibleRange
<bool> _Range
>
308 _LIBCPP_HIDE_FROM_ABI
constexpr void append_range(_Range
&& __range
) {
309 insert_range(end(), std::forward
<_Range
>(__range
));
313 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void pop_back() { --__size_
; }
315 #if _LIBCPP_STD_VER >= 14
316 template <class... _Args
>
317 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
emplace(const_iterator __position
, _Args
&&... __args
) {
318 return insert(__position
, value_type(std::forward
<_Args
>(__args
)...));
322 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
insert(const_iterator __position
, const value_type
& __x
);
323 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
324 insert(const_iterator __position
, size_type __n
, const value_type
& __x
);
325 template <class _InputIterator
, __enable_if_t
<__has_exactly_input_iterator_category
<_InputIterator
>::value
, int> = 0>
326 iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
327 insert(const_iterator __position
, _InputIterator __first
, _InputIterator __last
);
328 template <class _ForwardIterator
, __enable_if_t
<__has_forward_iterator_category
<_ForwardIterator
>::value
, int> = 0>
329 iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
330 insert(const_iterator __position
, _ForwardIterator __first
, _ForwardIterator __last
);
332 #if _LIBCPP_STD_VER >= 23
333 template <_ContainerCompatibleRange
<bool> _Range
>
334 _LIBCPP_HIDE_FROM_ABI
constexpr iterator
insert_range(const_iterator __position
, _Range
&& __range
) {
335 if constexpr (ranges::forward_range
<_Range
> || ranges::sized_range
<_Range
>) {
336 auto __n
= static_cast<size_type
>(ranges::distance(__range
));
337 return __insert_with_size(__position
, ranges::begin(__range
), ranges::end(__range
), __n
);
340 return __insert_with_sentinel(__position
, ranges::begin(__range
), ranges::end(__range
));
345 #ifndef _LIBCPP_CXX03_LANG
346 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
347 insert(const_iterator __position
, initializer_list
<value_type
> __il
) {
348 return insert(__position
, __il
.begin(), __il
.end());
352 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
erase(const_iterator __position
);
353 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
erase(const_iterator __first
, const_iterator __last
);
355 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void clear() _NOEXCEPT
{ __size_
= 0; }
357 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void swap(vector
&)
358 #if _LIBCPP_STD_VER >= 14
361 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value
|| __is_nothrow_swappable_v
<allocator_type
>);
363 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
static void swap(reference __x
, reference __y
) _NOEXCEPT
{
367 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void resize(size_type __sz
, value_type __x
= false);
368 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void flip() _NOEXCEPT
;
370 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
bool __invariants() const;
373 [[__noreturn__
]] _LIBCPP_HIDE_FROM_ABI
static void __throw_length_error() { std::__throw_length_error("vector"); }
375 [[__noreturn__
]] _LIBCPP_HIDE_FROM_ABI
static void __throw_out_of_range() { std::__throw_out_of_range("vector"); }
377 template <class _InputIterator
, class _Sentinel
>
378 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void
379 __init_with_size(_InputIterator __first
, _Sentinel __last
, size_type __n
) {
380 auto __guard
= std::__make_exception_guard(__destroy_vector(*this));
384 __construct_at_end(std::move(__first
), std::move(__last
), __n
);
387 __guard
.__complete();
390 template <class _InputIterator
, class _Sentinel
>
391 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void
392 __init_with_sentinel(_InputIterator __first
, _Sentinel __last
) {
393 #if _LIBCPP_HAS_EXCEPTIONS
395 #endif // _LIBCPP_HAS_EXCEPTIONS
396 for (; __first
!= __last
; ++__first
)
398 #if _LIBCPP_HAS_EXCEPTIONS
400 if (__begin_
!= nullptr)
401 __storage_traits::deallocate(__alloc_
, __begin_
, __cap_
);
404 #endif // _LIBCPP_HAS_EXCEPTIONS
407 template <class _Iterator
, class _Sentinel
>
408 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
void __assign_with_sentinel(_Iterator __first
, _Sentinel __last
);
410 template <class _ForwardIterator
, class _Sentinel
>
411 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
void
412 __assign_with_size(_ForwardIterator __first
, _Sentinel __last
, difference_type __ns
);
414 template <class _InputIterator
, class _Sentinel
>
415 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
416 __insert_with_sentinel(const_iterator __position
, _InputIterator __first
, _Sentinel __last
);
418 template <class _Iterator
, class _Sentinel
>
419 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
420 __insert_with_size(const_iterator __position
, _Iterator __first
, _Sentinel __last
, difference_type __n
);
422 // Allocate space for __n objects
423 // throws length_error if __n > max_size()
424 // throws (probably bad_alloc) if memory run out
425 // Precondition: __begin_ == __end_ == __cap_ == nullptr
426 // Precondition: __n > 0
427 // Postcondition: capacity() >= __n
428 // Postcondition: size() == 0
429 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __vallocate(size_type __n
) {
430 if (__n
> max_size())
431 __throw_length_error();
432 auto __allocation
= std::__allocate_at_least(__alloc_
, __external_cap_to_internal(__n
));
433 __begin_
= __allocation
.ptr
;
435 __cap_
= __allocation
.count
;
436 if (__libcpp_is_constant_evaluated()) {
437 for (size_type __i
= 0; __i
!= __cap_
; ++__i
)
438 std::__construct_at(std::__to_address(__begin_
) + __i
);
442 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __vdeallocate() _NOEXCEPT
;
443 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
static size_type
__align_it(size_type __new_size
) _NOEXCEPT
{
444 return (__new_size
+ (__bits_per_word
- 1)) & ~((size_type
)__bits_per_word
- 1);
446 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
__recommend(size_type __new_size
) const;
447 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __construct_at_end(size_type __n
, bool __x
);
448 template <class _InputIterator
, class _Sentinel
>
449 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void
450 __construct_at_end(_InputIterator __first
, _Sentinel __last
, size_type __n
);
451 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __append(size_type __n
, const_reference __x
);
452 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference
__make_ref(size_type __pos
) _NOEXCEPT
{
453 return reference(__begin_
+ __pos
/ __bits_per_word
, __storage_type(1) << __pos
% __bits_per_word
);
455 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference
__make_ref(size_type __pos
) const _NOEXCEPT
{
456 return __bit_const_reference
<vector
>(
457 __begin_
+ __pos
/ __bits_per_word
, __storage_type(1) << __pos
% __bits_per_word
);
459 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
__make_iter(size_type __pos
) _NOEXCEPT
{
460 return iterator(__begin_
+ __pos
/ __bits_per_word
, static_cast<unsigned>(__pos
% __bits_per_word
));
462 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator
__make_iter(size_type __pos
) const _NOEXCEPT
{
463 return const_iterator(__begin_
+ __pos
/ __bits_per_word
, static_cast<unsigned>(__pos
% __bits_per_word
));
465 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
__const_iterator_cast(const_iterator __p
) _NOEXCEPT
{
466 return begin() + (__p
- cbegin());
469 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __copy_assign_alloc(const vector
& __v
) {
471 __v
, integral_constant
<bool, __storage_traits::propagate_on_container_copy_assignment::value
>());
473 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __copy_assign_alloc(const vector
& __c
, true_type
) {
474 if (__alloc_
!= __c
.__alloc_
)
476 __alloc_
= __c
.__alloc_
;
479 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __copy_assign_alloc(const vector
&, false_type
) {}
481 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __move_assign(vector
& __c
, false_type
);
482 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __move_assign(vector
& __c
, true_type
)
483 _NOEXCEPT_(is_nothrow_move_assignable
<allocator_type
>::value
);
484 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __move_assign_alloc(vector
& __c
)
485 _NOEXCEPT_(!__storage_traits::propagate_on_container_move_assignment::value
||
486 is_nothrow_move_assignable
<allocator_type
>::value
) {
488 __c
, integral_constant
<bool, __storage_traits::propagate_on_container_move_assignment::value
>());
490 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __move_assign_alloc(vector
& __c
, true_type
)
491 _NOEXCEPT_(is_nothrow_move_assignable
<allocator_type
>::value
) {
492 __alloc_
= std::move(__c
.__alloc_
);
495 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void __move_assign_alloc(vector
&, false_type
) _NOEXCEPT
{}
497 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
size_t __hash_code() const _NOEXCEPT
;
499 friend class __bit_reference
<vector
>;
500 friend class __bit_const_reference
<vector
>;
501 friend class __bit_iterator
<vector
, false>;
502 friend class __bit_iterator
<vector
, true>;
503 friend struct __bit_array
<vector
>;
504 friend struct _LIBCPP_TEMPLATE_VIS hash
<vector
>;
507 template <class _Allocator
>
508 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::__vdeallocate() _NOEXCEPT
{
509 if (this->__begin_
!= nullptr) {
510 __storage_traits::deallocate(this->__alloc_
, this->__begin_
, __cap_
);
511 this->__begin_
= nullptr;
512 this->__size_
= this->__cap_
= 0;
516 template <class _Allocator
>
517 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector
<bool, _Allocator
>::size_type
518 vector
<bool, _Allocator
>::max_size() const _NOEXCEPT
{
519 size_type __amax
= __storage_traits::max_size(__alloc_
);
520 size_type __nmax
= numeric_limits
<size_type
>::max() / 2; // end() >= begin(), always
521 if (__nmax
/ __bits_per_word
<= __amax
)
523 return __internal_cap_to_external(__amax
);
526 // Precondition: __new_size > capacity()
527 template <class _Allocator
>
528 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector
<bool, _Allocator
>::size_type
529 vector
<bool, _Allocator
>::__recommend(size_type __new_size
) const {
530 const size_type __ms
= max_size();
531 if (__new_size
> __ms
)
532 this->__throw_length_error();
533 const size_type __cap
= capacity();
534 if (__cap
>= __ms
/ 2)
536 return std::max(2 * __cap
, __align_it(__new_size
));
539 // Default constructs __n objects starting at __end_
540 // Precondition: __n > 0
541 // Precondition: size() + __n <= capacity()
542 // Postcondition: size() == size() + __n
543 template <class _Allocator
>
544 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
void
545 vector
<bool, _Allocator
>::__construct_at_end(size_type __n
, bool __x
) {
546 size_type __old_size
= this->__size_
;
547 this->__size_
+= __n
;
548 if (__old_size
== 0 || ((__old_size
- 1) / __bits_per_word
) != ((this->__size_
- 1) / __bits_per_word
)) {
549 if (this->__size_
<= __bits_per_word
)
550 this->__begin_
[0] = __storage_type(0);
552 this->__begin_
[(this->__size_
- 1) / __bits_per_word
] = __storage_type(0);
554 std::fill_n(__make_iter(__old_size
), __n
, __x
);
557 template <class _Allocator
>
558 template <class _InputIterator
, class _Sentinel
>
559 _LIBCPP_CONSTEXPR_SINCE_CXX20
void
560 vector
<bool, _Allocator
>::__construct_at_end(_InputIterator __first
, _Sentinel __last
, size_type __n
) {
561 size_type __old_size
= this->__size_
;
562 this->__size_
+= __n
;
563 if (__old_size
== 0 || ((__old_size
- 1) / __bits_per_word
) != ((this->__size_
- 1) / __bits_per_word
)) {
564 if (this->__size_
<= __bits_per_word
)
565 this->__begin_
[0] = __storage_type(0);
567 this->__begin_
[(this->__size_
- 1) / __bits_per_word
] = __storage_type(0);
569 std::__copy(__first
, __last
, __make_iter(__old_size
));
572 template <class _Allocator
>
573 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>::vector()
574 _NOEXCEPT_(is_nothrow_default_constructible
<allocator_type
>::value
)
575 : __begin_(nullptr), __size_(0), __cap_(0) {}
577 template <class _Allocator
>
578 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>::vector(const allocator_type
& __a
)
579 #if _LIBCPP_STD_VER <= 14
580 _NOEXCEPT_(is_nothrow_copy_constructible
<allocator_type
>::value
)
584 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator
>(__a
)) {
587 template <class _Allocator
>
588 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>::vector(size_type __n
)
589 : __begin_(nullptr), __size_(0), __cap_(0) {
592 __construct_at_end(__n
, false);
596 #if _LIBCPP_STD_VER >= 14
597 template <class _Allocator
>
598 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>::vector(size_type __n
, const allocator_type
& __a
)
599 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator
>(__a
)) {
602 __construct_at_end(__n
, false);
607 template <class _Allocator
>
608 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>::vector(size_type __n
, const value_type
& __x
)
609 : __begin_(nullptr), __size_(0), __cap_(0) {
612 __construct_at_end(__n
, __x
);
616 template <class _Allocator
>
617 _LIBCPP_CONSTEXPR_SINCE_CXX20
618 vector
<bool, _Allocator
>::vector(size_type __n
, const value_type
& __x
, const allocator_type
& __a
)
619 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator
>(__a
)) {
622 __construct_at_end(__n
, __x
);
626 template <class _Allocator
>
627 template <class _InputIterator
, __enable_if_t
<__has_exactly_input_iterator_category
<_InputIterator
>::value
, int> >
628 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>::vector(_InputIterator __first
, _InputIterator __last
)
629 : __begin_(nullptr), __size_(0), __cap_(0) {
630 __init_with_sentinel(__first
, __last
);
633 template <class _Allocator
>
634 template <class _InputIterator
, __enable_if_t
<__has_exactly_input_iterator_category
<_InputIterator
>::value
, int> >
635 _LIBCPP_CONSTEXPR_SINCE_CXX20
636 vector
<bool, _Allocator
>::vector(_InputIterator __first
, _InputIterator __last
, const allocator_type
& __a
)
637 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator
>(__a
)) {
638 __init_with_sentinel(__first
, __last
);
641 template <class _Allocator
>
642 template <class _ForwardIterator
, __enable_if_t
<__has_forward_iterator_category
<_ForwardIterator
>::value
, int> >
643 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>::vector(_ForwardIterator __first
, _ForwardIterator __last
)
644 : __begin_(nullptr), __size_(0), __cap_(0) {
645 auto __n
= static_cast<size_type
>(std::distance(__first
, __last
));
646 __init_with_size(__first
, __last
, __n
);
649 template <class _Allocator
>
650 template <class _ForwardIterator
, __enable_if_t
<__has_forward_iterator_category
<_ForwardIterator
>::value
, int> >
651 _LIBCPP_CONSTEXPR_SINCE_CXX20
652 vector
<bool, _Allocator
>::vector(_ForwardIterator __first
, _ForwardIterator __last
, const allocator_type
& __a
)
653 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator
>(__a
)) {
654 auto __n
= static_cast<size_type
>(std::distance(__first
, __last
));
655 __init_with_size(__first
, __last
, __n
);
658 #ifndef _LIBCPP_CXX03_LANG
660 template <class _Allocator
>
661 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>::vector(initializer_list
<value_type
> __il
)
662 : __begin_(nullptr), __size_(0), __cap_(0) {
663 size_type __n
= static_cast<size_type
>(__il
.size());
666 __construct_at_end(__il
.begin(), __il
.end(), __n
);
670 template <class _Allocator
>
671 _LIBCPP_CONSTEXPR_SINCE_CXX20
672 vector
<bool, _Allocator
>::vector(initializer_list
<value_type
> __il
, const allocator_type
& __a
)
673 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(static_cast<__storage_allocator
>(__a
)) {
674 size_type __n
= static_cast<size_type
>(__il
.size());
677 __construct_at_end(__il
.begin(), __il
.end(), __n
);
681 #endif // _LIBCPP_CXX03_LANG
683 template <class _Allocator
>
684 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>::vector(const vector
& __v
)
688 __alloc_(__storage_traits::select_on_container_copy_construction(__v
.__alloc_
)) {
689 if (__v
.size() > 0) {
690 __vallocate(__v
.size());
691 __construct_at_end(__v
.begin(), __v
.end(), __v
.size());
695 template <class _Allocator
>
696 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>::vector(const vector
& __v
, const allocator_type
& __a
)
697 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(__a
) {
698 if (__v
.size() > 0) {
699 __vallocate(__v
.size());
700 __construct_at_end(__v
.begin(), __v
.end(), __v
.size());
704 template <class _Allocator
>
705 _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>& vector
<bool, _Allocator
>::operator=(const vector
& __v
) {
706 if (this != std::addressof(__v
)) {
707 __copy_assign_alloc(__v
);
709 if (__v
.__size_
> capacity()) {
711 __vallocate(__v
.__size_
);
713 std::copy(__v
.__begin_
, __v
.__begin_
+ __external_cap_to_internal(__v
.__size_
), __begin_
);
715 __size_
= __v
.__size_
;
720 template <class _Allocator
>
721 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>::vector(vector
&& __v
)
722 #if _LIBCPP_STD_VER >= 17
725 _NOEXCEPT_(is_nothrow_move_constructible
<allocator_type
>::value
)
727 : __begin_(__v
.__begin_
),
728 __size_(__v
.__size_
),
730 __alloc_(std::move(__v
.__alloc_
)) {
731 __v
.__begin_
= nullptr;
736 template <class _Allocator
>
737 _LIBCPP_CONSTEXPR_SINCE_CXX20
738 vector
<bool, _Allocator
>::vector(vector
&& __v
, const __type_identity_t
<allocator_type
>& __a
)
739 : __begin_(nullptr), __size_(0), __cap_(0), __alloc_(__a
) {
740 if (__a
== allocator_type(__v
.__alloc_
)) {
741 this->__begin_
= __v
.__begin_
;
742 this->__size_
= __v
.__size_
;
743 this->__cap_
= __v
.__cap_
;
744 __v
.__begin_
= nullptr;
745 __v
.__cap_
= __v
.__size_
= 0;
746 } else if (__v
.size() > 0) {
747 __vallocate(__v
.size());
748 __construct_at_end(__v
.begin(), __v
.end(), __v
.size());
752 template <class _Allocator
>
753 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector
<bool, _Allocator
>&
754 vector
<bool, _Allocator
>::operator=(vector
&& __v
)
755 _NOEXCEPT_(__noexcept_move_assign_container
<_Allocator
, __alloc_traits
>::value
) {
756 __move_assign(__v
, integral_constant
<bool, __storage_traits::propagate_on_container_move_assignment::value
>());
760 template <class _Allocator
>
761 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::__move_assign(vector
& __c
, false_type
) {
762 if (__alloc_
!= __c
.__alloc_
)
763 assign(__c
.begin(), __c
.end());
765 __move_assign(__c
, true_type());
768 template <class _Allocator
>
769 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::__move_assign(vector
& __c
, true_type
)
770 _NOEXCEPT_(is_nothrow_move_assignable
<allocator_type
>::value
) {
772 __move_assign_alloc(__c
);
773 this->__begin_
= __c
.__begin_
;
774 this->__size_
= __c
.__size_
;
775 this->__cap_
= __c
.__cap_
;
776 __c
.__begin_
= nullptr;
777 __c
.__cap_
= __c
.__size_
= 0;
780 template <class _Allocator
>
781 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::assign(size_type __n
, const value_type
& __x
) {
784 size_type __c
= capacity();
788 vector
__v(get_allocator());
789 __v
.reserve(__recommend(__n
));
793 std::fill_n(begin(), __n
, __x
);
797 template <class _Allocator
>
798 template <class _InputIterator
, __enable_if_t
<__has_exactly_input_iterator_category
<_InputIterator
>::value
, int> >
799 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::assign(_InputIterator __first
, _InputIterator __last
) {
800 __assign_with_sentinel(__first
, __last
);
803 template <class _Allocator
>
804 template <class _Iterator
, class _Sentinel
>
805 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
void
806 vector
<bool, _Allocator
>::__assign_with_sentinel(_Iterator __first
, _Sentinel __last
) {
808 for (; __first
!= __last
; ++__first
)
812 template <class _Allocator
>
813 template <class _ForwardIterator
, __enable_if_t
<__has_forward_iterator_category
<_ForwardIterator
>::value
, int> >
814 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::assign(_ForwardIterator __first
, _ForwardIterator __last
) {
815 __assign_with_size(__first
, __last
, std::distance(__first
, __last
));
818 template <class _Allocator
>
819 template <class _ForwardIterator
, class _Sentinel
>
820 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
void
821 vector
<bool, _Allocator
>::__assign_with_size(_ForwardIterator __first
, _Sentinel __last
, difference_type __ns
) {
822 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__ns
>= 0, "invalid range specified");
826 const size_t __n
= static_cast<size_type
>(__ns
);
828 if (__n
> capacity()) {
832 __construct_at_end(__first
, __last
, __n
);
836 template <class _Allocator
>
837 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::reserve(size_type __n
) {
838 if (__n
> capacity()) {
839 if (__n
> max_size())
840 this->__throw_length_error();
841 vector
__v(this->get_allocator());
842 __v
.__vallocate(__n
);
843 __v
.__construct_at_end(this->begin(), this->end(), this->size());
848 template <class _Allocator
>
849 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::shrink_to_fit() _NOEXCEPT
{
850 if (__external_cap_to_internal(size()) > __cap_
) {
851 #if _LIBCPP_HAS_EXCEPTIONS
853 #endif // _LIBCPP_HAS_EXCEPTIONS
854 vector(*this, allocator_type(__alloc_
)).swap(*this);
855 #if _LIBCPP_HAS_EXCEPTIONS
858 #endif // _LIBCPP_HAS_EXCEPTIONS
862 template <class _Allocator
>
863 typename vector
<bool, _Allocator
>::reference vector
<bool, _Allocator
>::at(size_type __n
) {
865 this->__throw_out_of_range();
869 template <class _Allocator
>
870 typename vector
<bool, _Allocator
>::const_reference vector
<bool, _Allocator
>::at(size_type __n
) const {
872 this->__throw_out_of_range();
876 template <class _Allocator
>
877 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::push_back(const value_type
& __x
) {
878 if (this->__size_
== this->capacity())
879 reserve(__recommend(this->__size_
+ 1));
884 template <class _Allocator
>
885 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector
<bool, _Allocator
>::iterator
886 vector
<bool, _Allocator
>::insert(const_iterator __position
, const value_type
& __x
) {
888 if (size() < capacity()) {
889 const_iterator __old_end
= end();
891 std::copy_backward(__position
, __old_end
, end());
892 __r
= __const_iterator_cast(__position
);
894 vector
__v(get_allocator());
895 __v
.reserve(__recommend(__size_
+ 1));
896 __v
.__size_
= __size_
+ 1;
897 __r
= std::copy(cbegin(), __position
, __v
.begin());
898 std::copy_backward(__position
, cend(), __v
.end());
905 template <class _Allocator
>
906 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector
<bool, _Allocator
>::iterator
907 vector
<bool, _Allocator
>::insert(const_iterator __position
, size_type __n
, const value_type
& __x
) {
909 size_type __c
= capacity();
910 if (__n
<= __c
&& size() <= __c
- __n
) {
911 const_iterator __old_end
= end();
913 std::copy_backward(__position
, __old_end
, end());
914 __r
= __const_iterator_cast(__position
);
916 vector
__v(get_allocator());
917 __v
.reserve(__recommend(__size_
+ __n
));
918 __v
.__size_
= __size_
+ __n
;
919 __r
= std::copy(cbegin(), __position
, __v
.begin());
920 std::copy_backward(__position
, cend(), __v
.end());
923 std::fill_n(__r
, __n
, __x
);
927 template <class _Allocator
>
928 template <class _InputIterator
, __enable_if_t
<__has_exactly_input_iterator_category
<_InputIterator
>::value
, int> >
929 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector
<bool, _Allocator
>::iterator
930 vector
<bool, _Allocator
>::insert(const_iterator __position
, _InputIterator __first
, _InputIterator __last
) {
931 return __insert_with_sentinel(__position
, __first
, __last
);
934 template <class _Allocator
>
935 template <class _InputIterator
, class _Sentinel
>
936 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector
<bool, _Allocator
>::iterator
937 vector
<bool, _Allocator
>::__insert_with_sentinel(const_iterator __position
, _InputIterator __first
, _Sentinel __last
) {
938 difference_type __off
= __position
- begin();
939 iterator __p
= __const_iterator_cast(__position
);
940 iterator __old_end
= end();
941 for (; size() != capacity() && __first
!= __last
; ++__first
) {
945 vector
__v(get_allocator());
946 if (__first
!= __last
) {
947 #if _LIBCPP_HAS_EXCEPTIONS
949 #endif // _LIBCPP_HAS_EXCEPTIONS
950 __v
.__assign_with_sentinel(std::move(__first
), std::move(__last
));
951 difference_type __old_size
= static_cast<difference_type
>(__old_end
- begin());
952 difference_type __old_p
= __p
- begin();
953 reserve(__recommend(size() + __v
.size()));
954 __p
= begin() + __old_p
;
955 __old_end
= begin() + __old_size
;
956 #if _LIBCPP_HAS_EXCEPTIONS
958 erase(__old_end
, end());
961 #endif // _LIBCPP_HAS_EXCEPTIONS
963 __p
= std::rotate(__p
, __old_end
, end());
964 insert(__p
, __v
.begin(), __v
.end());
965 return begin() + __off
;
968 template <class _Allocator
>
969 template <class _ForwardIterator
, __enable_if_t
<__has_forward_iterator_category
<_ForwardIterator
>::value
, int> >
970 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector
<bool, _Allocator
>::iterator
971 vector
<bool, _Allocator
>::insert(const_iterator __position
, _ForwardIterator __first
, _ForwardIterator __last
) {
972 return __insert_with_size(__position
, __first
, __last
, std::distance(__first
, __last
));
975 template <class _Allocator
>
976 template <class _ForwardIterator
, class _Sentinel
>
977 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector
<bool, _Allocator
>::iterator
978 vector
<bool, _Allocator
>::__insert_with_size(
979 const_iterator __position
, _ForwardIterator __first
, _Sentinel __last
, difference_type __n_signed
) {
980 _LIBCPP_ASSERT_VALID_INPUT_RANGE(__n_signed
>= 0, "invalid range specified");
981 const size_type __n
= static_cast<size_type
>(__n_signed
);
983 size_type __c
= capacity();
984 if (__n
<= __c
&& size() <= __c
- __n
) {
985 const_iterator __old_end
= end();
987 std::copy_backward(__position
, __old_end
, end());
988 __r
= __const_iterator_cast(__position
);
990 vector
__v(get_allocator());
991 __v
.reserve(__recommend(__size_
+ __n
));
992 __v
.__size_
= __size_
+ __n
;
993 __r
= std::copy(cbegin(), __position
, __v
.begin());
994 std::copy_backward(__position
, cend(), __v
.end());
997 std::__copy(__first
, __last
, __r
);
1001 template <class _Allocator
>
1002 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector
<bool, _Allocator
>::iterator
1003 vector
<bool, _Allocator
>::erase(const_iterator __position
) {
1004 iterator __r
= __const_iterator_cast(__position
);
1005 std::copy(__position
+ 1, this->cend(), __r
);
1010 template <class _Allocator
>
1011 _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector
<bool, _Allocator
>::iterator
1012 vector
<bool, _Allocator
>::erase(const_iterator __first
, const_iterator __last
) {
1013 iterator __r
= __const_iterator_cast(__first
);
1014 difference_type __d
= __last
- __first
;
1015 std::copy(__last
, this->cend(), __r
);
1020 template <class _Allocator
>
1021 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::swap(vector
& __x
)
1022 #if _LIBCPP_STD_VER >= 14
1025 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value
|| __is_nothrow_swappable_v
<allocator_type
>)
1028 std::swap(this->__begin_
, __x
.__begin_
);
1029 std::swap(this->__size_
, __x
.__size_
);
1030 std::swap(this->__cap_
, __x
.__cap_
);
1031 std::__swap_allocator(this->__alloc_
, __x
.__alloc_
);
1034 template <class _Allocator
>
1035 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::resize(size_type __sz
, value_type __x
) {
1036 size_type __cs
= size();
1039 size_type __c
= capacity();
1040 size_type __n
= __sz
- __cs
;
1041 if (__n
<= __c
&& __cs
<= __c
- __n
) {
1045 vector
__v(get_allocator());
1046 __v
.reserve(__recommend(__size_
+ __n
));
1047 __v
.__size_
= __size_
+ __n
;
1048 __r
= std::copy(cbegin(), cend(), __v
.begin());
1051 std::fill_n(__r
, __n
, __x
);
1056 template <class _Allocator
>
1057 _LIBCPP_CONSTEXPR_SINCE_CXX20
void vector
<bool, _Allocator
>::flip() _NOEXCEPT
{
1058 // do middle whole words
1059 size_type __n
= __size_
;
1060 __storage_pointer __p
= __begin_
;
1061 for (; __n
>= __bits_per_word
; ++__p
, __n
-= __bits_per_word
)
1063 // do last partial word
1065 __storage_type __m
= ~__storage_type(0) >> (__bits_per_word
- __n
);
1066 __storage_type __b
= *__p
& __m
;
1072 template <class _Allocator
>
1073 _LIBCPP_CONSTEXPR_SINCE_CXX20
bool vector
<bool, _Allocator
>::__invariants() const {
1074 if (this->__begin_
== nullptr) {
1075 if (this->__size_
!= 0 || this->__cap_
!= 0)
1078 if (this->__cap_
== 0)
1080 if (this->__size_
> this->capacity())
1086 template <class _Allocator
>
1087 _LIBCPP_CONSTEXPR_SINCE_CXX20
size_t vector
<bool, _Allocator
>::__hash_code() const _NOEXCEPT
{
1089 // do middle whole words
1090 size_type __n
= __size_
;
1091 __storage_pointer __p
= __begin_
;
1092 for (; __n
>= __bits_per_word
; ++__p
, __n
-= __bits_per_word
)
1094 // do last partial word
1096 const __storage_type __m
= ~__storage_type(0) >> (__bits_per_word
- __n
);
1102 template <class _Allocator
>
1103 struct _LIBCPP_TEMPLATE_VIS hash
<vector
<bool, _Allocator
> >
1104 : public __unary_function
<vector
<bool, _Allocator
>, size_t> {
1105 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
size_t
1106 operator()(const vector
<bool, _Allocator
>& __vec
) const _NOEXCEPT
{
1107 return __vec
.__hash_code();
1111 _LIBCPP_END_NAMESPACE_STD
1115 #endif // _LIBCPP___VECTOR_VECTOR_BOOL_H