2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_VECTOR
11 #define _LIBCPP_VECTOR
19 template <class T, class Allocator = allocator<T> >
24 typedef Allocator allocator_type;
25 typedef typename allocator_type::reference reference;
26 typedef typename allocator_type::const_reference const_reference;
27 typedef implementation-defined iterator;
28 typedef implementation-defined const_iterator;
29 typedef typename allocator_type::size_type size_type;
30 typedef typename allocator_type::difference_type difference_type;
31 typedef typename allocator_type::pointer pointer;
32 typedef typename allocator_type::const_pointer const_pointer;
33 typedef std::reverse_iterator<iterator> reverse_iterator;
34 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
37 noexcept(is_nothrow_default_constructible<allocator_type>::value);
38 explicit vector(const allocator_type&);
39 explicit vector(size_type n);
40 explicit vector(size_type n, const allocator_type&); // C++14
41 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
42 template <class InputIterator>
43 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
44 vector(const vector& x);
46 noexcept(is_nothrow_move_constructible<allocator_type>::value);
47 vector(initializer_list<value_type> il);
48 vector(initializer_list<value_type> il, const allocator_type& a);
50 vector& operator=(const vector& x);
51 vector& operator=(vector&& x)
53 allocator_type::propagate_on_container_move_assignment::value ||
54 allocator_type::is_always_equal::value); // C++17
55 vector& operator=(initializer_list<value_type> il);
56 template <class InputIterator>
57 void assign(InputIterator first, InputIterator last);
58 void assign(size_type n, const value_type& u);
59 void assign(initializer_list<value_type> il);
61 allocator_type get_allocator() const noexcept;
63 iterator begin() noexcept;
64 const_iterator begin() const noexcept;
65 iterator end() noexcept;
66 const_iterator end() const noexcept;
68 reverse_iterator rbegin() noexcept;
69 const_reverse_iterator rbegin() const noexcept;
70 reverse_iterator rend() noexcept;
71 const_reverse_iterator rend() const noexcept;
73 const_iterator cbegin() const noexcept;
74 const_iterator cend() const noexcept;
75 const_reverse_iterator crbegin() const noexcept;
76 const_reverse_iterator crend() const noexcept;
78 size_type size() const noexcept;
79 size_type max_size() const noexcept;
80 size_type capacity() const noexcept;
81 bool empty() const noexcept;
82 void reserve(size_type n);
83 void shrink_to_fit() noexcept;
85 reference operator[](size_type n);
86 const_reference operator[](size_type n) const;
87 reference at(size_type n);
88 const_reference at(size_type n) const;
91 const_reference front() const;
93 const_reference back() const;
95 value_type* data() noexcept;
96 const value_type* data() const noexcept;
98 void push_back(const value_type& x);
99 void push_back(value_type&& x);
100 template <class... Args>
101 reference emplace_back(Args&&... args); // reference in C++17
104 template <class... Args> iterator emplace(const_iterator position, Args&&... args);
105 iterator insert(const_iterator position, const value_type& x);
106 iterator insert(const_iterator position, value_type&& x);
107 iterator insert(const_iterator position, size_type n, const value_type& x);
108 template <class InputIterator>
109 iterator insert(const_iterator position, InputIterator first, InputIterator last);
110 iterator insert(const_iterator position, initializer_list<value_type> il);
112 iterator erase(const_iterator position);
113 iterator erase(const_iterator first, const_iterator last);
115 void clear() noexcept;
117 void resize(size_type sz);
118 void resize(size_type sz, const value_type& c);
121 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
122 allocator_traits<allocator_type>::is_always_equal::value); // C++17
124 bool __invariants() const;
127 template <class Allocator = allocator<T> >
128 class vector<bool, Allocator>
131 typedef bool value_type;
132 typedef Allocator allocator_type;
133 typedef implementation-defined iterator;
134 typedef implementation-defined const_iterator;
135 typedef typename allocator_type::size_type size_type;
136 typedef typename allocator_type::difference_type difference_type;
137 typedef iterator pointer;
138 typedef const_iterator const_pointer;
139 typedef std::reverse_iterator<iterator> reverse_iterator;
140 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
145 reference(const reference&) noexcept;
146 operator bool() const noexcept;
147 reference& operator=(bool x) noexcept;
148 reference& operator=(const reference& x) noexcept;
149 iterator operator&() const noexcept;
150 void flip() noexcept;
153 class const_reference
156 const_reference(const reference&) noexcept;
157 operator bool() const noexcept;
158 const_iterator operator&() const noexcept;
162 noexcept(is_nothrow_default_constructible<allocator_type>::value);
163 explicit vector(const allocator_type&);
164 explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
165 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
166 template <class InputIterator>
167 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
168 vector(const vector& x);
170 noexcept(is_nothrow_move_constructible<allocator_type>::value);
171 vector(initializer_list<value_type> il);
172 vector(initializer_list<value_type> il, const allocator_type& a);
174 vector& operator=(const vector& x);
175 vector& operator=(vector&& x)
177 allocator_type::propagate_on_container_move_assignment::value ||
178 allocator_type::is_always_equal::value); // C++17
179 vector& operator=(initializer_list<value_type> il);
180 template <class InputIterator>
181 void assign(InputIterator first, InputIterator last);
182 void assign(size_type n, const value_type& u);
183 void assign(initializer_list<value_type> il);
185 allocator_type get_allocator() const noexcept;
187 iterator begin() noexcept;
188 const_iterator begin() const noexcept;
189 iterator end() noexcept;
190 const_iterator end() const noexcept;
192 reverse_iterator rbegin() noexcept;
193 const_reverse_iterator rbegin() const noexcept;
194 reverse_iterator rend() noexcept;
195 const_reverse_iterator rend() const noexcept;
197 const_iterator cbegin() const noexcept;
198 const_iterator cend() const noexcept;
199 const_reverse_iterator crbegin() const noexcept;
200 const_reverse_iterator crend() const noexcept;
202 size_type size() const noexcept;
203 size_type max_size() const noexcept;
204 size_type capacity() const noexcept;
205 bool empty() const noexcept;
206 void reserve(size_type n);
207 void shrink_to_fit() noexcept;
209 reference operator[](size_type n);
210 const_reference operator[](size_type n) const;
211 reference at(size_type n);
212 const_reference at(size_type n) const;
215 const_reference front() const;
217 const_reference back() const;
219 void push_back(const value_type& x);
220 template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17
223 template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
224 iterator insert(const_iterator position, const value_type& x);
225 iterator insert(const_iterator position, size_type n, const value_type& x);
226 template <class InputIterator>
227 iterator insert(const_iterator position, InputIterator first, InputIterator last);
228 iterator insert(const_iterator position, initializer_list<value_type> il);
230 iterator erase(const_iterator position);
231 iterator erase(const_iterator first, const_iterator last);
233 void clear() noexcept;
235 void resize(size_type sz);
236 void resize(size_type sz, value_type x);
239 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
240 allocator_traits<allocator_type>::is_always_equal::value); // C++17
241 void flip() noexcept;
243 bool __invariants() const;
246 template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
247 vector(InputIterator, InputIterator, Allocator = Allocator())
248 -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
250 template <class Allocator> struct hash<std::vector<bool, Allocator>>;
252 template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
253 template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
254 template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
255 template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
256 template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
257 template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
259 template <class T, class Allocator>
260 void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
261 noexcept(noexcept(x.swap(y)));
263 template <class T, class Allocator, class U>
264 typename vector<T, Allocator>::size_type
265 erase(vector<T, Allocator>& c, const U& value); // C++20
266 template <class T, class Allocator, class Predicate>
267 typename vector<T, Allocator>::size_type
268 erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
274 #include <__algorithm/copy.h>
275 #include <__algorithm/equal.h>
276 #include <__algorithm/fill_n.h>
277 #include <__algorithm/lexicographical_compare.h>
278 #include <__algorithm/remove.h>
279 #include <__algorithm/remove_if.h>
280 #include <__algorithm/rotate.h>
281 #include <__algorithm/unwrap_iter.h>
282 #include <__assert> // all public C++ headers provide the assertion handler
283 #include <__bit_reference>
286 #include <__format/enable_insertable.h>
287 #include <__functional/hash.h>
288 #include <__functional/unary_function.h>
289 #include <__iterator/advance.h>
290 #include <__iterator/iterator_traits.h>
291 #include <__iterator/reverse_iterator.h>
292 #include <__iterator/wrap_iter.h>
293 #include <__memory/allocate_at_least.h>
294 #include <__split_buffer>
295 #include <__utility/forward.h>
296 #include <__utility/move.h>
297 #include <__utility/swap.h>
301 #include <iosfwd> // for forward declaration of vector
305 #include <type_traits>
308 #ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
309 # include <algorithm>
314 // standard-mandated includes
317 #include <__iterator/access.h>
318 #include <__iterator/data.h>
319 #include <__iterator/empty.h>
320 #include <__iterator/reverse_access.h>
321 #include <__iterator/size.h>
325 #include <initializer_list>
327 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
328 # pragma GCC system_header
332 #include <__undef_macros>
335 _LIBCPP_BEGIN_NAMESPACE_STD
337 template <class _Tp, class _Allocator /* = allocator<_Tp> */>
338 class _LIBCPP_TEMPLATE_VIS vector
341 typedef allocator<_Tp> __default_allocator_type;
343 typedef vector __self;
344 typedef _Tp value_type;
345 typedef _Allocator allocator_type;
346 typedef allocator_traits<allocator_type> __alloc_traits;
347 typedef value_type& reference;
348 typedef const value_type& const_reference;
349 typedef typename __alloc_traits::size_type size_type;
350 typedef typename __alloc_traits::difference_type difference_type;
351 typedef typename __alloc_traits::pointer pointer;
352 typedef typename __alloc_traits::const_pointer const_pointer;
353 typedef __wrap_iter<pointer> iterator;
354 typedef __wrap_iter<const_pointer> const_iterator;
355 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
356 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
358 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
359 "Allocator::value_type must be same type as value_type");
361 _LIBCPP_INLINE_VISIBILITY
362 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
364 _VSTD::__debug_db_insert_c(this);
366 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
367 #if _LIBCPP_STD_VER <= 14
368 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
372 : __end_cap_(nullptr, __a)
374 _VSTD::__debug_db_insert_c(this);
376 explicit vector(size_type __n);
377 #if _LIBCPP_STD_VER > 11
378 explicit vector(size_type __n, const allocator_type& __a);
380 vector(size_type __n, const value_type& __x);
382 template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
383 vector(size_type __n, const value_type& __x, const allocator_type& __a)
384 : __end_cap_(nullptr, __a)
386 _VSTD::__debug_db_insert_c(this);
390 __construct_at_end(__n, __x);
394 template <class _InputIterator>
395 vector(_InputIterator __first,
396 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
399 typename iterator_traits<_InputIterator>::reference>::value,
400 _InputIterator>::type __last);
401 template <class _InputIterator>
402 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
403 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
406 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
407 template <class _ForwardIterator>
408 vector(_ForwardIterator __first,
409 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
412 typename iterator_traits<_ForwardIterator>::reference>::value,
413 _ForwardIterator>::type __last);
414 template <class _ForwardIterator>
415 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
416 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
419 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
421 _LIBCPP_INLINE_VISIBILITY
425 std::__debug_db_erase_c(this);
427 if (this->__begin_ != nullptr)
430 __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
434 vector(const vector& __x);
435 vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
436 _LIBCPP_INLINE_VISIBILITY
437 vector& operator=(const vector& __x);
439 #ifndef _LIBCPP_CXX03_LANG
440 _LIBCPP_INLINE_VISIBILITY
441 vector(initializer_list<value_type> __il);
443 _LIBCPP_INLINE_VISIBILITY
444 vector(initializer_list<value_type> __il, const allocator_type& __a);
446 _LIBCPP_INLINE_VISIBILITY
447 vector& operator=(initializer_list<value_type> __il)
448 {assign(__il.begin(), __il.end()); return *this;}
449 #endif // !_LIBCPP_CXX03_LANG
451 _LIBCPP_INLINE_VISIBILITY
453 #if _LIBCPP_STD_VER > 14
456 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
459 _LIBCPP_INLINE_VISIBILITY
460 vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
461 _LIBCPP_INLINE_VISIBILITY
462 vector& operator=(vector&& __x)
463 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
465 template <class _InputIterator>
466 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
469 typename iterator_traits<_InputIterator>::reference>::value,
472 assign(_InputIterator __first, _InputIterator __last);
473 template <class _ForwardIterator>
476 __is_cpp17_forward_iterator<_ForwardIterator>::value &&
479 typename iterator_traits<_ForwardIterator>::reference>::value,
482 assign(_ForwardIterator __first, _ForwardIterator __last);
484 void assign(size_type __n, const_reference __u);
486 #ifndef _LIBCPP_CXX03_LANG
487 _LIBCPP_INLINE_VISIBILITY
488 void assign(initializer_list<value_type> __il)
489 {assign(__il.begin(), __il.end());}
492 _LIBCPP_INLINE_VISIBILITY
493 allocator_type get_allocator() const _NOEXCEPT
494 {return this->__alloc();}
496 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
497 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
498 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
499 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
501 _LIBCPP_INLINE_VISIBILITY
502 reverse_iterator rbegin() _NOEXCEPT
503 {return reverse_iterator(end());}
504 _LIBCPP_INLINE_VISIBILITY
505 const_reverse_iterator rbegin() const _NOEXCEPT
506 {return const_reverse_iterator(end());}
507 _LIBCPP_INLINE_VISIBILITY
508 reverse_iterator rend() _NOEXCEPT
509 {return reverse_iterator(begin());}
510 _LIBCPP_INLINE_VISIBILITY
511 const_reverse_iterator rend() const _NOEXCEPT
512 {return const_reverse_iterator(begin());}
514 _LIBCPP_INLINE_VISIBILITY
515 const_iterator cbegin() const _NOEXCEPT
517 _LIBCPP_INLINE_VISIBILITY
518 const_iterator cend() const _NOEXCEPT
520 _LIBCPP_INLINE_VISIBILITY
521 const_reverse_iterator crbegin() const _NOEXCEPT
523 _LIBCPP_INLINE_VISIBILITY
524 const_reverse_iterator crend() const _NOEXCEPT
527 _LIBCPP_INLINE_VISIBILITY
528 size_type size() const _NOEXCEPT
529 {return static_cast<size_type>(this->__end_ - this->__begin_);}
530 _LIBCPP_INLINE_VISIBILITY
531 size_type capacity() const _NOEXCEPT
532 {return static_cast<size_type>(__end_cap() - this->__begin_);}
533 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
534 bool empty() const _NOEXCEPT
535 {return this->__begin_ == this->__end_;}
536 size_type max_size() const _NOEXCEPT;
537 void reserve(size_type __n);
538 void shrink_to_fit() _NOEXCEPT;
540 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT;
541 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT;
542 reference at(size_type __n);
543 const_reference at(size_type __n) const;
545 _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT
547 _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
548 return *this->__begin_;
550 _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT
552 _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
553 return *this->__begin_;
555 _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT
557 _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
558 return *(this->__end_ - 1);
560 _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT
562 _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
563 return *(this->__end_ - 1);
566 _LIBCPP_INLINE_VISIBILITY
567 value_type* data() _NOEXCEPT
568 {return _VSTD::__to_address(this->__begin_);}
569 _LIBCPP_INLINE_VISIBILITY
570 const value_type* data() const _NOEXCEPT
571 {return _VSTD::__to_address(this->__begin_);}
573 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
575 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
577 template <class... _Args>
578 _LIBCPP_INLINE_VISIBILITY
579 #if _LIBCPP_STD_VER > 14
580 reference emplace_back(_Args&&... __args);
582 void emplace_back(_Args&&... __args);
585 _LIBCPP_INLINE_VISIBILITY
588 iterator insert(const_iterator __position, const_reference __x);
590 iterator insert(const_iterator __position, value_type&& __x);
591 template <class... _Args>
592 iterator emplace(const_iterator __position, _Args&&... __args);
594 iterator insert(const_iterator __position, size_type __n, const_reference __x);
595 template <class _InputIterator>
596 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
599 typename iterator_traits<_InputIterator>::reference>::value,
602 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
603 template <class _ForwardIterator>
606 __is_cpp17_forward_iterator<_ForwardIterator>::value &&
609 typename iterator_traits<_ForwardIterator>::reference>::value,
612 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
614 #ifndef _LIBCPP_CXX03_LANG
615 _LIBCPP_INLINE_VISIBILITY
616 iterator insert(const_iterator __position, initializer_list<value_type> __il)
617 {return insert(__position, __il.begin(), __il.end());}
620 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
621 iterator erase(const_iterator __first, const_iterator __last);
623 _LIBCPP_INLINE_VISIBILITY
624 void clear() _NOEXCEPT
626 size_type __old_size = size();
628 __annotate_shrink(__old_size);
629 std::__debug_db_invalidate_all(this);
632 void resize(size_type __sz);
633 void resize(size_type __sz, const_reference __x);
636 #if _LIBCPP_STD_VER >= 14
639 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
640 __is_nothrow_swappable<allocator_type>::value);
643 bool __invariants() const;
645 #ifdef _LIBCPP_ENABLE_DEBUG_MODE
647 bool __dereferenceable(const const_iterator* __i) const;
648 bool __decrementable(const const_iterator* __i) const;
649 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
650 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
652 #endif // _LIBCPP_ENABLE_DEBUG_MODE
655 pointer __begin_ = nullptr;
656 pointer __end_ = nullptr;
657 __compressed_pair<pointer, allocator_type> __end_cap_ =
658 __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
660 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
663 // Allocate space for __n objects
664 // throws length_error if __n > max_size()
665 // throws (probably bad_alloc) if memory run out
666 // Precondition: __begin_ == __end_ == __end_cap() == 0
667 // Precondition: __n > 0
668 // Postcondition: capacity() >= __n
669 // Postcondition: size() == 0
670 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
671 if (__n > max_size())
672 __throw_length_error();
673 auto __allocation = std::__allocate_at_least(__alloc(), __n);
674 __begin_ = __allocation.ptr;
675 __end_ = __allocation.ptr;
676 __end_cap() = __begin_ + __allocation.count;
680 void __vdeallocate() _NOEXCEPT;
681 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
682 void __construct_at_end(size_type __n);
683 _LIBCPP_INLINE_VISIBILITY
684 void __construct_at_end(size_type __n, const_reference __x);
685 template <class _ForwardIterator>
688 __is_cpp17_forward_iterator<_ForwardIterator>::value,
691 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
692 void __append(size_type __n);
693 void __append(size_type __n, const_reference __x);
694 _LIBCPP_INLINE_VISIBILITY
695 iterator __make_iter(pointer __p) _NOEXCEPT;
696 _LIBCPP_INLINE_VISIBILITY
697 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
698 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
699 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
700 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
701 void __move_assign(vector& __c, true_type)
702 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
703 void __move_assign(vector& __c, false_type)
704 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
705 _LIBCPP_INLINE_VISIBILITY
706 void __destruct_at_end(pointer __new_last) _NOEXCEPT
708 __invalidate_iterators_past(__new_last);
709 size_type __old_size = size();
710 __base_destruct_at_end(__new_last);
711 __annotate_shrink(__old_size);
715 _LIBCPP_INLINE_VISIBILITY
716 inline void __push_back_slow_path(_Up&& __x);
718 template <class... _Args>
719 _LIBCPP_INLINE_VISIBILITY
720 inline void __emplace_back_slow_path(_Args&&... __args);
722 // The following functions are no-ops outside of AddressSanitizer mode.
723 // We call annotatations only for the default Allocator because other allocators
724 // may not meet the AddressSanitizer alignment constraints.
725 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
726 #ifndef _LIBCPP_HAS_NO_ASAN
727 void __annotate_contiguous_container(const void *__beg, const void *__end,
728 const void *__old_mid,
729 const void *__new_mid) const
732 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
733 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
736 _LIBCPP_INLINE_VISIBILITY
737 void __annotate_contiguous_container(const void*, const void*, const void*,
738 const void*) const _NOEXCEPT {}
740 _LIBCPP_INLINE_VISIBILITY
741 void __annotate_new(size_type __current_size) const _NOEXCEPT {
742 __annotate_contiguous_container(data(), data() + capacity(),
743 data() + capacity(), data() + __current_size);
746 _LIBCPP_INLINE_VISIBILITY
747 void __annotate_delete() const _NOEXCEPT {
748 __annotate_contiguous_container(data(), data() + capacity(),
749 data() + size(), data() + capacity());
752 _LIBCPP_INLINE_VISIBILITY
753 void __annotate_increase(size_type __n) const _NOEXCEPT
755 __annotate_contiguous_container(data(), data() + capacity(),
756 data() + size(), data() + size() + __n);
759 _LIBCPP_INLINE_VISIBILITY
760 void __annotate_shrink(size_type __old_size) const _NOEXCEPT
762 __annotate_contiguous_container(data(), data() + capacity(),
763 data() + __old_size, data() + size());
766 struct _ConstructTransaction {
767 explicit _ConstructTransaction(vector &__v, size_type __n)
768 : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
769 #ifndef _LIBCPP_HAS_NO_ASAN
770 __v_.__annotate_increase(__n);
773 ~_ConstructTransaction() {
774 __v_.__end_ = __pos_;
775 #ifndef _LIBCPP_HAS_NO_ASAN
776 if (__pos_ != __new_end_) {
777 __v_.__annotate_shrink(__new_end_ - __v_.__begin_);
784 const_pointer const __new_end_;
787 _ConstructTransaction(_ConstructTransaction const&) = delete;
788 _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
791 template <class ..._Args>
792 _LIBCPP_INLINE_VISIBILITY
793 void __construct_one_at_end(_Args&& ...__args) {
794 _ConstructTransaction __tx(*this, 1);
795 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_),
796 _VSTD::forward<_Args>(__args)...);
800 _LIBCPP_INLINE_VISIBILITY
801 allocator_type& __alloc() _NOEXCEPT
802 {return this->__end_cap_.second();}
803 _LIBCPP_INLINE_VISIBILITY
804 const allocator_type& __alloc() const _NOEXCEPT
805 {return this->__end_cap_.second();}
806 _LIBCPP_INLINE_VISIBILITY
807 pointer& __end_cap() _NOEXCEPT
808 {return this->__end_cap_.first();}
809 _LIBCPP_INLINE_VISIBILITY
810 const pointer& __end_cap() const _NOEXCEPT
811 {return this->__end_cap_.first();}
813 _LIBCPP_INLINE_VISIBILITY
814 void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
816 _LIBCPP_INLINE_VISIBILITY
817 void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
818 pointer __soon_to_be_end = this->__end_;
819 while (__new_last != __soon_to_be_end)
820 __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
821 this->__end_ = __new_last;
824 _LIBCPP_INLINE_VISIBILITY
825 void __copy_assign_alloc(const vector& __c)
826 {__copy_assign_alloc(__c, integral_constant<bool,
827 __alloc_traits::propagate_on_container_copy_assignment::value>());}
829 _LIBCPP_INLINE_VISIBILITY
830 void __move_assign_alloc(vector& __c)
832 !__alloc_traits::propagate_on_container_move_assignment::value ||
833 is_nothrow_move_assignable<allocator_type>::value)
834 {__move_assign_alloc(__c, integral_constant<bool,
835 __alloc_traits::propagate_on_container_move_assignment::value>());}
837 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
838 void __throw_length_error() const {
839 _VSTD::__throw_length_error("vector");
842 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
843 void __throw_out_of_range() const {
844 _VSTD::__throw_out_of_range("vector");
847 _LIBCPP_INLINE_VISIBILITY
848 void __copy_assign_alloc(const vector& __c, true_type)
850 if (__alloc() != __c.__alloc())
853 __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
854 this->__begin_ = this->__end_ = __end_cap() = nullptr;
856 __alloc() = __c.__alloc();
859 _LIBCPP_INLINE_VISIBILITY
860 void __copy_assign_alloc(const vector&, false_type)
863 _LIBCPP_INLINE_VISIBILITY
864 void __move_assign_alloc(vector& __c, true_type)
865 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
867 __alloc() = _VSTD::move(__c.__alloc());
870 _LIBCPP_INLINE_VISIBILITY
871 void __move_assign_alloc(vector&, false_type)
876 #if _LIBCPP_STD_VER >= 17
877 template<class _InputIterator,
878 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
879 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
880 class = enable_if_t<__is_allocator<_Alloc>::value>
882 vector(_InputIterator, _InputIterator)
883 -> vector<__iter_value_type<_InputIterator>, _Alloc>;
885 template<class _InputIterator,
887 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
888 class = enable_if_t<__is_allocator<_Alloc>::value>
890 vector(_InputIterator, _InputIterator, _Alloc)
891 -> vector<__iter_value_type<_InputIterator>, _Alloc>;
894 template <class _Tp, class _Allocator>
896 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
900 _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
901 _VSTD::swap(this->__begin_, __v.__begin_);
902 _VSTD::swap(this->__end_, __v.__end_);
903 _VSTD::swap(this->__end_cap(), __v.__end_cap());
904 __v.__first_ = __v.__begin_;
905 __annotate_new(size());
906 std::__debug_db_invalidate_all(this);
909 template <class _Tp, class _Allocator>
910 typename vector<_Tp, _Allocator>::pointer
911 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
914 pointer __r = __v.__begin_;
915 _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, __p, __v.__begin_);
916 _VSTD::__construct_forward_with_exception_guarantees(this->__alloc(), __p, this->__end_, __v.__end_);
917 _VSTD::swap(this->__begin_, __v.__begin_);
918 _VSTD::swap(this->__end_, __v.__end_);
919 _VSTD::swap(this->__end_cap(), __v.__end_cap());
920 __v.__first_ = __v.__begin_;
921 __annotate_new(size());
922 std::__debug_db_invalidate_all(this);
926 template <class _Tp, class _Allocator>
928 vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
930 if (this->__begin_ != nullptr)
933 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
934 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
938 template <class _Tp, class _Allocator>
939 typename vector<_Tp, _Allocator>::size_type
940 vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
942 return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()),
943 numeric_limits<difference_type>::max());
946 // Precondition: __new_size > capacity()
947 template <class _Tp, class _Allocator>
948 inline _LIBCPP_INLINE_VISIBILITY
949 typename vector<_Tp, _Allocator>::size_type
950 vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
952 const size_type __ms = max_size();
953 if (__new_size > __ms)
954 this->__throw_length_error();
955 const size_type __cap = capacity();
956 if (__cap >= __ms / 2)
958 return _VSTD::max<size_type>(2 * __cap, __new_size);
961 // Default constructs __n objects starting at __end_
962 // throws if construction throws
963 // Precondition: __n > 0
964 // Precondition: size() + __n <= capacity()
965 // Postcondition: size() == size() + __n
966 template <class _Tp, class _Allocator>
968 vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
970 _ConstructTransaction __tx(*this, __n);
971 const_pointer __new_end = __tx.__new_end_;
972 for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
973 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos));
977 // Copy constructs __n objects starting at __end_ from __x
978 // throws if construction throws
979 // Precondition: __n > 0
980 // Precondition: size() + __n <= capacity()
981 // Postcondition: size() == old size() + __n
982 // Postcondition: [i] == __x for all i in [size() - __n, __n)
983 template <class _Tp, class _Allocator>
986 vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
988 _ConstructTransaction __tx(*this, __n);
989 const_pointer __new_end = __tx.__new_end_;
990 for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
991 __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x);
995 template <class _Tp, class _Allocator>
996 template <class _ForwardIterator>
999 __is_cpp17_forward_iterator<_ForwardIterator>::value,
1002 vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
1004 _ConstructTransaction __tx(*this, __n);
1005 _VSTD::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_);
1008 // Default constructs __n objects starting at __end_
1009 // throws if construction throws
1010 // Postcondition: size() == size() + __n
1011 // Exception safety: strong.
1012 template <class _Tp, class _Allocator>
1014 vector<_Tp, _Allocator>::__append(size_type __n)
1016 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1017 this->__construct_at_end(__n);
1020 allocator_type& __a = this->__alloc();
1021 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1022 __v.__construct_at_end(__n);
1023 __swap_out_circular_buffer(__v);
1027 // Default constructs __n objects starting at __end_
1028 // throws if construction throws
1029 // Postcondition: size() == size() + __n
1030 // Exception safety: strong.
1031 template <class _Tp, class _Allocator>
1033 vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1035 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1036 this->__construct_at_end(__n, __x);
1039 allocator_type& __a = this->__alloc();
1040 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1041 __v.__construct_at_end(__n, __x);
1042 __swap_out_circular_buffer(__v);
1046 template <class _Tp, class _Allocator>
1047 vector<_Tp, _Allocator>::vector(size_type __n)
1049 _VSTD::__debug_db_insert_c(this);
1053 __construct_at_end(__n);
1057 #if _LIBCPP_STD_VER > 11
1058 template <class _Tp, class _Allocator>
1059 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1060 : __end_cap_(nullptr, __a)
1062 _VSTD::__debug_db_insert_c(this);
1066 __construct_at_end(__n);
1071 template <class _Tp, class _Allocator>
1072 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
1074 _VSTD::__debug_db_insert_c(this);
1078 __construct_at_end(__n, __x);
1082 template <class _Tp, class _Allocator>
1083 template <class _InputIterator>
1084 vector<_Tp, _Allocator>::vector(_InputIterator __first,
1085 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
1088 typename iterator_traits<_InputIterator>::reference>::value,
1089 _InputIterator>::type __last)
1091 _VSTD::__debug_db_insert_c(this);
1092 for (; __first != __last; ++__first)
1093 emplace_back(*__first);
1096 template <class _Tp, class _Allocator>
1097 template <class _InputIterator>
1098 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1099 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
1102 typename iterator_traits<_InputIterator>::reference>::value>::type*)
1103 : __end_cap_(nullptr, __a)
1105 _VSTD::__debug_db_insert_c(this);
1106 for (; __first != __last; ++__first)
1107 emplace_back(*__first);
1110 template <class _Tp, class _Allocator>
1111 template <class _ForwardIterator>
1112 vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
1113 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
1116 typename iterator_traits<_ForwardIterator>::reference>::value,
1117 _ForwardIterator>::type __last)
1119 _VSTD::__debug_db_insert_c(this);
1120 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1124 __construct_at_end(__first, __last, __n);
1128 template <class _Tp, class _Allocator>
1129 template <class _ForwardIterator>
1130 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1131 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
1134 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1135 : __end_cap_(nullptr, __a)
1137 _VSTD::__debug_db_insert_c(this);
1138 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1142 __construct_at_end(__first, __last, __n);
1146 template <class _Tp, class _Allocator>
1147 vector<_Tp, _Allocator>::vector(const vector& __x)
1148 : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1150 _VSTD::__debug_db_insert_c(this);
1151 size_type __n = __x.size();
1155 __construct_at_end(__x.__begin_, __x.__end_, __n);
1159 template <class _Tp, class _Allocator>
1160 vector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
1161 : __end_cap_(nullptr, __a)
1163 _VSTD::__debug_db_insert_c(this);
1164 size_type __n = __x.size();
1168 __construct_at_end(__x.__begin_, __x.__end_, __n);
1172 template <class _Tp, class _Allocator>
1173 inline _LIBCPP_INLINE_VISIBILITY
1174 vector<_Tp, _Allocator>::vector(vector&& __x)
1175 #if _LIBCPP_STD_VER > 14
1178 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1180 : __end_cap_(nullptr, _VSTD::move(__x.__alloc()))
1182 _VSTD::__debug_db_insert_c(this);
1183 std::__debug_db_swap(this, std::addressof(__x));
1184 this->__begin_ = __x.__begin_;
1185 this->__end_ = __x.__end_;
1186 this->__end_cap() = __x.__end_cap();
1187 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1190 template <class _Tp, class _Allocator>
1191 inline _LIBCPP_INLINE_VISIBILITY
1192 vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
1193 : __end_cap_(nullptr, __a)
1195 _VSTD::__debug_db_insert_c(this);
1196 if (__a == __x.__alloc())
1198 this->__begin_ = __x.__begin_;
1199 this->__end_ = __x.__end_;
1200 this->__end_cap() = __x.__end_cap();
1201 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1202 std::__debug_db_swap(this, std::addressof(__x));
1206 typedef move_iterator<iterator> _Ip;
1207 assign(_Ip(__x.begin()), _Ip(__x.end()));
1211 #ifndef _LIBCPP_CXX03_LANG
1213 template <class _Tp, class _Allocator>
1214 inline _LIBCPP_INLINE_VISIBILITY
1215 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1217 _VSTD::__debug_db_insert_c(this);
1218 if (__il.size() > 0)
1220 __vallocate(__il.size());
1221 __construct_at_end(__il.begin(), __il.end(), __il.size());
1225 template <class _Tp, class _Allocator>
1226 inline _LIBCPP_INLINE_VISIBILITY
1227 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1228 : __end_cap_(nullptr, __a)
1230 _VSTD::__debug_db_insert_c(this);
1231 if (__il.size() > 0)
1233 __vallocate(__il.size());
1234 __construct_at_end(__il.begin(), __il.end(), __il.size());
1238 #endif // _LIBCPP_CXX03_LANG
1240 template <class _Tp, class _Allocator>
1241 inline _LIBCPP_INLINE_VISIBILITY
1242 vector<_Tp, _Allocator>&
1243 vector<_Tp, _Allocator>::operator=(vector&& __x)
1244 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
1246 __move_assign(__x, integral_constant<bool,
1247 __alloc_traits::propagate_on_container_move_assignment::value>());
1251 template <class _Tp, class _Allocator>
1253 vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1254 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
1256 if (__alloc() != __c.__alloc())
1258 typedef move_iterator<iterator> _Ip;
1259 assign(_Ip(__c.begin()), _Ip(__c.end()));
1262 __move_assign(__c, true_type());
1265 template <class _Tp, class _Allocator>
1267 vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1268 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1271 __move_assign_alloc(__c); // this can throw
1272 this->__begin_ = __c.__begin_;
1273 this->__end_ = __c.__end_;
1274 this->__end_cap() = __c.__end_cap();
1275 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1276 std::__debug_db_swap(this, std::addressof(__c));
1279 template <class _Tp, class _Allocator>
1280 inline _LIBCPP_INLINE_VISIBILITY
1281 vector<_Tp, _Allocator>&
1282 vector<_Tp, _Allocator>::operator=(const vector& __x)
1284 if (this != _VSTD::addressof(__x))
1286 __copy_assign_alloc(__x);
1287 assign(__x.__begin_, __x.__end_);
1292 template <class _Tp, class _Allocator>
1293 template <class _InputIterator>
1294 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
1297 typename iterator_traits<_InputIterator>::reference>::value,
1300 vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1303 for (; __first != __last; ++__first)
1304 emplace_back(*__first);
1307 template <class _Tp, class _Allocator>
1308 template <class _ForwardIterator>
1311 __is_cpp17_forward_iterator<_ForwardIterator>::value &&
1314 typename iterator_traits<_ForwardIterator>::reference>::value,
1317 vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1319 size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
1320 if (__new_size <= capacity())
1322 _ForwardIterator __mid = __last;
1323 bool __growing = false;
1324 if (__new_size > size())
1328 _VSTD::advance(__mid, size());
1330 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
1332 __construct_at_end(__mid, __last, __new_size - size());
1334 this->__destruct_at_end(__m);
1339 __vallocate(__recommend(__new_size));
1340 __construct_at_end(__first, __last, __new_size);
1342 std::__debug_db_invalidate_all(this);
1345 template <class _Tp, class _Allocator>
1347 vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1349 if (__n <= capacity())
1351 size_type __s = size();
1352 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
1354 __construct_at_end(__n - __s, __u);
1356 this->__destruct_at_end(this->__begin_ + __n);
1361 __vallocate(__recommend(static_cast<size_type>(__n)));
1362 __construct_at_end(__n, __u);
1364 std::__debug_db_invalidate_all(this);
1367 template <class _Tp, class _Allocator>
1368 inline _LIBCPP_INLINE_VISIBILITY
1369 typename vector<_Tp, _Allocator>::iterator
1370 vector<_Tp, _Allocator>::begin() _NOEXCEPT
1372 return iterator(this, this->__begin_);
1375 template <class _Tp, class _Allocator>
1376 inline _LIBCPP_INLINE_VISIBILITY
1377 typename vector<_Tp, _Allocator>::const_iterator
1378 vector<_Tp, _Allocator>::begin() const _NOEXCEPT
1380 return const_iterator(this, this->__begin_);
1383 template <class _Tp, class _Allocator>
1384 inline _LIBCPP_INLINE_VISIBILITY
1385 typename vector<_Tp, _Allocator>::iterator
1386 vector<_Tp, _Allocator>::end() _NOEXCEPT
1388 return iterator(this, this->__end_);
1391 template <class _Tp, class _Allocator>
1392 inline _LIBCPP_INLINE_VISIBILITY
1393 typename vector<_Tp, _Allocator>::const_iterator
1394 vector<_Tp, _Allocator>::end() const _NOEXCEPT
1396 return const_iterator(this, this->__end_);
1399 template <class _Tp, class _Allocator>
1400 inline _LIBCPP_INLINE_VISIBILITY
1401 typename vector<_Tp, _Allocator>::reference
1402 vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT
1404 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1405 return this->__begin_[__n];
1408 template <class _Tp, class _Allocator>
1409 inline _LIBCPP_INLINE_VISIBILITY
1410 typename vector<_Tp, _Allocator>::const_reference
1411 vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT
1413 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1414 return this->__begin_[__n];
1417 template <class _Tp, class _Allocator>
1418 typename vector<_Tp, _Allocator>::reference
1419 vector<_Tp, _Allocator>::at(size_type __n)
1422 this->__throw_out_of_range();
1423 return this->__begin_[__n];
1426 template <class _Tp, class _Allocator>
1427 typename vector<_Tp, _Allocator>::const_reference
1428 vector<_Tp, _Allocator>::at(size_type __n) const
1431 this->__throw_out_of_range();
1432 return this->__begin_[__n];
1435 template <class _Tp, class _Allocator>
1437 vector<_Tp, _Allocator>::reserve(size_type __n)
1439 if (__n > capacity())
1441 if (__n > max_size())
1442 this->__throw_length_error();
1443 allocator_type& __a = this->__alloc();
1444 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
1445 __swap_out_circular_buffer(__v);
1449 template <class _Tp, class _Allocator>
1451 vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1453 if (capacity() > size())
1455 #ifndef _LIBCPP_NO_EXCEPTIONS
1458 #endif // _LIBCPP_NO_EXCEPTIONS
1459 allocator_type& __a = this->__alloc();
1460 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1461 __swap_out_circular_buffer(__v);
1462 #ifndef _LIBCPP_NO_EXCEPTIONS
1467 #endif // _LIBCPP_NO_EXCEPTIONS
1471 template <class _Tp, class _Allocator>
1472 template <class _Up>
1474 vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1476 allocator_type& __a = this->__alloc();
1477 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1478 // __v.push_back(_VSTD::forward<_Up>(__x));
1479 __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Up>(__x));
1481 __swap_out_circular_buffer(__v);
1484 template <class _Tp, class _Allocator>
1485 inline _LIBCPP_INLINE_VISIBILITY
1487 vector<_Tp, _Allocator>::push_back(const_reference __x)
1489 if (this->__end_ != this->__end_cap())
1491 __construct_one_at_end(__x);
1494 __push_back_slow_path(__x);
1497 template <class _Tp, class _Allocator>
1498 inline _LIBCPP_INLINE_VISIBILITY
1500 vector<_Tp, _Allocator>::push_back(value_type&& __x)
1502 if (this->__end_ < this->__end_cap())
1504 __construct_one_at_end(_VSTD::move(__x));
1507 __push_back_slow_path(_VSTD::move(__x));
1510 template <class _Tp, class _Allocator>
1511 template <class... _Args>
1513 vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1515 allocator_type& __a = this->__alloc();
1516 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1517 // __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1518 __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Args>(__args)...);
1520 __swap_out_circular_buffer(__v);
1523 template <class _Tp, class _Allocator>
1524 template <class... _Args>
1526 #if _LIBCPP_STD_VER > 14
1527 typename vector<_Tp, _Allocator>::reference
1531 vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1533 if (this->__end_ < this->__end_cap())
1535 __construct_one_at_end(_VSTD::forward<_Args>(__args)...);
1538 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
1539 #if _LIBCPP_STD_VER > 14
1540 return this->back();
1544 template <class _Tp, class _Allocator>
1547 vector<_Tp, _Allocator>::pop_back()
1549 _LIBCPP_ASSERT(!empty(), "vector::pop_back called on an empty vector");
1550 this->__destruct_at_end(this->__end_ - 1);
1553 template <class _Tp, class _Allocator>
1554 inline _LIBCPP_INLINE_VISIBILITY
1555 typename vector<_Tp, _Allocator>::iterator
1556 vector<_Tp, _Allocator>::erase(const_iterator __position)
1558 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1559 "vector::erase(iterator) called with an iterator not referring to this vector");
1560 _LIBCPP_ASSERT(__position != end(),
1561 "vector::erase(iterator) called with a non-dereferenceable iterator");
1562 difference_type __ps = __position - cbegin();
1563 pointer __p = this->__begin_ + __ps;
1564 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
1565 this->__invalidate_iterators_past(__p-1);
1566 iterator __r = iterator(this, __p);
1570 template <class _Tp, class _Allocator>
1571 typename vector<_Tp, _Allocator>::iterator
1572 vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1574 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this,
1575 "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
1576 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this,
1577 "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
1579 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
1580 pointer __p = this->__begin_ + (__first - begin());
1581 if (__first != __last) {
1582 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1583 this->__invalidate_iterators_past(__p - 1);
1585 iterator __r = iterator(this, __p);
1589 template <class _Tp, class _Allocator>
1591 vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1593 pointer __old_last = this->__end_;
1594 difference_type __n = __old_last - __to;
1596 pointer __i = __from_s + __n;
1597 _ConstructTransaction __tx(*this, __from_e - __i);
1598 for (pointer __pos = __tx.__pos_; __i < __from_e;
1599 ++__i, (void) ++__pos, __tx.__pos_ = __pos) {
1600 __alloc_traits::construct(this->__alloc(),
1601 _VSTD::__to_address(__pos),
1605 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
1608 template <class _Tp, class _Allocator>
1609 typename vector<_Tp, _Allocator>::iterator
1610 vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1612 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1613 "vector::insert(iterator, x) called with an iterator not referring to this vector");
1614 pointer __p = this->__begin_ + (__position - begin());
1615 if (this->__end_ < this->__end_cap())
1617 if (__p == this->__end_)
1619 __construct_one_at_end(__x);
1623 __move_range(__p, this->__end_, __p + 1);
1624 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1625 if (__p <= __xr && __xr < this->__end_)
1632 allocator_type& __a = this->__alloc();
1633 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1635 __p = __swap_out_circular_buffer(__v, __p);
1637 return iterator(this, __p);
1640 template <class _Tp, class _Allocator>
1641 typename vector<_Tp, _Allocator>::iterator
1642 vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1644 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1645 "vector::insert(iterator, x) called with an iterator not referring to this vector");
1646 pointer __p = this->__begin_ + (__position - begin());
1647 if (this->__end_ < this->__end_cap())
1649 if (__p == this->__end_)
1651 __construct_one_at_end(_VSTD::move(__x));
1655 __move_range(__p, this->__end_, __p + 1);
1656 *__p = _VSTD::move(__x);
1661 allocator_type& __a = this->__alloc();
1662 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1663 __v.push_back(_VSTD::move(__x));
1664 __p = __swap_out_circular_buffer(__v, __p);
1666 return iterator(this, __p);
1669 template <class _Tp, class _Allocator>
1670 template <class... _Args>
1671 typename vector<_Tp, _Allocator>::iterator
1672 vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1674 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1675 "vector::emplace(iterator, x) called with an iterator not referring to this vector");
1676 pointer __p = this->__begin_ + (__position - begin());
1677 if (this->__end_ < this->__end_cap())
1679 if (__p == this->__end_)
1681 __construct_one_at_end(_VSTD::forward<_Args>(__args)...);
1685 __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
1686 __move_range(__p, this->__end_, __p + 1);
1687 *__p = _VSTD::move(__tmp.get());
1692 allocator_type& __a = this->__alloc();
1693 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1694 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1695 __p = __swap_out_circular_buffer(__v, __p);
1697 return iterator(this, __p);
1700 template <class _Tp, class _Allocator>
1701 typename vector<_Tp, _Allocator>::iterator
1702 vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1704 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1705 "vector::insert(iterator, n, x) called with an iterator not referring to this vector");
1706 pointer __p = this->__begin_ + (__position - begin());
1709 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1711 size_type __old_n = __n;
1712 pointer __old_last = this->__end_;
1713 if (__n > static_cast<size_type>(this->__end_ - __p))
1715 size_type __cx = __n - (this->__end_ - __p);
1716 __construct_at_end(__cx, __x);
1721 __move_range(__p, __old_last, __p + __old_n);
1722 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1723 if (__p <= __xr && __xr < this->__end_)
1725 _VSTD::fill_n(__p, __n, *__xr);
1730 allocator_type& __a = this->__alloc();
1731 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1732 __v.__construct_at_end(__n, __x);
1733 __p = __swap_out_circular_buffer(__v, __p);
1736 return iterator(this, __p);
1739 template <class _Tp, class _Allocator>
1740 template <class _InputIterator>
1741 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
1744 typename iterator_traits<_InputIterator>::reference>::value,
1745 typename vector<_Tp, _Allocator>::iterator
1747 vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1749 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1750 "vector::insert(iterator, range) called with an iterator not referring to this vector");
1751 difference_type __off = __position - begin();
1752 pointer __p = this->__begin_ + __off;
1753 allocator_type& __a = this->__alloc();
1754 pointer __old_last = this->__end_;
1755 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1757 __construct_one_at_end(*__first);
1759 __split_buffer<value_type, allocator_type&> __v(__a);
1760 if (__first != __last)
1762 #ifndef _LIBCPP_NO_EXCEPTIONS
1765 #endif // _LIBCPP_NO_EXCEPTIONS
1766 __v.__construct_at_end(__first, __last);
1767 difference_type __old_size = __old_last - this->__begin_;
1768 difference_type __old_p = __p - this->__begin_;
1769 reserve(__recommend(size() + __v.size()));
1770 __p = this->__begin_ + __old_p;
1771 __old_last = this->__begin_ + __old_size;
1772 #ifndef _LIBCPP_NO_EXCEPTIONS
1776 erase(iterator(this, __old_last), end());
1779 #endif // _LIBCPP_NO_EXCEPTIONS
1781 __p = _VSTD::rotate(__p, __old_last, this->__end_);
1782 insert(iterator(this, __p), _VSTD::make_move_iterator(__v.begin()),
1783 _VSTD::make_move_iterator(__v.end()));
1784 return begin() + __off;
1787 template <class _Tp, class _Allocator>
1788 template <class _ForwardIterator>
1791 __is_cpp17_forward_iterator<_ForwardIterator>::value &&
1794 typename iterator_traits<_ForwardIterator>::reference>::value,
1795 typename vector<_Tp, _Allocator>::iterator
1797 vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1799 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
1800 "vector::insert(iterator, range) called with an iterator not referring to this vector");
1801 pointer __p = this->__begin_ + (__position - begin());
1802 difference_type __n = _VSTD::distance(__first, __last);
1805 if (__n <= this->__end_cap() - this->__end_)
1807 size_type __old_n = __n;
1808 pointer __old_last = this->__end_;
1809 _ForwardIterator __m = __last;
1810 difference_type __dx = this->__end_ - __p;
1814 difference_type __diff = this->__end_ - __p;
1815 _VSTD::advance(__m, __diff);
1816 __construct_at_end(__m, __last, __n - __diff);
1821 __move_range(__p, __old_last, __p + __old_n);
1822 _VSTD::copy(__first, __m, __p);
1827 allocator_type& __a = this->__alloc();
1828 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1829 __v.__construct_at_end(__first, __last);
1830 __p = __swap_out_circular_buffer(__v, __p);
1833 return iterator(this, __p);
1836 template <class _Tp, class _Allocator>
1838 vector<_Tp, _Allocator>::resize(size_type __sz)
1840 size_type __cs = size();
1842 this->__append(__sz - __cs);
1843 else if (__cs > __sz)
1844 this->__destruct_at_end(this->__begin_ + __sz);
1847 template <class _Tp, class _Allocator>
1849 vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1851 size_type __cs = size();
1853 this->__append(__sz - __cs, __x);
1854 else if (__cs > __sz)
1855 this->__destruct_at_end(this->__begin_ + __sz);
1858 template <class _Tp, class _Allocator>
1860 vector<_Tp, _Allocator>::swap(vector& __x)
1861 #if _LIBCPP_STD_VER >= 14
1864 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1865 __is_nothrow_swappable<allocator_type>::value)
1868 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
1869 this->__alloc() == __x.__alloc(),
1870 "vector::swap: Either propagate_on_container_swap must be true"
1871 " or the allocators must compare equal");
1872 _VSTD::swap(this->__begin_, __x.__begin_);
1873 _VSTD::swap(this->__end_, __x.__end_);
1874 _VSTD::swap(this->__end_cap(), __x.__end_cap());
1875 _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
1876 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
1877 std::__debug_db_swap(this, std::addressof(__x));
1880 template <class _Tp, class _Allocator>
1882 vector<_Tp, _Allocator>::__invariants() const
1884 if (this->__begin_ == nullptr)
1886 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
1891 if (this->__begin_ > this->__end_)
1893 if (this->__begin_ == this->__end_cap())
1895 if (this->__end_ > this->__end_cap())
1901 #ifdef _LIBCPP_ENABLE_DEBUG_MODE
1903 template <class _Tp, class _Allocator>
1905 vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
1907 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
1910 template <class _Tp, class _Allocator>
1912 vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
1914 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
1917 template <class _Tp, class _Allocator>
1919 vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
1921 const_pointer __p = __i->base() + __n;
1922 return this->__begin_ <= __p && __p <= this->__end_;
1925 template <class _Tp, class _Allocator>
1927 vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1929 const_pointer __p = __i->base() + __n;
1930 return this->__begin_ <= __p && __p < this->__end_;
1933 #endif // _LIBCPP_ENABLE_DEBUG_MODE
1935 template <class _Tp, class _Allocator>
1936 inline _LIBCPP_INLINE_VISIBILITY
1938 vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
1939 #ifdef _LIBCPP_ENABLE_DEBUG_MODE
1940 __c_node* __c = __get_db()->__find_c_and_lock(this);
1941 for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
1943 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1944 if (__i->base() > __new_last) {
1945 (*__p)->__c_ = nullptr;
1946 if (--__c->end_ != __p)
1947 _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1950 __get_db()->unlock();
1958 template <class _Allocator> class vector<bool, _Allocator>;
1960 template <class _Allocator> struct hash<vector<bool, _Allocator> >;
1962 template <class _Allocator>
1963 struct __has_storage_type<vector<bool, _Allocator> >
1965 static const bool value = true;
1968 template <class _Allocator>
1969 class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
1972 typedef vector __self;
1973 typedef bool value_type;
1974 typedef _Allocator allocator_type;
1975 typedef allocator_traits<allocator_type> __alloc_traits;
1976 typedef typename __alloc_traits::size_type size_type;
1977 typedef typename __alloc_traits::difference_type difference_type;
1978 typedef size_type __storage_type;
1979 typedef __bit_iterator<vector, false> pointer;
1980 typedef __bit_iterator<vector, true> const_pointer;
1981 typedef pointer iterator;
1982 typedef const_pointer const_iterator;
1983 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1984 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1987 typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
1988 typedef allocator_traits<__storage_allocator> __storage_traits;
1989 typedef typename __storage_traits::pointer __storage_pointer;
1990 typedef typename __storage_traits::const_pointer __const_storage_pointer;
1992 __storage_pointer __begin_;
1994 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
1996 typedef __bit_reference<vector> reference;
1997 #ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
1998 using const_reference = bool;
2000 typedef __bit_const_reference<vector> const_reference;
2003 _LIBCPP_INLINE_VISIBILITY
2004 size_type& __cap() _NOEXCEPT
2005 {return __cap_alloc_.first();}
2006 _LIBCPP_INLINE_VISIBILITY
2007 const size_type& __cap() const _NOEXCEPT
2008 {return __cap_alloc_.first();}
2009 _LIBCPP_INLINE_VISIBILITY
2010 __storage_allocator& __alloc() _NOEXCEPT
2011 {return __cap_alloc_.second();}
2012 _LIBCPP_INLINE_VISIBILITY
2013 const __storage_allocator& __alloc() const _NOEXCEPT
2014 {return __cap_alloc_.second();}
2016 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2018 _LIBCPP_INLINE_VISIBILITY
2019 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
2020 {return __n * __bits_per_word;}
2021 _LIBCPP_INLINE_VISIBILITY
2022 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
2023 {return (__n - 1) / __bits_per_word + 1;}
2026 _LIBCPP_INLINE_VISIBILITY
2027 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
2029 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
2030 #if _LIBCPP_STD_VER <= 14
2031 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
2036 explicit vector(size_type __n);
2037 #if _LIBCPP_STD_VER > 11
2038 explicit vector(size_type __n, const allocator_type& __a);
2040 vector(size_type __n, const value_type& __v);
2041 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2042 template <class _InputIterator>
2043 vector(_InputIterator __first, _InputIterator __last,
2044 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
2045 template <class _InputIterator>
2046 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2047 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
2048 template <class _ForwardIterator>
2049 vector(_ForwardIterator __first, _ForwardIterator __last,
2050 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
2051 template <class _ForwardIterator>
2052 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2053 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
2055 vector(const vector& __v);
2056 vector(const vector& __v, const allocator_type& __a);
2057 vector& operator=(const vector& __v);
2059 #ifndef _LIBCPP_CXX03_LANG
2060 vector(initializer_list<value_type> __il);
2061 vector(initializer_list<value_type> __il, const allocator_type& __a);
2063 _LIBCPP_INLINE_VISIBILITY
2064 vector& operator=(initializer_list<value_type> __il)
2065 {assign(__il.begin(), __il.end()); return *this;}
2067 #endif // !_LIBCPP_CXX03_LANG
2069 _LIBCPP_INLINE_VISIBILITY
2070 vector(vector&& __v)
2071 #if _LIBCPP_STD_VER > 14
2074 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
2076 vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
2077 _LIBCPP_INLINE_VISIBILITY
2078 vector& operator=(vector&& __v)
2079 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
2081 template <class _InputIterator>
2082 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
2085 assign(_InputIterator __first, _InputIterator __last);
2086 template <class _ForwardIterator>
2089 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2092 assign(_ForwardIterator __first, _ForwardIterator __last);
2094 void assign(size_type __n, const value_type& __x);
2096 #ifndef _LIBCPP_CXX03_LANG
2097 _LIBCPP_INLINE_VISIBILITY
2098 void assign(initializer_list<value_type> __il)
2099 {assign(__il.begin(), __il.end());}
2102 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
2103 {return allocator_type(this->__alloc());}
2105 size_type max_size() const _NOEXCEPT;
2106 _LIBCPP_INLINE_VISIBILITY
2107 size_type capacity() const _NOEXCEPT
2108 {return __internal_cap_to_external(__cap());}
2109 _LIBCPP_INLINE_VISIBILITY
2110 size_type size() const _NOEXCEPT
2112 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
2113 bool empty() const _NOEXCEPT
2114 {return __size_ == 0;}
2115 void reserve(size_type __n);
2116 void shrink_to_fit() _NOEXCEPT;
2118 _LIBCPP_INLINE_VISIBILITY
2119 iterator begin() _NOEXCEPT
2120 {return __make_iter(0);}
2121 _LIBCPP_INLINE_VISIBILITY
2122 const_iterator begin() const _NOEXCEPT
2123 {return __make_iter(0);}
2124 _LIBCPP_INLINE_VISIBILITY
2125 iterator end() _NOEXCEPT
2126 {return __make_iter(__size_);}
2127 _LIBCPP_INLINE_VISIBILITY
2128 const_iterator end() const _NOEXCEPT
2129 {return __make_iter(__size_);}
2131 _LIBCPP_INLINE_VISIBILITY
2132 reverse_iterator rbegin() _NOEXCEPT
2133 {return reverse_iterator(end());}
2134 _LIBCPP_INLINE_VISIBILITY
2135 const_reverse_iterator rbegin() const _NOEXCEPT
2136 {return const_reverse_iterator(end());}
2137 _LIBCPP_INLINE_VISIBILITY
2138 reverse_iterator rend() _NOEXCEPT
2139 {return reverse_iterator(begin());}
2140 _LIBCPP_INLINE_VISIBILITY
2141 const_reverse_iterator rend() const _NOEXCEPT
2142 {return const_reverse_iterator(begin());}
2144 _LIBCPP_INLINE_VISIBILITY
2145 const_iterator cbegin() const _NOEXCEPT
2146 {return __make_iter(0);}
2147 _LIBCPP_INLINE_VISIBILITY
2148 const_iterator cend() const _NOEXCEPT
2149 {return __make_iter(__size_);}
2150 _LIBCPP_INLINE_VISIBILITY
2151 const_reverse_iterator crbegin() const _NOEXCEPT
2153 _LIBCPP_INLINE_VISIBILITY
2154 const_reverse_iterator crend() const _NOEXCEPT
2157 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2158 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2159 reference at(size_type __n);
2160 const_reference at(size_type __n) const;
2162 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2163 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2164 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2165 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2167 void push_back(const value_type& __x);
2168 #if _LIBCPP_STD_VER > 11
2169 template <class... _Args>
2170 #if _LIBCPP_STD_VER > 14
2171 _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args)
2173 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
2176 push_back ( value_type ( _VSTD::forward<_Args>(__args)... ));
2177 #if _LIBCPP_STD_VER > 14
2178 return this->back();
2183 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2185 #if _LIBCPP_STD_VER > 11
2186 template <class... _Args>
2187 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator __position, _Args&&... __args)
2188 { return insert ( __position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2191 iterator insert(const_iterator __position, const value_type& __x);
2192 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2193 template <class _InputIterator>
2194 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
2197 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2198 template <class _ForwardIterator>
2201 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2204 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
2206 #ifndef _LIBCPP_CXX03_LANG
2207 _LIBCPP_INLINE_VISIBILITY
2208 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2209 {return insert(__position, __il.begin(), __il.end());}
2212 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
2213 iterator erase(const_iterator __first, const_iterator __last);
2215 _LIBCPP_INLINE_VISIBILITY
2216 void clear() _NOEXCEPT {__size_ = 0;}
2219 #if _LIBCPP_STD_VER >= 14
2222 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2223 __is_nothrow_swappable<allocator_type>::value);
2225 static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
2227 void resize(size_type __sz, value_type __x = false);
2228 void flip() _NOEXCEPT;
2230 bool __invariants() const;
2233 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2234 void __throw_length_error() const {
2235 _VSTD::__throw_length_error("vector");
2238 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2239 void __throw_out_of_range() const {
2240 _VSTD::__throw_out_of_range("vector");
2243 // Allocate space for __n objects
2244 // throws length_error if __n > max_size()
2245 // throws (probably bad_alloc) if memory run out
2246 // Precondition: __begin_ == __end_ == __cap() == 0
2247 // Precondition: __n > 0
2248 // Postcondition: capacity() >= __n
2249 // Postcondition: size() == 0
2250 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
2251 if (__n > max_size())
2252 __throw_length_error();
2253 auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n));
2254 __begin_ = __allocation.ptr;
2256 __cap() = __allocation.count;
2259 void __vdeallocate() _NOEXCEPT;
2260 _LIBCPP_INLINE_VISIBILITY
2261 static size_type __align_it(size_type __new_size) _NOEXCEPT
2262 {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);}
2263 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2264 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
2265 template <class _ForwardIterator>
2268 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2271 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2272 void __append(size_type __n, const_reference __x);
2273 _LIBCPP_INLINE_VISIBILITY
2274 reference __make_ref(size_type __pos) _NOEXCEPT
2275 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2276 _LIBCPP_INLINE_VISIBILITY
2277 const_reference __make_ref(size_type __pos) const _NOEXCEPT {
2278 return __bit_const_reference<vector>(__begin_ + __pos / __bits_per_word,
2279 __storage_type(1) << __pos % __bits_per_word);
2281 _LIBCPP_INLINE_VISIBILITY
2282 iterator __make_iter(size_type __pos) _NOEXCEPT
2283 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2284 _LIBCPP_INLINE_VISIBILITY
2285 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
2286 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2287 _LIBCPP_INLINE_VISIBILITY
2288 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
2289 {return begin() + (__p - cbegin());}
2291 _LIBCPP_INLINE_VISIBILITY
2292 void __copy_assign_alloc(const vector& __v)
2293 {__copy_assign_alloc(__v, integral_constant<bool,
2294 __storage_traits::propagate_on_container_copy_assignment::value>());}
2295 _LIBCPP_INLINE_VISIBILITY
2296 void __copy_assign_alloc(const vector& __c, true_type)
2298 if (__alloc() != __c.__alloc())
2300 __alloc() = __c.__alloc();
2303 _LIBCPP_INLINE_VISIBILITY
2304 void __copy_assign_alloc(const vector&, false_type)
2307 void __move_assign(vector& __c, false_type);
2308 void __move_assign(vector& __c, true_type)
2309 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2310 _LIBCPP_INLINE_VISIBILITY
2311 void __move_assign_alloc(vector& __c)
2313 !__storage_traits::propagate_on_container_move_assignment::value ||
2314 is_nothrow_move_assignable<allocator_type>::value)
2315 {__move_assign_alloc(__c, integral_constant<bool,
2316 __storage_traits::propagate_on_container_move_assignment::value>());}
2317 _LIBCPP_INLINE_VISIBILITY
2318 void __move_assign_alloc(vector& __c, true_type)
2319 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2321 __alloc() = _VSTD::move(__c.__alloc());
2324 _LIBCPP_INLINE_VISIBILITY
2325 void __move_assign_alloc(vector&, false_type)
2329 size_t __hash_code() const _NOEXCEPT;
2331 friend class __bit_reference<vector>;
2332 friend class __bit_const_reference<vector>;
2333 friend class __bit_iterator<vector, false>;
2334 friend class __bit_iterator<vector, true>;
2335 friend struct __bit_array<vector>;
2336 friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
2339 template <class _Allocator>
2341 vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT
2343 if (this->__begin_ != nullptr)
2345 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2346 std::__debug_db_invalidate_all(this);
2347 this->__begin_ = nullptr;
2348 this->__size_ = this->__cap() = 0;
2352 template <class _Allocator>
2353 typename vector<bool, _Allocator>::size_type
2354 vector<bool, _Allocator>::max_size() const _NOEXCEPT
2356 size_type __amax = __storage_traits::max_size(__alloc());
2357 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2358 if (__nmax / __bits_per_word <= __amax)
2360 return __internal_cap_to_external(__amax);
2363 // Precondition: __new_size > capacity()
2364 template <class _Allocator>
2365 inline _LIBCPP_INLINE_VISIBILITY
2366 typename vector<bool, _Allocator>::size_type
2367 vector<bool, _Allocator>::__recommend(size_type __new_size) const
2369 const size_type __ms = max_size();
2370 if (__new_size > __ms)
2371 this->__throw_length_error();
2372 const size_type __cap = capacity();
2373 if (__cap >= __ms / 2)
2375 return _VSTD::max(2 * __cap, __align_it(__new_size));
2378 // Default constructs __n objects starting at __end_
2379 // Precondition: __n > 0
2380 // Precondition: size() + __n <= capacity()
2381 // Postcondition: size() == size() + __n
2382 template <class _Allocator>
2383 inline _LIBCPP_INLINE_VISIBILITY
2385 vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2387 size_type __old_size = this->__size_;
2388 this->__size_ += __n;
2389 if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
2391 if (this->__size_ <= __bits_per_word)
2392 this->__begin_[0] = __storage_type(0);
2394 this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
2396 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
2399 template <class _Allocator>
2400 template <class _ForwardIterator>
2403 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2406 vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2408 size_type __old_size = this->__size_;
2409 this->__size_ += _VSTD::distance(__first, __last);
2410 if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
2412 if (this->__size_ <= __bits_per_word)
2413 this->__begin_[0] = __storage_type(0);
2415 this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
2417 _VSTD::copy(__first, __last, __make_iter(__old_size));
2420 template <class _Allocator>
2421 inline _LIBCPP_INLINE_VISIBILITY
2422 vector<bool, _Allocator>::vector()
2423 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2424 : __begin_(nullptr),
2426 __cap_alloc_(0, __default_init_tag())
2430 template <class _Allocator>
2431 inline _LIBCPP_INLINE_VISIBILITY
2432 vector<bool, _Allocator>::vector(const allocator_type& __a)
2433 #if _LIBCPP_STD_VER <= 14
2434 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
2438 : __begin_(nullptr),
2440 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2444 template <class _Allocator>
2445 vector<bool, _Allocator>::vector(size_type __n)
2446 : __begin_(nullptr),
2448 __cap_alloc_(0, __default_init_tag())
2453 __construct_at_end(__n, false);
2457 #if _LIBCPP_STD_VER > 11
2458 template <class _Allocator>
2459 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2460 : __begin_(nullptr),
2462 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2467 __construct_at_end(__n, false);
2472 template <class _Allocator>
2473 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2474 : __begin_(nullptr),
2476 __cap_alloc_(0, __default_init_tag())
2481 __construct_at_end(__n, __x);
2485 template <class _Allocator>
2486 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2487 : __begin_(nullptr),
2489 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2494 __construct_at_end(__n, __x);
2498 template <class _Allocator>
2499 template <class _InputIterator>
2500 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2501 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
2502 : __begin_(nullptr),
2504 __cap_alloc_(0, __default_init_tag())
2506 #ifndef _LIBCPP_NO_EXCEPTIONS
2509 #endif // _LIBCPP_NO_EXCEPTIONS
2510 for (; __first != __last; ++__first)
2511 push_back(*__first);
2512 #ifndef _LIBCPP_NO_EXCEPTIONS
2516 if (__begin_ != nullptr)
2517 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2518 std::__debug_db_invalidate_all(this);
2521 #endif // _LIBCPP_NO_EXCEPTIONS
2524 template <class _Allocator>
2525 template <class _InputIterator>
2526 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2527 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
2528 : __begin_(nullptr),
2530 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2532 #ifndef _LIBCPP_NO_EXCEPTIONS
2535 #endif // _LIBCPP_NO_EXCEPTIONS
2536 for (; __first != __last; ++__first)
2537 push_back(*__first);
2538 #ifndef _LIBCPP_NO_EXCEPTIONS
2542 if (__begin_ != nullptr)
2543 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2544 std::__debug_db_invalidate_all(this);
2547 #endif // _LIBCPP_NO_EXCEPTIONS
2550 template <class _Allocator>
2551 template <class _ForwardIterator>
2552 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2553 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
2554 : __begin_(nullptr),
2556 __cap_alloc_(0, __default_init_tag())
2558 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2562 __construct_at_end(__first, __last);
2566 template <class _Allocator>
2567 template <class _ForwardIterator>
2568 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2569 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
2570 : __begin_(nullptr),
2572 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2574 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2578 __construct_at_end(__first, __last);
2582 #ifndef _LIBCPP_CXX03_LANG
2584 template <class _Allocator>
2585 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2586 : __begin_(nullptr),
2588 __cap_alloc_(0, __default_init_tag())
2590 size_type __n = static_cast<size_type>(__il.size());
2594 __construct_at_end(__il.begin(), __il.end());
2598 template <class _Allocator>
2599 vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2600 : __begin_(nullptr),
2602 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2604 size_type __n = static_cast<size_type>(__il.size());
2608 __construct_at_end(__il.begin(), __il.end());
2612 #endif // _LIBCPP_CXX03_LANG
2614 template <class _Allocator>
2615 vector<bool, _Allocator>::~vector()
2617 if (__begin_ != nullptr)
2618 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2619 std::__debug_db_invalidate_all(this);
2622 template <class _Allocator>
2623 vector<bool, _Allocator>::vector(const vector& __v)
2624 : __begin_(nullptr),
2626 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2630 __vallocate(__v.size());
2631 __construct_at_end(__v.begin(), __v.end());
2635 template <class _Allocator>
2636 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2637 : __begin_(nullptr),
2639 __cap_alloc_(0, __a)
2643 __vallocate(__v.size());
2644 __construct_at_end(__v.begin(), __v.end());
2648 template <class _Allocator>
2649 vector<bool, _Allocator>&
2650 vector<bool, _Allocator>::operator=(const vector& __v)
2652 if (this != _VSTD::addressof(__v))
2654 __copy_assign_alloc(__v);
2657 if (__v.__size_ > capacity())
2660 __vallocate(__v.__size_);
2662 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2664 __size_ = __v.__size_;
2669 template <class _Allocator>
2670 inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
2671 #if _LIBCPP_STD_VER > 14
2674 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2676 : __begin_(__v.__begin_),
2677 __size_(__v.__size_),
2678 __cap_alloc_(_VSTD::move(__v.__cap_alloc_)) {
2679 __v.__begin_ = nullptr;
2684 template <class _Allocator>
2685 vector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
2686 : __begin_(nullptr),
2688 __cap_alloc_(0, __a)
2690 if (__a == allocator_type(__v.__alloc()))
2692 this->__begin_ = __v.__begin_;
2693 this->__size_ = __v.__size_;
2694 this->__cap() = __v.__cap();
2695 __v.__begin_ = nullptr;
2696 __v.__cap() = __v.__size_ = 0;
2698 else if (__v.size() > 0)
2700 __vallocate(__v.size());
2701 __construct_at_end(__v.begin(), __v.end());
2705 template <class _Allocator>
2706 inline _LIBCPP_INLINE_VISIBILITY
2707 vector<bool, _Allocator>&
2708 vector<bool, _Allocator>::operator=(vector&& __v)
2709 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
2711 __move_assign(__v, integral_constant<bool,
2712 __storage_traits::propagate_on_container_move_assignment::value>());
2716 template <class _Allocator>
2718 vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2720 if (__alloc() != __c.__alloc())
2721 assign(__c.begin(), __c.end());
2723 __move_assign(__c, true_type());
2726 template <class _Allocator>
2728 vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2729 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2732 __move_assign_alloc(__c);
2733 this->__begin_ = __c.__begin_;
2734 this->__size_ = __c.__size_;
2735 this->__cap() = __c.__cap();
2736 __c.__begin_ = nullptr;
2737 __c.__cap() = __c.__size_ = 0;
2740 template <class _Allocator>
2742 vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2747 size_type __c = capacity();
2752 vector __v(get_allocator());
2753 __v.reserve(__recommend(__n));
2757 _VSTD::fill_n(begin(), __n, __x);
2759 std::__debug_db_invalidate_all(this);
2762 template <class _Allocator>
2763 template <class _InputIterator>
2764 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
2767 vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2770 for (; __first != __last; ++__first)
2771 push_back(*__first);
2774 template <class _Allocator>
2775 template <class _ForwardIterator>
2778 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2781 vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2784 difference_type __ns = _VSTD::distance(__first, __last);
2785 _LIBCPP_ASSERT(__ns >= 0, "invalid range specified");
2786 const size_t __n = static_cast<size_type>(__ns);
2789 if (__n > capacity())
2794 __construct_at_end(__first, __last);
2798 template <class _Allocator>
2800 vector<bool, _Allocator>::reserve(size_type __n)
2802 if (__n > capacity())
2804 if (__n > max_size())
2805 this->__throw_length_error();
2806 vector __v(this->get_allocator());
2807 __v.__vallocate(__n);
2808 __v.__construct_at_end(this->begin(), this->end());
2810 std::__debug_db_invalidate_all(this);
2814 template <class _Allocator>
2816 vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
2818 if (__external_cap_to_internal(size()) > __cap())
2820 #ifndef _LIBCPP_NO_EXCEPTIONS
2823 #endif // _LIBCPP_NO_EXCEPTIONS
2824 vector(*this, allocator_type(__alloc())).swap(*this);
2825 #ifndef _LIBCPP_NO_EXCEPTIONS
2830 #endif // _LIBCPP_NO_EXCEPTIONS
2834 template <class _Allocator>
2835 typename vector<bool, _Allocator>::reference
2836 vector<bool, _Allocator>::at(size_type __n)
2839 this->__throw_out_of_range();
2840 return (*this)[__n];
2843 template <class _Allocator>
2844 typename vector<bool, _Allocator>::const_reference
2845 vector<bool, _Allocator>::at(size_type __n) const
2848 this->__throw_out_of_range();
2849 return (*this)[__n];
2852 template <class _Allocator>
2854 vector<bool, _Allocator>::push_back(const value_type& __x)
2856 if (this->__size_ == this->capacity())
2857 reserve(__recommend(this->__size_ + 1));
2862 template <class _Allocator>
2863 typename vector<bool, _Allocator>::iterator
2864 vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2867 if (size() < capacity())
2869 const_iterator __old_end = end();
2871 _VSTD::copy_backward(__position, __old_end, end());
2872 __r = __const_iterator_cast(__position);
2876 vector __v(get_allocator());
2877 __v.reserve(__recommend(__size_ + 1));
2878 __v.__size_ = __size_ + 1;
2879 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2880 _VSTD::copy_backward(__position, cend(), __v.end());
2887 template <class _Allocator>
2888 typename vector<bool, _Allocator>::iterator
2889 vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
2892 size_type __c = capacity();
2893 if (__n <= __c && size() <= __c - __n)
2895 const_iterator __old_end = end();
2897 _VSTD::copy_backward(__position, __old_end, end());
2898 __r = __const_iterator_cast(__position);
2902 vector __v(get_allocator());
2903 __v.reserve(__recommend(__size_ + __n));
2904 __v.__size_ = __size_ + __n;
2905 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2906 _VSTD::copy_backward(__position, cend(), __v.end());
2909 _VSTD::fill_n(__r, __n, __x);
2913 template <class _Allocator>
2914 template <class _InputIterator>
2915 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
2916 typename vector<bool, _Allocator>::iterator
2918 vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
2920 difference_type __off = __position - begin();
2921 iterator __p = __const_iterator_cast(__position);
2922 iterator __old_end = end();
2923 for (; size() != capacity() && __first != __last; ++__first)
2928 vector __v(get_allocator());
2929 if (__first != __last)
2931 #ifndef _LIBCPP_NO_EXCEPTIONS
2934 #endif // _LIBCPP_NO_EXCEPTIONS
2935 __v.assign(__first, __last);
2936 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
2937 difference_type __old_p = __p - begin();
2938 reserve(__recommend(size() + __v.size()));
2939 __p = begin() + __old_p;
2940 __old_end = begin() + __old_size;
2941 #ifndef _LIBCPP_NO_EXCEPTIONS
2945 erase(__old_end, end());
2948 #endif // _LIBCPP_NO_EXCEPTIONS
2950 __p = _VSTD::rotate(__p, __old_end, end());
2951 insert(__p, __v.begin(), __v.end());
2952 return begin() + __off;
2955 template <class _Allocator>
2956 template <class _ForwardIterator>
2959 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2960 typename vector<bool, _Allocator>::iterator
2962 vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
2964 const difference_type __n_signed = _VSTD::distance(__first, __last);
2965 _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified");
2966 const size_type __n = static_cast<size_type>(__n_signed);
2968 size_type __c = capacity();
2969 if (__n <= __c && size() <= __c - __n)
2971 const_iterator __old_end = end();
2973 _VSTD::copy_backward(__position, __old_end, end());
2974 __r = __const_iterator_cast(__position);
2978 vector __v(get_allocator());
2979 __v.reserve(__recommend(__size_ + __n));
2980 __v.__size_ = __size_ + __n;
2981 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2982 _VSTD::copy_backward(__position, cend(), __v.end());
2985 _VSTD::copy(__first, __last, __r);
2989 template <class _Allocator>
2990 inline _LIBCPP_INLINE_VISIBILITY
2991 typename vector<bool, _Allocator>::iterator
2992 vector<bool, _Allocator>::erase(const_iterator __position)
2994 iterator __r = __const_iterator_cast(__position);
2995 _VSTD::copy(__position + 1, this->cend(), __r);
3000 template <class _Allocator>
3001 typename vector<bool, _Allocator>::iterator
3002 vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3004 iterator __r = __const_iterator_cast(__first);
3005 difference_type __d = __last - __first;
3006 _VSTD::copy(__last, this->cend(), __r);
3011 template <class _Allocator>
3013 vector<bool, _Allocator>::swap(vector& __x)
3014 #if _LIBCPP_STD_VER >= 14
3017 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3018 __is_nothrow_swappable<allocator_type>::value)
3021 _VSTD::swap(this->__begin_, __x.__begin_);
3022 _VSTD::swap(this->__size_, __x.__size_);
3023 _VSTD::swap(this->__cap(), __x.__cap());
3024 _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
3025 integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
3028 template <class _Allocator>
3030 vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3032 size_type __cs = size();
3036 size_type __c = capacity();
3037 size_type __n = __sz - __cs;
3038 if (__n <= __c && __cs <= __c - __n)
3045 vector __v(get_allocator());
3046 __v.reserve(__recommend(__size_ + __n));
3047 __v.__size_ = __size_ + __n;
3048 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
3051 _VSTD::fill_n(__r, __n, __x);
3057 template <class _Allocator>
3059 vector<bool, _Allocator>::flip() _NOEXCEPT
3061 // do middle whole words
3062 size_type __n = __size_;
3063 __storage_pointer __p = __begin_;
3064 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3066 // do last partial word
3069 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3070 __storage_type __b = *__p & __m;
3076 template <class _Allocator>
3078 vector<bool, _Allocator>::__invariants() const
3080 if (this->__begin_ == nullptr)
3082 if (this->__size_ != 0 || this->__cap() != 0)
3087 if (this->__cap() == 0)
3089 if (this->__size_ > this->capacity())
3095 template <class _Allocator>
3097 vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
3100 // do middle whole words
3101 size_type __n = __size_;
3102 __storage_pointer __p = __begin_;
3103 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3105 // do last partial word
3108 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3114 template <class _Allocator>
3115 struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
3116 : public __unary_function<vector<bool, _Allocator>, size_t>
3118 _LIBCPP_INLINE_VISIBILITY
3119 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
3120 {return __vec.__hash_code();}
3123 template <class _Tp, class _Allocator>
3124 inline _LIBCPP_INLINE_VISIBILITY
3126 operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3128 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
3129 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3132 template <class _Tp, class _Allocator>
3133 inline _LIBCPP_INLINE_VISIBILITY
3135 operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3137 return !(__x == __y);
3140 template <class _Tp, class _Allocator>
3141 inline _LIBCPP_INLINE_VISIBILITY
3143 operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3145 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
3148 template <class _Tp, class _Allocator>
3149 inline _LIBCPP_INLINE_VISIBILITY
3151 operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3156 template <class _Tp, class _Allocator>
3157 inline _LIBCPP_INLINE_VISIBILITY
3159 operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3161 return !(__x < __y);
3164 template <class _Tp, class _Allocator>
3165 inline _LIBCPP_INLINE_VISIBILITY
3167 operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3169 return !(__y < __x);
3172 template <class _Tp, class _Allocator>
3173 inline _LIBCPP_INLINE_VISIBILITY
3175 swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
3176 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
3181 #if _LIBCPP_STD_VER > 17
3182 template <class _Tp, class _Allocator, class _Up>
3183 inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
3184 erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
3185 auto __old_size = __c.size();
3186 __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end());
3187 return __old_size - __c.size();
3190 template <class _Tp, class _Allocator, class _Predicate>
3191 inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
3192 erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
3193 auto __old_size = __c.size();
3194 __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end());
3195 return __old_size - __c.size();
3199 inline constexpr bool __format::__enable_insertable<std::vector<char>> = true;
3200 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3202 inline constexpr bool __format::__enable_insertable<std::vector<wchar_t>> = true;
3205 #endif // _LIBCPP_STD_VER > 17
3207 _LIBCPP_END_NAMESPACE_STD
3211 #endif // _LIBCPP_VECTOR