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 _LIBCPP_INLINE_VISIBILITY
689 void emplace_back(_Args&&... __args);
690 #endif // _LIBCPP_HAS_NO_VARIADICS
691 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
692 _LIBCPP_INLINE_VISIBILITY
695 iterator insert(const_iterator __position, const_reference __x);
696 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
697 iterator insert(const_iterator __position, value_type&& __x);
698 #ifndef _LIBCPP_HAS_NO_VARIADICS
699 template <class... _Args>
700 iterator emplace(const_iterator __position, _Args&&... __args);
701 #endif // _LIBCPP_HAS_NO_VARIADICS
702 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
703 iterator insert(const_iterator __position, size_type __n, const_reference __x);
704 template <class _InputIterator>
707 __is_input_iterator <_InputIterator>::value &&
708 !__is_forward_iterator<_InputIterator>::value &&
711 typename iterator_traits<_InputIterator>::reference>::value,
714 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
715 template <class _ForwardIterator>
718 __is_forward_iterator<_ForwardIterator>::value &&
721 typename iterator_traits<_ForwardIterator>::reference>::value,
724 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
725 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
726 _LIBCPP_INLINE_VISIBILITY
727 iterator insert(const_iterator __position, initializer_list<value_type> __il)
728 {return insert(__position, __il.begin(), __il.end());}
729 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
731 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
732 iterator erase(const_iterator __first, const_iterator __last);
734 _LIBCPP_INLINE_VISIBILITY
735 void clear() _NOEXCEPT
737 size_type __old_size = size();
739 __annotate_shrink(__old_size);
740 __invalidate_all_iterators();
743 void resize(size_type __sz);
744 void resize(size_type __sz, const_reference __x);
747 #if _LIBCPP_STD_VER >= 14
750 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
751 __is_nothrow_swappable<allocator_type>::value);
754 bool __invariants() const;
756 #if _LIBCPP_DEBUG_LEVEL >= 2
758 bool __dereferenceable(const const_iterator* __i) const;
759 bool __decrementable(const const_iterator* __i) const;
760 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
761 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
763 #endif // _LIBCPP_DEBUG_LEVEL >= 2
766 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
767 void allocate(size_type __n);
768 void deallocate() _NOEXCEPT;
769 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
770 void __construct_at_end(size_type __n);
771 _LIBCPP_INLINE_VISIBILITY
772 void __construct_at_end(size_type __n, const_reference __x);
773 template <class _ForwardIterator>
776 __is_forward_iterator<_ForwardIterator>::value,
779 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
780 void __append(size_type __n);
781 void __append(size_type __n, const_reference __x);
782 _LIBCPP_INLINE_VISIBILITY
783 iterator __make_iter(pointer __p) _NOEXCEPT;
784 _LIBCPP_INLINE_VISIBILITY
785 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
786 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
787 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
788 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
789 void __move_assign(vector& __c, true_type)
790 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
791 void __move_assign(vector& __c, false_type)
792 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
793 _LIBCPP_INLINE_VISIBILITY
794 void __destruct_at_end(pointer __new_last) _NOEXCEPT
796 #if _LIBCPP_DEBUG_LEVEL >= 2
797 __c_node* __c = __get_db()->__find_c_and_lock(this);
798 for (__i_node** __p = __c->end_; __p != __c->beg_; )
801 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
802 if (__i->base() > __new_last)
804 (*__p)->__c_ = nullptr;
805 if (--__c->end_ != __p)
806 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
809 __get_db()->unlock();
811 size_type __old_size = size();
812 __base::__destruct_at_end(__new_last);
813 __annotate_shrink(__old_size);
817 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
818 __push_back_slow_path(_Up&& __x);
820 __push_back_slow_path(_Up& __x);
822 #if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
823 template <class... _Args>
825 __emplace_back_slow_path(_Args&&... __args);
827 // The following functions are no-ops outside of AddressSanitizer mode.
828 // We call annotatations only for the default Allocator because other allocators
829 // may not meet the AddressSanitizer alignment constraints.
830 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
831 void __annotate_contiguous_container
832 (const void *__beg, const void *__end, const void *__old_mid, const void *__new_mid) const
834 #ifndef _LIBCPP_HAS_NO_ASAN
835 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
836 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
840 void __annotate_new(size_type __current_size) const
842 __annotate_contiguous_container(data(), data() + capacity(),
843 data() + capacity(), data() + __current_size);
845 void __annotate_delete() const
847 __annotate_contiguous_container(data(), data() + capacity(),
848 data() + size(), data() + capacity());
850 void __annotate_increase(size_type __n) const
852 __annotate_contiguous_container(data(), data() + capacity(),
853 data() + size(), data() + size() + __n);
855 void __annotate_shrink(size_type __old_size) const
857 __annotate_contiguous_container(data(), data() + capacity(),
858 data() + __old_size, data() + size());
860 #ifndef _LIBCPP_HAS_NO_ASAN
861 // The annotation for size increase should happen before the actual increase,
862 // but if an exception is thrown after that the annotation has to be undone.
863 struct __RAII_IncreaseAnnotator {
864 __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1)
865 : __commit(false), __v(__v), __old_size(__v.size() + __n) {
866 __v.__annotate_increase(__n);
868 void __done() { __commit = true; }
869 ~__RAII_IncreaseAnnotator() {
870 if (__commit) return;
871 __v.__annotate_shrink(__old_size);
875 size_type __old_size;
878 struct __RAII_IncreaseAnnotator {
879 inline __RAII_IncreaseAnnotator(const vector &, size_type __n = 1) {}
880 inline void __done() {}
886 template <class _Tp, class _Allocator>
888 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
891 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
892 _VSTD::swap(this->__begin_, __v.__begin_);
893 _VSTD::swap(this->__end_, __v.__end_);
894 _VSTD::swap(this->__end_cap(), __v.__end_cap());
895 __v.__first_ = __v.__begin_;
896 __annotate_new(size());
897 __invalidate_all_iterators();
900 template <class _Tp, class _Allocator>
901 typename vector<_Tp, _Allocator>::pointer
902 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
905 pointer __r = __v.__begin_;
906 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
907 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
908 _VSTD::swap(this->__begin_, __v.__begin_);
909 _VSTD::swap(this->__end_, __v.__end_);
910 _VSTD::swap(this->__end_cap(), __v.__end_cap());
911 __v.__first_ = __v.__begin_;
912 __annotate_new(size());
913 __invalidate_all_iterators();
917 // Allocate space for __n objects
918 // throws length_error if __n > max_size()
919 // throws (probably bad_alloc) if memory run out
920 // Precondition: __begin_ == __end_ == __end_cap() == 0
921 // Precondition: __n > 0
922 // Postcondition: capacity() == __n
923 // Postcondition: size() == 0
924 template <class _Tp, class _Allocator>
926 vector<_Tp, _Allocator>::allocate(size_type __n)
928 if (__n > max_size())
929 this->__throw_length_error();
930 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
931 this->__end_cap() = this->__begin_ + __n;
935 template <class _Tp, class _Allocator>
937 vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
939 if (this->__begin_ != nullptr)
942 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
943 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
947 template <class _Tp, class _Allocator>
948 typename vector<_Tp, _Allocator>::size_type
949 vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
951 return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2); // end() >= begin(), always
954 // Precondition: __new_size > capacity()
955 template <class _Tp, class _Allocator>
956 inline _LIBCPP_INLINE_VISIBILITY
957 typename vector<_Tp, _Allocator>::size_type
958 vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
960 const size_type __ms = max_size();
961 if (__new_size > __ms)
962 this->__throw_length_error();
963 const size_type __cap = capacity();
964 if (__cap >= __ms / 2)
966 return _VSTD::max<size_type>(2*__cap, __new_size);
969 // Default constructs __n objects starting at __end_
970 // throws if construction throws
971 // Precondition: __n > 0
972 // Precondition: size() + __n <= capacity()
973 // Postcondition: size() == size() + __n
974 template <class _Tp, class _Allocator>
976 vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
978 allocator_type& __a = this->__alloc();
981 __RAII_IncreaseAnnotator __annotator(*this);
982 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
985 __annotator.__done();
989 // Copy constructs __n objects starting at __end_ from __x
990 // throws if construction throws
991 // Precondition: __n > 0
992 // Precondition: size() + __n <= capacity()
993 // Postcondition: size() == old size() + __n
994 // Postcondition: [i] == __x for all i in [size() - __n, __n)
995 template <class _Tp, class _Allocator>
998 vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
1000 allocator_type& __a = this->__alloc();
1003 __RAII_IncreaseAnnotator __annotator(*this);
1004 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
1007 __annotator.__done();
1011 template <class _Tp, class _Allocator>
1012 template <class _ForwardIterator>
1015 __is_forward_iterator<_ForwardIterator>::value,
1018 vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
1020 allocator_type& __a = this->__alloc();
1021 __RAII_IncreaseAnnotator __annotator(*this, __n);
1022 __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_);
1023 __annotator.__done();
1026 // Default constructs __n objects starting at __end_
1027 // throws if construction throws
1028 // Postcondition: size() == size() + __n
1029 // Exception safety: strong.
1030 template <class _Tp, class _Allocator>
1032 vector<_Tp, _Allocator>::__append(size_type __n)
1034 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1035 this->__construct_at_end(__n);
1038 allocator_type& __a = this->__alloc();
1039 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1040 __v.__construct_at_end(__n);
1041 __swap_out_circular_buffer(__v);
1045 // Default constructs __n objects starting at __end_
1046 // throws if construction throws
1047 // Postcondition: size() == size() + __n
1048 // Exception safety: strong.
1049 template <class _Tp, class _Allocator>
1051 vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1053 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1054 this->__construct_at_end(__n, __x);
1057 allocator_type& __a = this->__alloc();
1058 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1059 __v.__construct_at_end(__n, __x);
1060 __swap_out_circular_buffer(__v);
1064 template <class _Tp, class _Allocator>
1065 vector<_Tp, _Allocator>::vector(size_type __n)
1067 #if _LIBCPP_DEBUG_LEVEL >= 2
1068 __get_db()->__insert_c(this);
1073 __construct_at_end(__n);
1077 #if _LIBCPP_STD_VER > 11
1078 template <class _Tp, class _Allocator>
1079 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1082 #if _LIBCPP_DEBUG_LEVEL >= 2
1083 __get_db()->__insert_c(this);
1088 __construct_at_end(__n);
1093 template <class _Tp, class _Allocator>
1094 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1096 #if _LIBCPP_DEBUG_LEVEL >= 2
1097 __get_db()->__insert_c(this);
1102 __construct_at_end(__n, __x);
1106 template <class _Tp, class _Allocator>
1107 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1110 #if _LIBCPP_DEBUG_LEVEL >= 2
1111 __get_db()->__insert_c(this);
1116 __construct_at_end(__n, __x);
1120 template <class _Tp, class _Allocator>
1121 template <class _InputIterator>
1122 vector<_Tp, _Allocator>::vector(_InputIterator __first,
1123 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1124 !__is_forward_iterator<_InputIterator>::value &&
1127 typename iterator_traits<_InputIterator>::reference>::value,
1128 _InputIterator>::type __last)
1130 #if _LIBCPP_DEBUG_LEVEL >= 2
1131 __get_db()->__insert_c(this);
1133 for (; __first != __last; ++__first)
1134 push_back(*__first);
1137 template <class _Tp, class _Allocator>
1138 template <class _InputIterator>
1139 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1140 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1141 !__is_forward_iterator<_InputIterator>::value &&
1144 typename iterator_traits<_InputIterator>::reference>::value>::type*)
1147 #if _LIBCPP_DEBUG_LEVEL >= 2
1148 __get_db()->__insert_c(this);
1150 for (; __first != __last; ++__first)
1151 push_back(*__first);
1154 template <class _Tp, class _Allocator>
1155 template <class _ForwardIterator>
1156 vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
1157 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1160 typename iterator_traits<_ForwardIterator>::reference>::value,
1161 _ForwardIterator>::type __last)
1163 #if _LIBCPP_DEBUG_LEVEL >= 2
1164 __get_db()->__insert_c(this);
1166 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1170 __construct_at_end(__first, __last, __n);
1174 template <class _Tp, class _Allocator>
1175 template <class _ForwardIterator>
1176 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1177 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1180 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1183 #if _LIBCPP_DEBUG_LEVEL >= 2
1184 __get_db()->__insert_c(this);
1186 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1190 __construct_at_end(__first, __last, __n);
1194 template <class _Tp, class _Allocator>
1195 vector<_Tp, _Allocator>::vector(const vector& __x)
1196 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1198 #if _LIBCPP_DEBUG_LEVEL >= 2
1199 __get_db()->__insert_c(this);
1201 size_type __n = __x.size();
1205 __construct_at_end(__x.__begin_, __x.__end_, __n);
1209 template <class _Tp, class _Allocator>
1210 vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1213 #if _LIBCPP_DEBUG_LEVEL >= 2
1214 __get_db()->__insert_c(this);
1216 size_type __n = __x.size();
1220 __construct_at_end(__x.__begin_, __x.__end_, __n);
1224 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1226 template <class _Tp, class _Allocator>
1227 inline _LIBCPP_INLINE_VISIBILITY
1228 vector<_Tp, _Allocator>::vector(vector&& __x)
1229 #if _LIBCPP_STD_VER > 14
1232 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1234 : __base(_VSTD::move(__x.__alloc()))
1236 #if _LIBCPP_DEBUG_LEVEL >= 2
1237 __get_db()->__insert_c(this);
1238 __get_db()->swap(this, &__x);
1240 this->__begin_ = __x.__begin_;
1241 this->__end_ = __x.__end_;
1242 this->__end_cap() = __x.__end_cap();
1243 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1246 template <class _Tp, class _Allocator>
1247 inline _LIBCPP_INLINE_VISIBILITY
1248 vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1251 #if _LIBCPP_DEBUG_LEVEL >= 2
1252 __get_db()->__insert_c(this);
1254 if (__a == __x.__alloc())
1256 this->__begin_ = __x.__begin_;
1257 this->__end_ = __x.__end_;
1258 this->__end_cap() = __x.__end_cap();
1259 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1260 #if _LIBCPP_DEBUG_LEVEL >= 2
1261 __get_db()->swap(this, &__x);
1266 typedef move_iterator<iterator> _Ip;
1267 assign(_Ip(__x.begin()), _Ip(__x.end()));
1271 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1273 template <class _Tp, class _Allocator>
1274 inline _LIBCPP_INLINE_VISIBILITY
1275 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1277 #if _LIBCPP_DEBUG_LEVEL >= 2
1278 __get_db()->__insert_c(this);
1280 if (__il.size() > 0)
1282 allocate(__il.size());
1283 __construct_at_end(__il.begin(), __il.end(), __il.size());
1287 template <class _Tp, class _Allocator>
1288 inline _LIBCPP_INLINE_VISIBILITY
1289 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1292 #if _LIBCPP_DEBUG_LEVEL >= 2
1293 __get_db()->__insert_c(this);
1295 if (__il.size() > 0)
1297 allocate(__il.size());
1298 __construct_at_end(__il.begin(), __il.end(), __il.size());
1302 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1304 template <class _Tp, class _Allocator>
1305 inline _LIBCPP_INLINE_VISIBILITY
1306 vector<_Tp, _Allocator>&
1307 vector<_Tp, _Allocator>::operator=(vector&& __x)
1308 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
1310 __move_assign(__x, integral_constant<bool,
1311 __alloc_traits::propagate_on_container_move_assignment::value>());
1315 template <class _Tp, class _Allocator>
1317 vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1318 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
1320 if (__base::__alloc() != __c.__alloc())
1322 typedef move_iterator<iterator> _Ip;
1323 assign(_Ip(__c.begin()), _Ip(__c.end()));
1326 __move_assign(__c, true_type());
1329 template <class _Tp, class _Allocator>
1331 vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1332 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1335 __base::__move_assign_alloc(__c); // this can throw
1336 this->__begin_ = __c.__begin_;
1337 this->__end_ = __c.__end_;
1338 this->__end_cap() = __c.__end_cap();
1339 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1340 #if _LIBCPP_DEBUG_LEVEL >= 2
1341 __get_db()->swap(this, &__c);
1345 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1347 template <class _Tp, class _Allocator>
1348 inline _LIBCPP_INLINE_VISIBILITY
1349 vector<_Tp, _Allocator>&
1350 vector<_Tp, _Allocator>::operator=(const vector& __x)
1354 __base::__copy_assign_alloc(__x);
1355 assign(__x.__begin_, __x.__end_);
1360 template <class _Tp, class _Allocator>
1361 template <class _InputIterator>
1364 __is_input_iterator <_InputIterator>::value &&
1365 !__is_forward_iterator<_InputIterator>::value &&
1368 typename iterator_traits<_InputIterator>::reference>::value,
1371 vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1374 for (; __first != __last; ++__first)
1375 push_back(*__first);
1378 template <class _Tp, class _Allocator>
1379 template <class _ForwardIterator>
1382 __is_forward_iterator<_ForwardIterator>::value &&
1385 typename iterator_traits<_ForwardIterator>::reference>::value,
1388 vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1390 size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
1391 if (__new_size <= capacity())
1393 _ForwardIterator __mid = __last;
1394 bool __growing = false;
1395 if (__new_size > size())
1399 _VSTD::advance(__mid, size());
1401 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
1403 __construct_at_end(__mid, __last, __new_size - size());
1405 this->__destruct_at_end(__m);
1410 allocate(__recommend(__new_size));
1411 __construct_at_end(__first, __last, __new_size);
1415 template <class _Tp, class _Allocator>
1417 vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1419 if (__n <= capacity())
1421 size_type __s = size();
1422 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
1424 __construct_at_end(__n - __s, __u);
1426 this->__destruct_at_end(this->__begin_ + __n);
1431 allocate(__recommend(static_cast<size_type>(__n)));
1432 __construct_at_end(__n, __u);
1436 template <class _Tp, class _Allocator>
1437 inline _LIBCPP_INLINE_VISIBILITY
1438 typename vector<_Tp, _Allocator>::iterator
1439 vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
1441 #if _LIBCPP_DEBUG_LEVEL >= 2
1442 return iterator(this, __p);
1444 return iterator(__p);
1448 template <class _Tp, class _Allocator>
1449 inline _LIBCPP_INLINE_VISIBILITY
1450 typename vector<_Tp, _Allocator>::const_iterator
1451 vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
1453 #if _LIBCPP_DEBUG_LEVEL >= 2
1454 return const_iterator(this, __p);
1456 return const_iterator(__p);
1460 template <class _Tp, class _Allocator>
1461 inline _LIBCPP_INLINE_VISIBILITY
1462 typename vector<_Tp, _Allocator>::iterator
1463 vector<_Tp, _Allocator>::begin() _NOEXCEPT
1465 return __make_iter(this->__begin_);
1468 template <class _Tp, class _Allocator>
1469 inline _LIBCPP_INLINE_VISIBILITY
1470 typename vector<_Tp, _Allocator>::const_iterator
1471 vector<_Tp, _Allocator>::begin() const _NOEXCEPT
1473 return __make_iter(this->__begin_);
1476 template <class _Tp, class _Allocator>
1477 inline _LIBCPP_INLINE_VISIBILITY
1478 typename vector<_Tp, _Allocator>::iterator
1479 vector<_Tp, _Allocator>::end() _NOEXCEPT
1481 return __make_iter(this->__end_);
1484 template <class _Tp, class _Allocator>
1485 inline _LIBCPP_INLINE_VISIBILITY
1486 typename vector<_Tp, _Allocator>::const_iterator
1487 vector<_Tp, _Allocator>::end() const _NOEXCEPT
1489 return __make_iter(this->__end_);
1492 template <class _Tp, class _Allocator>
1493 inline _LIBCPP_INLINE_VISIBILITY
1494 typename vector<_Tp, _Allocator>::reference
1495 vector<_Tp, _Allocator>::operator[](size_type __n)
1497 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1498 return this->__begin_[__n];
1501 template <class _Tp, class _Allocator>
1502 inline _LIBCPP_INLINE_VISIBILITY
1503 typename vector<_Tp, _Allocator>::const_reference
1504 vector<_Tp, _Allocator>::operator[](size_type __n) const
1506 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1507 return this->__begin_[__n];
1510 template <class _Tp, class _Allocator>
1511 typename vector<_Tp, _Allocator>::reference
1512 vector<_Tp, _Allocator>::at(size_type __n)
1515 this->__throw_out_of_range();
1516 return this->__begin_[__n];
1519 template <class _Tp, class _Allocator>
1520 typename vector<_Tp, _Allocator>::const_reference
1521 vector<_Tp, _Allocator>::at(size_type __n) const
1524 this->__throw_out_of_range();
1525 return this->__begin_[__n];
1528 template <class _Tp, class _Allocator>
1530 vector<_Tp, _Allocator>::reserve(size_type __n)
1532 if (__n > capacity())
1534 allocator_type& __a = this->__alloc();
1535 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
1536 __swap_out_circular_buffer(__v);
1540 template <class _Tp, class _Allocator>
1542 vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1544 if (capacity() > size())
1546 #ifndef _LIBCPP_NO_EXCEPTIONS
1549 #endif // _LIBCPP_NO_EXCEPTIONS
1550 allocator_type& __a = this->__alloc();
1551 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1552 __swap_out_circular_buffer(__v);
1553 #ifndef _LIBCPP_NO_EXCEPTIONS
1558 #endif // _LIBCPP_NO_EXCEPTIONS
1562 template <class _Tp, class _Allocator>
1563 template <class _Up>
1565 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1566 vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1568 vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1571 allocator_type& __a = this->__alloc();
1572 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1573 // __v.push_back(_VSTD::forward<_Up>(__x));
1574 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
1576 __swap_out_circular_buffer(__v);
1579 template <class _Tp, class _Allocator>
1580 inline _LIBCPP_INLINE_VISIBILITY
1582 vector<_Tp, _Allocator>::push_back(const_reference __x)
1584 if (this->__end_ != this->__end_cap())
1586 __RAII_IncreaseAnnotator __annotator(*this);
1587 __alloc_traits::construct(this->__alloc(),
1588 _VSTD::__to_raw_pointer(this->__end_), __x);
1589 __annotator.__done();
1593 __push_back_slow_path(__x);
1596 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1598 template <class _Tp, class _Allocator>
1599 inline _LIBCPP_INLINE_VISIBILITY
1601 vector<_Tp, _Allocator>::push_back(value_type&& __x)
1603 if (this->__end_ < this->__end_cap())
1605 __RAII_IncreaseAnnotator __annotator(*this);
1606 __alloc_traits::construct(this->__alloc(),
1607 _VSTD::__to_raw_pointer(this->__end_),
1609 __annotator.__done();
1613 __push_back_slow_path(_VSTD::move(__x));
1616 #ifndef _LIBCPP_HAS_NO_VARIADICS
1618 template <class _Tp, class _Allocator>
1619 template <class... _Args>
1621 vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1623 allocator_type& __a = this->__alloc();
1624 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1625 // __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1626 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
1628 __swap_out_circular_buffer(__v);
1631 template <class _Tp, class _Allocator>
1632 template <class... _Args>
1635 vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1637 if (this->__end_ < this->__end_cap())
1639 __RAII_IncreaseAnnotator __annotator(*this);
1640 __alloc_traits::construct(this->__alloc(),
1641 _VSTD::__to_raw_pointer(this->__end_),
1642 _VSTD::forward<_Args>(__args)...);
1643 __annotator.__done();
1647 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
1650 #endif // _LIBCPP_HAS_NO_VARIADICS
1651 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1653 template <class _Tp, class _Allocator>
1656 vector<_Tp, _Allocator>::pop_back()
1658 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
1659 this->__destruct_at_end(this->__end_ - 1);
1662 template <class _Tp, class _Allocator>
1663 inline _LIBCPP_INLINE_VISIBILITY
1664 typename vector<_Tp, _Allocator>::iterator
1665 vector<_Tp, _Allocator>::erase(const_iterator __position)
1667 #if _LIBCPP_DEBUG_LEVEL >= 2
1668 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1669 "vector::erase(iterator) called with an iterator not"
1670 " referring to this vector");
1672 _LIBCPP_ASSERT(__position != end(),
1673 "vector::erase(iterator) called with a non-dereferenceable iterator");
1674 difference_type __ps = __position - cbegin();
1675 pointer __p = this->__begin_ + __ps;
1676 iterator __r = __make_iter(__p);
1677 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
1681 template <class _Tp, class _Allocator>
1682 typename vector<_Tp, _Allocator>::iterator
1683 vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1685 #if _LIBCPP_DEBUG_LEVEL >= 2
1686 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1687 "vector::erase(iterator, iterator) called with an iterator not"
1688 " referring to this vector");
1690 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
1691 pointer __p = this->__begin_ + (__first - begin());
1692 iterator __r = __make_iter(__p);
1693 if (__first != __last)
1694 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1698 template <class _Tp, class _Allocator>
1700 vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1702 pointer __old_last = this->__end_;
1703 difference_type __n = __old_last - __to;
1704 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1705 __alloc_traits::construct(this->__alloc(),
1706 _VSTD::__to_raw_pointer(this->__end_),
1708 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
1711 template <class _Tp, class _Allocator>
1712 typename vector<_Tp, _Allocator>::iterator
1713 vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1715 #if _LIBCPP_DEBUG_LEVEL >= 2
1716 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1717 "vector::insert(iterator, x) called with an iterator not"
1718 " referring to this vector");
1720 pointer __p = this->__begin_ + (__position - begin());
1721 if (this->__end_ < this->__end_cap())
1723 __RAII_IncreaseAnnotator __annotator(*this);
1724 if (__p == this->__end_)
1726 __alloc_traits::construct(this->__alloc(),
1727 _VSTD::__to_raw_pointer(this->__end_), __x);
1732 __move_range(__p, this->__end_, __p + 1);
1733 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1734 if (__p <= __xr && __xr < this->__end_)
1738 __annotator.__done();
1742 allocator_type& __a = this->__alloc();
1743 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1745 __p = __swap_out_circular_buffer(__v, __p);
1747 return __make_iter(__p);
1750 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1752 template <class _Tp, class _Allocator>
1753 typename vector<_Tp, _Allocator>::iterator
1754 vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1756 #if _LIBCPP_DEBUG_LEVEL >= 2
1757 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1758 "vector::insert(iterator, x) called with an iterator not"
1759 " referring to this vector");
1761 pointer __p = this->__begin_ + (__position - begin());
1762 if (this->__end_ < this->__end_cap())
1764 __RAII_IncreaseAnnotator __annotator(*this);
1765 if (__p == this->__end_)
1767 __alloc_traits::construct(this->__alloc(),
1768 _VSTD::__to_raw_pointer(this->__end_),
1774 __move_range(__p, this->__end_, __p + 1);
1775 *__p = _VSTD::move(__x);
1777 __annotator.__done();
1781 allocator_type& __a = this->__alloc();
1782 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1783 __v.push_back(_VSTD::move(__x));
1784 __p = __swap_out_circular_buffer(__v, __p);
1786 return __make_iter(__p);
1789 #ifndef _LIBCPP_HAS_NO_VARIADICS
1791 template <class _Tp, class _Allocator>
1792 template <class... _Args>
1793 typename vector<_Tp, _Allocator>::iterator
1794 vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1796 #if _LIBCPP_DEBUG_LEVEL >= 2
1797 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1798 "vector::emplace(iterator, x) called with an iterator not"
1799 " referring to this vector");
1801 pointer __p = this->__begin_ + (__position - begin());
1802 if (this->__end_ < this->__end_cap())
1804 __RAII_IncreaseAnnotator __annotator(*this);
1805 if (__p == this->__end_)
1807 __alloc_traits::construct(this->__alloc(),
1808 _VSTD::__to_raw_pointer(this->__end_),
1809 _VSTD::forward<_Args>(__args)...);
1814 value_type __tmp(_VSTD::forward<_Args>(__args)...);
1815 __move_range(__p, this->__end_, __p + 1);
1816 *__p = _VSTD::move(__tmp);
1818 __annotator.__done();
1822 allocator_type& __a = this->__alloc();
1823 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1824 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1825 __p = __swap_out_circular_buffer(__v, __p);
1827 return __make_iter(__p);
1830 #endif // _LIBCPP_HAS_NO_VARIADICS
1831 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1833 template <class _Tp, class _Allocator>
1834 typename vector<_Tp, _Allocator>::iterator
1835 vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1837 #if _LIBCPP_DEBUG_LEVEL >= 2
1838 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1839 "vector::insert(iterator, n, x) called with an iterator not"
1840 " referring to this vector");
1842 pointer __p = this->__begin_ + (__position - begin());
1845 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1847 size_type __old_n = __n;
1848 pointer __old_last = this->__end_;
1849 if (__n > static_cast<size_type>(this->__end_ - __p))
1851 size_type __cx = __n - (this->__end_ - __p);
1852 __construct_at_end(__cx, __x);
1857 __RAII_IncreaseAnnotator __annotator(*this, __n);
1858 __move_range(__p, __old_last, __p + __old_n);
1859 __annotator.__done();
1860 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1861 if (__p <= __xr && __xr < this->__end_)
1863 _VSTD::fill_n(__p, __n, *__xr);
1868 allocator_type& __a = this->__alloc();
1869 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1870 __v.__construct_at_end(__n, __x);
1871 __p = __swap_out_circular_buffer(__v, __p);
1874 return __make_iter(__p);
1877 template <class _Tp, class _Allocator>
1878 template <class _InputIterator>
1881 __is_input_iterator <_InputIterator>::value &&
1882 !__is_forward_iterator<_InputIterator>::value &&
1885 typename iterator_traits<_InputIterator>::reference>::value,
1886 typename vector<_Tp, _Allocator>::iterator
1888 vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1890 #if _LIBCPP_DEBUG_LEVEL >= 2
1891 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1892 "vector::insert(iterator, range) called with an iterator not"
1893 " referring to this vector");
1895 difference_type __off = __position - begin();
1896 pointer __p = this->__begin_ + __off;
1897 allocator_type& __a = this->__alloc();
1898 pointer __old_last = this->__end_;
1899 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1901 __RAII_IncreaseAnnotator __annotator(*this);
1902 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
1905 __annotator.__done();
1907 __split_buffer<value_type, allocator_type&> __v(__a);
1908 if (__first != __last)
1910 #ifndef _LIBCPP_NO_EXCEPTIONS
1913 #endif // _LIBCPP_NO_EXCEPTIONS
1914 __v.__construct_at_end(__first, __last);
1915 difference_type __old_size = __old_last - this->__begin_;
1916 difference_type __old_p = __p - this->__begin_;
1917 reserve(__recommend(size() + __v.size()));
1918 __p = this->__begin_ + __old_p;
1919 __old_last = this->__begin_ + __old_size;
1920 #ifndef _LIBCPP_NO_EXCEPTIONS
1924 erase(__make_iter(__old_last), end());
1927 #endif // _LIBCPP_NO_EXCEPTIONS
1929 __p = _VSTD::rotate(__p, __old_last, this->__end_);
1930 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1931 make_move_iterator(__v.end()));
1932 return begin() + __off;
1935 template <class _Tp, class _Allocator>
1936 template <class _ForwardIterator>
1939 __is_forward_iterator<_ForwardIterator>::value &&
1942 typename iterator_traits<_ForwardIterator>::reference>::value,
1943 typename vector<_Tp, _Allocator>::iterator
1945 vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1947 #if _LIBCPP_DEBUG_LEVEL >= 2
1948 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1949 "vector::insert(iterator, range) called with an iterator not"
1950 " referring to this vector");
1952 pointer __p = this->__begin_ + (__position - begin());
1953 difference_type __n = _VSTD::distance(__first, __last);
1956 if (__n <= this->__end_cap() - this->__end_)
1958 size_type __old_n = __n;
1959 pointer __old_last = this->__end_;
1960 _ForwardIterator __m = __last;
1961 difference_type __dx = this->__end_ - __p;
1965 difference_type __diff = this->__end_ - __p;
1966 _VSTD::advance(__m, __diff);
1967 __construct_at_end(__m, __last, __n - __diff);
1972 __RAII_IncreaseAnnotator __annotator(*this, __n);
1973 __move_range(__p, __old_last, __p + __old_n);
1974 __annotator.__done();
1975 _VSTD::copy(__first, __m, __p);
1980 allocator_type& __a = this->__alloc();
1981 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1982 __v.__construct_at_end(__first, __last);
1983 __p = __swap_out_circular_buffer(__v, __p);
1986 return __make_iter(__p);
1989 template <class _Tp, class _Allocator>
1991 vector<_Tp, _Allocator>::resize(size_type __sz)
1993 size_type __cs = size();
1995 this->__append(__sz - __cs);
1996 else if (__cs > __sz)
1997 this->__destruct_at_end(this->__begin_ + __sz);
2000 template <class _Tp, class _Allocator>
2002 vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
2004 size_type __cs = size();
2006 this->__append(__sz - __cs, __x);
2007 else if (__cs > __sz)
2008 this->__destruct_at_end(this->__begin_ + __sz);
2011 template <class _Tp, class _Allocator>
2013 vector<_Tp, _Allocator>::swap(vector& __x)
2014 #if _LIBCPP_STD_VER >= 14
2017 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2018 __is_nothrow_swappable<allocator_type>::value)
2021 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
2022 this->__alloc() == __x.__alloc(),
2023 "vector::swap: Either propagate_on_container_swap must be true"
2024 " or the allocators must compare equal");
2025 _VSTD::swap(this->__begin_, __x.__begin_);
2026 _VSTD::swap(this->__end_, __x.__end_);
2027 _VSTD::swap(this->__end_cap(), __x.__end_cap());
2028 __swap_allocator(this->__alloc(), __x.__alloc(),
2029 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
2030 #if _LIBCPP_DEBUG_LEVEL >= 2
2031 __get_db()->swap(this, &__x);
2032 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2035 template <class _Tp, class _Allocator>
2037 vector<_Tp, _Allocator>::__invariants() const
2039 if (this->__begin_ == nullptr)
2041 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
2046 if (this->__begin_ > this->__end_)
2048 if (this->__begin_ == this->__end_cap())
2050 if (this->__end_ > this->__end_cap())
2056 #if _LIBCPP_DEBUG_LEVEL >= 2
2058 template <class _Tp, class _Allocator>
2060 vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
2062 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
2065 template <class _Tp, class _Allocator>
2067 vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
2069 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
2072 template <class _Tp, class _Allocator>
2074 vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2076 const_pointer __p = __i->base() + __n;
2077 return this->__begin_ <= __p && __p <= this->__end_;
2080 template <class _Tp, class _Allocator>
2082 vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2084 const_pointer __p = __i->base() + __n;
2085 return this->__begin_ <= __p && __p < this->__end_;
2088 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2090 template <class _Tp, class _Allocator>
2091 inline _LIBCPP_INLINE_VISIBILITY
2093 vector<_Tp, _Allocator>::__invalidate_all_iterators()
2095 #if _LIBCPP_DEBUG_LEVEL >= 2
2096 __get_db()->__invalidate_all(this);
2097 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2102 template <class _Allocator> class vector<bool, _Allocator>;
2104 template <class _Allocator> struct hash<vector<bool, _Allocator> >;
2106 template <class _Allocator>
2107 struct __has_storage_type<vector<bool, _Allocator> >
2109 static const bool value = true;
2112 template <class _Allocator>
2113 class _LIBCPP_TYPE_VIS_ONLY vector<bool, _Allocator>
2114 : private __vector_base_common<true>
2117 typedef vector __self;
2118 typedef bool value_type;
2119 typedef _Allocator allocator_type;
2120 typedef allocator_traits<allocator_type> __alloc_traits;
2121 typedef typename __alloc_traits::size_type size_type;
2122 typedef typename __alloc_traits::difference_type difference_type;
2123 typedef size_type __storage_type;
2124 typedef __bit_iterator<vector, false> pointer;
2125 typedef __bit_iterator<vector, true> const_pointer;
2126 typedef pointer iterator;
2127 typedef const_pointer const_iterator;
2128 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
2129 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
2132 typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
2133 typedef allocator_traits<__storage_allocator> __storage_traits;
2134 typedef typename __storage_traits::pointer __storage_pointer;
2135 typedef typename __storage_traits::const_pointer __const_storage_pointer;
2137 __storage_pointer __begin_;
2139 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
2141 typedef __bit_reference<vector> reference;
2142 typedef __bit_const_reference<vector> const_reference;
2144 _LIBCPP_INLINE_VISIBILITY
2145 size_type& __cap() _NOEXCEPT
2146 {return __cap_alloc_.first();}
2147 _LIBCPP_INLINE_VISIBILITY
2148 const size_type& __cap() const _NOEXCEPT
2149 {return __cap_alloc_.first();}
2150 _LIBCPP_INLINE_VISIBILITY
2151 __storage_allocator& __alloc() _NOEXCEPT
2152 {return __cap_alloc_.second();}
2153 _LIBCPP_INLINE_VISIBILITY
2154 const __storage_allocator& __alloc() const _NOEXCEPT
2155 {return __cap_alloc_.second();}
2157 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2159 _LIBCPP_INLINE_VISIBILITY
2160 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
2161 {return __n * __bits_per_word;}
2162 _LIBCPP_INLINE_VISIBILITY
2163 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
2164 {return (__n - 1) / __bits_per_word + 1;}
2167 _LIBCPP_INLINE_VISIBILITY
2168 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
2170 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
2171 #if _LIBCPP_STD_VER <= 14
2172 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
2177 explicit vector(size_type __n);
2178 #if _LIBCPP_STD_VER > 11
2179 explicit vector(size_type __n, const allocator_type& __a);
2181 vector(size_type __n, const value_type& __v);
2182 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2183 template <class _InputIterator>
2184 vector(_InputIterator __first, _InputIterator __last,
2185 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2186 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2187 template <class _InputIterator>
2188 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2189 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2190 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2191 template <class _ForwardIterator>
2192 vector(_ForwardIterator __first, _ForwardIterator __last,
2193 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2194 template <class _ForwardIterator>
2195 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2196 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2198 vector(const vector& __v);
2199 vector(const vector& __v, const allocator_type& __a);
2200 vector& operator=(const vector& __v);
2201 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2202 vector(initializer_list<value_type> __il);
2203 vector(initializer_list<value_type> __il, const allocator_type& __a);
2204 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2206 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2207 _LIBCPP_INLINE_VISIBILITY
2208 vector(vector&& __v)
2209 #if _LIBCPP_STD_VER > 14
2212 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
2214 vector(vector&& __v, const allocator_type& __a);
2215 _LIBCPP_INLINE_VISIBILITY
2216 vector& operator=(vector&& __v)
2217 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
2218 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2219 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2220 _LIBCPP_INLINE_VISIBILITY
2221 vector& operator=(initializer_list<value_type> __il)
2222 {assign(__il.begin(), __il.end()); return *this;}
2223 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2225 template <class _InputIterator>
2228 __is_input_iterator<_InputIterator>::value &&
2229 !__is_forward_iterator<_InputIterator>::value,
2232 assign(_InputIterator __first, _InputIterator __last);
2233 template <class _ForwardIterator>
2236 __is_forward_iterator<_ForwardIterator>::value,
2239 assign(_ForwardIterator __first, _ForwardIterator __last);
2241 void assign(size_type __n, const value_type& __x);
2242 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2243 _LIBCPP_INLINE_VISIBILITY
2244 void assign(initializer_list<value_type> __il)
2245 {assign(__il.begin(), __il.end());}
2246 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2248 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
2249 {return allocator_type(this->__alloc());}
2251 size_type max_size() const _NOEXCEPT;
2252 _LIBCPP_INLINE_VISIBILITY
2253 size_type capacity() const _NOEXCEPT
2254 {return __internal_cap_to_external(__cap());}
2255 _LIBCPP_INLINE_VISIBILITY
2256 size_type size() const _NOEXCEPT
2258 _LIBCPP_INLINE_VISIBILITY
2259 bool empty() const _NOEXCEPT
2260 {return __size_ == 0;}
2261 void reserve(size_type __n);
2262 void shrink_to_fit() _NOEXCEPT;
2264 _LIBCPP_INLINE_VISIBILITY
2265 iterator begin() _NOEXCEPT
2266 {return __make_iter(0);}
2267 _LIBCPP_INLINE_VISIBILITY
2268 const_iterator begin() const _NOEXCEPT
2269 {return __make_iter(0);}
2270 _LIBCPP_INLINE_VISIBILITY
2271 iterator end() _NOEXCEPT
2272 {return __make_iter(__size_);}
2273 _LIBCPP_INLINE_VISIBILITY
2274 const_iterator end() const _NOEXCEPT
2275 {return __make_iter(__size_);}
2277 _LIBCPP_INLINE_VISIBILITY
2278 reverse_iterator rbegin() _NOEXCEPT
2279 {return reverse_iterator(end());}
2280 _LIBCPP_INLINE_VISIBILITY
2281 const_reverse_iterator rbegin() const _NOEXCEPT
2282 {return const_reverse_iterator(end());}
2283 _LIBCPP_INLINE_VISIBILITY
2284 reverse_iterator rend() _NOEXCEPT
2285 {return reverse_iterator(begin());}
2286 _LIBCPP_INLINE_VISIBILITY
2287 const_reverse_iterator rend() const _NOEXCEPT
2288 {return const_reverse_iterator(begin());}
2290 _LIBCPP_INLINE_VISIBILITY
2291 const_iterator cbegin() const _NOEXCEPT
2292 {return __make_iter(0);}
2293 _LIBCPP_INLINE_VISIBILITY
2294 const_iterator cend() const _NOEXCEPT
2295 {return __make_iter(__size_);}
2296 _LIBCPP_INLINE_VISIBILITY
2297 const_reverse_iterator crbegin() const _NOEXCEPT
2299 _LIBCPP_INLINE_VISIBILITY
2300 const_reverse_iterator crend() const _NOEXCEPT
2303 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2304 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2305 reference at(size_type __n);
2306 const_reference at(size_type __n) const;
2308 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2309 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2310 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2311 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2313 void push_back(const value_type& __x);
2314 #if _LIBCPP_STD_VER > 11
2315 template <class... _Args>
2316 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
2317 { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); }
2320 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2322 #if _LIBCPP_STD_VER > 11
2323 template <class... _Args>
2324 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2325 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2328 iterator insert(const_iterator __position, const value_type& __x);
2329 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2330 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2331 template <class _InputIterator>
2334 __is_input_iterator <_InputIterator>::value &&
2335 !__is_forward_iterator<_InputIterator>::value,
2338 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2339 template <class _ForwardIterator>
2342 __is_forward_iterator<_ForwardIterator>::value,
2345 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
2346 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2347 _LIBCPP_INLINE_VISIBILITY
2348 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2349 {return insert(__position, __il.begin(), __il.end());}
2350 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2352 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
2353 iterator erase(const_iterator __first, const_iterator __last);
2355 _LIBCPP_INLINE_VISIBILITY
2356 void clear() _NOEXCEPT {__size_ = 0;}
2359 #if _LIBCPP_STD_VER >= 14
2362 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2363 __is_nothrow_swappable<allocator_type>::value);
2366 void resize(size_type __sz, value_type __x = false);
2367 void flip() _NOEXCEPT;
2369 bool __invariants() const;
2372 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
2373 void allocate(size_type __n);
2374 void deallocate() _NOEXCEPT;
2375 _LIBCPP_INLINE_VISIBILITY
2376 static size_type __align_it(size_type __new_size) _NOEXCEPT
2377 {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);};
2378 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2379 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
2380 template <class _ForwardIterator>
2383 __is_forward_iterator<_ForwardIterator>::value,
2386 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2387 void __append(size_type __n, const_reference __x);
2388 _LIBCPP_INLINE_VISIBILITY
2389 reference __make_ref(size_type __pos) _NOEXCEPT
2390 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2391 _LIBCPP_INLINE_VISIBILITY
2392 const_reference __make_ref(size_type __pos) const _NOEXCEPT
2393 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2394 _LIBCPP_INLINE_VISIBILITY
2395 iterator __make_iter(size_type __pos) _NOEXCEPT
2396 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2397 _LIBCPP_INLINE_VISIBILITY
2398 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
2399 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2400 _LIBCPP_INLINE_VISIBILITY
2401 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
2402 {return begin() + (__p - cbegin());}
2404 _LIBCPP_INLINE_VISIBILITY
2405 void __copy_assign_alloc(const vector& __v)
2406 {__copy_assign_alloc(__v, integral_constant<bool,
2407 __storage_traits::propagate_on_container_copy_assignment::value>());}
2408 _LIBCPP_INLINE_VISIBILITY
2409 void __copy_assign_alloc(const vector& __c, true_type)
2411 if (__alloc() != __c.__alloc())
2413 __alloc() = __c.__alloc();
2416 _LIBCPP_INLINE_VISIBILITY
2417 void __copy_assign_alloc(const vector&, false_type)
2420 void __move_assign(vector& __c, false_type);
2421 void __move_assign(vector& __c, true_type)
2422 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2423 _LIBCPP_INLINE_VISIBILITY
2424 void __move_assign_alloc(vector& __c)
2426 !__storage_traits::propagate_on_container_move_assignment::value ||
2427 is_nothrow_move_assignable<allocator_type>::value)
2428 {__move_assign_alloc(__c, integral_constant<bool,
2429 __storage_traits::propagate_on_container_move_assignment::value>());}
2430 _LIBCPP_INLINE_VISIBILITY
2431 void __move_assign_alloc(vector& __c, true_type)
2432 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2434 __alloc() = _VSTD::move(__c.__alloc());
2437 _LIBCPP_INLINE_VISIBILITY
2438 void __move_assign_alloc(vector&, false_type)
2442 size_t __hash_code() const _NOEXCEPT;
2444 friend class __bit_reference<vector>;
2445 friend class __bit_const_reference<vector>;
2446 friend class __bit_iterator<vector, false>;
2447 friend class __bit_iterator<vector, true>;
2448 friend struct __bit_array<vector>;
2449 friend struct _LIBCPP_TYPE_VIS_ONLY hash<vector>;
2452 template <class _Allocator>
2453 inline _LIBCPP_INLINE_VISIBILITY
2455 vector<bool, _Allocator>::__invalidate_all_iterators()
2459 // Allocate space for __n objects
2460 // throws length_error if __n > max_size()
2461 // throws (probably bad_alloc) if memory run out
2462 // Precondition: __begin_ == __end_ == __cap() == 0
2463 // Precondition: __n > 0
2464 // Postcondition: capacity() == __n
2465 // Postcondition: size() == 0
2466 template <class _Allocator>
2468 vector<bool, _Allocator>::allocate(size_type __n)
2470 if (__n > max_size())
2471 this->__throw_length_error();
2472 __n = __external_cap_to_internal(__n);
2473 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2475 this->__cap() = __n;
2478 template <class _Allocator>
2480 vector<bool, _Allocator>::deallocate() _NOEXCEPT
2482 if (this->__begin_ != nullptr)
2484 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2485 __invalidate_all_iterators();
2486 this->__begin_ = nullptr;
2487 this->__size_ = this->__cap() = 0;
2491 template <class _Allocator>
2492 typename vector<bool, _Allocator>::size_type
2493 vector<bool, _Allocator>::max_size() const _NOEXCEPT
2495 size_type __amax = __storage_traits::max_size(__alloc());
2496 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2497 if (__nmax / __bits_per_word <= __amax)
2499 return __internal_cap_to_external(__amax);
2502 // Precondition: __new_size > capacity()
2503 template <class _Allocator>
2504 inline _LIBCPP_INLINE_VISIBILITY
2505 typename vector<bool, _Allocator>::size_type
2506 vector<bool, _Allocator>::__recommend(size_type __new_size) const
2508 const size_type __ms = max_size();
2509 if (__new_size > __ms)
2510 this->__throw_length_error();
2511 const size_type __cap = capacity();
2512 if (__cap >= __ms / 2)
2514 return _VSTD::max(2*__cap, __align_it(__new_size));
2517 // Default constructs __n objects starting at __end_
2518 // Precondition: __n > 0
2519 // Precondition: size() + __n <= capacity()
2520 // Postcondition: size() == size() + __n
2521 template <class _Allocator>
2522 inline _LIBCPP_INLINE_VISIBILITY
2524 vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2526 size_type __old_size = this->__size_;
2527 this->__size_ += __n;
2528 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
2531 template <class _Allocator>
2532 template <class _ForwardIterator>
2535 __is_forward_iterator<_ForwardIterator>::value,
2538 vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2540 size_type __old_size = this->__size_;
2541 this->__size_ += _VSTD::distance(__first, __last);
2542 _VSTD::copy(__first, __last, __make_iter(__old_size));
2545 template <class _Allocator>
2546 inline _LIBCPP_INLINE_VISIBILITY
2547 vector<bool, _Allocator>::vector()
2548 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2549 : __begin_(nullptr),
2555 template <class _Allocator>
2556 inline _LIBCPP_INLINE_VISIBILITY
2557 vector<bool, _Allocator>::vector(const allocator_type& __a)
2558 #if _LIBCPP_STD_VER <= 14
2559 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
2563 : __begin_(nullptr),
2565 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2569 template <class _Allocator>
2570 vector<bool, _Allocator>::vector(size_type __n)
2571 : __begin_(nullptr),
2578 __construct_at_end(__n, false);
2582 #if _LIBCPP_STD_VER > 11
2583 template <class _Allocator>
2584 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2585 : __begin_(nullptr),
2587 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2592 __construct_at_end(__n, false);
2597 template <class _Allocator>
2598 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2599 : __begin_(nullptr),
2606 __construct_at_end(__n, __x);
2610 template <class _Allocator>
2611 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2612 : __begin_(nullptr),
2614 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2619 __construct_at_end(__n, __x);
2623 template <class _Allocator>
2624 template <class _InputIterator>
2625 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2626 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2627 !__is_forward_iterator<_InputIterator>::value>::type*)
2628 : __begin_(nullptr),
2632 #ifndef _LIBCPP_NO_EXCEPTIONS
2635 #endif // _LIBCPP_NO_EXCEPTIONS
2636 for (; __first != __last; ++__first)
2637 push_back(*__first);
2638 #ifndef _LIBCPP_NO_EXCEPTIONS
2642 if (__begin_ != nullptr)
2643 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2644 __invalidate_all_iterators();
2647 #endif // _LIBCPP_NO_EXCEPTIONS
2650 template <class _Allocator>
2651 template <class _InputIterator>
2652 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2653 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2654 !__is_forward_iterator<_InputIterator>::value>::type*)
2655 : __begin_(nullptr),
2657 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2659 #ifndef _LIBCPP_NO_EXCEPTIONS
2662 #endif // _LIBCPP_NO_EXCEPTIONS
2663 for (; __first != __last; ++__first)
2664 push_back(*__first);
2665 #ifndef _LIBCPP_NO_EXCEPTIONS
2669 if (__begin_ != nullptr)
2670 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2671 __invalidate_all_iterators();
2674 #endif // _LIBCPP_NO_EXCEPTIONS
2677 template <class _Allocator>
2678 template <class _ForwardIterator>
2679 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2680 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2681 : __begin_(nullptr),
2685 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2689 __construct_at_end(__first, __last);
2693 template <class _Allocator>
2694 template <class _ForwardIterator>
2695 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2696 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2697 : __begin_(nullptr),
2699 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2701 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2705 __construct_at_end(__first, __last);
2709 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2711 template <class _Allocator>
2712 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2713 : __begin_(nullptr),
2717 size_type __n = static_cast<size_type>(__il.size());
2721 __construct_at_end(__il.begin(), __il.end());
2725 template <class _Allocator>
2726 vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2727 : __begin_(nullptr),
2729 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2731 size_type __n = static_cast<size_type>(__il.size());
2735 __construct_at_end(__il.begin(), __il.end());
2739 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2741 template <class _Allocator>
2742 vector<bool, _Allocator>::~vector()
2744 if (__begin_ != nullptr)
2745 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2746 __invalidate_all_iterators();
2749 template <class _Allocator>
2750 vector<bool, _Allocator>::vector(const vector& __v)
2751 : __begin_(nullptr),
2753 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2757 allocate(__v.size());
2758 __construct_at_end(__v.begin(), __v.end());
2762 template <class _Allocator>
2763 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2764 : __begin_(nullptr),
2766 __cap_alloc_(0, __a)
2770 allocate(__v.size());
2771 __construct_at_end(__v.begin(), __v.end());
2775 template <class _Allocator>
2776 vector<bool, _Allocator>&
2777 vector<bool, _Allocator>::operator=(const vector& __v)
2781 __copy_assign_alloc(__v);
2784 if (__v.__size_ > capacity())
2787 allocate(__v.__size_);
2789 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2791 __size_ = __v.__size_;
2796 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2798 template <class _Allocator>
2799 inline _LIBCPP_INLINE_VISIBILITY
2800 vector<bool, _Allocator>::vector(vector&& __v)
2801 #if _LIBCPP_STD_VER > 14
2804 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2806 : __begin_(__v.__begin_),
2807 __size_(__v.__size_),
2808 __cap_alloc_(__v.__cap_alloc_)
2810 __v.__begin_ = nullptr;
2815 template <class _Allocator>
2816 vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2817 : __begin_(nullptr),
2819 __cap_alloc_(0, __a)
2821 if (__a == allocator_type(__v.__alloc()))
2823 this->__begin_ = __v.__begin_;
2824 this->__size_ = __v.__size_;
2825 this->__cap() = __v.__cap();
2826 __v.__begin_ = nullptr;
2827 __v.__cap() = __v.__size_ = 0;
2829 else if (__v.size() > 0)
2831 allocate(__v.size());
2832 __construct_at_end(__v.begin(), __v.end());
2836 template <class _Allocator>
2837 inline _LIBCPP_INLINE_VISIBILITY
2838 vector<bool, _Allocator>&
2839 vector<bool, _Allocator>::operator=(vector&& __v)
2840 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
2842 __move_assign(__v, integral_constant<bool,
2843 __storage_traits::propagate_on_container_move_assignment::value>());
2847 template <class _Allocator>
2849 vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2851 if (__alloc() != __c.__alloc())
2852 assign(__c.begin(), __c.end());
2854 __move_assign(__c, true_type());
2857 template <class _Allocator>
2859 vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2860 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2863 __move_assign_alloc(__c);
2864 this->__begin_ = __c.__begin_;
2865 this->__size_ = __c.__size_;
2866 this->__cap() = __c.__cap();
2867 __c.__begin_ = nullptr;
2868 __c.__cap() = __c.__size_ = 0;
2871 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2873 template <class _Allocator>
2875 vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2880 size_type __c = capacity();
2885 vector __v(__alloc());
2886 __v.reserve(__recommend(__n));
2890 _VSTD::fill_n(begin(), __n, __x);
2894 template <class _Allocator>
2895 template <class _InputIterator>
2898 __is_input_iterator<_InputIterator>::value &&
2899 !__is_forward_iterator<_InputIterator>::value,
2902 vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2905 for (; __first != __last; ++__first)
2906 push_back(*__first);
2909 template <class _Allocator>
2910 template <class _ForwardIterator>
2913 __is_forward_iterator<_ForwardIterator>::value,
2916 vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2919 difference_type __n = _VSTD::distance(__first, __last);
2922 if (__n > capacity())
2927 __construct_at_end(__first, __last);
2931 template <class _Allocator>
2933 vector<bool, _Allocator>::reserve(size_type __n)
2935 if (__n > capacity())
2937 vector __v(this->__alloc());
2939 __v.__construct_at_end(this->begin(), this->end());
2941 __invalidate_all_iterators();
2945 template <class _Allocator>
2947 vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
2949 if (__external_cap_to_internal(size()) > __cap())
2951 #ifndef _LIBCPP_NO_EXCEPTIONS
2954 #endif // _LIBCPP_NO_EXCEPTIONS
2955 vector(*this, allocator_type(__alloc())).swap(*this);
2956 #ifndef _LIBCPP_NO_EXCEPTIONS
2961 #endif // _LIBCPP_NO_EXCEPTIONS
2965 template <class _Allocator>
2966 typename vector<bool, _Allocator>::reference
2967 vector<bool, _Allocator>::at(size_type __n)
2970 this->__throw_out_of_range();
2971 return (*this)[__n];
2974 template <class _Allocator>
2975 typename vector<bool, _Allocator>::const_reference
2976 vector<bool, _Allocator>::at(size_type __n) const
2979 this->__throw_out_of_range();
2980 return (*this)[__n];
2983 template <class _Allocator>
2985 vector<bool, _Allocator>::push_back(const value_type& __x)
2987 if (this->__size_ == this->capacity())
2988 reserve(__recommend(this->__size_ + 1));
2993 template <class _Allocator>
2994 typename vector<bool, _Allocator>::iterator
2995 vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2998 if (size() < capacity())
3000 const_iterator __old_end = end();
3002 _VSTD::copy_backward(__position, __old_end, end());
3003 __r = __const_iterator_cast(__position);
3007 vector __v(__alloc());
3008 __v.reserve(__recommend(__size_ + 1));
3009 __v.__size_ = __size_ + 1;
3010 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3011 _VSTD::copy_backward(__position, cend(), __v.end());
3018 template <class _Allocator>
3019 typename vector<bool, _Allocator>::iterator
3020 vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
3023 size_type __c = capacity();
3024 if (__n <= __c && size() <= __c - __n)
3026 const_iterator __old_end = end();
3028 _VSTD::copy_backward(__position, __old_end, end());
3029 __r = __const_iterator_cast(__position);
3033 vector __v(__alloc());
3034 __v.reserve(__recommend(__size_ + __n));
3035 __v.__size_ = __size_ + __n;
3036 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3037 _VSTD::copy_backward(__position, cend(), __v.end());
3040 _VSTD::fill_n(__r, __n, __x);
3044 template <class _Allocator>
3045 template <class _InputIterator>
3048 __is_input_iterator <_InputIterator>::value &&
3049 !__is_forward_iterator<_InputIterator>::value,
3050 typename vector<bool, _Allocator>::iterator
3052 vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
3054 difference_type __off = __position - begin();
3055 iterator __p = __const_iterator_cast(__position);
3056 iterator __old_end = end();
3057 for (; size() != capacity() && __first != __last; ++__first)
3062 vector __v(__alloc());
3063 if (__first != __last)
3065 #ifndef _LIBCPP_NO_EXCEPTIONS
3068 #endif // _LIBCPP_NO_EXCEPTIONS
3069 __v.assign(__first, __last);
3070 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
3071 difference_type __old_p = __p - begin();
3072 reserve(__recommend(size() + __v.size()));
3073 __p = begin() + __old_p;
3074 __old_end = begin() + __old_size;
3075 #ifndef _LIBCPP_NO_EXCEPTIONS
3079 erase(__old_end, end());
3082 #endif // _LIBCPP_NO_EXCEPTIONS
3084 __p = _VSTD::rotate(__p, __old_end, end());
3085 insert(__p, __v.begin(), __v.end());
3086 return begin() + __off;
3089 template <class _Allocator>
3090 template <class _ForwardIterator>
3093 __is_forward_iterator<_ForwardIterator>::value,
3094 typename vector<bool, _Allocator>::iterator
3096 vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
3098 difference_type __n = _VSTD::distance(__first, __last);
3100 size_type __c = capacity();
3101 if (__n <= __c && size() <= __c - __n)
3103 const_iterator __old_end = end();
3105 _VSTD::copy_backward(__position, __old_end, end());
3106 __r = __const_iterator_cast(__position);
3110 vector __v(__alloc());
3111 __v.reserve(__recommend(__size_ + __n));
3112 __v.__size_ = __size_ + __n;
3113 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3114 _VSTD::copy_backward(__position, cend(), __v.end());
3117 _VSTD::copy(__first, __last, __r);
3121 template <class _Allocator>
3122 inline _LIBCPP_INLINE_VISIBILITY
3123 typename vector<bool, _Allocator>::iterator
3124 vector<bool, _Allocator>::erase(const_iterator __position)
3126 iterator __r = __const_iterator_cast(__position);
3127 _VSTD::copy(__position + 1, this->cend(), __r);
3132 template <class _Allocator>
3133 typename vector<bool, _Allocator>::iterator
3134 vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3136 iterator __r = __const_iterator_cast(__first);
3137 difference_type __d = __last - __first;
3138 _VSTD::copy(__last, this->cend(), __r);
3143 template <class _Allocator>
3145 vector<bool, _Allocator>::swap(vector& __x)
3146 #if _LIBCPP_STD_VER >= 14
3149 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3150 __is_nothrow_swappable<allocator_type>::value)
3153 _VSTD::swap(this->__begin_, __x.__begin_);
3154 _VSTD::swap(this->__size_, __x.__size_);
3155 _VSTD::swap(this->__cap(), __x.__cap());
3156 __swap_allocator(this->__alloc(), __x.__alloc(),
3157 integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
3160 template <class _Allocator>
3162 vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3164 size_type __cs = size();
3168 size_type __c = capacity();
3169 size_type __n = __sz - __cs;
3170 if (__n <= __c && __cs <= __c - __n)
3177 vector __v(__alloc());
3178 __v.reserve(__recommend(__size_ + __n));
3179 __v.__size_ = __size_ + __n;
3180 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
3183 _VSTD::fill_n(__r, __n, __x);
3189 template <class _Allocator>
3191 vector<bool, _Allocator>::flip() _NOEXCEPT
3193 // do middle whole words
3194 size_type __n = __size_;
3195 __storage_pointer __p = __begin_;
3196 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3198 // do last partial word
3201 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3202 __storage_type __b = *__p & __m;
3208 template <class _Allocator>
3210 vector<bool, _Allocator>::__invariants() const
3212 if (this->__begin_ == nullptr)
3214 if (this->__size_ != 0 || this->__cap() != 0)
3219 if (this->__cap() == 0)
3221 if (this->__size_ > this->capacity())
3227 template <class _Allocator>
3229 vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
3232 // do middle whole words
3233 size_type __n = __size_;
3234 __storage_pointer __p = __begin_;
3235 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3237 // do last partial word
3240 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3246 template <class _Allocator>
3247 struct _LIBCPP_TYPE_VIS_ONLY hash<vector<bool, _Allocator> >
3248 : public unary_function<vector<bool, _Allocator>, size_t>
3250 _LIBCPP_INLINE_VISIBILITY
3251 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
3252 {return __vec.__hash_code();}
3255 template <class _Tp, class _Allocator>
3256 inline _LIBCPP_INLINE_VISIBILITY
3258 operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3260 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
3261 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3264 template <class _Tp, class _Allocator>
3265 inline _LIBCPP_INLINE_VISIBILITY
3267 operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3269 return !(__x == __y);
3272 template <class _Tp, class _Allocator>
3273 inline _LIBCPP_INLINE_VISIBILITY
3275 operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3277 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
3280 template <class _Tp, class _Allocator>
3281 inline _LIBCPP_INLINE_VISIBILITY
3283 operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3288 template <class _Tp, class _Allocator>
3289 inline _LIBCPP_INLINE_VISIBILITY
3291 operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3293 return !(__x < __y);
3296 template <class _Tp, class _Allocator>
3297 inline _LIBCPP_INLINE_VISIBILITY
3299 operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3301 return !(__y < __x);
3304 template <class _Tp, class _Allocator>
3305 inline _LIBCPP_INLINE_VISIBILITY
3307 swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
3308 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
3313 _LIBCPP_END_NAMESPACE_STD
3315 #endif // _LIBCPP_VECTOR