2 //===------------------------------ vector --------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_VECTOR
12 #define _LIBCPP_VECTOR
20 template <class T, class Allocator = allocator<T> >
25 typedef Allocator allocator_type;
26 typedef typename allocator_type::reference reference;
27 typedef typename allocator_type::const_reference const_reference;
28 typedef implementation-defined iterator;
29 typedef implementation-defined const_iterator;
30 typedef typename allocator_type::size_type size_type;
31 typedef typename allocator_type::difference_type difference_type;
32 typedef typename allocator_type::pointer pointer;
33 typedef typename allocator_type::const_pointer const_pointer;
34 typedef std::reverse_iterator<iterator> reverse_iterator;
35 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
38 noexcept(is_nothrow_default_constructible<allocator_type>::value);
39 explicit vector(const allocator_type&);
40 explicit vector(size_type n);
41 explicit vector(size_type n, const allocator_type&); // C++14
42 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
43 template <class InputIterator>
44 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
45 vector(const vector& x);
47 noexcept(is_nothrow_move_constructible<allocator_type>::value);
48 vector(initializer_list<value_type> il);
49 vector(initializer_list<value_type> il, const allocator_type& a);
51 vector& operator=(const vector& x);
52 vector& operator=(vector&& x)
54 allocator_type::propagate_on_container_move_assignment::value ||
55 allocator_type::is_always_equal::value); // C++17
56 vector& operator=(initializer_list<value_type> il);
57 template <class InputIterator>
58 void assign(InputIterator first, InputIterator last);
59 void assign(size_type n, const value_type& u);
60 void assign(initializer_list<value_type> il);
62 allocator_type get_allocator() const noexcept;
64 iterator begin() noexcept;
65 const_iterator begin() const noexcept;
66 iterator end() noexcept;
67 const_iterator end() const noexcept;
69 reverse_iterator rbegin() noexcept;
70 const_reverse_iterator rbegin() const noexcept;
71 reverse_iterator rend() noexcept;
72 const_reverse_iterator rend() const noexcept;
74 const_iterator cbegin() const noexcept;
75 const_iterator cend() const noexcept;
76 const_reverse_iterator crbegin() const noexcept;
77 const_reverse_iterator crend() const noexcept;
79 size_type size() const noexcept;
80 size_type max_size() const noexcept;
81 size_type capacity() const noexcept;
82 bool empty() const noexcept;
83 void reserve(size_type n);
84 void shrink_to_fit() noexcept;
86 reference operator[](size_type n);
87 const_reference operator[](size_type n) const;
88 reference at(size_type n);
89 const_reference at(size_type n) const;
92 const_reference front() const;
94 const_reference back() const;
96 value_type* data() noexcept;
97 const value_type* data() const noexcept;
99 void push_back(const value_type& x);
100 void push_back(value_type&& x);
101 template <class... Args>
102 reference emplace_back(Args&&... args);
105 template <class... Args> iterator emplace(const_iterator position, Args&&... args);
106 iterator insert(const_iterator position, const value_type& x);
107 iterator insert(const_iterator position, value_type&& x);
108 iterator insert(const_iterator position, size_type n, const value_type& x);
109 template <class InputIterator>
110 iterator insert(const_iterator position, InputIterator first, InputIterator last);
111 iterator insert(const_iterator position, initializer_list<value_type> il);
113 iterator erase(const_iterator position);
114 iterator erase(const_iterator first, const_iterator last);
116 void clear() noexcept;
118 void resize(size_type sz);
119 void resize(size_type sz, const value_type& c);
122 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
123 allocator_traits<allocator_type>::is_always_equal::value); // C++17
125 bool __invariants() const;
128 template <class Allocator = allocator<T> >
129 class vector<bool, Allocator>
132 typedef bool value_type;
133 typedef Allocator allocator_type;
134 typedef implementation-defined iterator;
135 typedef implementation-defined const_iterator;
136 typedef typename allocator_type::size_type size_type;
137 typedef typename allocator_type::difference_type difference_type;
138 typedef iterator pointer;
139 typedef const_iterator const_pointer;
140 typedef std::reverse_iterator<iterator> reverse_iterator;
141 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
146 reference(const reference&) noexcept;
147 operator bool() const noexcept;
148 reference& operator=(const bool x) noexcept;
149 reference& operator=(const reference& x) noexcept;
150 iterator operator&() const noexcept;
151 void flip() noexcept;
154 class const_reference
157 const_reference(const reference&) noexcept;
158 operator bool() const noexcept;
159 const_iterator operator&() const noexcept;
163 noexcept(is_nothrow_default_constructible<allocator_type>::value);
164 explicit vector(const allocator_type&);
165 explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
166 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
167 template <class InputIterator>
168 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
169 vector(const vector& x);
171 noexcept(is_nothrow_move_constructible<allocator_type>::value);
172 vector(initializer_list<value_type> il);
173 vector(initializer_list<value_type> il, const allocator_type& a);
175 vector& operator=(const vector& x);
176 vector& operator=(vector&& x)
178 allocator_type::propagate_on_container_move_assignment::value ||
179 allocator_type::is_always_equal::value); // C++17
180 vector& operator=(initializer_list<value_type> il);
181 template <class InputIterator>
182 void assign(InputIterator first, InputIterator last);
183 void assign(size_type n, const value_type& u);
184 void assign(initializer_list<value_type> il);
186 allocator_type get_allocator() const noexcept;
188 iterator begin() noexcept;
189 const_iterator begin() const noexcept;
190 iterator end() noexcept;
191 const_iterator end() const noexcept;
193 reverse_iterator rbegin() noexcept;
194 const_reverse_iterator rbegin() const noexcept;
195 reverse_iterator rend() noexcept;
196 const_reverse_iterator rend() const noexcept;
198 const_iterator cbegin() const noexcept;
199 const_iterator cend() const noexcept;
200 const_reverse_iterator crbegin() const noexcept;
201 const_reverse_iterator crend() const noexcept;
203 size_type size() const noexcept;
204 size_type max_size() const noexcept;
205 size_type capacity() const noexcept;
206 bool empty() const noexcept;
207 void reserve(size_type n);
208 void shrink_to_fit() noexcept;
210 reference operator[](size_type n);
211 const_reference operator[](size_type n) const;
212 reference at(size_type n);
213 const_reference at(size_type n) const;
216 const_reference front() const;
218 const_reference back() const;
220 void push_back(const value_type& x);
221 template <class... Args> reference emplace_back(Args&&... args); // C++14
224 template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
225 iterator insert(const_iterator position, const value_type& x);
226 iterator insert(const_iterator position, size_type n, const value_type& x);
227 template <class InputIterator>
228 iterator insert(const_iterator position, InputIterator first, InputIterator last);
229 iterator insert(const_iterator position, initializer_list<value_type> il);
231 iterator erase(const_iterator position);
232 iterator erase(const_iterator first, const_iterator last);
234 void clear() noexcept;
236 void resize(size_type sz);
237 void resize(size_type sz, value_type x);
240 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
241 allocator_traits<allocator_type>::is_always_equal::value); // C++17
242 void flip() noexcept;
244 bool __invariants() const;
247 template <class Allocator> struct hash<std::vector<bool, Allocator>>;
249 template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
250 template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
251 template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
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);
256 template <class T, class Allocator>
257 void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
258 noexcept(noexcept(x.swap(y)));
265 #include <iosfwd> // for forward declaration of vector
266 #include <__bit_reference>
267 #include <type_traits>
270 #include <initializer_list>
275 #include <__split_buffer>
276 #include <__functional_base>
278 #include <__undef_min_max>
282 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
283 #pragma GCC system_header
286 _LIBCPP_BEGIN_NAMESPACE_STD
289 class __vector_base_common
292 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
293 _LIBCPP_NORETURN void __throw_length_error() const;
294 _LIBCPP_NORETURN void __throw_out_of_range() const;
299 __vector_base_common<__b>::__throw_length_error() const
301 _VSTD::__throw_length_error("vector");
306 __vector_base_common<__b>::__throw_out_of_range() const
308 _VSTD::__throw_out_of_range("vector");
312 #pragma warning( push )
313 #pragma warning( disable: 4231 )
314 #endif // _LIBCPP_MSVC
315 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>)
317 #pragma warning( pop )
318 #endif // _LIBCPP_MSVC
320 template <class _Tp, class _Allocator>
322 : protected __vector_base_common<true>
325 typedef _Tp value_type;
326 typedef _Allocator allocator_type;
327 typedef allocator_traits<allocator_type> __alloc_traits;
328 typedef value_type& reference;
329 typedef const value_type& const_reference;
330 typedef typename __alloc_traits::size_type size_type;
331 typedef typename __alloc_traits::difference_type difference_type;
332 typedef typename __alloc_traits::pointer pointer;
333 typedef typename __alloc_traits::const_pointer const_pointer;
334 typedef pointer iterator;
335 typedef const_pointer const_iterator;
339 __compressed_pair<pointer, allocator_type> __end_cap_;
341 _LIBCPP_INLINE_VISIBILITY
342 allocator_type& __alloc() _NOEXCEPT
343 {return __end_cap_.second();}
344 _LIBCPP_INLINE_VISIBILITY
345 const allocator_type& __alloc() const _NOEXCEPT
346 {return __end_cap_.second();}
347 _LIBCPP_INLINE_VISIBILITY
348 pointer& __end_cap() _NOEXCEPT
349 {return __end_cap_.first();}
350 _LIBCPP_INLINE_VISIBILITY
351 const pointer& __end_cap() const _NOEXCEPT
352 {return __end_cap_.first();}
354 _LIBCPP_INLINE_VISIBILITY
356 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
357 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
360 _LIBCPP_INLINE_VISIBILITY
361 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
362 _LIBCPP_INLINE_VISIBILITY
363 size_type capacity() const _NOEXCEPT
364 {return static_cast<size_type>(__end_cap() - __begin_);}
366 _LIBCPP_INLINE_VISIBILITY
367 void __destruct_at_end(pointer __new_last) _NOEXCEPT;
369 _LIBCPP_INLINE_VISIBILITY
370 void __copy_assign_alloc(const __vector_base& __c)
371 {__copy_assign_alloc(__c, integral_constant<bool,
372 __alloc_traits::propagate_on_container_copy_assignment::value>());}
374 _LIBCPP_INLINE_VISIBILITY
375 void __move_assign_alloc(__vector_base& __c)
377 !__alloc_traits::propagate_on_container_move_assignment::value ||
378 is_nothrow_move_assignable<allocator_type>::value)
379 {__move_assign_alloc(__c, integral_constant<bool,
380 __alloc_traits::propagate_on_container_move_assignment::value>());}
382 _LIBCPP_INLINE_VISIBILITY
383 void __copy_assign_alloc(const __vector_base& __c, true_type)
385 if (__alloc() != __c.__alloc())
388 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
389 __begin_ = __end_ = __end_cap() = nullptr;
391 __alloc() = __c.__alloc();
394 _LIBCPP_INLINE_VISIBILITY
395 void __copy_assign_alloc(const __vector_base&, false_type)
398 _LIBCPP_INLINE_VISIBILITY
399 void __move_assign_alloc(__vector_base& __c, true_type)
400 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
402 __alloc() = _VSTD::move(__c.__alloc());
405 _LIBCPP_INLINE_VISIBILITY
406 void __move_assign_alloc(__vector_base&, false_type)
411 template <class _Tp, class _Allocator>
412 inline _LIBCPP_INLINE_VISIBILITY
414 __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
416 while (__new_last != __end_)
417 __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
420 template <class _Tp, class _Allocator>
421 inline _LIBCPP_INLINE_VISIBILITY
422 __vector_base<_Tp, _Allocator>::__vector_base()
423 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
430 template <class _Tp, class _Allocator>
431 inline _LIBCPP_INLINE_VISIBILITY
432 __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
435 __end_cap_(nullptr, __a)
439 template <class _Tp, class _Allocator>
440 __vector_base<_Tp, _Allocator>::~__vector_base()
442 if (__begin_ != nullptr)
445 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
449 template <class _Tp, class _Allocator /* = allocator<_Tp> */>
450 class _LIBCPP_TEMPLATE_VIS vector
451 : private __vector_base<_Tp, _Allocator>
454 typedef __vector_base<_Tp, _Allocator> __base;
455 typedef allocator<_Tp> __default_allocator_type;
457 typedef vector __self;
458 typedef _Tp value_type;
459 typedef _Allocator allocator_type;
460 typedef typename __base::__alloc_traits __alloc_traits;
461 typedef typename __base::reference reference;
462 typedef typename __base::const_reference const_reference;
463 typedef typename __base::size_type size_type;
464 typedef typename __base::difference_type difference_type;
465 typedef typename __base::pointer pointer;
466 typedef typename __base::const_pointer const_pointer;
467 typedef __wrap_iter<pointer> iterator;
468 typedef __wrap_iter<const_pointer> const_iterator;
469 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
470 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
472 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
473 "Allocator::value_type must be same type as value_type");
475 _LIBCPP_INLINE_VISIBILITY
476 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
478 #if _LIBCPP_DEBUG_LEVEL >= 2
479 __get_db()->__insert_c(this);
482 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
483 #if _LIBCPP_STD_VER <= 14
484 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
490 #if _LIBCPP_DEBUG_LEVEL >= 2
491 __get_db()->__insert_c(this);
494 explicit vector(size_type __n);
495 #if _LIBCPP_STD_VER > 11
496 explicit vector(size_type __n, const allocator_type& __a);
498 vector(size_type __n, const_reference __x);
499 vector(size_type __n, const_reference __x, const allocator_type& __a);
500 template <class _InputIterator>
501 vector(_InputIterator __first,
502 typename enable_if<__is_input_iterator <_InputIterator>::value &&
503 !__is_forward_iterator<_InputIterator>::value &&
506 typename iterator_traits<_InputIterator>::reference>::value,
507 _InputIterator>::type __last);
508 template <class _InputIterator>
509 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
510 typename enable_if<__is_input_iterator <_InputIterator>::value &&
511 !__is_forward_iterator<_InputIterator>::value &&
514 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
515 template <class _ForwardIterator>
516 vector(_ForwardIterator __first,
517 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
520 typename iterator_traits<_ForwardIterator>::reference>::value,
521 _ForwardIterator>::type __last);
522 template <class _ForwardIterator>
523 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
524 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
527 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
528 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
529 _LIBCPP_INLINE_VISIBILITY
530 vector(initializer_list<value_type> __il);
531 _LIBCPP_INLINE_VISIBILITY
532 vector(initializer_list<value_type> __il, const allocator_type& __a);
533 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
534 #if _LIBCPP_DEBUG_LEVEL >= 2
535 _LIBCPP_INLINE_VISIBILITY
538 __get_db()->__erase_c(this);
542 vector(const vector& __x);
543 vector(const vector& __x, const allocator_type& __a);
544 _LIBCPP_INLINE_VISIBILITY
545 vector& operator=(const vector& __x);
546 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
547 _LIBCPP_INLINE_VISIBILITY
549 #if _LIBCPP_STD_VER > 14
552 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
554 _LIBCPP_INLINE_VISIBILITY
555 vector(vector&& __x, const allocator_type& __a);
556 _LIBCPP_INLINE_VISIBILITY
557 vector& operator=(vector&& __x)
558 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
559 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
560 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
561 _LIBCPP_INLINE_VISIBILITY
562 vector& operator=(initializer_list<value_type> __il)
563 {assign(__il.begin(), __il.end()); return *this;}
564 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
566 template <class _InputIterator>
569 __is_input_iterator <_InputIterator>::value &&
570 !__is_forward_iterator<_InputIterator>::value &&
573 typename iterator_traits<_InputIterator>::reference>::value,
576 assign(_InputIterator __first, _InputIterator __last);
577 template <class _ForwardIterator>
580 __is_forward_iterator<_ForwardIterator>::value &&
583 typename iterator_traits<_ForwardIterator>::reference>::value,
586 assign(_ForwardIterator __first, _ForwardIterator __last);
588 void assign(size_type __n, const_reference __u);
589 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
590 _LIBCPP_INLINE_VISIBILITY
591 void assign(initializer_list<value_type> __il)
592 {assign(__il.begin(), __il.end());}
593 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
595 _LIBCPP_INLINE_VISIBILITY
596 allocator_type get_allocator() const _NOEXCEPT
597 {return this->__alloc();}
599 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
600 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
601 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
602 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
604 _LIBCPP_INLINE_VISIBILITY
605 reverse_iterator rbegin() _NOEXCEPT
606 {return reverse_iterator(end());}
607 _LIBCPP_INLINE_VISIBILITY
608 const_reverse_iterator rbegin() const _NOEXCEPT
609 {return const_reverse_iterator(end());}
610 _LIBCPP_INLINE_VISIBILITY
611 reverse_iterator rend() _NOEXCEPT
612 {return reverse_iterator(begin());}
613 _LIBCPP_INLINE_VISIBILITY
614 const_reverse_iterator rend() const _NOEXCEPT
615 {return const_reverse_iterator(begin());}
617 _LIBCPP_INLINE_VISIBILITY
618 const_iterator cbegin() const _NOEXCEPT
620 _LIBCPP_INLINE_VISIBILITY
621 const_iterator cend() const _NOEXCEPT
623 _LIBCPP_INLINE_VISIBILITY
624 const_reverse_iterator crbegin() const _NOEXCEPT
626 _LIBCPP_INLINE_VISIBILITY
627 const_reverse_iterator crend() const _NOEXCEPT
630 _LIBCPP_INLINE_VISIBILITY
631 size_type size() const _NOEXCEPT
632 {return static_cast<size_type>(this->__end_ - this->__begin_);}
633 _LIBCPP_INLINE_VISIBILITY
634 size_type capacity() const _NOEXCEPT
635 {return __base::capacity();}
636 _LIBCPP_INLINE_VISIBILITY
637 bool empty() const _NOEXCEPT
638 {return this->__begin_ == this->__end_;}
639 size_type max_size() const _NOEXCEPT;
640 void reserve(size_type __n);
641 void shrink_to_fit() _NOEXCEPT;
643 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
644 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
645 reference at(size_type __n);
646 const_reference at(size_type __n) const;
648 _LIBCPP_INLINE_VISIBILITY reference front()
650 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
651 return *this->__begin_;
653 _LIBCPP_INLINE_VISIBILITY const_reference front() const
655 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
656 return *this->__begin_;
658 _LIBCPP_INLINE_VISIBILITY reference back()
660 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
661 return *(this->__end_ - 1);
663 _LIBCPP_INLINE_VISIBILITY const_reference back() const
665 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
666 return *(this->__end_ - 1);
669 _LIBCPP_INLINE_VISIBILITY
670 value_type* data() _NOEXCEPT
671 {return _VSTD::__to_raw_pointer(this->__begin_);}
672 _LIBCPP_INLINE_VISIBILITY
673 const value_type* data() const _NOEXCEPT
674 {return _VSTD::__to_raw_pointer(this->__begin_);}
676 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
677 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
678 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
679 #ifndef _LIBCPP_HAS_NO_VARIADICS
680 template <class... _Args>
681 _LIBCPP_INLINE_VISIBILITY
682 reference emplace_back(_Args&&... __args);
683 #endif // _LIBCPP_HAS_NO_VARIADICS
684 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
685 _LIBCPP_INLINE_VISIBILITY
688 iterator insert(const_iterator __position, const_reference __x);
689 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
690 iterator insert(const_iterator __position, value_type&& __x);
691 #ifndef _LIBCPP_HAS_NO_VARIADICS
692 template <class... _Args>
693 iterator emplace(const_iterator __position, _Args&&... __args);
694 #endif // _LIBCPP_HAS_NO_VARIADICS
695 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
696 iterator insert(const_iterator __position, size_type __n, const_reference __x);
697 template <class _InputIterator>
700 __is_input_iterator <_InputIterator>::value &&
701 !__is_forward_iterator<_InputIterator>::value &&
704 typename iterator_traits<_InputIterator>::reference>::value,
707 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
708 template <class _ForwardIterator>
711 __is_forward_iterator<_ForwardIterator>::value &&
714 typename iterator_traits<_ForwardIterator>::reference>::value,
717 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
718 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
719 _LIBCPP_INLINE_VISIBILITY
720 iterator insert(const_iterator __position, initializer_list<value_type> __il)
721 {return insert(__position, __il.begin(), __il.end());}
722 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
724 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
725 iterator erase(const_iterator __first, const_iterator __last);
727 _LIBCPP_INLINE_VISIBILITY
728 void clear() _NOEXCEPT
730 size_type __old_size = size();
732 __annotate_shrink(__old_size);
733 __invalidate_all_iterators();
736 void resize(size_type __sz);
737 void resize(size_type __sz, const_reference __x);
740 #if _LIBCPP_STD_VER >= 14
743 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
744 __is_nothrow_swappable<allocator_type>::value);
747 bool __invariants() const;
749 #if _LIBCPP_DEBUG_LEVEL >= 2
751 bool __dereferenceable(const const_iterator* __i) const;
752 bool __decrementable(const const_iterator* __i) const;
753 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
754 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
756 #endif // _LIBCPP_DEBUG_LEVEL >= 2
759 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
760 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
761 void allocate(size_type __n);
762 void deallocate() _NOEXCEPT;
763 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
764 void __construct_at_end(size_type __n);
765 _LIBCPP_INLINE_VISIBILITY
766 void __construct_at_end(size_type __n, const_reference __x);
767 template <class _ForwardIterator>
770 __is_forward_iterator<_ForwardIterator>::value,
773 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
774 void __append(size_type __n);
775 void __append(size_type __n, const_reference __x);
776 _LIBCPP_INLINE_VISIBILITY
777 iterator __make_iter(pointer __p) _NOEXCEPT;
778 _LIBCPP_INLINE_VISIBILITY
779 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
780 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
781 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
782 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
783 void __move_assign(vector& __c, true_type)
784 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
785 void __move_assign(vector& __c, false_type)
786 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
787 _LIBCPP_INLINE_VISIBILITY
788 void __destruct_at_end(pointer __new_last) _NOEXCEPT
790 __invalidate_iterators_past(__new_last);
791 size_type __old_size = size();
792 __base::__destruct_at_end(__new_last);
793 __annotate_shrink(__old_size);
797 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
798 __push_back_slow_path(_Up&& __x);
800 __push_back_slow_path(_Up& __x);
802 #if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
803 template <class... _Args>
805 __emplace_back_slow_path(_Args&&... __args);
807 // The following functions are no-ops outside of AddressSanitizer mode.
808 // We call annotatations only for the default Allocator because other allocators
809 // may not meet the AddressSanitizer alignment constraints.
810 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
811 #ifndef _LIBCPP_HAS_NO_ASAN
812 void __annotate_contiguous_container(const void *__beg, const void *__end,
813 const void *__old_mid,
814 const void *__new_mid) const
817 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
818 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
821 _LIBCPP_INLINE_VISIBILITY
822 void __annotate_contiguous_container(const void*, const void*, const void*,
823 const void*) const {}
825 _LIBCPP_INLINE_VISIBILITY
826 void __annotate_new(size_type __current_size) const {
827 __annotate_contiguous_container(data(), data() + capacity(),
828 data() + capacity(), data() + __current_size);
831 _LIBCPP_INLINE_VISIBILITY
832 void __annotate_delete() const {
833 __annotate_contiguous_container(data(), data() + capacity(),
834 data() + size(), data() + capacity());
837 _LIBCPP_INLINE_VISIBILITY
838 void __annotate_increase(size_type __n) const
840 __annotate_contiguous_container(data(), data() + capacity(),
841 data() + size(), data() + size() + __n);
844 _LIBCPP_INLINE_VISIBILITY
845 void __annotate_shrink(size_type __old_size) const
847 __annotate_contiguous_container(data(), data() + capacity(),
848 data() + __old_size, data() + size());
850 #ifndef _LIBCPP_HAS_NO_ASAN
851 // The annotation for size increase should happen before the actual increase,
852 // but if an exception is thrown after that the annotation has to be undone.
853 struct __RAII_IncreaseAnnotator {
854 __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1)
855 : __commit(false), __v(__v), __old_size(__v.size() + __n) {
856 __v.__annotate_increase(__n);
858 void __done() { __commit = true; }
859 ~__RAII_IncreaseAnnotator() {
860 if (__commit) return;
861 __v.__annotate_shrink(__old_size);
865 size_type __old_size;
868 struct __RAII_IncreaseAnnotator {
869 _LIBCPP_INLINE_VISIBILITY
870 __RAII_IncreaseAnnotator(const vector &, size_type = 1) {}
871 _LIBCPP_INLINE_VISIBILITY void __done() {}
877 template <class _Tp, class _Allocator>
879 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
882 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
883 _VSTD::swap(this->__begin_, __v.__begin_);
884 _VSTD::swap(this->__end_, __v.__end_);
885 _VSTD::swap(this->__end_cap(), __v.__end_cap());
886 __v.__first_ = __v.__begin_;
887 __annotate_new(size());
888 __invalidate_all_iterators();
891 template <class _Tp, class _Allocator>
892 typename vector<_Tp, _Allocator>::pointer
893 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
896 pointer __r = __v.__begin_;
897 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
898 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
899 _VSTD::swap(this->__begin_, __v.__begin_);
900 _VSTD::swap(this->__end_, __v.__end_);
901 _VSTD::swap(this->__end_cap(), __v.__end_cap());
902 __v.__first_ = __v.__begin_;
903 __annotate_new(size());
904 __invalidate_all_iterators();
908 // Allocate space for __n objects
909 // throws length_error if __n > max_size()
910 // throws (probably bad_alloc) if memory run out
911 // Precondition: __begin_ == __end_ == __end_cap() == 0
912 // Precondition: __n > 0
913 // Postcondition: capacity() == __n
914 // Postcondition: size() == 0
915 template <class _Tp, class _Allocator>
917 vector<_Tp, _Allocator>::allocate(size_type __n)
919 if (__n > max_size())
920 this->__throw_length_error();
921 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
922 this->__end_cap() = this->__begin_ + __n;
926 template <class _Tp, class _Allocator>
928 vector<_Tp, _Allocator>::deallocate() _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 allocator_type& __a = this->__alloc();
973 __RAII_IncreaseAnnotator __annotator(*this);
974 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
977 __annotator.__done();
981 // Copy constructs __n objects starting at __end_ from __x
982 // throws if construction throws
983 // Precondition: __n > 0
984 // Precondition: size() + __n <= capacity()
985 // Postcondition: size() == old size() + __n
986 // Postcondition: [i] == __x for all i in [size() - __n, __n)
987 template <class _Tp, class _Allocator>
990 vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
992 allocator_type& __a = this->__alloc();
995 __RAII_IncreaseAnnotator __annotator(*this);
996 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
999 __annotator.__done();
1003 template <class _Tp, class _Allocator>
1004 template <class _ForwardIterator>
1007 __is_forward_iterator<_ForwardIterator>::value,
1010 vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
1012 allocator_type& __a = this->__alloc();
1013 __RAII_IncreaseAnnotator __annotator(*this, __n);
1014 __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_);
1015 __annotator.__done();
1018 // Default constructs __n objects starting at __end_
1019 // throws if construction throws
1020 // Postcondition: size() == size() + __n
1021 // Exception safety: strong.
1022 template <class _Tp, class _Allocator>
1024 vector<_Tp, _Allocator>::__append(size_type __n)
1026 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1027 this->__construct_at_end(__n);
1030 allocator_type& __a = this->__alloc();
1031 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1032 __v.__construct_at_end(__n);
1033 __swap_out_circular_buffer(__v);
1037 // Default constructs __n objects starting at __end_
1038 // throws if construction throws
1039 // Postcondition: size() == size() + __n
1040 // Exception safety: strong.
1041 template <class _Tp, class _Allocator>
1043 vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1045 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1046 this->__construct_at_end(__n, __x);
1049 allocator_type& __a = this->__alloc();
1050 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1051 __v.__construct_at_end(__n, __x);
1052 __swap_out_circular_buffer(__v);
1056 template <class _Tp, class _Allocator>
1057 vector<_Tp, _Allocator>::vector(size_type __n)
1059 #if _LIBCPP_DEBUG_LEVEL >= 2
1060 __get_db()->__insert_c(this);
1065 __construct_at_end(__n);
1069 #if _LIBCPP_STD_VER > 11
1070 template <class _Tp, class _Allocator>
1071 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1074 #if _LIBCPP_DEBUG_LEVEL >= 2
1075 __get_db()->__insert_c(this);
1080 __construct_at_end(__n);
1085 template <class _Tp, class _Allocator>
1086 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1088 #if _LIBCPP_DEBUG_LEVEL >= 2
1089 __get_db()->__insert_c(this);
1094 __construct_at_end(__n, __x);
1098 template <class _Tp, class _Allocator>
1099 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1102 #if _LIBCPP_DEBUG_LEVEL >= 2
1103 __get_db()->__insert_c(this);
1108 __construct_at_end(__n, __x);
1112 template <class _Tp, class _Allocator>
1113 template <class _InputIterator>
1114 vector<_Tp, _Allocator>::vector(_InputIterator __first,
1115 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1116 !__is_forward_iterator<_InputIterator>::value &&
1119 typename iterator_traits<_InputIterator>::reference>::value,
1120 _InputIterator>::type __last)
1122 #if _LIBCPP_DEBUG_LEVEL >= 2
1123 __get_db()->__insert_c(this);
1125 for (; __first != __last; ++__first)
1126 push_back(*__first);
1129 template <class _Tp, class _Allocator>
1130 template <class _InputIterator>
1131 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1132 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1133 !__is_forward_iterator<_InputIterator>::value &&
1136 typename iterator_traits<_InputIterator>::reference>::value>::type*)
1139 #if _LIBCPP_DEBUG_LEVEL >= 2
1140 __get_db()->__insert_c(this);
1142 for (; __first != __last; ++__first)
1143 push_back(*__first);
1146 template <class _Tp, class _Allocator>
1147 template <class _ForwardIterator>
1148 vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
1149 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1152 typename iterator_traits<_ForwardIterator>::reference>::value,
1153 _ForwardIterator>::type __last)
1155 #if _LIBCPP_DEBUG_LEVEL >= 2
1156 __get_db()->__insert_c(this);
1158 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1162 __construct_at_end(__first, __last, __n);
1166 template <class _Tp, class _Allocator>
1167 template <class _ForwardIterator>
1168 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1169 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1172 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1175 #if _LIBCPP_DEBUG_LEVEL >= 2
1176 __get_db()->__insert_c(this);
1178 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1182 __construct_at_end(__first, __last, __n);
1186 template <class _Tp, class _Allocator>
1187 vector<_Tp, _Allocator>::vector(const vector& __x)
1188 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1190 #if _LIBCPP_DEBUG_LEVEL >= 2
1191 __get_db()->__insert_c(this);
1193 size_type __n = __x.size();
1197 __construct_at_end(__x.__begin_, __x.__end_, __n);
1201 template <class _Tp, class _Allocator>
1202 vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1205 #if _LIBCPP_DEBUG_LEVEL >= 2
1206 __get_db()->__insert_c(this);
1208 size_type __n = __x.size();
1212 __construct_at_end(__x.__begin_, __x.__end_, __n);
1216 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1218 template <class _Tp, class _Allocator>
1219 inline _LIBCPP_INLINE_VISIBILITY
1220 vector<_Tp, _Allocator>::vector(vector&& __x)
1221 #if _LIBCPP_STD_VER > 14
1224 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1226 : __base(_VSTD::move(__x.__alloc()))
1228 #if _LIBCPP_DEBUG_LEVEL >= 2
1229 __get_db()->__insert_c(this);
1230 __get_db()->swap(this, &__x);
1232 this->__begin_ = __x.__begin_;
1233 this->__end_ = __x.__end_;
1234 this->__end_cap() = __x.__end_cap();
1235 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1238 template <class _Tp, class _Allocator>
1239 inline _LIBCPP_INLINE_VISIBILITY
1240 vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1243 #if _LIBCPP_DEBUG_LEVEL >= 2
1244 __get_db()->__insert_c(this);
1246 if (__a == __x.__alloc())
1248 this->__begin_ = __x.__begin_;
1249 this->__end_ = __x.__end_;
1250 this->__end_cap() = __x.__end_cap();
1251 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1252 #if _LIBCPP_DEBUG_LEVEL >= 2
1253 __get_db()->swap(this, &__x);
1258 typedef move_iterator<iterator> _Ip;
1259 assign(_Ip(__x.begin()), _Ip(__x.end()));
1263 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1265 template <class _Tp, class _Allocator>
1266 inline _LIBCPP_INLINE_VISIBILITY
1267 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1269 #if _LIBCPP_DEBUG_LEVEL >= 2
1270 __get_db()->__insert_c(this);
1272 if (__il.size() > 0)
1274 allocate(__il.size());
1275 __construct_at_end(__il.begin(), __il.end(), __il.size());
1279 template <class _Tp, class _Allocator>
1280 inline _LIBCPP_INLINE_VISIBILITY
1281 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1284 #if _LIBCPP_DEBUG_LEVEL >= 2
1285 __get_db()->__insert_c(this);
1287 if (__il.size() > 0)
1289 allocate(__il.size());
1290 __construct_at_end(__il.begin(), __il.end(), __il.size());
1294 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1296 template <class _Tp, class _Allocator>
1297 inline _LIBCPP_INLINE_VISIBILITY
1298 vector<_Tp, _Allocator>&
1299 vector<_Tp, _Allocator>::operator=(vector&& __x)
1300 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
1302 __move_assign(__x, integral_constant<bool,
1303 __alloc_traits::propagate_on_container_move_assignment::value>());
1307 template <class _Tp, class _Allocator>
1309 vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1310 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
1312 if (__base::__alloc() != __c.__alloc())
1314 typedef move_iterator<iterator> _Ip;
1315 assign(_Ip(__c.begin()), _Ip(__c.end()));
1318 __move_assign(__c, true_type());
1321 template <class _Tp, class _Allocator>
1323 vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1324 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1327 __base::__move_assign_alloc(__c); // this can throw
1328 this->__begin_ = __c.__begin_;
1329 this->__end_ = __c.__end_;
1330 this->__end_cap() = __c.__end_cap();
1331 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1332 #if _LIBCPP_DEBUG_LEVEL >= 2
1333 __get_db()->swap(this, &__c);
1337 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1339 template <class _Tp, class _Allocator>
1340 inline _LIBCPP_INLINE_VISIBILITY
1341 vector<_Tp, _Allocator>&
1342 vector<_Tp, _Allocator>::operator=(const vector& __x)
1346 __base::__copy_assign_alloc(__x);
1347 assign(__x.__begin_, __x.__end_);
1352 template <class _Tp, class _Allocator>
1353 template <class _InputIterator>
1356 __is_input_iterator <_InputIterator>::value &&
1357 !__is_forward_iterator<_InputIterator>::value &&
1360 typename iterator_traits<_InputIterator>::reference>::value,
1363 vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1366 for (; __first != __last; ++__first)
1367 push_back(*__first);
1370 template <class _Tp, class _Allocator>
1371 template <class _ForwardIterator>
1374 __is_forward_iterator<_ForwardIterator>::value &&
1377 typename iterator_traits<_ForwardIterator>::reference>::value,
1380 vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1382 size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
1383 if (__new_size <= capacity())
1385 _ForwardIterator __mid = __last;
1386 bool __growing = false;
1387 if (__new_size > size())
1391 _VSTD::advance(__mid, size());
1393 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
1395 __construct_at_end(__mid, __last, __new_size - size());
1397 this->__destruct_at_end(__m);
1402 allocate(__recommend(__new_size));
1403 __construct_at_end(__first, __last, __new_size);
1405 __invalidate_all_iterators();
1408 template <class _Tp, class _Allocator>
1410 vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1412 if (__n <= capacity())
1414 size_type __s = size();
1415 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
1417 __construct_at_end(__n - __s, __u);
1419 this->__destruct_at_end(this->__begin_ + __n);
1424 allocate(__recommend(static_cast<size_type>(__n)));
1425 __construct_at_end(__n, __u);
1427 __invalidate_all_iterators();
1430 template <class _Tp, class _Allocator>
1431 inline _LIBCPP_INLINE_VISIBILITY
1432 typename vector<_Tp, _Allocator>::iterator
1433 vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
1435 #if _LIBCPP_DEBUG_LEVEL >= 2
1436 return iterator(this, __p);
1438 return iterator(__p);
1442 template <class _Tp, class _Allocator>
1443 inline _LIBCPP_INLINE_VISIBILITY
1444 typename vector<_Tp, _Allocator>::const_iterator
1445 vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
1447 #if _LIBCPP_DEBUG_LEVEL >= 2
1448 return const_iterator(this, __p);
1450 return const_iterator(__p);
1454 template <class _Tp, class _Allocator>
1455 inline _LIBCPP_INLINE_VISIBILITY
1456 typename vector<_Tp, _Allocator>::iterator
1457 vector<_Tp, _Allocator>::begin() _NOEXCEPT
1459 return __make_iter(this->__begin_);
1462 template <class _Tp, class _Allocator>
1463 inline _LIBCPP_INLINE_VISIBILITY
1464 typename vector<_Tp, _Allocator>::const_iterator
1465 vector<_Tp, _Allocator>::begin() const _NOEXCEPT
1467 return __make_iter(this->__begin_);
1470 template <class _Tp, class _Allocator>
1471 inline _LIBCPP_INLINE_VISIBILITY
1472 typename vector<_Tp, _Allocator>::iterator
1473 vector<_Tp, _Allocator>::end() _NOEXCEPT
1475 return __make_iter(this->__end_);
1478 template <class _Tp, class _Allocator>
1479 inline _LIBCPP_INLINE_VISIBILITY
1480 typename vector<_Tp, _Allocator>::const_iterator
1481 vector<_Tp, _Allocator>::end() const _NOEXCEPT
1483 return __make_iter(this->__end_);
1486 template <class _Tp, class _Allocator>
1487 inline _LIBCPP_INLINE_VISIBILITY
1488 typename vector<_Tp, _Allocator>::reference
1489 vector<_Tp, _Allocator>::operator[](size_type __n)
1491 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1492 return this->__begin_[__n];
1495 template <class _Tp, class _Allocator>
1496 inline _LIBCPP_INLINE_VISIBILITY
1497 typename vector<_Tp, _Allocator>::const_reference
1498 vector<_Tp, _Allocator>::operator[](size_type __n) const
1500 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1501 return this->__begin_[__n];
1504 template <class _Tp, class _Allocator>
1505 typename vector<_Tp, _Allocator>::reference
1506 vector<_Tp, _Allocator>::at(size_type __n)
1509 this->__throw_out_of_range();
1510 return this->__begin_[__n];
1513 template <class _Tp, class _Allocator>
1514 typename vector<_Tp, _Allocator>::const_reference
1515 vector<_Tp, _Allocator>::at(size_type __n) const
1518 this->__throw_out_of_range();
1519 return this->__begin_[__n];
1522 template <class _Tp, class _Allocator>
1524 vector<_Tp, _Allocator>::reserve(size_type __n)
1526 if (__n > capacity())
1528 allocator_type& __a = this->__alloc();
1529 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
1530 __swap_out_circular_buffer(__v);
1534 template <class _Tp, class _Allocator>
1536 vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1538 if (capacity() > size())
1540 #ifndef _LIBCPP_NO_EXCEPTIONS
1543 #endif // _LIBCPP_NO_EXCEPTIONS
1544 allocator_type& __a = this->__alloc();
1545 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1546 __swap_out_circular_buffer(__v);
1547 #ifndef _LIBCPP_NO_EXCEPTIONS
1552 #endif // _LIBCPP_NO_EXCEPTIONS
1556 template <class _Tp, class _Allocator>
1557 template <class _Up>
1559 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1560 vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1562 vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1565 allocator_type& __a = this->__alloc();
1566 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1567 // __v.push_back(_VSTD::forward<_Up>(__x));
1568 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
1570 __swap_out_circular_buffer(__v);
1573 template <class _Tp, class _Allocator>
1574 inline _LIBCPP_INLINE_VISIBILITY
1576 vector<_Tp, _Allocator>::push_back(const_reference __x)
1578 if (this->__end_ != this->__end_cap())
1580 __RAII_IncreaseAnnotator __annotator(*this);
1581 __alloc_traits::construct(this->__alloc(),
1582 _VSTD::__to_raw_pointer(this->__end_), __x);
1583 __annotator.__done();
1587 __push_back_slow_path(__x);
1590 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1592 template <class _Tp, class _Allocator>
1593 inline _LIBCPP_INLINE_VISIBILITY
1595 vector<_Tp, _Allocator>::push_back(value_type&& __x)
1597 if (this->__end_ < this->__end_cap())
1599 __RAII_IncreaseAnnotator __annotator(*this);
1600 __alloc_traits::construct(this->__alloc(),
1601 _VSTD::__to_raw_pointer(this->__end_),
1603 __annotator.__done();
1607 __push_back_slow_path(_VSTD::move(__x));
1610 #ifndef _LIBCPP_HAS_NO_VARIADICS
1612 template <class _Tp, class _Allocator>
1613 template <class... _Args>
1615 vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1617 allocator_type& __a = this->__alloc();
1618 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1619 // __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1620 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
1622 __swap_out_circular_buffer(__v);
1625 template <class _Tp, class _Allocator>
1626 template <class... _Args>
1628 typename vector<_Tp, _Allocator>::reference
1629 vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1631 if (this->__end_ < this->__end_cap())
1633 __RAII_IncreaseAnnotator __annotator(*this);
1634 __alloc_traits::construct(this->__alloc(),
1635 _VSTD::__to_raw_pointer(this->__end_),
1636 _VSTD::forward<_Args>(__args)...);
1637 __annotator.__done();
1641 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
1642 return this->back();
1645 #endif // _LIBCPP_HAS_NO_VARIADICS
1646 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1648 template <class _Tp, class _Allocator>
1651 vector<_Tp, _Allocator>::pop_back()
1653 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
1654 this->__destruct_at_end(this->__end_ - 1);
1657 template <class _Tp, class _Allocator>
1658 inline _LIBCPP_INLINE_VISIBILITY
1659 typename vector<_Tp, _Allocator>::iterator
1660 vector<_Tp, _Allocator>::erase(const_iterator __position)
1662 #if _LIBCPP_DEBUG_LEVEL >= 2
1663 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1664 "vector::erase(iterator) called with an iterator not"
1665 " referring to this vector");
1667 _LIBCPP_ASSERT(__position != end(),
1668 "vector::erase(iterator) called with a non-dereferenceable iterator");
1669 difference_type __ps = __position - cbegin();
1670 pointer __p = this->__begin_ + __ps;
1671 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
1672 this->__invalidate_iterators_past(__p-1);
1673 iterator __r = __make_iter(__p);
1677 template <class _Tp, class _Allocator>
1678 typename vector<_Tp, _Allocator>::iterator
1679 vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1681 #if _LIBCPP_DEBUG_LEVEL >= 2
1682 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1683 "vector::erase(iterator, iterator) called with an iterator not"
1684 " referring to this vector");
1685 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
1686 "vector::erase(iterator, iterator) called with an iterator not"
1687 " referring to this vector");
1689 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
1690 pointer __p = this->__begin_ + (__first - begin());
1691 if (__first != __last) {
1692 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1693 this->__invalidate_iterators_past(__p - 1);
1695 iterator __r = __make_iter(__p);
1699 template <class _Tp, class _Allocator>
1701 vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1703 pointer __old_last = this->__end_;
1704 difference_type __n = __old_last - __to;
1705 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1706 __alloc_traits::construct(this->__alloc(),
1707 _VSTD::__to_raw_pointer(this->__end_),
1709 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
1712 template <class _Tp, class _Allocator>
1713 typename vector<_Tp, _Allocator>::iterator
1714 vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1716 #if _LIBCPP_DEBUG_LEVEL >= 2
1717 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1718 "vector::insert(iterator, x) called with an iterator not"
1719 " referring to this vector");
1721 pointer __p = this->__begin_ + (__position - begin());
1722 if (this->__end_ < this->__end_cap())
1724 __RAII_IncreaseAnnotator __annotator(*this);
1725 if (__p == this->__end_)
1727 __alloc_traits::construct(this->__alloc(),
1728 _VSTD::__to_raw_pointer(this->__end_), __x);
1733 __move_range(__p, this->__end_, __p + 1);
1734 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1735 if (__p <= __xr && __xr < this->__end_)
1739 __annotator.__done();
1743 allocator_type& __a = this->__alloc();
1744 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1746 __p = __swap_out_circular_buffer(__v, __p);
1748 return __make_iter(__p);
1751 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1753 template <class _Tp, class _Allocator>
1754 typename vector<_Tp, _Allocator>::iterator
1755 vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1757 #if _LIBCPP_DEBUG_LEVEL >= 2
1758 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1759 "vector::insert(iterator, x) called with an iterator not"
1760 " referring to this vector");
1762 pointer __p = this->__begin_ + (__position - begin());
1763 if (this->__end_ < this->__end_cap())
1765 __RAII_IncreaseAnnotator __annotator(*this);
1766 if (__p == this->__end_)
1768 __alloc_traits::construct(this->__alloc(),
1769 _VSTD::__to_raw_pointer(this->__end_),
1775 __move_range(__p, this->__end_, __p + 1);
1776 *__p = _VSTD::move(__x);
1778 __annotator.__done();
1782 allocator_type& __a = this->__alloc();
1783 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1784 __v.push_back(_VSTD::move(__x));
1785 __p = __swap_out_circular_buffer(__v, __p);
1787 return __make_iter(__p);
1790 #ifndef _LIBCPP_HAS_NO_VARIADICS
1792 template <class _Tp, class _Allocator>
1793 template <class... _Args>
1794 typename vector<_Tp, _Allocator>::iterator
1795 vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1797 #if _LIBCPP_DEBUG_LEVEL >= 2
1798 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1799 "vector::emplace(iterator, x) called with an iterator not"
1800 " referring to this vector");
1802 pointer __p = this->__begin_ + (__position - begin());
1803 if (this->__end_ < this->__end_cap())
1805 __RAII_IncreaseAnnotator __annotator(*this);
1806 if (__p == this->__end_)
1808 __alloc_traits::construct(this->__alloc(),
1809 _VSTD::__to_raw_pointer(this->__end_),
1810 _VSTD::forward<_Args>(__args)...);
1815 __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
1816 __move_range(__p, this->__end_, __p + 1);
1817 *__p = _VSTD::move(__tmp.get());
1819 __annotator.__done();
1823 allocator_type& __a = this->__alloc();
1824 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1825 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1826 __p = __swap_out_circular_buffer(__v, __p);
1828 return __make_iter(__p);
1831 #endif // _LIBCPP_HAS_NO_VARIADICS
1832 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1834 template <class _Tp, class _Allocator>
1835 typename vector<_Tp, _Allocator>::iterator
1836 vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1838 #if _LIBCPP_DEBUG_LEVEL >= 2
1839 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1840 "vector::insert(iterator, n, x) called with an iterator not"
1841 " referring to this vector");
1843 pointer __p = this->__begin_ + (__position - begin());
1846 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1848 size_type __old_n = __n;
1849 pointer __old_last = this->__end_;
1850 if (__n > static_cast<size_type>(this->__end_ - __p))
1852 size_type __cx = __n - (this->__end_ - __p);
1853 __construct_at_end(__cx, __x);
1858 __RAII_IncreaseAnnotator __annotator(*this, __n);
1859 __move_range(__p, __old_last, __p + __old_n);
1860 __annotator.__done();
1861 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1862 if (__p <= __xr && __xr < this->__end_)
1864 _VSTD::fill_n(__p, __n, *__xr);
1869 allocator_type& __a = this->__alloc();
1870 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1871 __v.__construct_at_end(__n, __x);
1872 __p = __swap_out_circular_buffer(__v, __p);
1875 return __make_iter(__p);
1878 template <class _Tp, class _Allocator>
1879 template <class _InputIterator>
1882 __is_input_iterator <_InputIterator>::value &&
1883 !__is_forward_iterator<_InputIterator>::value &&
1886 typename iterator_traits<_InputIterator>::reference>::value,
1887 typename vector<_Tp, _Allocator>::iterator
1889 vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1891 #if _LIBCPP_DEBUG_LEVEL >= 2
1892 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1893 "vector::insert(iterator, range) called with an iterator not"
1894 " referring to this vector");
1896 difference_type __off = __position - begin();
1897 pointer __p = this->__begin_ + __off;
1898 allocator_type& __a = this->__alloc();
1899 pointer __old_last = this->__end_;
1900 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1902 __RAII_IncreaseAnnotator __annotator(*this);
1903 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
1906 __annotator.__done();
1908 __split_buffer<value_type, allocator_type&> __v(__a);
1909 if (__first != __last)
1911 #ifndef _LIBCPP_NO_EXCEPTIONS
1914 #endif // _LIBCPP_NO_EXCEPTIONS
1915 __v.__construct_at_end(__first, __last);
1916 difference_type __old_size = __old_last - this->__begin_;
1917 difference_type __old_p = __p - this->__begin_;
1918 reserve(__recommend(size() + __v.size()));
1919 __p = this->__begin_ + __old_p;
1920 __old_last = this->__begin_ + __old_size;
1921 #ifndef _LIBCPP_NO_EXCEPTIONS
1925 erase(__make_iter(__old_last), end());
1928 #endif // _LIBCPP_NO_EXCEPTIONS
1930 __p = _VSTD::rotate(__p, __old_last, this->__end_);
1931 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1932 make_move_iterator(__v.end()));
1933 return begin() + __off;
1936 template <class _Tp, class _Allocator>
1937 template <class _ForwardIterator>
1940 __is_forward_iterator<_ForwardIterator>::value &&
1943 typename iterator_traits<_ForwardIterator>::reference>::value,
1944 typename vector<_Tp, _Allocator>::iterator
1946 vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1948 #if _LIBCPP_DEBUG_LEVEL >= 2
1949 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1950 "vector::insert(iterator, range) called with an iterator not"
1951 " referring to this vector");
1953 pointer __p = this->__begin_ + (__position - begin());
1954 difference_type __n = _VSTD::distance(__first, __last);
1957 if (__n <= this->__end_cap() - this->__end_)
1959 size_type __old_n = __n;
1960 pointer __old_last = this->__end_;
1961 _ForwardIterator __m = __last;
1962 difference_type __dx = this->__end_ - __p;
1966 difference_type __diff = this->__end_ - __p;
1967 _VSTD::advance(__m, __diff);
1968 __construct_at_end(__m, __last, __n - __diff);
1973 __RAII_IncreaseAnnotator __annotator(*this, __n);
1974 __move_range(__p, __old_last, __p + __old_n);
1975 __annotator.__done();
1976 _VSTD::copy(__first, __m, __p);
1981 allocator_type& __a = this->__alloc();
1982 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1983 __v.__construct_at_end(__first, __last);
1984 __p = __swap_out_circular_buffer(__v, __p);
1987 return __make_iter(__p);
1990 template <class _Tp, class _Allocator>
1992 vector<_Tp, _Allocator>::resize(size_type __sz)
1994 size_type __cs = size();
1996 this->__append(__sz - __cs);
1997 else if (__cs > __sz)
1998 this->__destruct_at_end(this->__begin_ + __sz);
2001 template <class _Tp, class _Allocator>
2003 vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
2005 size_type __cs = size();
2007 this->__append(__sz - __cs, __x);
2008 else if (__cs > __sz)
2009 this->__destruct_at_end(this->__begin_ + __sz);
2012 template <class _Tp, class _Allocator>
2014 vector<_Tp, _Allocator>::swap(vector& __x)
2015 #if _LIBCPP_STD_VER >= 14
2018 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
2019 __is_nothrow_swappable<allocator_type>::value)
2022 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
2023 this->__alloc() == __x.__alloc(),
2024 "vector::swap: Either propagate_on_container_swap must be true"
2025 " or the allocators must compare equal");
2026 _VSTD::swap(this->__begin_, __x.__begin_);
2027 _VSTD::swap(this->__end_, __x.__end_);
2028 _VSTD::swap(this->__end_cap(), __x.__end_cap());
2029 __swap_allocator(this->__alloc(), __x.__alloc(),
2030 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
2031 #if _LIBCPP_DEBUG_LEVEL >= 2
2032 __get_db()->swap(this, &__x);
2033 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2036 template <class _Tp, class _Allocator>
2038 vector<_Tp, _Allocator>::__invariants() const
2040 if (this->__begin_ == nullptr)
2042 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
2047 if (this->__begin_ > this->__end_)
2049 if (this->__begin_ == this->__end_cap())
2051 if (this->__end_ > this->__end_cap())
2057 #if _LIBCPP_DEBUG_LEVEL >= 2
2059 template <class _Tp, class _Allocator>
2061 vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
2063 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
2066 template <class _Tp, class _Allocator>
2068 vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
2070 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
2073 template <class _Tp, class _Allocator>
2075 vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2077 const_pointer __p = __i->base() + __n;
2078 return this->__begin_ <= __p && __p <= this->__end_;
2081 template <class _Tp, class _Allocator>
2083 vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2085 const_pointer __p = __i->base() + __n;
2086 return this->__begin_ <= __p && __p < this->__end_;
2089 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2091 template <class _Tp, class _Allocator>
2092 inline _LIBCPP_INLINE_VISIBILITY
2094 vector<_Tp, _Allocator>::__invalidate_all_iterators()
2096 #if _LIBCPP_DEBUG_LEVEL >= 2
2097 __get_db()->__invalidate_all(this);
2098 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2102 template <class _Tp, class _Allocator>
2103 inline _LIBCPP_INLINE_VISIBILITY
2105 vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
2106 #if _LIBCPP_DEBUG_LEVEL >= 2
2107 __c_node* __c = __get_db()->__find_c_and_lock(this);
2108 for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
2110 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
2111 if (__i->base() > __new_last) {
2112 (*__p)->__c_ = nullptr;
2113 if (--__c->end_ != __p)
2114 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
2117 __get_db()->unlock();
2125 template <class _Allocator> class vector<bool, _Allocator>;
2127 template <class _Allocator> struct hash<vector<bool, _Allocator> >;
2129 template <class _Allocator>
2130 struct __has_storage_type<vector<bool, _Allocator> >
2132 static const bool value = true;
2135 template <class _Allocator>
2136 class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
2137 : private __vector_base_common<true>
2140 typedef vector __self;
2141 typedef bool value_type;
2142 typedef _Allocator allocator_type;
2143 typedef allocator_traits<allocator_type> __alloc_traits;
2144 typedef typename __alloc_traits::size_type size_type;
2145 typedef typename __alloc_traits::difference_type difference_type;
2146 typedef size_type __storage_type;
2147 typedef __bit_iterator<vector, false> pointer;
2148 typedef __bit_iterator<vector, true> const_pointer;
2149 typedef pointer iterator;
2150 typedef const_pointer const_iterator;
2151 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
2152 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
2155 typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
2156 typedef allocator_traits<__storage_allocator> __storage_traits;
2157 typedef typename __storage_traits::pointer __storage_pointer;
2158 typedef typename __storage_traits::const_pointer __const_storage_pointer;
2160 __storage_pointer __begin_;
2162 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
2164 typedef __bit_reference<vector> reference;
2165 typedef __bit_const_reference<vector> const_reference;
2167 _LIBCPP_INLINE_VISIBILITY
2168 size_type& __cap() _NOEXCEPT
2169 {return __cap_alloc_.first();}
2170 _LIBCPP_INLINE_VISIBILITY
2171 const size_type& __cap() const _NOEXCEPT
2172 {return __cap_alloc_.first();}
2173 _LIBCPP_INLINE_VISIBILITY
2174 __storage_allocator& __alloc() _NOEXCEPT
2175 {return __cap_alloc_.second();}
2176 _LIBCPP_INLINE_VISIBILITY
2177 const __storage_allocator& __alloc() const _NOEXCEPT
2178 {return __cap_alloc_.second();}
2180 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2182 _LIBCPP_INLINE_VISIBILITY
2183 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
2184 {return __n * __bits_per_word;}
2185 _LIBCPP_INLINE_VISIBILITY
2186 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
2187 {return (__n - 1) / __bits_per_word + 1;}
2190 _LIBCPP_INLINE_VISIBILITY
2191 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
2193 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
2194 #if _LIBCPP_STD_VER <= 14
2195 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
2200 explicit vector(size_type __n);
2201 #if _LIBCPP_STD_VER > 11
2202 explicit vector(size_type __n, const allocator_type& __a);
2204 vector(size_type __n, const value_type& __v);
2205 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2206 template <class _InputIterator>
2207 vector(_InputIterator __first, _InputIterator __last,
2208 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2209 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2210 template <class _InputIterator>
2211 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2212 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2213 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2214 template <class _ForwardIterator>
2215 vector(_ForwardIterator __first, _ForwardIterator __last,
2216 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2217 template <class _ForwardIterator>
2218 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2219 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2221 vector(const vector& __v);
2222 vector(const vector& __v, const allocator_type& __a);
2223 vector& operator=(const vector& __v);
2224 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2225 vector(initializer_list<value_type> __il);
2226 vector(initializer_list<value_type> __il, const allocator_type& __a);
2227 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2229 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2230 _LIBCPP_INLINE_VISIBILITY
2231 vector(vector&& __v)
2232 #if _LIBCPP_STD_VER > 14
2235 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
2237 vector(vector&& __v, const allocator_type& __a);
2238 _LIBCPP_INLINE_VISIBILITY
2239 vector& operator=(vector&& __v)
2240 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
2241 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2242 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2243 _LIBCPP_INLINE_VISIBILITY
2244 vector& operator=(initializer_list<value_type> __il)
2245 {assign(__il.begin(), __il.end()); return *this;}
2246 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2248 template <class _InputIterator>
2251 __is_input_iterator<_InputIterator>::value &&
2252 !__is_forward_iterator<_InputIterator>::value,
2255 assign(_InputIterator __first, _InputIterator __last);
2256 template <class _ForwardIterator>
2259 __is_forward_iterator<_ForwardIterator>::value,
2262 assign(_ForwardIterator __first, _ForwardIterator __last);
2264 void assign(size_type __n, const value_type& __x);
2265 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2266 _LIBCPP_INLINE_VISIBILITY
2267 void assign(initializer_list<value_type> __il)
2268 {assign(__il.begin(), __il.end());}
2269 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2271 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
2272 {return allocator_type(this->__alloc());}
2274 size_type max_size() const _NOEXCEPT;
2275 _LIBCPP_INLINE_VISIBILITY
2276 size_type capacity() const _NOEXCEPT
2277 {return __internal_cap_to_external(__cap());}
2278 _LIBCPP_INLINE_VISIBILITY
2279 size_type size() const _NOEXCEPT
2281 _LIBCPP_INLINE_VISIBILITY
2282 bool empty() const _NOEXCEPT
2283 {return __size_ == 0;}
2284 void reserve(size_type __n);
2285 void shrink_to_fit() _NOEXCEPT;
2287 _LIBCPP_INLINE_VISIBILITY
2288 iterator begin() _NOEXCEPT
2289 {return __make_iter(0);}
2290 _LIBCPP_INLINE_VISIBILITY
2291 const_iterator begin() const _NOEXCEPT
2292 {return __make_iter(0);}
2293 _LIBCPP_INLINE_VISIBILITY
2294 iterator end() _NOEXCEPT
2295 {return __make_iter(__size_);}
2296 _LIBCPP_INLINE_VISIBILITY
2297 const_iterator end() const _NOEXCEPT
2298 {return __make_iter(__size_);}
2300 _LIBCPP_INLINE_VISIBILITY
2301 reverse_iterator rbegin() _NOEXCEPT
2302 {return reverse_iterator(end());}
2303 _LIBCPP_INLINE_VISIBILITY
2304 const_reverse_iterator rbegin() const _NOEXCEPT
2305 {return const_reverse_iterator(end());}
2306 _LIBCPP_INLINE_VISIBILITY
2307 reverse_iterator rend() _NOEXCEPT
2308 {return reverse_iterator(begin());}
2309 _LIBCPP_INLINE_VISIBILITY
2310 const_reverse_iterator rend() const _NOEXCEPT
2311 {return const_reverse_iterator(begin());}
2313 _LIBCPP_INLINE_VISIBILITY
2314 const_iterator cbegin() const _NOEXCEPT
2315 {return __make_iter(0);}
2316 _LIBCPP_INLINE_VISIBILITY
2317 const_iterator cend() const _NOEXCEPT
2318 {return __make_iter(__size_);}
2319 _LIBCPP_INLINE_VISIBILITY
2320 const_reverse_iterator crbegin() const _NOEXCEPT
2322 _LIBCPP_INLINE_VISIBILITY
2323 const_reverse_iterator crend() const _NOEXCEPT
2326 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2327 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2328 reference at(size_type __n);
2329 const_reference at(size_type __n) const;
2331 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2332 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2333 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2334 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2336 void push_back(const value_type& __x);
2337 #if _LIBCPP_STD_VER > 11
2338 template <class... _Args>
2339 _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args) {
2340 push_back ( value_type ( _VSTD::forward<_Args>(__args)... ));
2341 return this->back();
2345 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2347 #if _LIBCPP_STD_VER > 11
2348 template <class... _Args>
2349 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2350 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2353 iterator insert(const_iterator __position, const value_type& __x);
2354 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2355 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2356 template <class _InputIterator>
2359 __is_input_iterator <_InputIterator>::value &&
2360 !__is_forward_iterator<_InputIterator>::value,
2363 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2364 template <class _ForwardIterator>
2367 __is_forward_iterator<_ForwardIterator>::value,
2370 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
2371 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2372 _LIBCPP_INLINE_VISIBILITY
2373 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2374 {return insert(__position, __il.begin(), __il.end());}
2375 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2377 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
2378 iterator erase(const_iterator __first, const_iterator __last);
2380 _LIBCPP_INLINE_VISIBILITY
2381 void clear() _NOEXCEPT {__size_ = 0;}
2384 #if _LIBCPP_STD_VER >= 14
2387 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2388 __is_nothrow_swappable<allocator_type>::value);
2390 static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
2392 void resize(size_type __sz, value_type __x = false);
2393 void flip() _NOEXCEPT;
2395 bool __invariants() const;
2398 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
2399 void allocate(size_type __n);
2400 void deallocate() _NOEXCEPT;
2401 _LIBCPP_INLINE_VISIBILITY
2402 static size_type __align_it(size_type __new_size) _NOEXCEPT
2403 {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);};
2404 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2405 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
2406 template <class _ForwardIterator>
2409 __is_forward_iterator<_ForwardIterator>::value,
2412 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2413 void __append(size_type __n, const_reference __x);
2414 _LIBCPP_INLINE_VISIBILITY
2415 reference __make_ref(size_type __pos) _NOEXCEPT
2416 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2417 _LIBCPP_INLINE_VISIBILITY
2418 const_reference __make_ref(size_type __pos) const _NOEXCEPT
2419 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2420 _LIBCPP_INLINE_VISIBILITY
2421 iterator __make_iter(size_type __pos) _NOEXCEPT
2422 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2423 _LIBCPP_INLINE_VISIBILITY
2424 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
2425 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2426 _LIBCPP_INLINE_VISIBILITY
2427 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
2428 {return begin() + (__p - cbegin());}
2430 _LIBCPP_INLINE_VISIBILITY
2431 void __copy_assign_alloc(const vector& __v)
2432 {__copy_assign_alloc(__v, integral_constant<bool,
2433 __storage_traits::propagate_on_container_copy_assignment::value>());}
2434 _LIBCPP_INLINE_VISIBILITY
2435 void __copy_assign_alloc(const vector& __c, true_type)
2437 if (__alloc() != __c.__alloc())
2439 __alloc() = __c.__alloc();
2442 _LIBCPP_INLINE_VISIBILITY
2443 void __copy_assign_alloc(const vector&, false_type)
2446 void __move_assign(vector& __c, false_type);
2447 void __move_assign(vector& __c, true_type)
2448 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2449 _LIBCPP_INLINE_VISIBILITY
2450 void __move_assign_alloc(vector& __c)
2452 !__storage_traits::propagate_on_container_move_assignment::value ||
2453 is_nothrow_move_assignable<allocator_type>::value)
2454 {__move_assign_alloc(__c, integral_constant<bool,
2455 __storage_traits::propagate_on_container_move_assignment::value>());}
2456 _LIBCPP_INLINE_VISIBILITY
2457 void __move_assign_alloc(vector& __c, true_type)
2458 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2460 __alloc() = _VSTD::move(__c.__alloc());
2463 _LIBCPP_INLINE_VISIBILITY
2464 void __move_assign_alloc(vector&, false_type)
2468 size_t __hash_code() const _NOEXCEPT;
2470 friend class __bit_reference<vector>;
2471 friend class __bit_const_reference<vector>;
2472 friend class __bit_iterator<vector, false>;
2473 friend class __bit_iterator<vector, true>;
2474 friend struct __bit_array<vector>;
2475 friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
2478 template <class _Allocator>
2479 inline _LIBCPP_INLINE_VISIBILITY
2481 vector<bool, _Allocator>::__invalidate_all_iterators()
2485 // Allocate space for __n objects
2486 // throws length_error if __n > max_size()
2487 // throws (probably bad_alloc) if memory run out
2488 // Precondition: __begin_ == __end_ == __cap() == 0
2489 // Precondition: __n > 0
2490 // Postcondition: capacity() == __n
2491 // Postcondition: size() == 0
2492 template <class _Allocator>
2494 vector<bool, _Allocator>::allocate(size_type __n)
2496 if (__n > max_size())
2497 this->__throw_length_error();
2498 __n = __external_cap_to_internal(__n);
2499 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2501 this->__cap() = __n;
2504 template <class _Allocator>
2506 vector<bool, _Allocator>::deallocate() _NOEXCEPT
2508 if (this->__begin_ != nullptr)
2510 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2511 __invalidate_all_iterators();
2512 this->__begin_ = nullptr;
2513 this->__size_ = this->__cap() = 0;
2517 template <class _Allocator>
2518 typename vector<bool, _Allocator>::size_type
2519 vector<bool, _Allocator>::max_size() const _NOEXCEPT
2521 size_type __amax = __storage_traits::max_size(__alloc());
2522 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2523 if (__nmax / __bits_per_word <= __amax)
2525 return __internal_cap_to_external(__amax);
2528 // Precondition: __new_size > capacity()
2529 template <class _Allocator>
2530 inline _LIBCPP_INLINE_VISIBILITY
2531 typename vector<bool, _Allocator>::size_type
2532 vector<bool, _Allocator>::__recommend(size_type __new_size) const
2534 const size_type __ms = max_size();
2535 if (__new_size > __ms)
2536 this->__throw_length_error();
2537 const size_type __cap = capacity();
2538 if (__cap >= __ms / 2)
2540 return _VSTD::max(2*__cap, __align_it(__new_size));
2543 // Default constructs __n objects starting at __end_
2544 // Precondition: __n > 0
2545 // Precondition: size() + __n <= capacity()
2546 // Postcondition: size() == size() + __n
2547 template <class _Allocator>
2548 inline _LIBCPP_INLINE_VISIBILITY
2550 vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2552 size_type __old_size = this->__size_;
2553 this->__size_ += __n;
2554 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
2557 template <class _Allocator>
2558 template <class _ForwardIterator>
2561 __is_forward_iterator<_ForwardIterator>::value,
2564 vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2566 size_type __old_size = this->__size_;
2567 this->__size_ += _VSTD::distance(__first, __last);
2568 _VSTD::copy(__first, __last, __make_iter(__old_size));
2571 template <class _Allocator>
2572 inline _LIBCPP_INLINE_VISIBILITY
2573 vector<bool, _Allocator>::vector()
2574 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2575 : __begin_(nullptr),
2581 template <class _Allocator>
2582 inline _LIBCPP_INLINE_VISIBILITY
2583 vector<bool, _Allocator>::vector(const allocator_type& __a)
2584 #if _LIBCPP_STD_VER <= 14
2585 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
2589 : __begin_(nullptr),
2591 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2595 template <class _Allocator>
2596 vector<bool, _Allocator>::vector(size_type __n)
2597 : __begin_(nullptr),
2604 __construct_at_end(__n, false);
2608 #if _LIBCPP_STD_VER > 11
2609 template <class _Allocator>
2610 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2611 : __begin_(nullptr),
2613 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2618 __construct_at_end(__n, false);
2623 template <class _Allocator>
2624 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2625 : __begin_(nullptr),
2632 __construct_at_end(__n, __x);
2636 template <class _Allocator>
2637 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2638 : __begin_(nullptr),
2640 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2645 __construct_at_end(__n, __x);
2649 template <class _Allocator>
2650 template <class _InputIterator>
2651 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2652 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2653 !__is_forward_iterator<_InputIterator>::value>::type*)
2654 : __begin_(nullptr),
2658 #ifndef _LIBCPP_NO_EXCEPTIONS
2661 #endif // _LIBCPP_NO_EXCEPTIONS
2662 for (; __first != __last; ++__first)
2663 push_back(*__first);
2664 #ifndef _LIBCPP_NO_EXCEPTIONS
2668 if (__begin_ != nullptr)
2669 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2670 __invalidate_all_iterators();
2673 #endif // _LIBCPP_NO_EXCEPTIONS
2676 template <class _Allocator>
2677 template <class _InputIterator>
2678 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2679 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2680 !__is_forward_iterator<_InputIterator>::value>::type*)
2681 : __begin_(nullptr),
2683 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2685 #ifndef _LIBCPP_NO_EXCEPTIONS
2688 #endif // _LIBCPP_NO_EXCEPTIONS
2689 for (; __first != __last; ++__first)
2690 push_back(*__first);
2691 #ifndef _LIBCPP_NO_EXCEPTIONS
2695 if (__begin_ != nullptr)
2696 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2697 __invalidate_all_iterators();
2700 #endif // _LIBCPP_NO_EXCEPTIONS
2703 template <class _Allocator>
2704 template <class _ForwardIterator>
2705 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2706 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2707 : __begin_(nullptr),
2711 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2715 __construct_at_end(__first, __last);
2719 template <class _Allocator>
2720 template <class _ForwardIterator>
2721 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2722 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2723 : __begin_(nullptr),
2725 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2727 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2731 __construct_at_end(__first, __last);
2735 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2737 template <class _Allocator>
2738 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2739 : __begin_(nullptr),
2743 size_type __n = static_cast<size_type>(__il.size());
2747 __construct_at_end(__il.begin(), __il.end());
2751 template <class _Allocator>
2752 vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2753 : __begin_(nullptr),
2755 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2757 size_type __n = static_cast<size_type>(__il.size());
2761 __construct_at_end(__il.begin(), __il.end());
2765 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2767 template <class _Allocator>
2768 vector<bool, _Allocator>::~vector()
2770 if (__begin_ != nullptr)
2771 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2772 __invalidate_all_iterators();
2775 template <class _Allocator>
2776 vector<bool, _Allocator>::vector(const vector& __v)
2777 : __begin_(nullptr),
2779 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2783 allocate(__v.size());
2784 __construct_at_end(__v.begin(), __v.end());
2788 template <class _Allocator>
2789 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2790 : __begin_(nullptr),
2792 __cap_alloc_(0, __a)
2796 allocate(__v.size());
2797 __construct_at_end(__v.begin(), __v.end());
2801 template <class _Allocator>
2802 vector<bool, _Allocator>&
2803 vector<bool, _Allocator>::operator=(const vector& __v)
2807 __copy_assign_alloc(__v);
2810 if (__v.__size_ > capacity())
2813 allocate(__v.__size_);
2815 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2817 __size_ = __v.__size_;
2822 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2824 template <class _Allocator>
2825 inline _LIBCPP_INLINE_VISIBILITY
2826 vector<bool, _Allocator>::vector(vector&& __v)
2827 #if _LIBCPP_STD_VER > 14
2830 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2832 : __begin_(__v.__begin_),
2833 __size_(__v.__size_),
2834 __cap_alloc_(__v.__cap_alloc_)
2836 __v.__begin_ = nullptr;
2841 template <class _Allocator>
2842 vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2843 : __begin_(nullptr),
2845 __cap_alloc_(0, __a)
2847 if (__a == allocator_type(__v.__alloc()))
2849 this->__begin_ = __v.__begin_;
2850 this->__size_ = __v.__size_;
2851 this->__cap() = __v.__cap();
2852 __v.__begin_ = nullptr;
2853 __v.__cap() = __v.__size_ = 0;
2855 else if (__v.size() > 0)
2857 allocate(__v.size());
2858 __construct_at_end(__v.begin(), __v.end());
2862 template <class _Allocator>
2863 inline _LIBCPP_INLINE_VISIBILITY
2864 vector<bool, _Allocator>&
2865 vector<bool, _Allocator>::operator=(vector&& __v)
2866 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
2868 __move_assign(__v, integral_constant<bool,
2869 __storage_traits::propagate_on_container_move_assignment::value>());
2873 template <class _Allocator>
2875 vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2877 if (__alloc() != __c.__alloc())
2878 assign(__c.begin(), __c.end());
2880 __move_assign(__c, true_type());
2883 template <class _Allocator>
2885 vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2886 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2889 __move_assign_alloc(__c);
2890 this->__begin_ = __c.__begin_;
2891 this->__size_ = __c.__size_;
2892 this->__cap() = __c.__cap();
2893 __c.__begin_ = nullptr;
2894 __c.__cap() = __c.__size_ = 0;
2897 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2899 template <class _Allocator>
2901 vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2906 size_type __c = capacity();
2911 vector __v(__alloc());
2912 __v.reserve(__recommend(__n));
2916 _VSTD::fill_n(begin(), __n, __x);
2918 __invalidate_all_iterators();
2921 template <class _Allocator>
2922 template <class _InputIterator>
2925 __is_input_iterator<_InputIterator>::value &&
2926 !__is_forward_iterator<_InputIterator>::value,
2929 vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2932 for (; __first != __last; ++__first)
2933 push_back(*__first);
2936 template <class _Allocator>
2937 template <class _ForwardIterator>
2940 __is_forward_iterator<_ForwardIterator>::value,
2943 vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2946 difference_type __ns = _VSTD::distance(__first, __last);
2947 _LIBCPP_ASSERT(__ns >= 0, "invalid range specified");
2948 const size_t __n = static_cast<size_type>(__ns);
2951 if (__n > capacity())
2956 __construct_at_end(__first, __last);
2960 template <class _Allocator>
2962 vector<bool, _Allocator>::reserve(size_type __n)
2964 if (__n > capacity())
2966 vector __v(this->__alloc());
2968 __v.__construct_at_end(this->begin(), this->end());
2970 __invalidate_all_iterators();
2974 template <class _Allocator>
2976 vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
2978 if (__external_cap_to_internal(size()) > __cap())
2980 #ifndef _LIBCPP_NO_EXCEPTIONS
2983 #endif // _LIBCPP_NO_EXCEPTIONS
2984 vector(*this, allocator_type(__alloc())).swap(*this);
2985 #ifndef _LIBCPP_NO_EXCEPTIONS
2990 #endif // _LIBCPP_NO_EXCEPTIONS
2994 template <class _Allocator>
2995 typename vector<bool, _Allocator>::reference
2996 vector<bool, _Allocator>::at(size_type __n)
2999 this->__throw_out_of_range();
3000 return (*this)[__n];
3003 template <class _Allocator>
3004 typename vector<bool, _Allocator>::const_reference
3005 vector<bool, _Allocator>::at(size_type __n) const
3008 this->__throw_out_of_range();
3009 return (*this)[__n];
3012 template <class _Allocator>
3014 vector<bool, _Allocator>::push_back(const value_type& __x)
3016 if (this->__size_ == this->capacity())
3017 reserve(__recommend(this->__size_ + 1));
3022 template <class _Allocator>
3023 typename vector<bool, _Allocator>::iterator
3024 vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
3027 if (size() < capacity())
3029 const_iterator __old_end = end();
3031 _VSTD::copy_backward(__position, __old_end, end());
3032 __r = __const_iterator_cast(__position);
3036 vector __v(__alloc());
3037 __v.reserve(__recommend(__size_ + 1));
3038 __v.__size_ = __size_ + 1;
3039 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3040 _VSTD::copy_backward(__position, cend(), __v.end());
3047 template <class _Allocator>
3048 typename vector<bool, _Allocator>::iterator
3049 vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
3052 size_type __c = capacity();
3053 if (__n <= __c && size() <= __c - __n)
3055 const_iterator __old_end = end();
3057 _VSTD::copy_backward(__position, __old_end, end());
3058 __r = __const_iterator_cast(__position);
3062 vector __v(__alloc());
3063 __v.reserve(__recommend(__size_ + __n));
3064 __v.__size_ = __size_ + __n;
3065 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3066 _VSTD::copy_backward(__position, cend(), __v.end());
3069 _VSTD::fill_n(__r, __n, __x);
3073 template <class _Allocator>
3074 template <class _InputIterator>
3077 __is_input_iterator <_InputIterator>::value &&
3078 !__is_forward_iterator<_InputIterator>::value,
3079 typename vector<bool, _Allocator>::iterator
3081 vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
3083 difference_type __off = __position - begin();
3084 iterator __p = __const_iterator_cast(__position);
3085 iterator __old_end = end();
3086 for (; size() != capacity() && __first != __last; ++__first)
3091 vector __v(__alloc());
3092 if (__first != __last)
3094 #ifndef _LIBCPP_NO_EXCEPTIONS
3097 #endif // _LIBCPP_NO_EXCEPTIONS
3098 __v.assign(__first, __last);
3099 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
3100 difference_type __old_p = __p - begin();
3101 reserve(__recommend(size() + __v.size()));
3102 __p = begin() + __old_p;
3103 __old_end = begin() + __old_size;
3104 #ifndef _LIBCPP_NO_EXCEPTIONS
3108 erase(__old_end, end());
3111 #endif // _LIBCPP_NO_EXCEPTIONS
3113 __p = _VSTD::rotate(__p, __old_end, end());
3114 insert(__p, __v.begin(), __v.end());
3115 return begin() + __off;
3118 template <class _Allocator>
3119 template <class _ForwardIterator>
3122 __is_forward_iterator<_ForwardIterator>::value,
3123 typename vector<bool, _Allocator>::iterator
3125 vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
3127 const difference_type __n_signed = _VSTD::distance(__first, __last);
3128 _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified");
3129 const size_type __n = static_cast<size_type>(__n_signed);
3131 size_type __c = capacity();
3132 if (__n <= __c && size() <= __c - __n)
3134 const_iterator __old_end = end();
3136 _VSTD::copy_backward(__position, __old_end, end());
3137 __r = __const_iterator_cast(__position);
3141 vector __v(__alloc());
3142 __v.reserve(__recommend(__size_ + __n));
3143 __v.__size_ = __size_ + __n;
3144 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3145 _VSTD::copy_backward(__position, cend(), __v.end());
3148 _VSTD::copy(__first, __last, __r);
3152 template <class _Allocator>
3153 inline _LIBCPP_INLINE_VISIBILITY
3154 typename vector<bool, _Allocator>::iterator
3155 vector<bool, _Allocator>::erase(const_iterator __position)
3157 iterator __r = __const_iterator_cast(__position);
3158 _VSTD::copy(__position + 1, this->cend(), __r);
3163 template <class _Allocator>
3164 typename vector<bool, _Allocator>::iterator
3165 vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3167 iterator __r = __const_iterator_cast(__first);
3168 difference_type __d = __last - __first;
3169 _VSTD::copy(__last, this->cend(), __r);
3174 template <class _Allocator>
3176 vector<bool, _Allocator>::swap(vector& __x)
3177 #if _LIBCPP_STD_VER >= 14
3180 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3181 __is_nothrow_swappable<allocator_type>::value)
3184 _VSTD::swap(this->__begin_, __x.__begin_);
3185 _VSTD::swap(this->__size_, __x.__size_);
3186 _VSTD::swap(this->__cap(), __x.__cap());
3187 __swap_allocator(this->__alloc(), __x.__alloc(),
3188 integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
3191 template <class _Allocator>
3193 vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3195 size_type __cs = size();
3199 size_type __c = capacity();
3200 size_type __n = __sz - __cs;
3201 if (__n <= __c && __cs <= __c - __n)
3208 vector __v(__alloc());
3209 __v.reserve(__recommend(__size_ + __n));
3210 __v.__size_ = __size_ + __n;
3211 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
3214 _VSTD::fill_n(__r, __n, __x);
3220 template <class _Allocator>
3222 vector<bool, _Allocator>::flip() _NOEXCEPT
3224 // do middle whole words
3225 size_type __n = __size_;
3226 __storage_pointer __p = __begin_;
3227 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3229 // do last partial word
3232 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3233 __storage_type __b = *__p & __m;
3239 template <class _Allocator>
3241 vector<bool, _Allocator>::__invariants() const
3243 if (this->__begin_ == nullptr)
3245 if (this->__size_ != 0 || this->__cap() != 0)
3250 if (this->__cap() == 0)
3252 if (this->__size_ > this->capacity())
3258 template <class _Allocator>
3260 vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
3263 // do middle whole words
3264 size_type __n = __size_;
3265 __storage_pointer __p = __begin_;
3266 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3268 // do last partial word
3271 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3277 template <class _Allocator>
3278 struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
3279 : public unary_function<vector<bool, _Allocator>, size_t>
3281 _LIBCPP_INLINE_VISIBILITY
3282 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
3283 {return __vec.__hash_code();}
3286 template <class _Tp, class _Allocator>
3287 inline _LIBCPP_INLINE_VISIBILITY
3289 operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3291 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
3292 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3295 template <class _Tp, class _Allocator>
3296 inline _LIBCPP_INLINE_VISIBILITY
3298 operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3300 return !(__x == __y);
3303 template <class _Tp, class _Allocator>
3304 inline _LIBCPP_INLINE_VISIBILITY
3306 operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3308 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
3311 template <class _Tp, class _Allocator>
3312 inline _LIBCPP_INLINE_VISIBILITY
3314 operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3319 template <class _Tp, class _Allocator>
3320 inline _LIBCPP_INLINE_VISIBILITY
3322 operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3324 return !(__x < __y);
3327 template <class _Tp, class _Allocator>
3328 inline _LIBCPP_INLINE_VISIBILITY
3330 operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3332 return !(__y < __x);
3335 template <class _Tp, class _Allocator>
3336 inline _LIBCPP_INLINE_VISIBILITY
3338 swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
3339 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
3344 _LIBCPP_END_NAMESPACE_STD
3346 #endif // _LIBCPP_VECTOR