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 void 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> void 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 <__bit_reference>
266 #include <type_traits>
269 #include <initializer_list>
274 #include <__split_buffer>
275 #include <__functional_base>
277 #include <__undef_min_max>
281 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
282 #pragma GCC system_header
285 _LIBCPP_BEGIN_NAMESPACE_STD
288 class __vector_base_common
291 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
292 void __throw_length_error() const;
293 void __throw_out_of_range() const;
298 __vector_base_common<__b>::__throw_length_error() const
300 #ifndef _LIBCPP_NO_EXCEPTIONS
301 throw length_error("vector");
303 assert(!"vector length_error");
309 __vector_base_common<__b>::__throw_out_of_range() const
311 #ifndef _LIBCPP_NO_EXCEPTIONS
312 throw out_of_range("vector");
314 assert(!"vector out_of_range");
319 #pragma warning( push )
320 #pragma warning( disable: 4231 )
321 #endif // _LIBCPP_MSVC
322 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common<true>)
324 #pragma warning( pop )
325 #endif // _LIBCPP_MSVC
327 template <class _Tp, class _Allocator>
329 : protected __vector_base_common<true>
332 typedef _Tp value_type;
333 typedef _Allocator allocator_type;
334 typedef allocator_traits<allocator_type> __alloc_traits;
335 typedef value_type& reference;
336 typedef const value_type& const_reference;
337 typedef typename __alloc_traits::size_type size_type;
338 typedef typename __alloc_traits::difference_type difference_type;
339 typedef typename __alloc_traits::pointer pointer;
340 typedef typename __alloc_traits::const_pointer const_pointer;
341 typedef pointer iterator;
342 typedef const_pointer const_iterator;
346 __compressed_pair<pointer, allocator_type> __end_cap_;
348 _LIBCPP_INLINE_VISIBILITY
349 allocator_type& __alloc() _NOEXCEPT
350 {return __end_cap_.second();}
351 _LIBCPP_INLINE_VISIBILITY
352 const allocator_type& __alloc() const _NOEXCEPT
353 {return __end_cap_.second();}
354 _LIBCPP_INLINE_VISIBILITY
355 pointer& __end_cap() _NOEXCEPT
356 {return __end_cap_.first();}
357 _LIBCPP_INLINE_VISIBILITY
358 const pointer& __end_cap() const _NOEXCEPT
359 {return __end_cap_.first();}
361 _LIBCPP_INLINE_VISIBILITY
363 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
364 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
367 _LIBCPP_INLINE_VISIBILITY
368 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
369 _LIBCPP_INLINE_VISIBILITY
370 size_type capacity() const _NOEXCEPT
371 {return static_cast<size_type>(__end_cap() - __begin_);}
373 _LIBCPP_INLINE_VISIBILITY
374 void __destruct_at_end(pointer __new_last) _NOEXCEPT;
376 _LIBCPP_INLINE_VISIBILITY
377 void __copy_assign_alloc(const __vector_base& __c)
378 {__copy_assign_alloc(__c, integral_constant<bool,
379 __alloc_traits::propagate_on_container_copy_assignment::value>());}
381 _LIBCPP_INLINE_VISIBILITY
382 void __move_assign_alloc(__vector_base& __c)
384 !__alloc_traits::propagate_on_container_move_assignment::value ||
385 is_nothrow_move_assignable<allocator_type>::value)
386 {__move_assign_alloc(__c, integral_constant<bool,
387 __alloc_traits::propagate_on_container_move_assignment::value>());}
389 _LIBCPP_INLINE_VISIBILITY
390 void __copy_assign_alloc(const __vector_base& __c, true_type)
392 if (__alloc() != __c.__alloc())
395 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
396 __begin_ = __end_ = __end_cap() = nullptr;
398 __alloc() = __c.__alloc();
401 _LIBCPP_INLINE_VISIBILITY
402 void __copy_assign_alloc(const __vector_base&, false_type)
405 _LIBCPP_INLINE_VISIBILITY
406 void __move_assign_alloc(__vector_base& __c, true_type)
407 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
409 __alloc() = _VSTD::move(__c.__alloc());
412 _LIBCPP_INLINE_VISIBILITY
413 void __move_assign_alloc(__vector_base&, false_type)
418 template <class _Tp, class _Allocator>
419 inline _LIBCPP_INLINE_VISIBILITY
421 __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
423 while (__new_last != __end_)
424 __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
427 template <class _Tp, class _Allocator>
428 inline _LIBCPP_INLINE_VISIBILITY
429 __vector_base<_Tp, _Allocator>::__vector_base()
430 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
437 template <class _Tp, class _Allocator>
438 inline _LIBCPP_INLINE_VISIBILITY
439 __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
442 __end_cap_(nullptr, __a)
446 template <class _Tp, class _Allocator>
447 __vector_base<_Tp, _Allocator>::~__vector_base()
449 if (__begin_ != nullptr)
452 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
456 template <class _Tp, class _Allocator = allocator<_Tp> >
457 class _LIBCPP_TYPE_VIS_ONLY vector
458 : private __vector_base<_Tp, _Allocator>
461 typedef __vector_base<_Tp, _Allocator> __base;
462 typedef allocator<_Tp> __default_allocator_type;
464 typedef vector __self;
465 typedef _Tp value_type;
466 typedef _Allocator allocator_type;
467 typedef typename __base::__alloc_traits __alloc_traits;
468 typedef typename __base::reference reference;
469 typedef typename __base::const_reference const_reference;
470 typedef typename __base::size_type size_type;
471 typedef typename __base::difference_type difference_type;
472 typedef typename __base::pointer pointer;
473 typedef typename __base::const_pointer const_pointer;
474 typedef __wrap_iter<pointer> iterator;
475 typedef __wrap_iter<const_pointer> const_iterator;
476 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
477 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
479 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
480 "Allocator::value_type must be same type as value_type");
482 _LIBCPP_INLINE_VISIBILITY
483 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
485 #if _LIBCPP_DEBUG_LEVEL >= 2
486 __get_db()->__insert_c(this);
489 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
490 #if _LIBCPP_STD_VER <= 14
491 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
497 #if _LIBCPP_DEBUG_LEVEL >= 2
498 __get_db()->__insert_c(this);
501 explicit vector(size_type __n);
502 #if _LIBCPP_STD_VER > 11
503 explicit vector(size_type __n, const allocator_type& __a);
505 vector(size_type __n, const_reference __x);
506 vector(size_type __n, const_reference __x, const allocator_type& __a);
507 template <class _InputIterator>
508 vector(_InputIterator __first,
509 typename enable_if<__is_input_iterator <_InputIterator>::value &&
510 !__is_forward_iterator<_InputIterator>::value &&
513 typename iterator_traits<_InputIterator>::reference>::value,
514 _InputIterator>::type __last);
515 template <class _InputIterator>
516 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
517 typename enable_if<__is_input_iterator <_InputIterator>::value &&
518 !__is_forward_iterator<_InputIterator>::value &&
521 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
522 template <class _ForwardIterator>
523 vector(_ForwardIterator __first,
524 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
527 typename iterator_traits<_ForwardIterator>::reference>::value,
528 _ForwardIterator>::type __last);
529 template <class _ForwardIterator>
530 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
531 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
534 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
535 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
536 _LIBCPP_INLINE_VISIBILITY
537 vector(initializer_list<value_type> __il);
538 _LIBCPP_INLINE_VISIBILITY
539 vector(initializer_list<value_type> __il, const allocator_type& __a);
540 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
541 #if _LIBCPP_DEBUG_LEVEL >= 2
542 _LIBCPP_INLINE_VISIBILITY
545 __get_db()->__erase_c(this);
549 vector(const vector& __x);
550 vector(const vector& __x, const allocator_type& __a);
551 _LIBCPP_INLINE_VISIBILITY
552 vector& operator=(const vector& __x);
553 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
554 _LIBCPP_INLINE_VISIBILITY
556 #if _LIBCPP_STD_VER > 14
559 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
561 _LIBCPP_INLINE_VISIBILITY
562 vector(vector&& __x, const allocator_type& __a);
563 _LIBCPP_INLINE_VISIBILITY
564 vector& operator=(vector&& __x)
565 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
566 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
567 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
568 _LIBCPP_INLINE_VISIBILITY
569 vector& operator=(initializer_list<value_type> __il)
570 {assign(__il.begin(), __il.end()); return *this;}
571 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
573 template <class _InputIterator>
576 __is_input_iterator <_InputIterator>::value &&
577 !__is_forward_iterator<_InputIterator>::value &&
580 typename iterator_traits<_InputIterator>::reference>::value,
583 assign(_InputIterator __first, _InputIterator __last);
584 template <class _ForwardIterator>
587 __is_forward_iterator<_ForwardIterator>::value &&
590 typename iterator_traits<_ForwardIterator>::reference>::value,
593 assign(_ForwardIterator __first, _ForwardIterator __last);
595 void assign(size_type __n, const_reference __u);
596 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
597 _LIBCPP_INLINE_VISIBILITY
598 void assign(initializer_list<value_type> __il)
599 {assign(__il.begin(), __il.end());}
600 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
602 _LIBCPP_INLINE_VISIBILITY
603 allocator_type get_allocator() const _NOEXCEPT
604 {return this->__alloc();}
606 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
607 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
608 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
609 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
611 _LIBCPP_INLINE_VISIBILITY
612 reverse_iterator rbegin() _NOEXCEPT
613 {return reverse_iterator(end());}
614 _LIBCPP_INLINE_VISIBILITY
615 const_reverse_iterator rbegin() const _NOEXCEPT
616 {return const_reverse_iterator(end());}
617 _LIBCPP_INLINE_VISIBILITY
618 reverse_iterator rend() _NOEXCEPT
619 {return reverse_iterator(begin());}
620 _LIBCPP_INLINE_VISIBILITY
621 const_reverse_iterator rend() const _NOEXCEPT
622 {return const_reverse_iterator(begin());}
624 _LIBCPP_INLINE_VISIBILITY
625 const_iterator cbegin() const _NOEXCEPT
627 _LIBCPP_INLINE_VISIBILITY
628 const_iterator cend() const _NOEXCEPT
630 _LIBCPP_INLINE_VISIBILITY
631 const_reverse_iterator crbegin() const _NOEXCEPT
633 _LIBCPP_INLINE_VISIBILITY
634 const_reverse_iterator crend() const _NOEXCEPT
637 _LIBCPP_INLINE_VISIBILITY
638 size_type size() const _NOEXCEPT
639 {return static_cast<size_type>(this->__end_ - this->__begin_);}
640 _LIBCPP_INLINE_VISIBILITY
641 size_type capacity() const _NOEXCEPT
642 {return __base::capacity();}
643 _LIBCPP_INLINE_VISIBILITY
644 bool empty() const _NOEXCEPT
645 {return this->__begin_ == this->__end_;}
646 size_type max_size() const _NOEXCEPT;
647 void reserve(size_type __n);
648 void shrink_to_fit() _NOEXCEPT;
650 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
651 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
652 reference at(size_type __n);
653 const_reference at(size_type __n) const;
655 _LIBCPP_INLINE_VISIBILITY reference front()
657 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
658 return *this->__begin_;
660 _LIBCPP_INLINE_VISIBILITY const_reference front() const
662 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
663 return *this->__begin_;
665 _LIBCPP_INLINE_VISIBILITY reference back()
667 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
668 return *(this->__end_ - 1);
670 _LIBCPP_INLINE_VISIBILITY const_reference back() const
672 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
673 return *(this->__end_ - 1);
676 _LIBCPP_INLINE_VISIBILITY
677 value_type* data() _NOEXCEPT
678 {return _VSTD::__to_raw_pointer(this->__begin_);}
679 _LIBCPP_INLINE_VISIBILITY
680 const value_type* data() const _NOEXCEPT
681 {return _VSTD::__to_raw_pointer(this->__begin_);}
683 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
684 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
685 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
686 #ifndef _LIBCPP_HAS_NO_VARIADICS
687 template <class... _Args>
688 void emplace_back(_Args&&... __args);
689 #endif // _LIBCPP_HAS_NO_VARIADICS
690 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
693 iterator insert(const_iterator __position, const_reference __x);
694 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
695 iterator insert(const_iterator __position, value_type&& __x);
696 #ifndef _LIBCPP_HAS_NO_VARIADICS
697 template <class... _Args>
698 iterator emplace(const_iterator __position, _Args&&... __args);
699 #endif // _LIBCPP_HAS_NO_VARIADICS
700 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
701 iterator insert(const_iterator __position, size_type __n, const_reference __x);
702 template <class _InputIterator>
705 __is_input_iterator <_InputIterator>::value &&
706 !__is_forward_iterator<_InputIterator>::value &&
709 typename iterator_traits<_InputIterator>::reference>::value,
712 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
713 template <class _ForwardIterator>
716 __is_forward_iterator<_ForwardIterator>::value &&
719 typename iterator_traits<_ForwardIterator>::reference>::value,
722 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
723 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
724 _LIBCPP_INLINE_VISIBILITY
725 iterator insert(const_iterator __position, initializer_list<value_type> __il)
726 {return insert(__position, __il.begin(), __il.end());}
727 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
729 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
730 iterator erase(const_iterator __first, const_iterator __last);
732 _LIBCPP_INLINE_VISIBILITY
733 void clear() _NOEXCEPT
735 size_type __old_size = size();
737 __annotate_shrink(__old_size);
738 __invalidate_all_iterators();
741 void resize(size_type __sz);
742 void resize(size_type __sz, const_reference __x);
745 #if _LIBCPP_STD_VER >= 14
748 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
749 __is_nothrow_swappable<allocator_type>::value);
752 bool __invariants() const;
754 #if _LIBCPP_DEBUG_LEVEL >= 2
756 bool __dereferenceable(const const_iterator* __i) const;
757 bool __decrementable(const const_iterator* __i) const;
758 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
759 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
761 #endif // _LIBCPP_DEBUG_LEVEL >= 2
764 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
765 void allocate(size_type __n);
766 void deallocate() _NOEXCEPT;
767 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
768 void __construct_at_end(size_type __n);
769 void __construct_at_end(size_type __n, const_reference __x);
770 template <class _ForwardIterator>
773 __is_forward_iterator<_ForwardIterator>::value,
776 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
777 void __append(size_type __n);
778 void __append(size_type __n, const_reference __x);
779 _LIBCPP_INLINE_VISIBILITY
780 iterator __make_iter(pointer __p) _NOEXCEPT;
781 _LIBCPP_INLINE_VISIBILITY
782 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
783 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
784 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
785 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
786 void __move_assign(vector& __c, true_type)
787 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
788 void __move_assign(vector& __c, false_type)
789 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
790 _LIBCPP_INLINE_VISIBILITY
791 void __destruct_at_end(pointer __new_last) _NOEXCEPT
793 #if _LIBCPP_DEBUG_LEVEL >= 2
794 __c_node* __c = __get_db()->__find_c_and_lock(this);
795 for (__i_node** __p = __c->end_; __p != __c->beg_; )
798 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
799 if (__i->base() > __new_last)
801 (*__p)->__c_ = nullptr;
802 if (--__c->end_ != __p)
803 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
806 __get_db()->unlock();
808 size_type __old_size = size();
809 __base::__destruct_at_end(__new_last);
810 __annotate_shrink(__old_size);
814 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
815 __push_back_slow_path(_Up&& __x);
817 __push_back_slow_path(_Up& __x);
819 #if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
820 template <class... _Args>
822 __emplace_back_slow_path(_Args&&... __args);
824 // The following functions are no-ops outside of AddressSanitizer mode.
825 // We call annotatations only for the default Allocator because other allocators
826 // may not meet the AddressSanitizer alignment constraints.
827 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
828 void __annotate_contiguous_container
829 (const void *__beg, const void *__end, const void *__old_mid, const void *__new_mid) const
831 #ifndef _LIBCPP_HAS_NO_ASAN
832 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
833 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
837 void __annotate_new(size_type __current_size) const
839 __annotate_contiguous_container(data(), data() + capacity(),
840 data() + capacity(), data() + __current_size);
842 void __annotate_delete() const
844 __annotate_contiguous_container(data(), data() + capacity(),
845 data() + size(), data() + capacity());
847 void __annotate_increase(size_type __n) const
849 __annotate_contiguous_container(data(), data() + capacity(),
850 data() + size(), data() + size() + __n);
852 void __annotate_shrink(size_type __old_size) const
854 __annotate_contiguous_container(data(), data() + capacity(),
855 data() + __old_size, data() + size());
857 #ifndef _LIBCPP_HAS_NO_ASAN
858 // The annotation for size increase should happen before the actual increase,
859 // but if an exception is thrown after that the annotation has to be undone.
860 struct __RAII_IncreaseAnnotator {
861 __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1)
862 : __commit(false), __v(__v), __old_size(__v.size() + __n) {
863 __v.__annotate_increase(__n);
865 void __done() { __commit = true; }
866 ~__RAII_IncreaseAnnotator() {
867 if (__commit) return;
868 __v.__annotate_shrink(__old_size);
872 size_type __old_size;
875 struct __RAII_IncreaseAnnotator {
876 inline __RAII_IncreaseAnnotator(const vector &, size_type __n = 1) {}
877 inline void __done() {}
883 template <class _Tp, class _Allocator>
885 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
888 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
889 _VSTD::swap(this->__begin_, __v.__begin_);
890 _VSTD::swap(this->__end_, __v.__end_);
891 _VSTD::swap(this->__end_cap(), __v.__end_cap());
892 __v.__first_ = __v.__begin_;
893 __annotate_new(size());
894 __invalidate_all_iterators();
897 template <class _Tp, class _Allocator>
898 typename vector<_Tp, _Allocator>::pointer
899 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
902 pointer __r = __v.__begin_;
903 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
904 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
905 _VSTD::swap(this->__begin_, __v.__begin_);
906 _VSTD::swap(this->__end_, __v.__end_);
907 _VSTD::swap(this->__end_cap(), __v.__end_cap());
908 __v.__first_ = __v.__begin_;
909 __annotate_new(size());
910 __invalidate_all_iterators();
914 // Allocate space for __n objects
915 // throws length_error if __n > max_size()
916 // throws (probably bad_alloc) if memory run out
917 // Precondition: __begin_ == __end_ == __end_cap() == 0
918 // Precondition: __n > 0
919 // Postcondition: capacity() == __n
920 // Postcondition: size() == 0
921 template <class _Tp, class _Allocator>
923 vector<_Tp, _Allocator>::allocate(size_type __n)
925 if (__n > max_size())
926 this->__throw_length_error();
927 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
928 this->__end_cap() = this->__begin_ + __n;
932 template <class _Tp, class _Allocator>
934 vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
936 if (this->__begin_ != nullptr)
939 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
940 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
944 template <class _Tp, class _Allocator>
945 typename vector<_Tp, _Allocator>::size_type
946 vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
948 return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2); // end() >= begin(), always
951 // Precondition: __new_size > capacity()
952 template <class _Tp, class _Allocator>
953 inline _LIBCPP_INLINE_VISIBILITY
954 typename vector<_Tp, _Allocator>::size_type
955 vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
957 const size_type __ms = max_size();
958 if (__new_size > __ms)
959 this->__throw_length_error();
960 const size_type __cap = capacity();
961 if (__cap >= __ms / 2)
963 return _VSTD::max<size_type>(2*__cap, __new_size);
966 // Default constructs __n objects starting at __end_
967 // throws if construction throws
968 // Precondition: __n > 0
969 // Precondition: size() + __n <= capacity()
970 // Postcondition: size() == size() + __n
971 template <class _Tp, class _Allocator>
973 vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
975 allocator_type& __a = this->__alloc();
978 __RAII_IncreaseAnnotator __annotator(*this);
979 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
982 __annotator.__done();
986 // Copy constructs __n objects starting at __end_ from __x
987 // throws if construction throws
988 // Precondition: __n > 0
989 // Precondition: size() + __n <= capacity()
990 // Postcondition: size() == old size() + __n
991 // Postcondition: [i] == __x for all i in [size() - __n, __n)
992 template <class _Tp, class _Allocator>
993 inline _LIBCPP_INLINE_VISIBILITY
995 vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
997 allocator_type& __a = this->__alloc();
1000 __RAII_IncreaseAnnotator __annotator(*this);
1001 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
1004 __annotator.__done();
1008 template <class _Tp, class _Allocator>
1009 template <class _ForwardIterator>
1012 __is_forward_iterator<_ForwardIterator>::value,
1015 vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
1017 allocator_type& __a = this->__alloc();
1018 __RAII_IncreaseAnnotator __annotator(*this, __n);
1019 __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_);
1020 __annotator.__done();
1023 // Default constructs __n objects starting at __end_
1024 // throws if construction throws
1025 // Postcondition: size() == size() + __n
1026 // Exception safety: strong.
1027 template <class _Tp, class _Allocator>
1029 vector<_Tp, _Allocator>::__append(size_type __n)
1031 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1032 this->__construct_at_end(__n);
1035 allocator_type& __a = this->__alloc();
1036 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1037 __v.__construct_at_end(__n);
1038 __swap_out_circular_buffer(__v);
1042 // Default constructs __n objects starting at __end_
1043 // throws if construction throws
1044 // Postcondition: size() == size() + __n
1045 // Exception safety: strong.
1046 template <class _Tp, class _Allocator>
1048 vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1050 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1051 this->__construct_at_end(__n, __x);
1054 allocator_type& __a = this->__alloc();
1055 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1056 __v.__construct_at_end(__n, __x);
1057 __swap_out_circular_buffer(__v);
1061 template <class _Tp, class _Allocator>
1062 vector<_Tp, _Allocator>::vector(size_type __n)
1064 #if _LIBCPP_DEBUG_LEVEL >= 2
1065 __get_db()->__insert_c(this);
1070 __construct_at_end(__n);
1074 #if _LIBCPP_STD_VER > 11
1075 template <class _Tp, class _Allocator>
1076 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1079 #if _LIBCPP_DEBUG_LEVEL >= 2
1080 __get_db()->__insert_c(this);
1085 __construct_at_end(__n);
1090 template <class _Tp, class _Allocator>
1091 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1093 #if _LIBCPP_DEBUG_LEVEL >= 2
1094 __get_db()->__insert_c(this);
1099 __construct_at_end(__n, __x);
1103 template <class _Tp, class _Allocator>
1104 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1107 #if _LIBCPP_DEBUG_LEVEL >= 2
1108 __get_db()->__insert_c(this);
1113 __construct_at_end(__n, __x);
1117 template <class _Tp, class _Allocator>
1118 template <class _InputIterator>
1119 vector<_Tp, _Allocator>::vector(_InputIterator __first,
1120 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1121 !__is_forward_iterator<_InputIterator>::value &&
1124 typename iterator_traits<_InputIterator>::reference>::value,
1125 _InputIterator>::type __last)
1127 #if _LIBCPP_DEBUG_LEVEL >= 2
1128 __get_db()->__insert_c(this);
1130 for (; __first != __last; ++__first)
1131 push_back(*__first);
1134 template <class _Tp, class _Allocator>
1135 template <class _InputIterator>
1136 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1137 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1138 !__is_forward_iterator<_InputIterator>::value &&
1141 typename iterator_traits<_InputIterator>::reference>::value>::type*)
1144 #if _LIBCPP_DEBUG_LEVEL >= 2
1145 __get_db()->__insert_c(this);
1147 for (; __first != __last; ++__first)
1148 push_back(*__first);
1151 template <class _Tp, class _Allocator>
1152 template <class _ForwardIterator>
1153 vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
1154 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1157 typename iterator_traits<_ForwardIterator>::reference>::value,
1158 _ForwardIterator>::type __last)
1160 #if _LIBCPP_DEBUG_LEVEL >= 2
1161 __get_db()->__insert_c(this);
1163 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1167 __construct_at_end(__first, __last, __n);
1171 template <class _Tp, class _Allocator>
1172 template <class _ForwardIterator>
1173 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1174 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1177 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1180 #if _LIBCPP_DEBUG_LEVEL >= 2
1181 __get_db()->__insert_c(this);
1183 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1187 __construct_at_end(__first, __last, __n);
1191 template <class _Tp, class _Allocator>
1192 vector<_Tp, _Allocator>::vector(const vector& __x)
1193 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1195 #if _LIBCPP_DEBUG_LEVEL >= 2
1196 __get_db()->__insert_c(this);
1198 size_type __n = __x.size();
1202 __construct_at_end(__x.__begin_, __x.__end_, __n);
1206 template <class _Tp, class _Allocator>
1207 vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1210 #if _LIBCPP_DEBUG_LEVEL >= 2
1211 __get_db()->__insert_c(this);
1213 size_type __n = __x.size();
1217 __construct_at_end(__x.__begin_, __x.__end_, __n);
1221 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1223 template <class _Tp, class _Allocator>
1224 inline _LIBCPP_INLINE_VISIBILITY
1225 vector<_Tp, _Allocator>::vector(vector&& __x)
1226 #if _LIBCPP_STD_VER > 14
1229 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1231 : __base(_VSTD::move(__x.__alloc()))
1233 #if _LIBCPP_DEBUG_LEVEL >= 2
1234 __get_db()->__insert_c(this);
1235 __get_db()->swap(this, &__x);
1237 this->__begin_ = __x.__begin_;
1238 this->__end_ = __x.__end_;
1239 this->__end_cap() = __x.__end_cap();
1240 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1243 template <class _Tp, class _Allocator>
1244 inline _LIBCPP_INLINE_VISIBILITY
1245 vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1248 #if _LIBCPP_DEBUG_LEVEL >= 2
1249 __get_db()->__insert_c(this);
1251 if (__a == __x.__alloc())
1253 this->__begin_ = __x.__begin_;
1254 this->__end_ = __x.__end_;
1255 this->__end_cap() = __x.__end_cap();
1256 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1257 #if _LIBCPP_DEBUG_LEVEL >= 2
1258 __get_db()->swap(this, &__x);
1263 typedef move_iterator<iterator> _Ip;
1264 assign(_Ip(__x.begin()), _Ip(__x.end()));
1268 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1270 template <class _Tp, class _Allocator>
1271 inline _LIBCPP_INLINE_VISIBILITY
1272 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1274 #if _LIBCPP_DEBUG_LEVEL >= 2
1275 __get_db()->__insert_c(this);
1277 if (__il.size() > 0)
1279 allocate(__il.size());
1280 __construct_at_end(__il.begin(), __il.end(), __il.size());
1284 template <class _Tp, class _Allocator>
1285 inline _LIBCPP_INLINE_VISIBILITY
1286 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1289 #if _LIBCPP_DEBUG_LEVEL >= 2
1290 __get_db()->__insert_c(this);
1292 if (__il.size() > 0)
1294 allocate(__il.size());
1295 __construct_at_end(__il.begin(), __il.end(), __il.size());
1299 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1301 template <class _Tp, class _Allocator>
1302 inline _LIBCPP_INLINE_VISIBILITY
1303 vector<_Tp, _Allocator>&
1304 vector<_Tp, _Allocator>::operator=(vector&& __x)
1305 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
1307 __move_assign(__x, integral_constant<bool,
1308 __alloc_traits::propagate_on_container_move_assignment::value>());
1312 template <class _Tp, class _Allocator>
1314 vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1315 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
1317 if (__base::__alloc() != __c.__alloc())
1319 typedef move_iterator<iterator> _Ip;
1320 assign(_Ip(__c.begin()), _Ip(__c.end()));
1323 __move_assign(__c, true_type());
1326 template <class _Tp, class _Allocator>
1328 vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1329 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1332 __base::__move_assign_alloc(__c); // this can throw
1333 this->__begin_ = __c.__begin_;
1334 this->__end_ = __c.__end_;
1335 this->__end_cap() = __c.__end_cap();
1336 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1337 #if _LIBCPP_DEBUG_LEVEL >= 2
1338 __get_db()->swap(this, &__c);
1342 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1344 template <class _Tp, class _Allocator>
1345 inline _LIBCPP_INLINE_VISIBILITY
1346 vector<_Tp, _Allocator>&
1347 vector<_Tp, _Allocator>::operator=(const vector& __x)
1351 __base::__copy_assign_alloc(__x);
1352 assign(__x.__begin_, __x.__end_);
1357 template <class _Tp, class _Allocator>
1358 template <class _InputIterator>
1361 __is_input_iterator <_InputIterator>::value &&
1362 !__is_forward_iterator<_InputIterator>::value &&
1365 typename iterator_traits<_InputIterator>::reference>::value,
1368 vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1371 for (; __first != __last; ++__first)
1372 push_back(*__first);
1375 template <class _Tp, class _Allocator>
1376 template <class _ForwardIterator>
1379 __is_forward_iterator<_ForwardIterator>::value &&
1382 typename iterator_traits<_ForwardIterator>::reference>::value,
1385 vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1387 size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
1388 if (__new_size <= capacity())
1390 _ForwardIterator __mid = __last;
1391 bool __growing = false;
1392 if (__new_size > size())
1396 _VSTD::advance(__mid, size());
1398 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
1400 __construct_at_end(__mid, __last, __new_size - size());
1402 this->__destruct_at_end(__m);
1407 allocate(__recommend(__new_size));
1408 __construct_at_end(__first, __last, __new_size);
1412 template <class _Tp, class _Allocator>
1414 vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1416 if (__n <= capacity())
1418 size_type __s = size();
1419 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
1421 __construct_at_end(__n - __s, __u);
1423 this->__destruct_at_end(this->__begin_ + __n);
1428 allocate(__recommend(static_cast<size_type>(__n)));
1429 __construct_at_end(__n, __u);
1433 template <class _Tp, class _Allocator>
1434 inline _LIBCPP_INLINE_VISIBILITY
1435 typename vector<_Tp, _Allocator>::iterator
1436 vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
1438 #if _LIBCPP_DEBUG_LEVEL >= 2
1439 return iterator(this, __p);
1441 return iterator(__p);
1445 template <class _Tp, class _Allocator>
1446 inline _LIBCPP_INLINE_VISIBILITY
1447 typename vector<_Tp, _Allocator>::const_iterator
1448 vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
1450 #if _LIBCPP_DEBUG_LEVEL >= 2
1451 return const_iterator(this, __p);
1453 return const_iterator(__p);
1457 template <class _Tp, class _Allocator>
1458 inline _LIBCPP_INLINE_VISIBILITY
1459 typename vector<_Tp, _Allocator>::iterator
1460 vector<_Tp, _Allocator>::begin() _NOEXCEPT
1462 return __make_iter(this->__begin_);
1465 template <class _Tp, class _Allocator>
1466 inline _LIBCPP_INLINE_VISIBILITY
1467 typename vector<_Tp, _Allocator>::const_iterator
1468 vector<_Tp, _Allocator>::begin() const _NOEXCEPT
1470 return __make_iter(this->__begin_);
1473 template <class _Tp, class _Allocator>
1474 inline _LIBCPP_INLINE_VISIBILITY
1475 typename vector<_Tp, _Allocator>::iterator
1476 vector<_Tp, _Allocator>::end() _NOEXCEPT
1478 return __make_iter(this->__end_);
1481 template <class _Tp, class _Allocator>
1482 inline _LIBCPP_INLINE_VISIBILITY
1483 typename vector<_Tp, _Allocator>::const_iterator
1484 vector<_Tp, _Allocator>::end() const _NOEXCEPT
1486 return __make_iter(this->__end_);
1489 template <class _Tp, class _Allocator>
1490 inline _LIBCPP_INLINE_VISIBILITY
1491 typename vector<_Tp, _Allocator>::reference
1492 vector<_Tp, _Allocator>::operator[](size_type __n)
1494 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1495 return this->__begin_[__n];
1498 template <class _Tp, class _Allocator>
1499 inline _LIBCPP_INLINE_VISIBILITY
1500 typename vector<_Tp, _Allocator>::const_reference
1501 vector<_Tp, _Allocator>::operator[](size_type __n) const
1503 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1504 return this->__begin_[__n];
1507 template <class _Tp, class _Allocator>
1508 typename vector<_Tp, _Allocator>::reference
1509 vector<_Tp, _Allocator>::at(size_type __n)
1512 this->__throw_out_of_range();
1513 return this->__begin_[__n];
1516 template <class _Tp, class _Allocator>
1517 typename vector<_Tp, _Allocator>::const_reference
1518 vector<_Tp, _Allocator>::at(size_type __n) const
1521 this->__throw_out_of_range();
1522 return this->__begin_[__n];
1525 template <class _Tp, class _Allocator>
1527 vector<_Tp, _Allocator>::reserve(size_type __n)
1529 if (__n > capacity())
1531 allocator_type& __a = this->__alloc();
1532 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
1533 __swap_out_circular_buffer(__v);
1537 template <class _Tp, class _Allocator>
1539 vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1541 if (capacity() > size())
1543 #ifndef _LIBCPP_NO_EXCEPTIONS
1546 #endif // _LIBCPP_NO_EXCEPTIONS
1547 allocator_type& __a = this->__alloc();
1548 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1549 __swap_out_circular_buffer(__v);
1550 #ifndef _LIBCPP_NO_EXCEPTIONS
1555 #endif // _LIBCPP_NO_EXCEPTIONS
1559 template <class _Tp, class _Allocator>
1560 template <class _Up>
1562 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1563 vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1565 vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1568 allocator_type& __a = this->__alloc();
1569 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1570 // __v.push_back(_VSTD::forward<_Up>(__x));
1571 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
1573 __swap_out_circular_buffer(__v);
1576 template <class _Tp, class _Allocator>
1577 inline _LIBCPP_INLINE_VISIBILITY
1579 vector<_Tp, _Allocator>::push_back(const_reference __x)
1581 if (this->__end_ != this->__end_cap())
1583 __RAII_IncreaseAnnotator __annotator(*this);
1584 __alloc_traits::construct(this->__alloc(),
1585 _VSTD::__to_raw_pointer(this->__end_), __x);
1586 __annotator.__done();
1590 __push_back_slow_path(__x);
1593 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1595 template <class _Tp, class _Allocator>
1596 inline _LIBCPP_INLINE_VISIBILITY
1598 vector<_Tp, _Allocator>::push_back(value_type&& __x)
1600 if (this->__end_ < this->__end_cap())
1602 __RAII_IncreaseAnnotator __annotator(*this);
1603 __alloc_traits::construct(this->__alloc(),
1604 _VSTD::__to_raw_pointer(this->__end_),
1606 __annotator.__done();
1610 __push_back_slow_path(_VSTD::move(__x));
1613 #ifndef _LIBCPP_HAS_NO_VARIADICS
1615 template <class _Tp, class _Allocator>
1616 template <class... _Args>
1618 vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1620 allocator_type& __a = this->__alloc();
1621 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1622 // __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1623 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
1625 __swap_out_circular_buffer(__v);
1628 template <class _Tp, class _Allocator>
1629 template <class... _Args>
1630 inline _LIBCPP_INLINE_VISIBILITY
1632 vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1634 if (this->__end_ < this->__end_cap())
1636 __RAII_IncreaseAnnotator __annotator(*this);
1637 __alloc_traits::construct(this->__alloc(),
1638 _VSTD::__to_raw_pointer(this->__end_),
1639 _VSTD::forward<_Args>(__args)...);
1640 __annotator.__done();
1644 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
1647 #endif // _LIBCPP_HAS_NO_VARIADICS
1648 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1650 template <class _Tp, class _Allocator>
1651 inline _LIBCPP_INLINE_VISIBILITY
1653 vector<_Tp, _Allocator>::pop_back()
1655 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
1656 this->__destruct_at_end(this->__end_ - 1);
1659 template <class _Tp, class _Allocator>
1660 inline _LIBCPP_INLINE_VISIBILITY
1661 typename vector<_Tp, _Allocator>::iterator
1662 vector<_Tp, _Allocator>::erase(const_iterator __position)
1664 #if _LIBCPP_DEBUG_LEVEL >= 2
1665 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1666 "vector::erase(iterator) called with an iterator not"
1667 " referring to this vector");
1669 _LIBCPP_ASSERT(__position != end(),
1670 "vector::erase(iterator) called with a non-dereferenceable iterator");
1671 difference_type __ps = __position - cbegin();
1672 pointer __p = this->__begin_ + __ps;
1673 iterator __r = __make_iter(__p);
1674 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
1678 template <class _Tp, class _Allocator>
1679 typename vector<_Tp, _Allocator>::iterator
1680 vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1682 #if _LIBCPP_DEBUG_LEVEL >= 2
1683 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1684 "vector::erase(iterator, iterator) called with an iterator not"
1685 " referring to this vector");
1687 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
1688 pointer __p = this->__begin_ + (__first - begin());
1689 iterator __r = __make_iter(__p);
1690 if (__first != __last)
1691 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1695 template <class _Tp, class _Allocator>
1697 vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1699 pointer __old_last = this->__end_;
1700 difference_type __n = __old_last - __to;
1701 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1702 __alloc_traits::construct(this->__alloc(),
1703 _VSTD::__to_raw_pointer(this->__end_),
1705 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
1708 template <class _Tp, class _Allocator>
1709 typename vector<_Tp, _Allocator>::iterator
1710 vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1712 #if _LIBCPP_DEBUG_LEVEL >= 2
1713 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1714 "vector::insert(iterator, x) called with an iterator not"
1715 " referring to this vector");
1717 pointer __p = this->__begin_ + (__position - begin());
1718 if (this->__end_ < this->__end_cap())
1720 __RAII_IncreaseAnnotator __annotator(*this);
1721 if (__p == this->__end_)
1723 __alloc_traits::construct(this->__alloc(),
1724 _VSTD::__to_raw_pointer(this->__end_), __x);
1729 __move_range(__p, this->__end_, __p + 1);
1730 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1731 if (__p <= __xr && __xr < this->__end_)
1735 __annotator.__done();
1739 allocator_type& __a = this->__alloc();
1740 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1742 __p = __swap_out_circular_buffer(__v, __p);
1744 return __make_iter(__p);
1747 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1749 template <class _Tp, class _Allocator>
1750 typename vector<_Tp, _Allocator>::iterator
1751 vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1753 #if _LIBCPP_DEBUG_LEVEL >= 2
1754 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1755 "vector::insert(iterator, x) called with an iterator not"
1756 " referring to this vector");
1758 pointer __p = this->__begin_ + (__position - begin());
1759 if (this->__end_ < this->__end_cap())
1761 __RAII_IncreaseAnnotator __annotator(*this);
1762 if (__p == this->__end_)
1764 __alloc_traits::construct(this->__alloc(),
1765 _VSTD::__to_raw_pointer(this->__end_),
1771 __move_range(__p, this->__end_, __p + 1);
1772 *__p = _VSTD::move(__x);
1774 __annotator.__done();
1778 allocator_type& __a = this->__alloc();
1779 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1780 __v.push_back(_VSTD::move(__x));
1781 __p = __swap_out_circular_buffer(__v, __p);
1783 return __make_iter(__p);
1786 #ifndef _LIBCPP_HAS_NO_VARIADICS
1788 template <class _Tp, class _Allocator>
1789 template <class... _Args>
1790 typename vector<_Tp, _Allocator>::iterator
1791 vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1793 #if _LIBCPP_DEBUG_LEVEL >= 2
1794 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1795 "vector::emplace(iterator, x) called with an iterator not"
1796 " referring to this vector");
1798 pointer __p = this->__begin_ + (__position - begin());
1799 if (this->__end_ < this->__end_cap())
1801 __RAII_IncreaseAnnotator __annotator(*this);
1802 if (__p == this->__end_)
1804 __alloc_traits::construct(this->__alloc(),
1805 _VSTD::__to_raw_pointer(this->__end_),
1806 _VSTD::forward<_Args>(__args)...);
1811 value_type __tmp(_VSTD::forward<_Args>(__args)...);
1812 __move_range(__p, this->__end_, __p + 1);
1813 *__p = _VSTD::move(__tmp);
1815 __annotator.__done();
1819 allocator_type& __a = this->__alloc();
1820 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1821 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1822 __p = __swap_out_circular_buffer(__v, __p);
1824 return __make_iter(__p);
1827 #endif // _LIBCPP_HAS_NO_VARIADICS
1828 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1830 template <class _Tp, class _Allocator>
1831 typename vector<_Tp, _Allocator>::iterator
1832 vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1834 #if _LIBCPP_DEBUG_LEVEL >= 2
1835 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1836 "vector::insert(iterator, n, x) called with an iterator not"
1837 " referring to this vector");
1839 pointer __p = this->__begin_ + (__position - begin());
1842 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1844 size_type __old_n = __n;
1845 pointer __old_last = this->__end_;
1846 if (__n > static_cast<size_type>(this->__end_ - __p))
1848 size_type __cx = __n - (this->__end_ - __p);
1849 __construct_at_end(__cx, __x);
1854 __RAII_IncreaseAnnotator __annotator(*this, __n);
1855 __move_range(__p, __old_last, __p + __old_n);
1856 __annotator.__done();
1857 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1858 if (__p <= __xr && __xr < this->__end_)
1860 _VSTD::fill_n(__p, __n, *__xr);
1865 allocator_type& __a = this->__alloc();
1866 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1867 __v.__construct_at_end(__n, __x);
1868 __p = __swap_out_circular_buffer(__v, __p);
1871 return __make_iter(__p);
1874 template <class _Tp, class _Allocator>
1875 template <class _InputIterator>
1878 __is_input_iterator <_InputIterator>::value &&
1879 !__is_forward_iterator<_InputIterator>::value &&
1882 typename iterator_traits<_InputIterator>::reference>::value,
1883 typename vector<_Tp, _Allocator>::iterator
1885 vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1887 #if _LIBCPP_DEBUG_LEVEL >= 2
1888 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1889 "vector::insert(iterator, range) called with an iterator not"
1890 " referring to this vector");
1892 difference_type __off = __position - begin();
1893 pointer __p = this->__begin_ + __off;
1894 allocator_type& __a = this->__alloc();
1895 pointer __old_last = this->__end_;
1896 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1898 __RAII_IncreaseAnnotator __annotator(*this);
1899 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
1902 __annotator.__done();
1904 __split_buffer<value_type, allocator_type&> __v(__a);
1905 if (__first != __last)
1907 #ifndef _LIBCPP_NO_EXCEPTIONS
1910 #endif // _LIBCPP_NO_EXCEPTIONS
1911 __v.__construct_at_end(__first, __last);
1912 difference_type __old_size = __old_last - this->__begin_;
1913 difference_type __old_p = __p - this->__begin_;
1914 reserve(__recommend(size() + __v.size()));
1915 __p = this->__begin_ + __old_p;
1916 __old_last = this->__begin_ + __old_size;
1917 #ifndef _LIBCPP_NO_EXCEPTIONS
1921 erase(__make_iter(__old_last), end());
1924 #endif // _LIBCPP_NO_EXCEPTIONS
1926 __p = _VSTD::rotate(__p, __old_last, this->__end_);
1927 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1928 make_move_iterator(__v.end()));
1929 return begin() + __off;
1932 template <class _Tp, class _Allocator>
1933 template <class _ForwardIterator>
1936 __is_forward_iterator<_ForwardIterator>::value &&
1939 typename iterator_traits<_ForwardIterator>::reference>::value,
1940 typename vector<_Tp, _Allocator>::iterator
1942 vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1944 #if _LIBCPP_DEBUG_LEVEL >= 2
1945 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1946 "vector::insert(iterator, range) called with an iterator not"
1947 " referring to this vector");
1949 pointer __p = this->__begin_ + (__position - begin());
1950 difference_type __n = _VSTD::distance(__first, __last);
1953 if (__n <= this->__end_cap() - this->__end_)
1955 size_type __old_n = __n;
1956 pointer __old_last = this->__end_;
1957 _ForwardIterator __m = __last;
1958 difference_type __dx = this->__end_ - __p;
1962 difference_type __diff = this->__end_ - __p;
1963 _VSTD::advance(__m, __diff);
1964 __construct_at_end(__m, __last, __n - __diff);
1969 __RAII_IncreaseAnnotator __annotator(*this, __n);
1970 __move_range(__p, __old_last, __p + __old_n);
1971 __annotator.__done();
1972 _VSTD::copy(__first, __m, __p);
1977 allocator_type& __a = this->__alloc();
1978 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1979 __v.__construct_at_end(__first, __last);
1980 __p = __swap_out_circular_buffer(__v, __p);
1983 return __make_iter(__p);
1986 template <class _Tp, class _Allocator>
1988 vector<_Tp, _Allocator>::resize(size_type __sz)
1990 size_type __cs = size();
1992 this->__append(__sz - __cs);
1993 else if (__cs > __sz)
1994 this->__destruct_at_end(this->__begin_ + __sz);
1997 template <class _Tp, class _Allocator>
1999 vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
2001 size_type __cs = size();
2003 this->__append(__sz - __cs, __x);
2004 else if (__cs > __sz)
2005 this->__destruct_at_end(this->__begin_ + __sz);
2008 template <class _Tp, class _Allocator>
2010 vector<_Tp, _Allocator>::swap(vector& __x)
2011 #if _LIBCPP_STD_VER >= 14
2014 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2015 __is_nothrow_swappable<allocator_type>::value)
2018 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
2019 this->__alloc() == __x.__alloc(),
2020 "vector::swap: Either propagate_on_container_swap must be true"
2021 " or the allocators must compare equal");
2022 _VSTD::swap(this->__begin_, __x.__begin_);
2023 _VSTD::swap(this->__end_, __x.__end_);
2024 _VSTD::swap(this->__end_cap(), __x.__end_cap());
2025 __swap_allocator(this->__alloc(), __x.__alloc(),
2026 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
2027 #if _LIBCPP_DEBUG_LEVEL >= 2
2028 __get_db()->swap(this, &__x);
2029 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2032 template <class _Tp, class _Allocator>
2034 vector<_Tp, _Allocator>::__invariants() const
2036 if (this->__begin_ == nullptr)
2038 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
2043 if (this->__begin_ > this->__end_)
2045 if (this->__begin_ == this->__end_cap())
2047 if (this->__end_ > this->__end_cap())
2053 #if _LIBCPP_DEBUG_LEVEL >= 2
2055 template <class _Tp, class _Allocator>
2057 vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
2059 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
2062 template <class _Tp, class _Allocator>
2064 vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
2066 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
2069 template <class _Tp, class _Allocator>
2071 vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2073 const_pointer __p = __i->base() + __n;
2074 return this->__begin_ <= __p && __p <= this->__end_;
2077 template <class _Tp, class _Allocator>
2079 vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2081 const_pointer __p = __i->base() + __n;
2082 return this->__begin_ <= __p && __p < this->__end_;
2085 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2087 template <class _Tp, class _Allocator>
2088 inline _LIBCPP_INLINE_VISIBILITY
2090 vector<_Tp, _Allocator>::__invalidate_all_iterators()
2092 #if _LIBCPP_DEBUG_LEVEL >= 2
2093 __get_db()->__invalidate_all(this);
2094 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2099 template <class _Allocator> class vector<bool, _Allocator>;
2101 template <class _Allocator> struct hash<vector<bool, _Allocator> >;
2103 template <class _Allocator>
2104 struct __has_storage_type<vector<bool, _Allocator> >
2106 static const bool value = true;
2109 template <class _Allocator>
2110 class _LIBCPP_TYPE_VIS_ONLY vector<bool, _Allocator>
2111 : private __vector_base_common<true>
2114 typedef vector __self;
2115 typedef bool value_type;
2116 typedef _Allocator allocator_type;
2117 typedef allocator_traits<allocator_type> __alloc_traits;
2118 typedef typename __alloc_traits::size_type size_type;
2119 typedef typename __alloc_traits::difference_type difference_type;
2120 typedef size_type __storage_type;
2121 typedef __bit_iterator<vector, false> pointer;
2122 typedef __bit_iterator<vector, true> const_pointer;
2123 typedef pointer iterator;
2124 typedef const_pointer const_iterator;
2125 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
2126 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
2129 typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
2130 typedef allocator_traits<__storage_allocator> __storage_traits;
2131 typedef typename __storage_traits::pointer __storage_pointer;
2132 typedef typename __storage_traits::const_pointer __const_storage_pointer;
2134 __storage_pointer __begin_;
2136 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
2138 typedef __bit_reference<vector> reference;
2139 typedef __bit_const_reference<vector> const_reference;
2141 _LIBCPP_INLINE_VISIBILITY
2142 size_type& __cap() _NOEXCEPT
2143 {return __cap_alloc_.first();}
2144 _LIBCPP_INLINE_VISIBILITY
2145 const size_type& __cap() const _NOEXCEPT
2146 {return __cap_alloc_.first();}
2147 _LIBCPP_INLINE_VISIBILITY
2148 __storage_allocator& __alloc() _NOEXCEPT
2149 {return __cap_alloc_.second();}
2150 _LIBCPP_INLINE_VISIBILITY
2151 const __storage_allocator& __alloc() const _NOEXCEPT
2152 {return __cap_alloc_.second();}
2154 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2156 _LIBCPP_INLINE_VISIBILITY
2157 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
2158 {return __n * __bits_per_word;}
2159 _LIBCPP_INLINE_VISIBILITY
2160 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
2161 {return (__n - 1) / __bits_per_word + 1;}
2164 _LIBCPP_INLINE_VISIBILITY
2165 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
2167 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
2168 #if _LIBCPP_STD_VER <= 14
2169 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
2174 explicit vector(size_type __n);
2175 #if _LIBCPP_STD_VER > 11
2176 explicit vector(size_type __n, const allocator_type& __a);
2178 vector(size_type __n, const value_type& __v);
2179 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2180 template <class _InputIterator>
2181 vector(_InputIterator __first, _InputIterator __last,
2182 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2183 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2184 template <class _InputIterator>
2185 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2186 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2187 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2188 template <class _ForwardIterator>
2189 vector(_ForwardIterator __first, _ForwardIterator __last,
2190 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2191 template <class _ForwardIterator>
2192 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2193 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2195 vector(const vector& __v);
2196 vector(const vector& __v, const allocator_type& __a);
2197 vector& operator=(const vector& __v);
2198 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2199 vector(initializer_list<value_type> __il);
2200 vector(initializer_list<value_type> __il, const allocator_type& __a);
2201 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2203 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2204 _LIBCPP_INLINE_VISIBILITY
2205 vector(vector&& __v)
2206 #if _LIBCPP_STD_VER > 14
2209 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
2211 vector(vector&& __v, const allocator_type& __a);
2212 _LIBCPP_INLINE_VISIBILITY
2213 vector& operator=(vector&& __v)
2214 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
2215 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2216 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2217 _LIBCPP_INLINE_VISIBILITY
2218 vector& operator=(initializer_list<value_type> __il)
2219 {assign(__il.begin(), __il.end()); return *this;}
2220 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2222 template <class _InputIterator>
2225 __is_input_iterator<_InputIterator>::value &&
2226 !__is_forward_iterator<_InputIterator>::value,
2229 assign(_InputIterator __first, _InputIterator __last);
2230 template <class _ForwardIterator>
2233 __is_forward_iterator<_ForwardIterator>::value,
2236 assign(_ForwardIterator __first, _ForwardIterator __last);
2238 void assign(size_type __n, const value_type& __x);
2239 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2240 _LIBCPP_INLINE_VISIBILITY
2241 void assign(initializer_list<value_type> __il)
2242 {assign(__il.begin(), __il.end());}
2243 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2245 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
2246 {return allocator_type(this->__alloc());}
2248 size_type max_size() const _NOEXCEPT;
2249 _LIBCPP_INLINE_VISIBILITY
2250 size_type capacity() const _NOEXCEPT
2251 {return __internal_cap_to_external(__cap());}
2252 _LIBCPP_INLINE_VISIBILITY
2253 size_type size() const _NOEXCEPT
2255 _LIBCPP_INLINE_VISIBILITY
2256 bool empty() const _NOEXCEPT
2257 {return __size_ == 0;}
2258 void reserve(size_type __n);
2259 void shrink_to_fit() _NOEXCEPT;
2261 _LIBCPP_INLINE_VISIBILITY
2262 iterator begin() _NOEXCEPT
2263 {return __make_iter(0);}
2264 _LIBCPP_INLINE_VISIBILITY
2265 const_iterator begin() const _NOEXCEPT
2266 {return __make_iter(0);}
2267 _LIBCPP_INLINE_VISIBILITY
2268 iterator end() _NOEXCEPT
2269 {return __make_iter(__size_);}
2270 _LIBCPP_INLINE_VISIBILITY
2271 const_iterator end() const _NOEXCEPT
2272 {return __make_iter(__size_);}
2274 _LIBCPP_INLINE_VISIBILITY
2275 reverse_iterator rbegin() _NOEXCEPT
2276 {return reverse_iterator(end());}
2277 _LIBCPP_INLINE_VISIBILITY
2278 const_reverse_iterator rbegin() const _NOEXCEPT
2279 {return const_reverse_iterator(end());}
2280 _LIBCPP_INLINE_VISIBILITY
2281 reverse_iterator rend() _NOEXCEPT
2282 {return reverse_iterator(begin());}
2283 _LIBCPP_INLINE_VISIBILITY
2284 const_reverse_iterator rend() const _NOEXCEPT
2285 {return const_reverse_iterator(begin());}
2287 _LIBCPP_INLINE_VISIBILITY
2288 const_iterator cbegin() const _NOEXCEPT
2289 {return __make_iter(0);}
2290 _LIBCPP_INLINE_VISIBILITY
2291 const_iterator cend() const _NOEXCEPT
2292 {return __make_iter(__size_);}
2293 _LIBCPP_INLINE_VISIBILITY
2294 const_reverse_iterator crbegin() const _NOEXCEPT
2296 _LIBCPP_INLINE_VISIBILITY
2297 const_reverse_iterator crend() const _NOEXCEPT
2300 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2301 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2302 reference at(size_type __n);
2303 const_reference at(size_type __n) const;
2305 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2306 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2307 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2308 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2310 void push_back(const value_type& __x);
2311 #if _LIBCPP_STD_VER > 11
2312 template <class... _Args>
2313 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
2314 { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); }
2317 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2319 #if _LIBCPP_STD_VER > 11
2320 template <class... _Args>
2321 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2322 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2325 iterator insert(const_iterator __position, const value_type& __x);
2326 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2327 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2328 template <class _InputIterator>
2331 __is_input_iterator <_InputIterator>::value &&
2332 !__is_forward_iterator<_InputIterator>::value,
2335 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2336 template <class _ForwardIterator>
2339 __is_forward_iterator<_ForwardIterator>::value,
2342 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
2343 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2344 _LIBCPP_INLINE_VISIBILITY
2345 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2346 {return insert(__position, __il.begin(), __il.end());}
2347 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2349 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
2350 iterator erase(const_iterator __first, const_iterator __last);
2352 _LIBCPP_INLINE_VISIBILITY
2353 void clear() _NOEXCEPT {__size_ = 0;}
2356 #if _LIBCPP_STD_VER >= 14
2359 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2360 __is_nothrow_swappable<allocator_type>::value);
2363 void resize(size_type __sz, value_type __x = false);
2364 void flip() _NOEXCEPT;
2366 bool __invariants() const;
2369 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
2370 void allocate(size_type __n);
2371 void deallocate() _NOEXCEPT;
2372 _LIBCPP_INLINE_VISIBILITY
2373 static size_type __align_it(size_type __new_size) _NOEXCEPT
2374 {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);};
2375 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2376 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
2377 template <class _ForwardIterator>
2380 __is_forward_iterator<_ForwardIterator>::value,
2383 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2384 void __append(size_type __n, const_reference __x);
2385 _LIBCPP_INLINE_VISIBILITY
2386 reference __make_ref(size_type __pos) _NOEXCEPT
2387 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2388 _LIBCPP_INLINE_VISIBILITY
2389 const_reference __make_ref(size_type __pos) const _NOEXCEPT
2390 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2391 _LIBCPP_INLINE_VISIBILITY
2392 iterator __make_iter(size_type __pos) _NOEXCEPT
2393 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2394 _LIBCPP_INLINE_VISIBILITY
2395 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
2396 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2397 _LIBCPP_INLINE_VISIBILITY
2398 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
2399 {return begin() + (__p - cbegin());}
2401 _LIBCPP_INLINE_VISIBILITY
2402 void __copy_assign_alloc(const vector& __v)
2403 {__copy_assign_alloc(__v, integral_constant<bool,
2404 __storage_traits::propagate_on_container_copy_assignment::value>());}
2405 _LIBCPP_INLINE_VISIBILITY
2406 void __copy_assign_alloc(const vector& __c, true_type)
2408 if (__alloc() != __c.__alloc())
2410 __alloc() = __c.__alloc();
2413 _LIBCPP_INLINE_VISIBILITY
2414 void __copy_assign_alloc(const vector&, false_type)
2417 void __move_assign(vector& __c, false_type);
2418 void __move_assign(vector& __c, true_type)
2419 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2420 _LIBCPP_INLINE_VISIBILITY
2421 void __move_assign_alloc(vector& __c)
2423 !__storage_traits::propagate_on_container_move_assignment::value ||
2424 is_nothrow_move_assignable<allocator_type>::value)
2425 {__move_assign_alloc(__c, integral_constant<bool,
2426 __storage_traits::propagate_on_container_move_assignment::value>());}
2427 _LIBCPP_INLINE_VISIBILITY
2428 void __move_assign_alloc(vector& __c, true_type)
2429 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2431 __alloc() = _VSTD::move(__c.__alloc());
2434 _LIBCPP_INLINE_VISIBILITY
2435 void __move_assign_alloc(vector&, false_type)
2439 size_t __hash_code() const _NOEXCEPT;
2441 friend class __bit_reference<vector>;
2442 friend class __bit_const_reference<vector>;
2443 friend class __bit_iterator<vector, false>;
2444 friend class __bit_iterator<vector, true>;
2445 friend struct __bit_array<vector>;
2446 friend struct _LIBCPP_TYPE_VIS_ONLY hash<vector>;
2449 template <class _Allocator>
2450 inline _LIBCPP_INLINE_VISIBILITY
2452 vector<bool, _Allocator>::__invalidate_all_iterators()
2456 // Allocate space for __n objects
2457 // throws length_error if __n > max_size()
2458 // throws (probably bad_alloc) if memory run out
2459 // Precondition: __begin_ == __end_ == __cap() == 0
2460 // Precondition: __n > 0
2461 // Postcondition: capacity() == __n
2462 // Postcondition: size() == 0
2463 template <class _Allocator>
2465 vector<bool, _Allocator>::allocate(size_type __n)
2467 if (__n > max_size())
2468 this->__throw_length_error();
2469 __n = __external_cap_to_internal(__n);
2470 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2472 this->__cap() = __n;
2475 template <class _Allocator>
2477 vector<bool, _Allocator>::deallocate() _NOEXCEPT
2479 if (this->__begin_ != nullptr)
2481 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2482 __invalidate_all_iterators();
2483 this->__begin_ = nullptr;
2484 this->__size_ = this->__cap() = 0;
2488 template <class _Allocator>
2489 typename vector<bool, _Allocator>::size_type
2490 vector<bool, _Allocator>::max_size() const _NOEXCEPT
2492 size_type __amax = __storage_traits::max_size(__alloc());
2493 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2494 if (__nmax / __bits_per_word <= __amax)
2496 return __internal_cap_to_external(__amax);
2499 // Precondition: __new_size > capacity()
2500 template <class _Allocator>
2501 inline _LIBCPP_INLINE_VISIBILITY
2502 typename vector<bool, _Allocator>::size_type
2503 vector<bool, _Allocator>::__recommend(size_type __new_size) const
2505 const size_type __ms = max_size();
2506 if (__new_size > __ms)
2507 this->__throw_length_error();
2508 const size_type __cap = capacity();
2509 if (__cap >= __ms / 2)
2511 return _VSTD::max(2*__cap, __align_it(__new_size));
2514 // Default constructs __n objects starting at __end_
2515 // Precondition: __n > 0
2516 // Precondition: size() + __n <= capacity()
2517 // Postcondition: size() == size() + __n
2518 template <class _Allocator>
2519 inline _LIBCPP_INLINE_VISIBILITY
2521 vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2523 size_type __old_size = this->__size_;
2524 this->__size_ += __n;
2525 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
2528 template <class _Allocator>
2529 template <class _ForwardIterator>
2532 __is_forward_iterator<_ForwardIterator>::value,
2535 vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2537 size_type __old_size = this->__size_;
2538 this->__size_ += _VSTD::distance(__first, __last);
2539 _VSTD::copy(__first, __last, __make_iter(__old_size));
2542 template <class _Allocator>
2543 inline _LIBCPP_INLINE_VISIBILITY
2544 vector<bool, _Allocator>::vector()
2545 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2546 : __begin_(nullptr),
2552 template <class _Allocator>
2553 inline _LIBCPP_INLINE_VISIBILITY
2554 vector<bool, _Allocator>::vector(const allocator_type& __a)
2555 #if _LIBCPP_STD_VER <= 14
2556 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
2560 : __begin_(nullptr),
2562 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2566 template <class _Allocator>
2567 vector<bool, _Allocator>::vector(size_type __n)
2568 : __begin_(nullptr),
2575 __construct_at_end(__n, false);
2579 #if _LIBCPP_STD_VER > 11
2580 template <class _Allocator>
2581 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2582 : __begin_(nullptr),
2584 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2589 __construct_at_end(__n, false);
2594 template <class _Allocator>
2595 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2596 : __begin_(nullptr),
2603 __construct_at_end(__n, __x);
2607 template <class _Allocator>
2608 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2609 : __begin_(nullptr),
2611 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2616 __construct_at_end(__n, __x);
2620 template <class _Allocator>
2621 template <class _InputIterator>
2622 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2623 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2624 !__is_forward_iterator<_InputIterator>::value>::type*)
2625 : __begin_(nullptr),
2629 #ifndef _LIBCPP_NO_EXCEPTIONS
2632 #endif // _LIBCPP_NO_EXCEPTIONS
2633 for (; __first != __last; ++__first)
2634 push_back(*__first);
2635 #ifndef _LIBCPP_NO_EXCEPTIONS
2639 if (__begin_ != nullptr)
2640 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2641 __invalidate_all_iterators();
2644 #endif // _LIBCPP_NO_EXCEPTIONS
2647 template <class _Allocator>
2648 template <class _InputIterator>
2649 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2650 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2651 !__is_forward_iterator<_InputIterator>::value>::type*)
2652 : __begin_(nullptr),
2654 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2656 #ifndef _LIBCPP_NO_EXCEPTIONS
2659 #endif // _LIBCPP_NO_EXCEPTIONS
2660 for (; __first != __last; ++__first)
2661 push_back(*__first);
2662 #ifndef _LIBCPP_NO_EXCEPTIONS
2666 if (__begin_ != nullptr)
2667 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2668 __invalidate_all_iterators();
2671 #endif // _LIBCPP_NO_EXCEPTIONS
2674 template <class _Allocator>
2675 template <class _ForwardIterator>
2676 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2677 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2678 : __begin_(nullptr),
2682 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2686 __construct_at_end(__first, __last);
2690 template <class _Allocator>
2691 template <class _ForwardIterator>
2692 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2693 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2694 : __begin_(nullptr),
2696 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2698 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2702 __construct_at_end(__first, __last);
2706 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2708 template <class _Allocator>
2709 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2710 : __begin_(nullptr),
2714 size_type __n = static_cast<size_type>(__il.size());
2718 __construct_at_end(__il.begin(), __il.end());
2722 template <class _Allocator>
2723 vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2724 : __begin_(nullptr),
2726 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2728 size_type __n = static_cast<size_type>(__il.size());
2732 __construct_at_end(__il.begin(), __il.end());
2736 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2738 template <class _Allocator>
2739 vector<bool, _Allocator>::~vector()
2741 if (__begin_ != nullptr)
2742 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2743 __invalidate_all_iterators();
2746 template <class _Allocator>
2747 vector<bool, _Allocator>::vector(const vector& __v)
2748 : __begin_(nullptr),
2750 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2754 allocate(__v.size());
2755 __construct_at_end(__v.begin(), __v.end());
2759 template <class _Allocator>
2760 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2761 : __begin_(nullptr),
2763 __cap_alloc_(0, __a)
2767 allocate(__v.size());
2768 __construct_at_end(__v.begin(), __v.end());
2772 template <class _Allocator>
2773 vector<bool, _Allocator>&
2774 vector<bool, _Allocator>::operator=(const vector& __v)
2778 __copy_assign_alloc(__v);
2781 if (__v.__size_ > capacity())
2784 allocate(__v.__size_);
2786 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2788 __size_ = __v.__size_;
2793 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2795 template <class _Allocator>
2796 inline _LIBCPP_INLINE_VISIBILITY
2797 vector<bool, _Allocator>::vector(vector&& __v)
2798 #if _LIBCPP_STD_VER > 14
2801 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2803 : __begin_(__v.__begin_),
2804 __size_(__v.__size_),
2805 __cap_alloc_(__v.__cap_alloc_)
2807 __v.__begin_ = nullptr;
2812 template <class _Allocator>
2813 vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2814 : __begin_(nullptr),
2816 __cap_alloc_(0, __a)
2818 if (__a == allocator_type(__v.__alloc()))
2820 this->__begin_ = __v.__begin_;
2821 this->__size_ = __v.__size_;
2822 this->__cap() = __v.__cap();
2823 __v.__begin_ = nullptr;
2824 __v.__cap() = __v.__size_ = 0;
2826 else if (__v.size() > 0)
2828 allocate(__v.size());
2829 __construct_at_end(__v.begin(), __v.end());
2833 template <class _Allocator>
2834 inline _LIBCPP_INLINE_VISIBILITY
2835 vector<bool, _Allocator>&
2836 vector<bool, _Allocator>::operator=(vector&& __v)
2837 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
2839 __move_assign(__v, integral_constant<bool,
2840 __storage_traits::propagate_on_container_move_assignment::value>());
2844 template <class _Allocator>
2846 vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2848 if (__alloc() != __c.__alloc())
2849 assign(__c.begin(), __c.end());
2851 __move_assign(__c, true_type());
2854 template <class _Allocator>
2856 vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2857 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2860 __move_assign_alloc(__c);
2861 this->__begin_ = __c.__begin_;
2862 this->__size_ = __c.__size_;
2863 this->__cap() = __c.__cap();
2864 __c.__begin_ = nullptr;
2865 __c.__cap() = __c.__size_ = 0;
2868 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2870 template <class _Allocator>
2872 vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2877 size_type __c = capacity();
2882 vector __v(__alloc());
2883 __v.reserve(__recommend(__n));
2887 _VSTD::fill_n(begin(), __n, __x);
2891 template <class _Allocator>
2892 template <class _InputIterator>
2895 __is_input_iterator<_InputIterator>::value &&
2896 !__is_forward_iterator<_InputIterator>::value,
2899 vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2902 for (; __first != __last; ++__first)
2903 push_back(*__first);
2906 template <class _Allocator>
2907 template <class _ForwardIterator>
2910 __is_forward_iterator<_ForwardIterator>::value,
2913 vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2916 difference_type __n = _VSTD::distance(__first, __last);
2919 if (__n > capacity())
2924 __construct_at_end(__first, __last);
2928 template <class _Allocator>
2930 vector<bool, _Allocator>::reserve(size_type __n)
2932 if (__n > capacity())
2934 vector __v(this->__alloc());
2936 __v.__construct_at_end(this->begin(), this->end());
2938 __invalidate_all_iterators();
2942 template <class _Allocator>
2944 vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
2946 if (__external_cap_to_internal(size()) > __cap())
2948 #ifndef _LIBCPP_NO_EXCEPTIONS
2951 #endif // _LIBCPP_NO_EXCEPTIONS
2952 vector(*this, allocator_type(__alloc())).swap(*this);
2953 #ifndef _LIBCPP_NO_EXCEPTIONS
2958 #endif // _LIBCPP_NO_EXCEPTIONS
2962 template <class _Allocator>
2963 typename vector<bool, _Allocator>::reference
2964 vector<bool, _Allocator>::at(size_type __n)
2967 this->__throw_out_of_range();
2968 return (*this)[__n];
2971 template <class _Allocator>
2972 typename vector<bool, _Allocator>::const_reference
2973 vector<bool, _Allocator>::at(size_type __n) const
2976 this->__throw_out_of_range();
2977 return (*this)[__n];
2980 template <class _Allocator>
2982 vector<bool, _Allocator>::push_back(const value_type& __x)
2984 if (this->__size_ == this->capacity())
2985 reserve(__recommend(this->__size_ + 1));
2990 template <class _Allocator>
2991 typename vector<bool, _Allocator>::iterator
2992 vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2995 if (size() < capacity())
2997 const_iterator __old_end = end();
2999 _VSTD::copy_backward(__position, __old_end, end());
3000 __r = __const_iterator_cast(__position);
3004 vector __v(__alloc());
3005 __v.reserve(__recommend(__size_ + 1));
3006 __v.__size_ = __size_ + 1;
3007 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3008 _VSTD::copy_backward(__position, cend(), __v.end());
3015 template <class _Allocator>
3016 typename vector<bool, _Allocator>::iterator
3017 vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
3020 size_type __c = capacity();
3021 if (__n <= __c && size() <= __c - __n)
3023 const_iterator __old_end = end();
3025 _VSTD::copy_backward(__position, __old_end, end());
3026 __r = __const_iterator_cast(__position);
3030 vector __v(__alloc());
3031 __v.reserve(__recommend(__size_ + __n));
3032 __v.__size_ = __size_ + __n;
3033 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3034 _VSTD::copy_backward(__position, cend(), __v.end());
3037 _VSTD::fill_n(__r, __n, __x);
3041 template <class _Allocator>
3042 template <class _InputIterator>
3045 __is_input_iterator <_InputIterator>::value &&
3046 !__is_forward_iterator<_InputIterator>::value,
3047 typename vector<bool, _Allocator>::iterator
3049 vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
3051 difference_type __off = __position - begin();
3052 iterator __p = __const_iterator_cast(__position);
3053 iterator __old_end = end();
3054 for (; size() != capacity() && __first != __last; ++__first)
3059 vector __v(__alloc());
3060 if (__first != __last)
3062 #ifndef _LIBCPP_NO_EXCEPTIONS
3065 #endif // _LIBCPP_NO_EXCEPTIONS
3066 __v.assign(__first, __last);
3067 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
3068 difference_type __old_p = __p - begin();
3069 reserve(__recommend(size() + __v.size()));
3070 __p = begin() + __old_p;
3071 __old_end = begin() + __old_size;
3072 #ifndef _LIBCPP_NO_EXCEPTIONS
3076 erase(__old_end, end());
3079 #endif // _LIBCPP_NO_EXCEPTIONS
3081 __p = _VSTD::rotate(__p, __old_end, end());
3082 insert(__p, __v.begin(), __v.end());
3083 return begin() + __off;
3086 template <class _Allocator>
3087 template <class _ForwardIterator>
3090 __is_forward_iterator<_ForwardIterator>::value,
3091 typename vector<bool, _Allocator>::iterator
3093 vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
3095 difference_type __n = _VSTD::distance(__first, __last);
3097 size_type __c = capacity();
3098 if (__n <= __c && size() <= __c - __n)
3100 const_iterator __old_end = end();
3102 _VSTD::copy_backward(__position, __old_end, end());
3103 __r = __const_iterator_cast(__position);
3107 vector __v(__alloc());
3108 __v.reserve(__recommend(__size_ + __n));
3109 __v.__size_ = __size_ + __n;
3110 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3111 _VSTD::copy_backward(__position, cend(), __v.end());
3114 _VSTD::copy(__first, __last, __r);
3118 template <class _Allocator>
3119 inline _LIBCPP_INLINE_VISIBILITY
3120 typename vector<bool, _Allocator>::iterator
3121 vector<bool, _Allocator>::erase(const_iterator __position)
3123 iterator __r = __const_iterator_cast(__position);
3124 _VSTD::copy(__position + 1, this->cend(), __r);
3129 template <class _Allocator>
3130 typename vector<bool, _Allocator>::iterator
3131 vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3133 iterator __r = __const_iterator_cast(__first);
3134 difference_type __d = __last - __first;
3135 _VSTD::copy(__last, this->cend(), __r);
3140 template <class _Allocator>
3142 vector<bool, _Allocator>::swap(vector& __x)
3143 #if _LIBCPP_STD_VER >= 14
3146 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3147 __is_nothrow_swappable<allocator_type>::value)
3150 _VSTD::swap(this->__begin_, __x.__begin_);
3151 _VSTD::swap(this->__size_, __x.__size_);
3152 _VSTD::swap(this->__cap(), __x.__cap());
3153 __swap_allocator(this->__alloc(), __x.__alloc(),
3154 integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
3157 template <class _Allocator>
3159 vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3161 size_type __cs = size();
3165 size_type __c = capacity();
3166 size_type __n = __sz - __cs;
3167 if (__n <= __c && __cs <= __c - __n)
3174 vector __v(__alloc());
3175 __v.reserve(__recommend(__size_ + __n));
3176 __v.__size_ = __size_ + __n;
3177 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
3180 _VSTD::fill_n(__r, __n, __x);
3186 template <class _Allocator>
3188 vector<bool, _Allocator>::flip() _NOEXCEPT
3190 // do middle whole words
3191 size_type __n = __size_;
3192 __storage_pointer __p = __begin_;
3193 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3195 // do last partial word
3198 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3199 __storage_type __b = *__p & __m;
3205 template <class _Allocator>
3207 vector<bool, _Allocator>::__invariants() const
3209 if (this->__begin_ == nullptr)
3211 if (this->__size_ != 0 || this->__cap() != 0)
3216 if (this->__cap() == 0)
3218 if (this->__size_ > this->capacity())
3224 template <class _Allocator>
3226 vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
3229 // do middle whole words
3230 size_type __n = __size_;
3231 __storage_pointer __p = __begin_;
3232 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3234 // do last partial word
3237 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3243 template <class _Allocator>
3244 struct _LIBCPP_TYPE_VIS_ONLY hash<vector<bool, _Allocator> >
3245 : public unary_function<vector<bool, _Allocator>, size_t>
3247 _LIBCPP_INLINE_VISIBILITY
3248 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
3249 {return __vec.__hash_code();}
3252 template <class _Tp, class _Allocator>
3253 inline _LIBCPP_INLINE_VISIBILITY
3255 operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3257 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
3258 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3261 template <class _Tp, class _Allocator>
3262 inline _LIBCPP_INLINE_VISIBILITY
3264 operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3266 return !(__x == __y);
3269 template <class _Tp, class _Allocator>
3270 inline _LIBCPP_INLINE_VISIBILITY
3272 operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3274 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
3277 template <class _Tp, class _Allocator>
3278 inline _LIBCPP_INLINE_VISIBILITY
3280 operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3285 template <class _Tp, class _Allocator>
3286 inline _LIBCPP_INLINE_VISIBILITY
3288 operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3290 return !(__x < __y);
3293 template <class _Tp, class _Allocator>
3294 inline _LIBCPP_INLINE_VISIBILITY
3296 operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3298 return !(__y < __x);
3301 template <class _Tp, class _Allocator>
3302 inline _LIBCPP_INLINE_VISIBILITY
3304 swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
3305 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
3310 _LIBCPP_END_NAMESPACE_STD
3312 #endif // _LIBCPP_VECTOR