2 //===------------------------------ vector --------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_VECTOR
12 #define _LIBCPP_VECTOR
20 template <class T, class Allocator = allocator<T> >
25 typedef Allocator allocator_type;
26 typedef typename allocator_type::reference reference;
27 typedef typename allocator_type::const_reference const_reference;
28 typedef implementation-defined iterator;
29 typedef implementation-defined const_iterator;
30 typedef typename allocator_type::size_type size_type;
31 typedef typename allocator_type::difference_type difference_type;
32 typedef typename allocator_type::pointer pointer;
33 typedef typename allocator_type::const_pointer const_pointer;
34 typedef std::reverse_iterator<iterator> reverse_iterator;
35 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
38 noexcept(is_nothrow_default_constructible<allocator_type>::value);
39 explicit vector(const allocator_type&);
40 explicit vector(size_type n);
41 explicit vector(size_type n, const allocator_type&); // C++14
42 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
43 template <class InputIterator>
44 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
45 vector(const vector& x);
47 noexcept(is_nothrow_move_constructible<allocator_type>::value);
48 vector(initializer_list<value_type> il);
49 vector(initializer_list<value_type> il, const allocator_type& a);
51 vector& operator=(const vector& x);
52 vector& operator=(vector&& x)
54 allocator_type::propagate_on_container_move_assignment::value ||
55 allocator_type::is_always_equal::value); // C++17
56 vector& operator=(initializer_list<value_type> il);
57 template <class InputIterator>
58 void assign(InputIterator first, InputIterator last);
59 void assign(size_type n, const value_type& u);
60 void assign(initializer_list<value_type> il);
62 allocator_type get_allocator() const noexcept;
64 iterator begin() noexcept;
65 const_iterator begin() const noexcept;
66 iterator end() noexcept;
67 const_iterator end() const noexcept;
69 reverse_iterator rbegin() noexcept;
70 const_reverse_iterator rbegin() const noexcept;
71 reverse_iterator rend() noexcept;
72 const_reverse_iterator rend() const noexcept;
74 const_iterator cbegin() const noexcept;
75 const_iterator cend() const noexcept;
76 const_reverse_iterator crbegin() const noexcept;
77 const_reverse_iterator crend() const noexcept;
79 size_type size() const noexcept;
80 size_type max_size() const noexcept;
81 size_type capacity() const noexcept;
82 bool empty() const noexcept;
83 void reserve(size_type n);
84 void shrink_to_fit() noexcept;
86 reference operator[](size_type n);
87 const_reference operator[](size_type n) const;
88 reference at(size_type n);
89 const_reference at(size_type n) const;
92 const_reference front() const;
94 const_reference back() const;
96 value_type* data() noexcept;
97 const value_type* data() const noexcept;
99 void push_back(const value_type& x);
100 void push_back(value_type&& x);
101 template <class... Args>
102 reference emplace_back(Args&&... args); // reference in C++17
105 template <class... Args> iterator emplace(const_iterator position, Args&&... args);
106 iterator insert(const_iterator position, const value_type& x);
107 iterator insert(const_iterator position, value_type&& x);
108 iterator insert(const_iterator position, size_type n, const value_type& x);
109 template <class InputIterator>
110 iterator insert(const_iterator position, InputIterator first, InputIterator last);
111 iterator insert(const_iterator position, initializer_list<value_type> il);
113 iterator erase(const_iterator position);
114 iterator erase(const_iterator first, const_iterator last);
116 void clear() noexcept;
118 void resize(size_type sz);
119 void resize(size_type sz, const value_type& c);
122 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
123 allocator_traits<allocator_type>::is_always_equal::value); // C++17
125 bool __invariants() const;
128 template <class Allocator = allocator<T> >
129 class vector<bool, Allocator>
132 typedef bool value_type;
133 typedef Allocator allocator_type;
134 typedef implementation-defined iterator;
135 typedef implementation-defined const_iterator;
136 typedef typename allocator_type::size_type size_type;
137 typedef typename allocator_type::difference_type difference_type;
138 typedef iterator pointer;
139 typedef const_iterator const_pointer;
140 typedef std::reverse_iterator<iterator> reverse_iterator;
141 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
146 reference(const reference&) noexcept;
147 operator bool() const noexcept;
148 reference& operator=(const bool x) noexcept;
149 reference& operator=(const reference& x) noexcept;
150 iterator operator&() const noexcept;
151 void flip() noexcept;
154 class const_reference
157 const_reference(const reference&) noexcept;
158 operator bool() const noexcept;
159 const_iterator operator&() const noexcept;
163 noexcept(is_nothrow_default_constructible<allocator_type>::value);
164 explicit vector(const allocator_type&);
165 explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
166 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
167 template <class InputIterator>
168 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
169 vector(const vector& x);
171 noexcept(is_nothrow_move_constructible<allocator_type>::value);
172 vector(initializer_list<value_type> il);
173 vector(initializer_list<value_type> il, const allocator_type& a);
175 vector& operator=(const vector& x);
176 vector& operator=(vector&& x)
178 allocator_type::propagate_on_container_move_assignment::value ||
179 allocator_type::is_always_equal::value); // C++17
180 vector& operator=(initializer_list<value_type> il);
181 template <class InputIterator>
182 void assign(InputIterator first, InputIterator last);
183 void assign(size_type n, const value_type& u);
184 void assign(initializer_list<value_type> il);
186 allocator_type get_allocator() const noexcept;
188 iterator begin() noexcept;
189 const_iterator begin() const noexcept;
190 iterator end() noexcept;
191 const_iterator end() const noexcept;
193 reverse_iterator rbegin() noexcept;
194 const_reverse_iterator rbegin() const noexcept;
195 reverse_iterator rend() noexcept;
196 const_reverse_iterator rend() const noexcept;
198 const_iterator cbegin() const noexcept;
199 const_iterator cend() const noexcept;
200 const_reverse_iterator crbegin() const noexcept;
201 const_reverse_iterator crend() const noexcept;
203 size_type size() const noexcept;
204 size_type max_size() const noexcept;
205 size_type capacity() const noexcept;
206 bool empty() const noexcept;
207 void reserve(size_type n);
208 void shrink_to_fit() noexcept;
210 reference operator[](size_type n);
211 const_reference operator[](size_type n) const;
212 reference at(size_type n);
213 const_reference at(size_type n) const;
216 const_reference front() const;
218 const_reference back() const;
220 void push_back(const value_type& x);
221 template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17
224 template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
225 iterator insert(const_iterator position, const value_type& x);
226 iterator insert(const_iterator position, size_type n, const value_type& x);
227 template <class InputIterator>
228 iterator insert(const_iterator position, InputIterator first, InputIterator last);
229 iterator insert(const_iterator position, initializer_list<value_type> il);
231 iterator erase(const_iterator position);
232 iterator erase(const_iterator first, const_iterator last);
234 void clear() noexcept;
236 void resize(size_type sz);
237 void resize(size_type sz, value_type x);
240 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
241 allocator_traits<allocator_type>::is_always_equal::value); // C++17
242 void flip() noexcept;
244 bool __invariants() const;
247 template <class Allocator> struct hash<std::vector<bool, Allocator>>;
249 template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
250 template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
251 template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
252 template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
253 template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
254 template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
256 template <class T, class Allocator>
257 void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
258 noexcept(noexcept(x.swap(y)));
265 #include <iosfwd> // for forward declaration of vector
266 #include <__bit_reference>
267 #include <type_traits>
270 #include <initializer_list>
275 #include <__split_buffer>
276 #include <__functional_base>
280 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
281 #pragma GCC system_header
285 #include <__undef_macros>
288 _LIBCPP_BEGIN_NAMESPACE_STD
291 class __vector_base_common
294 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
295 _LIBCPP_NORETURN void __throw_length_error() const;
296 _LIBCPP_NORETURN void __throw_out_of_range() const;
301 __vector_base_common<__b>::__throw_length_error() const
303 _VSTD::__throw_length_error("vector");
308 __vector_base_common<__b>::__throw_out_of_range() const
310 _VSTD::__throw_out_of_range("vector");
313 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>)
315 template <class _Tp, class _Allocator>
317 : protected __vector_base_common<true>
320 typedef _Tp value_type;
321 typedef _Allocator allocator_type;
322 typedef allocator_traits<allocator_type> __alloc_traits;
323 typedef value_type& reference;
324 typedef const value_type& const_reference;
325 typedef typename __alloc_traits::size_type size_type;
326 typedef typename __alloc_traits::difference_type difference_type;
327 typedef typename __alloc_traits::pointer pointer;
328 typedef typename __alloc_traits::const_pointer const_pointer;
329 typedef pointer iterator;
330 typedef const_pointer const_iterator;
334 __compressed_pair<pointer, allocator_type> __end_cap_;
336 _LIBCPP_INLINE_VISIBILITY
337 allocator_type& __alloc() _NOEXCEPT
338 {return __end_cap_.second();}
339 _LIBCPP_INLINE_VISIBILITY
340 const allocator_type& __alloc() const _NOEXCEPT
341 {return __end_cap_.second();}
342 _LIBCPP_INLINE_VISIBILITY
343 pointer& __end_cap() _NOEXCEPT
344 {return __end_cap_.first();}
345 _LIBCPP_INLINE_VISIBILITY
346 const pointer& __end_cap() const _NOEXCEPT
347 {return __end_cap_.first();}
349 _LIBCPP_INLINE_VISIBILITY
351 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
352 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
355 _LIBCPP_INLINE_VISIBILITY
356 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
357 _LIBCPP_INLINE_VISIBILITY
358 size_type capacity() const _NOEXCEPT
359 {return static_cast<size_type>(__end_cap() - __begin_);}
361 _LIBCPP_INLINE_VISIBILITY
362 void __destruct_at_end(pointer __new_last) _NOEXCEPT;
364 _LIBCPP_INLINE_VISIBILITY
365 void __copy_assign_alloc(const __vector_base& __c)
366 {__copy_assign_alloc(__c, integral_constant<bool,
367 __alloc_traits::propagate_on_container_copy_assignment::value>());}
369 _LIBCPP_INLINE_VISIBILITY
370 void __move_assign_alloc(__vector_base& __c)
372 !__alloc_traits::propagate_on_container_move_assignment::value ||
373 is_nothrow_move_assignable<allocator_type>::value)
374 {__move_assign_alloc(__c, integral_constant<bool,
375 __alloc_traits::propagate_on_container_move_assignment::value>());}
377 _LIBCPP_INLINE_VISIBILITY
378 void __copy_assign_alloc(const __vector_base& __c, true_type)
380 if (__alloc() != __c.__alloc())
383 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
384 __begin_ = __end_ = __end_cap() = nullptr;
386 __alloc() = __c.__alloc();
389 _LIBCPP_INLINE_VISIBILITY
390 void __copy_assign_alloc(const __vector_base&, false_type)
393 _LIBCPP_INLINE_VISIBILITY
394 void __move_assign_alloc(__vector_base& __c, true_type)
395 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
397 __alloc() = _VSTD::move(__c.__alloc());
400 _LIBCPP_INLINE_VISIBILITY
401 void __move_assign_alloc(__vector_base&, false_type)
406 template <class _Tp, class _Allocator>
407 inline _LIBCPP_INLINE_VISIBILITY
409 __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
411 pointer __soon_to_be_end = __end_;
412 while (__new_last != __soon_to_be_end)
413 __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__soon_to_be_end));
417 template <class _Tp, class _Allocator>
418 inline _LIBCPP_INLINE_VISIBILITY
419 __vector_base<_Tp, _Allocator>::__vector_base()
420 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
427 template <class _Tp, class _Allocator>
428 inline _LIBCPP_INLINE_VISIBILITY
429 __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
432 __end_cap_(nullptr, __a)
436 template <class _Tp, class _Allocator>
437 __vector_base<_Tp, _Allocator>::~__vector_base()
439 if (__begin_ != nullptr)
442 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
446 template <class _Tp, class _Allocator /* = allocator<_Tp> */>
447 class _LIBCPP_TEMPLATE_VIS vector
448 : private __vector_base<_Tp, _Allocator>
451 typedef __vector_base<_Tp, _Allocator> __base;
452 typedef allocator<_Tp> __default_allocator_type;
454 typedef vector __self;
455 typedef _Tp value_type;
456 typedef _Allocator allocator_type;
457 typedef typename __base::__alloc_traits __alloc_traits;
458 typedef typename __base::reference reference;
459 typedef typename __base::const_reference const_reference;
460 typedef typename __base::size_type size_type;
461 typedef typename __base::difference_type difference_type;
462 typedef typename __base::pointer pointer;
463 typedef typename __base::const_pointer const_pointer;
464 typedef __wrap_iter<pointer> iterator;
465 typedef __wrap_iter<const_pointer> const_iterator;
466 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
467 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
469 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
470 "Allocator::value_type must be same type as value_type");
472 _LIBCPP_INLINE_VISIBILITY
473 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
475 #if _LIBCPP_DEBUG_LEVEL >= 2
476 __get_db()->__insert_c(this);
479 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
480 #if _LIBCPP_STD_VER <= 14
481 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
487 #if _LIBCPP_DEBUG_LEVEL >= 2
488 __get_db()->__insert_c(this);
491 explicit vector(size_type __n);
492 #if _LIBCPP_STD_VER > 11
493 explicit vector(size_type __n, const allocator_type& __a);
495 vector(size_type __n, const_reference __x);
496 vector(size_type __n, const_reference __x, const allocator_type& __a);
497 template <class _InputIterator>
498 vector(_InputIterator __first,
499 typename enable_if<__is_input_iterator <_InputIterator>::value &&
500 !__is_forward_iterator<_InputIterator>::value &&
503 typename iterator_traits<_InputIterator>::reference>::value,
504 _InputIterator>::type __last);
505 template <class _InputIterator>
506 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
507 typename enable_if<__is_input_iterator <_InputIterator>::value &&
508 !__is_forward_iterator<_InputIterator>::value &&
511 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
512 template <class _ForwardIterator>
513 vector(_ForwardIterator __first,
514 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
517 typename iterator_traits<_ForwardIterator>::reference>::value,
518 _ForwardIterator>::type __last);
519 template <class _ForwardIterator>
520 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
521 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
524 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
526 #if _LIBCPP_DEBUG_LEVEL >= 2
527 _LIBCPP_INLINE_VISIBILITY
530 __get_db()->__erase_c(this);
534 vector(const vector& __x);
535 vector(const vector& __x, const allocator_type& __a);
536 _LIBCPP_INLINE_VISIBILITY
537 vector& operator=(const vector& __x);
539 #ifndef _LIBCPP_CXX03_LANG
540 _LIBCPP_INLINE_VISIBILITY
541 vector(initializer_list<value_type> __il);
543 _LIBCPP_INLINE_VISIBILITY
544 vector(initializer_list<value_type> __il, const allocator_type& __a);
546 _LIBCPP_INLINE_VISIBILITY
548 #if _LIBCPP_STD_VER > 14
551 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
554 _LIBCPP_INLINE_VISIBILITY
555 vector(vector&& __x, const allocator_type& __a);
556 _LIBCPP_INLINE_VISIBILITY
557 vector& operator=(vector&& __x)
558 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
560 _LIBCPP_INLINE_VISIBILITY
561 vector& operator=(initializer_list<value_type> __il)
562 {assign(__il.begin(), __il.end()); return *this;}
564 #endif // !_LIBCPP_CXX03_LANG
566 template <class _InputIterator>
569 __is_input_iterator <_InputIterator>::value &&
570 !__is_forward_iterator<_InputIterator>::value &&
573 typename iterator_traits<_InputIterator>::reference>::value,
576 assign(_InputIterator __first, _InputIterator __last);
577 template <class _ForwardIterator>
580 __is_forward_iterator<_ForwardIterator>::value &&
583 typename iterator_traits<_ForwardIterator>::reference>::value,
586 assign(_ForwardIterator __first, _ForwardIterator __last);
588 void assign(size_type __n, const_reference __u);
590 #ifndef _LIBCPP_CXX03_LANG
591 _LIBCPP_INLINE_VISIBILITY
592 void assign(initializer_list<value_type> __il)
593 {assign(__il.begin(), __il.end());}
596 _LIBCPP_INLINE_VISIBILITY
597 allocator_type get_allocator() const _NOEXCEPT
598 {return this->__alloc();}
600 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
601 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
602 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
603 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
605 _LIBCPP_INLINE_VISIBILITY
606 reverse_iterator rbegin() _NOEXCEPT
607 {return reverse_iterator(end());}
608 _LIBCPP_INLINE_VISIBILITY
609 const_reverse_iterator rbegin() const _NOEXCEPT
610 {return const_reverse_iterator(end());}
611 _LIBCPP_INLINE_VISIBILITY
612 reverse_iterator rend() _NOEXCEPT
613 {return reverse_iterator(begin());}
614 _LIBCPP_INLINE_VISIBILITY
615 const_reverse_iterator rend() const _NOEXCEPT
616 {return const_reverse_iterator(begin());}
618 _LIBCPP_INLINE_VISIBILITY
619 const_iterator cbegin() const _NOEXCEPT
621 _LIBCPP_INLINE_VISIBILITY
622 const_iterator cend() const _NOEXCEPT
624 _LIBCPP_INLINE_VISIBILITY
625 const_reverse_iterator crbegin() const _NOEXCEPT
627 _LIBCPP_INLINE_VISIBILITY
628 const_reverse_iterator crend() const _NOEXCEPT
631 _LIBCPP_INLINE_VISIBILITY
632 size_type size() const _NOEXCEPT
633 {return static_cast<size_type>(this->__end_ - this->__begin_);}
634 _LIBCPP_INLINE_VISIBILITY
635 size_type capacity() const _NOEXCEPT
636 {return __base::capacity();}
637 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
638 bool empty() const _NOEXCEPT
639 {return this->__begin_ == this->__end_;}
640 size_type max_size() const _NOEXCEPT;
641 void reserve(size_type __n);
642 void shrink_to_fit() _NOEXCEPT;
644 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
645 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
646 reference at(size_type __n);
647 const_reference at(size_type __n) const;
649 _LIBCPP_INLINE_VISIBILITY reference front()
651 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
652 return *this->__begin_;
654 _LIBCPP_INLINE_VISIBILITY const_reference front() const
656 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
657 return *this->__begin_;
659 _LIBCPP_INLINE_VISIBILITY reference back()
661 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
662 return *(this->__end_ - 1);
664 _LIBCPP_INLINE_VISIBILITY const_reference back() const
666 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
667 return *(this->__end_ - 1);
670 _LIBCPP_INLINE_VISIBILITY
671 value_type* data() _NOEXCEPT
672 {return _VSTD::__to_raw_pointer(this->__begin_);}
673 _LIBCPP_INLINE_VISIBILITY
674 const value_type* data() const _NOEXCEPT
675 {return _VSTD::__to_raw_pointer(this->__begin_);}
677 #ifdef _LIBCPP_CXX03_LANG
678 _LIBCPP_INLINE_VISIBILITY
679 void __emplace_back(const value_type& __x) { push_back(__x); }
681 template <class _Arg>
682 _LIBCPP_INLINE_VISIBILITY
683 void __emplace_back(_Arg&& __arg) {
684 emplace_back(_VSTD::forward<_Arg>(__arg));
688 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
690 #ifndef _LIBCPP_CXX03_LANG
691 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
693 template <class... _Args>
694 _LIBCPP_INLINE_VISIBILITY
695 #if _LIBCPP_STD_VER > 14
696 reference emplace_back(_Args&&... __args);
698 void emplace_back(_Args&&... __args);
700 #endif // !_LIBCPP_CXX03_LANG
702 _LIBCPP_INLINE_VISIBILITY
705 iterator insert(const_iterator __position, const_reference __x);
707 #ifndef _LIBCPP_CXX03_LANG
708 iterator insert(const_iterator __position, value_type&& __x);
709 template <class... _Args>
710 iterator emplace(const_iterator __position, _Args&&... __args);
711 #endif // !_LIBCPP_CXX03_LANG
713 iterator insert(const_iterator __position, size_type __n, const_reference __x);
714 template <class _InputIterator>
717 __is_input_iterator <_InputIterator>::value &&
718 !__is_forward_iterator<_InputIterator>::value &&
721 typename iterator_traits<_InputIterator>::reference>::value,
724 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
725 template <class _ForwardIterator>
728 __is_forward_iterator<_ForwardIterator>::value &&
731 typename iterator_traits<_ForwardIterator>::reference>::value,
734 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
736 #ifndef _LIBCPP_CXX03_LANG
737 _LIBCPP_INLINE_VISIBILITY
738 iterator insert(const_iterator __position, initializer_list<value_type> __il)
739 {return insert(__position, __il.begin(), __il.end());}
742 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
743 iterator erase(const_iterator __first, const_iterator __last);
745 _LIBCPP_INLINE_VISIBILITY
746 void clear() _NOEXCEPT
748 size_type __old_size = size();
750 __annotate_shrink(__old_size);
751 __invalidate_all_iterators();
754 void resize(size_type __sz);
755 void resize(size_type __sz, const_reference __x);
758 #if _LIBCPP_STD_VER >= 14
761 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
762 __is_nothrow_swappable<allocator_type>::value);
765 bool __invariants() const;
767 #if _LIBCPP_DEBUG_LEVEL >= 2
769 bool __dereferenceable(const const_iterator* __i) const;
770 bool __decrementable(const const_iterator* __i) const;
771 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
772 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
774 #endif // _LIBCPP_DEBUG_LEVEL >= 2
777 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
778 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
779 void allocate(size_type __n);
780 void deallocate() _NOEXCEPT;
781 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
782 void __construct_at_end(size_type __n);
783 _LIBCPP_INLINE_VISIBILITY
784 void __construct_at_end(size_type __n, const_reference __x);
785 template <class _ForwardIterator>
788 __is_forward_iterator<_ForwardIterator>::value,
791 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
792 void __append(size_type __n);
793 void __append(size_type __n, const_reference __x);
794 _LIBCPP_INLINE_VISIBILITY
795 iterator __make_iter(pointer __p) _NOEXCEPT;
796 _LIBCPP_INLINE_VISIBILITY
797 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
798 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
799 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
800 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
801 void __move_assign(vector& __c, true_type)
802 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
803 void __move_assign(vector& __c, false_type)
804 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
805 _LIBCPP_INLINE_VISIBILITY
806 void __destruct_at_end(pointer __new_last) _NOEXCEPT
808 __invalidate_iterators_past(__new_last);
809 size_type __old_size = size();
810 __base::__destruct_at_end(__new_last);
811 __annotate_shrink(__old_size);
814 #ifndef _LIBCPP_CXX03_LANG
815 template <class _Up> void __push_back_slow_path(_Up&& __x);
817 template <class... _Args>
818 void __emplace_back_slow_path(_Args&&... __args);
820 template <class _Up> void __push_back_slow_path(_Up& __x);
823 // The following functions are no-ops outside of AddressSanitizer mode.
824 // We call annotatations only for the default Allocator because other allocators
825 // may not meet the AddressSanitizer alignment constraints.
826 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
827 #ifndef _LIBCPP_HAS_NO_ASAN
828 void __annotate_contiguous_container(const void *__beg, const void *__end,
829 const void *__old_mid,
830 const void *__new_mid) const
833 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
834 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
837 _LIBCPP_INLINE_VISIBILITY
838 void __annotate_contiguous_container(const void*, const void*, const void*,
839 const void*) const {}
841 _LIBCPP_INLINE_VISIBILITY
842 void __annotate_new(size_type __current_size) const {
843 __annotate_contiguous_container(data(), data() + capacity(),
844 data() + capacity(), data() + __current_size);
847 _LIBCPP_INLINE_VISIBILITY
848 void __annotate_delete() const {
849 __annotate_contiguous_container(data(), data() + capacity(),
850 data() + size(), data() + capacity());
853 _LIBCPP_INLINE_VISIBILITY
854 void __annotate_increase(size_type __n) const
856 __annotate_contiguous_container(data(), data() + capacity(),
857 data() + size(), data() + size() + __n);
860 _LIBCPP_INLINE_VISIBILITY
861 void __annotate_shrink(size_type __old_size) const
863 __annotate_contiguous_container(data(), data() + capacity(),
864 data() + __old_size, data() + size());
866 #ifndef _LIBCPP_HAS_NO_ASAN
867 // The annotation for size increase should happen before the actual increase,
868 // but if an exception is thrown after that the annotation has to be undone.
869 struct __RAII_IncreaseAnnotator {
870 __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1)
871 : __commit(false), __v(__v), __old_size(__v.size() + __n) {
872 __v.__annotate_increase(__n);
874 void __done() { __commit = true; }
875 ~__RAII_IncreaseAnnotator() {
876 if (__commit) return;
877 __v.__annotate_shrink(__old_size);
881 size_type __old_size;
884 struct __RAII_IncreaseAnnotator {
885 _LIBCPP_INLINE_VISIBILITY
886 __RAII_IncreaseAnnotator(const vector &, size_type = 1) {}
887 _LIBCPP_INLINE_VISIBILITY void __done() {}
893 template <class _Tp, class _Allocator>
895 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
898 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
899 _VSTD::swap(this->__begin_, __v.__begin_);
900 _VSTD::swap(this->__end_, __v.__end_);
901 _VSTD::swap(this->__end_cap(), __v.__end_cap());
902 __v.__first_ = __v.__begin_;
903 __annotate_new(size());
904 __invalidate_all_iterators();
907 template <class _Tp, class _Allocator>
908 typename vector<_Tp, _Allocator>::pointer
909 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
912 pointer __r = __v.__begin_;
913 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
914 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
915 _VSTD::swap(this->__begin_, __v.__begin_);
916 _VSTD::swap(this->__end_, __v.__end_);
917 _VSTD::swap(this->__end_cap(), __v.__end_cap());
918 __v.__first_ = __v.__begin_;
919 __annotate_new(size());
920 __invalidate_all_iterators();
924 // Allocate space for __n objects
925 // throws length_error if __n > max_size()
926 // throws (probably bad_alloc) if memory run out
927 // Precondition: __begin_ == __end_ == __end_cap() == 0
928 // Precondition: __n > 0
929 // Postcondition: capacity() == __n
930 // Postcondition: size() == 0
931 template <class _Tp, class _Allocator>
933 vector<_Tp, _Allocator>::allocate(size_type __n)
935 if (__n > max_size())
936 this->__throw_length_error();
937 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
938 this->__end_cap() = this->__begin_ + __n;
942 template <class _Tp, class _Allocator>
944 vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
946 if (this->__begin_ != nullptr)
949 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
950 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
954 template <class _Tp, class _Allocator>
955 typename vector<_Tp, _Allocator>::size_type
956 vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
958 return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()),
959 numeric_limits<difference_type>::max());
962 // Precondition: __new_size > capacity()
963 template <class _Tp, class _Allocator>
964 inline _LIBCPP_INLINE_VISIBILITY
965 typename vector<_Tp, _Allocator>::size_type
966 vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
968 const size_type __ms = max_size();
969 if (__new_size > __ms)
970 this->__throw_length_error();
971 const size_type __cap = capacity();
972 if (__cap >= __ms / 2)
974 return _VSTD::max<size_type>(2*__cap, __new_size);
977 // Default constructs __n objects starting at __end_
978 // throws if construction throws
979 // Precondition: __n > 0
980 // Precondition: size() + __n <= capacity()
981 // Postcondition: size() == size() + __n
982 template <class _Tp, class _Allocator>
984 vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
986 allocator_type& __a = this->__alloc();
989 __RAII_IncreaseAnnotator __annotator(*this);
990 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
993 __annotator.__done();
997 // Copy constructs __n objects starting at __end_ from __x
998 // throws if construction throws
999 // Precondition: __n > 0
1000 // Precondition: size() + __n <= capacity()
1001 // Postcondition: size() == old size() + __n
1002 // Postcondition: [i] == __x for all i in [size() - __n, __n)
1003 template <class _Tp, class _Allocator>
1006 vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
1008 allocator_type& __a = this->__alloc();
1011 __RAII_IncreaseAnnotator __annotator(*this);
1012 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
1015 __annotator.__done();
1019 template <class _Tp, class _Allocator>
1020 template <class _ForwardIterator>
1023 __is_forward_iterator<_ForwardIterator>::value,
1026 vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
1028 allocator_type& __a = this->__alloc();
1029 __RAII_IncreaseAnnotator __annotator(*this, __n);
1030 __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_);
1031 __annotator.__done();
1034 // Default constructs __n objects starting at __end_
1035 // throws if construction throws
1036 // Postcondition: size() == size() + __n
1037 // Exception safety: strong.
1038 template <class _Tp, class _Allocator>
1040 vector<_Tp, _Allocator>::__append(size_type __n)
1042 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1043 this->__construct_at_end(__n);
1046 allocator_type& __a = this->__alloc();
1047 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1048 __v.__construct_at_end(__n);
1049 __swap_out_circular_buffer(__v);
1053 // Default constructs __n objects starting at __end_
1054 // throws if construction throws
1055 // Postcondition: size() == size() + __n
1056 // Exception safety: strong.
1057 template <class _Tp, class _Allocator>
1059 vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1061 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1062 this->__construct_at_end(__n, __x);
1065 allocator_type& __a = this->__alloc();
1066 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1067 __v.__construct_at_end(__n, __x);
1068 __swap_out_circular_buffer(__v);
1072 template <class _Tp, class _Allocator>
1073 vector<_Tp, _Allocator>::vector(size_type __n)
1075 #if _LIBCPP_DEBUG_LEVEL >= 2
1076 __get_db()->__insert_c(this);
1081 __construct_at_end(__n);
1085 #if _LIBCPP_STD_VER > 11
1086 template <class _Tp, class _Allocator>
1087 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1090 #if _LIBCPP_DEBUG_LEVEL >= 2
1091 __get_db()->__insert_c(this);
1096 __construct_at_end(__n);
1101 template <class _Tp, class _Allocator>
1102 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1104 #if _LIBCPP_DEBUG_LEVEL >= 2
1105 __get_db()->__insert_c(this);
1110 __construct_at_end(__n, __x);
1114 template <class _Tp, class _Allocator>
1115 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1118 #if _LIBCPP_DEBUG_LEVEL >= 2
1119 __get_db()->__insert_c(this);
1124 __construct_at_end(__n, __x);
1128 template <class _Tp, class _Allocator>
1129 template <class _InputIterator>
1130 vector<_Tp, _Allocator>::vector(_InputIterator __first,
1131 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1132 !__is_forward_iterator<_InputIterator>::value &&
1135 typename iterator_traits<_InputIterator>::reference>::value,
1136 _InputIterator>::type __last)
1138 #if _LIBCPP_DEBUG_LEVEL >= 2
1139 __get_db()->__insert_c(this);
1141 for (; __first != __last; ++__first)
1142 __emplace_back(*__first);
1145 template <class _Tp, class _Allocator>
1146 template <class _InputIterator>
1147 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1148 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1149 !__is_forward_iterator<_InputIterator>::value &&
1152 typename iterator_traits<_InputIterator>::reference>::value>::type*)
1155 #if _LIBCPP_DEBUG_LEVEL >= 2
1156 __get_db()->__insert_c(this);
1158 for (; __first != __last; ++__first)
1159 __emplace_back(*__first);
1162 template <class _Tp, class _Allocator>
1163 template <class _ForwardIterator>
1164 vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
1165 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1168 typename iterator_traits<_ForwardIterator>::reference>::value,
1169 _ForwardIterator>::type __last)
1171 #if _LIBCPP_DEBUG_LEVEL >= 2
1172 __get_db()->__insert_c(this);
1174 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1178 __construct_at_end(__first, __last, __n);
1182 template <class _Tp, class _Allocator>
1183 template <class _ForwardIterator>
1184 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1185 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1188 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1191 #if _LIBCPP_DEBUG_LEVEL >= 2
1192 __get_db()->__insert_c(this);
1194 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1198 __construct_at_end(__first, __last, __n);
1202 template <class _Tp, class _Allocator>
1203 vector<_Tp, _Allocator>::vector(const vector& __x)
1204 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1206 #if _LIBCPP_DEBUG_LEVEL >= 2
1207 __get_db()->__insert_c(this);
1209 size_type __n = __x.size();
1213 __construct_at_end(__x.__begin_, __x.__end_, __n);
1217 template <class _Tp, class _Allocator>
1218 vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1221 #if _LIBCPP_DEBUG_LEVEL >= 2
1222 __get_db()->__insert_c(this);
1224 size_type __n = __x.size();
1228 __construct_at_end(__x.__begin_, __x.__end_, __n);
1232 #ifndef _LIBCPP_CXX03_LANG
1234 template <class _Tp, class _Allocator>
1235 inline _LIBCPP_INLINE_VISIBILITY
1236 vector<_Tp, _Allocator>::vector(vector&& __x)
1237 #if _LIBCPP_STD_VER > 14
1240 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1242 : __base(_VSTD::move(__x.__alloc()))
1244 #if _LIBCPP_DEBUG_LEVEL >= 2
1245 __get_db()->__insert_c(this);
1246 __get_db()->swap(this, &__x);
1248 this->__begin_ = __x.__begin_;
1249 this->__end_ = __x.__end_;
1250 this->__end_cap() = __x.__end_cap();
1251 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1254 template <class _Tp, class _Allocator>
1255 inline _LIBCPP_INLINE_VISIBILITY
1256 vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1259 #if _LIBCPP_DEBUG_LEVEL >= 2
1260 __get_db()->__insert_c(this);
1262 if (__a == __x.__alloc())
1264 this->__begin_ = __x.__begin_;
1265 this->__end_ = __x.__end_;
1266 this->__end_cap() = __x.__end_cap();
1267 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1268 #if _LIBCPP_DEBUG_LEVEL >= 2
1269 __get_db()->swap(this, &__x);
1274 typedef move_iterator<iterator> _Ip;
1275 assign(_Ip(__x.begin()), _Ip(__x.end()));
1279 template <class _Tp, class _Allocator>
1280 inline _LIBCPP_INLINE_VISIBILITY
1281 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1283 #if _LIBCPP_DEBUG_LEVEL >= 2
1284 __get_db()->__insert_c(this);
1286 if (__il.size() > 0)
1288 allocate(__il.size());
1289 __construct_at_end(__il.begin(), __il.end(), __il.size());
1293 template <class _Tp, class _Allocator>
1294 inline _LIBCPP_INLINE_VISIBILITY
1295 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1298 #if _LIBCPP_DEBUG_LEVEL >= 2
1299 __get_db()->__insert_c(this);
1301 if (__il.size() > 0)
1303 allocate(__il.size());
1304 __construct_at_end(__il.begin(), __il.end(), __il.size());
1308 template <class _Tp, class _Allocator>
1309 inline _LIBCPP_INLINE_VISIBILITY
1310 vector<_Tp, _Allocator>&
1311 vector<_Tp, _Allocator>::operator=(vector&& __x)
1312 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
1314 __move_assign(__x, integral_constant<bool,
1315 __alloc_traits::propagate_on_container_move_assignment::value>());
1319 template <class _Tp, class _Allocator>
1321 vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1322 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
1324 if (__base::__alloc() != __c.__alloc())
1326 typedef move_iterator<iterator> _Ip;
1327 assign(_Ip(__c.begin()), _Ip(__c.end()));
1330 __move_assign(__c, true_type());
1333 template <class _Tp, class _Allocator>
1335 vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1336 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1339 __base::__move_assign_alloc(__c); // this can throw
1340 this->__begin_ = __c.__begin_;
1341 this->__end_ = __c.__end_;
1342 this->__end_cap() = __c.__end_cap();
1343 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1344 #if _LIBCPP_DEBUG_LEVEL >= 2
1345 __get_db()->swap(this, &__c);
1349 #endif // !_LIBCPP_CXX03_LANG
1351 template <class _Tp, class _Allocator>
1352 inline _LIBCPP_INLINE_VISIBILITY
1353 vector<_Tp, _Allocator>&
1354 vector<_Tp, _Allocator>::operator=(const vector& __x)
1358 __base::__copy_assign_alloc(__x);
1359 assign(__x.__begin_, __x.__end_);
1364 template <class _Tp, class _Allocator>
1365 template <class _InputIterator>
1368 __is_input_iterator <_InputIterator>::value &&
1369 !__is_forward_iterator<_InputIterator>::value &&
1372 typename iterator_traits<_InputIterator>::reference>::value,
1375 vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1378 for (; __first != __last; ++__first)
1379 __emplace_back(*__first);
1382 template <class _Tp, class _Allocator>
1383 template <class _ForwardIterator>
1386 __is_forward_iterator<_ForwardIterator>::value &&
1389 typename iterator_traits<_ForwardIterator>::reference>::value,
1392 vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1394 size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
1395 if (__new_size <= capacity())
1397 _ForwardIterator __mid = __last;
1398 bool __growing = false;
1399 if (__new_size > size())
1403 _VSTD::advance(__mid, size());
1405 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
1407 __construct_at_end(__mid, __last, __new_size - size());
1409 this->__destruct_at_end(__m);
1414 allocate(__recommend(__new_size));
1415 __construct_at_end(__first, __last, __new_size);
1417 __invalidate_all_iterators();
1420 template <class _Tp, class _Allocator>
1422 vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1424 if (__n <= capacity())
1426 size_type __s = size();
1427 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
1429 __construct_at_end(__n - __s, __u);
1431 this->__destruct_at_end(this->__begin_ + __n);
1436 allocate(__recommend(static_cast<size_type>(__n)));
1437 __construct_at_end(__n, __u);
1439 __invalidate_all_iterators();
1442 template <class _Tp, class _Allocator>
1443 inline _LIBCPP_INLINE_VISIBILITY
1444 typename vector<_Tp, _Allocator>::iterator
1445 vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
1447 #if _LIBCPP_DEBUG_LEVEL >= 2
1448 return iterator(this, __p);
1450 return iterator(__p);
1454 template <class _Tp, class _Allocator>
1455 inline _LIBCPP_INLINE_VISIBILITY
1456 typename vector<_Tp, _Allocator>::const_iterator
1457 vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
1459 #if _LIBCPP_DEBUG_LEVEL >= 2
1460 return const_iterator(this, __p);
1462 return const_iterator(__p);
1466 template <class _Tp, class _Allocator>
1467 inline _LIBCPP_INLINE_VISIBILITY
1468 typename vector<_Tp, _Allocator>::iterator
1469 vector<_Tp, _Allocator>::begin() _NOEXCEPT
1471 return __make_iter(this->__begin_);
1474 template <class _Tp, class _Allocator>
1475 inline _LIBCPP_INLINE_VISIBILITY
1476 typename vector<_Tp, _Allocator>::const_iterator
1477 vector<_Tp, _Allocator>::begin() const _NOEXCEPT
1479 return __make_iter(this->__begin_);
1482 template <class _Tp, class _Allocator>
1483 inline _LIBCPP_INLINE_VISIBILITY
1484 typename vector<_Tp, _Allocator>::iterator
1485 vector<_Tp, _Allocator>::end() _NOEXCEPT
1487 return __make_iter(this->__end_);
1490 template <class _Tp, class _Allocator>
1491 inline _LIBCPP_INLINE_VISIBILITY
1492 typename vector<_Tp, _Allocator>::const_iterator
1493 vector<_Tp, _Allocator>::end() const _NOEXCEPT
1495 return __make_iter(this->__end_);
1498 template <class _Tp, class _Allocator>
1499 inline _LIBCPP_INLINE_VISIBILITY
1500 typename vector<_Tp, _Allocator>::reference
1501 vector<_Tp, _Allocator>::operator[](size_type __n)
1503 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1504 return this->__begin_[__n];
1507 template <class _Tp, class _Allocator>
1508 inline _LIBCPP_INLINE_VISIBILITY
1509 typename vector<_Tp, _Allocator>::const_reference
1510 vector<_Tp, _Allocator>::operator[](size_type __n) const
1512 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1513 return this->__begin_[__n];
1516 template <class _Tp, class _Allocator>
1517 typename vector<_Tp, _Allocator>::reference
1518 vector<_Tp, _Allocator>::at(size_type __n)
1521 this->__throw_out_of_range();
1522 return this->__begin_[__n];
1525 template <class _Tp, class _Allocator>
1526 typename vector<_Tp, _Allocator>::const_reference
1527 vector<_Tp, _Allocator>::at(size_type __n) const
1530 this->__throw_out_of_range();
1531 return this->__begin_[__n];
1534 template <class _Tp, class _Allocator>
1536 vector<_Tp, _Allocator>::reserve(size_type __n)
1538 if (__n > capacity())
1540 allocator_type& __a = this->__alloc();
1541 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
1542 __swap_out_circular_buffer(__v);
1546 template <class _Tp, class _Allocator>
1548 vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1550 if (capacity() > size())
1552 #ifndef _LIBCPP_NO_EXCEPTIONS
1555 #endif // _LIBCPP_NO_EXCEPTIONS
1556 allocator_type& __a = this->__alloc();
1557 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1558 __swap_out_circular_buffer(__v);
1559 #ifndef _LIBCPP_NO_EXCEPTIONS
1564 #endif // _LIBCPP_NO_EXCEPTIONS
1568 template <class _Tp, class _Allocator>
1569 template <class _Up>
1571 #ifndef _LIBCPP_CXX03_LANG
1572 vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1574 vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1577 allocator_type& __a = this->__alloc();
1578 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1579 // __v.push_back(_VSTD::forward<_Up>(__x));
1580 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
1582 __swap_out_circular_buffer(__v);
1585 template <class _Tp, class _Allocator>
1586 inline _LIBCPP_INLINE_VISIBILITY
1588 vector<_Tp, _Allocator>::push_back(const_reference __x)
1590 if (this->__end_ != this->__end_cap())
1592 __RAII_IncreaseAnnotator __annotator(*this);
1593 __alloc_traits::construct(this->__alloc(),
1594 _VSTD::__to_raw_pointer(this->__end_), __x);
1595 __annotator.__done();
1599 __push_back_slow_path(__x);
1602 #ifndef _LIBCPP_CXX03_LANG
1604 template <class _Tp, class _Allocator>
1605 inline _LIBCPP_INLINE_VISIBILITY
1607 vector<_Tp, _Allocator>::push_back(value_type&& __x)
1609 if (this->__end_ < this->__end_cap())
1611 __RAII_IncreaseAnnotator __annotator(*this);
1612 __alloc_traits::construct(this->__alloc(),
1613 _VSTD::__to_raw_pointer(this->__end_),
1615 __annotator.__done();
1619 __push_back_slow_path(_VSTD::move(__x));
1622 template <class _Tp, class _Allocator>
1623 template <class... _Args>
1625 vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1627 allocator_type& __a = this->__alloc();
1628 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1629 // __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1630 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
1632 __swap_out_circular_buffer(__v);
1635 template <class _Tp, class _Allocator>
1636 template <class... _Args>
1638 #if _LIBCPP_STD_VER > 14
1639 typename vector<_Tp, _Allocator>::reference
1643 vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1645 if (this->__end_ < this->__end_cap())
1647 __RAII_IncreaseAnnotator __annotator(*this);
1648 __alloc_traits::construct(this->__alloc(),
1649 _VSTD::__to_raw_pointer(this->__end_),
1650 _VSTD::forward<_Args>(__args)...);
1651 __annotator.__done();
1655 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
1656 #if _LIBCPP_STD_VER > 14
1657 return this->back();
1661 #endif // !_LIBCPP_CXX03_LANG
1663 template <class _Tp, class _Allocator>
1666 vector<_Tp, _Allocator>::pop_back()
1668 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
1669 this->__destruct_at_end(this->__end_ - 1);
1672 template <class _Tp, class _Allocator>
1673 inline _LIBCPP_INLINE_VISIBILITY
1674 typename vector<_Tp, _Allocator>::iterator
1675 vector<_Tp, _Allocator>::erase(const_iterator __position)
1677 #if _LIBCPP_DEBUG_LEVEL >= 2
1678 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1679 "vector::erase(iterator) called with an iterator not"
1680 " referring to this vector");
1682 _LIBCPP_ASSERT(__position != end(),
1683 "vector::erase(iterator) called with a non-dereferenceable iterator");
1684 difference_type __ps = __position - cbegin();
1685 pointer __p = this->__begin_ + __ps;
1686 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
1687 this->__invalidate_iterators_past(__p-1);
1688 iterator __r = __make_iter(__p);
1692 template <class _Tp, class _Allocator>
1693 typename vector<_Tp, _Allocator>::iterator
1694 vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1696 #if _LIBCPP_DEBUG_LEVEL >= 2
1697 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1698 "vector::erase(iterator, iterator) called with an iterator not"
1699 " referring to this vector");
1700 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
1701 "vector::erase(iterator, iterator) called with an iterator not"
1702 " referring to this vector");
1704 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
1705 pointer __p = this->__begin_ + (__first - begin());
1706 if (__first != __last) {
1707 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1708 this->__invalidate_iterators_past(__p - 1);
1710 iterator __r = __make_iter(__p);
1714 template <class _Tp, class _Allocator>
1716 vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1718 pointer __old_last = this->__end_;
1719 difference_type __n = __old_last - __to;
1720 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1721 __alloc_traits::construct(this->__alloc(),
1722 _VSTD::__to_raw_pointer(this->__end_),
1724 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
1727 template <class _Tp, class _Allocator>
1728 typename vector<_Tp, _Allocator>::iterator
1729 vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1731 #if _LIBCPP_DEBUG_LEVEL >= 2
1732 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1733 "vector::insert(iterator, x) called with an iterator not"
1734 " referring to this vector");
1736 pointer __p = this->__begin_ + (__position - begin());
1737 if (this->__end_ < this->__end_cap())
1739 __RAII_IncreaseAnnotator __annotator(*this);
1740 if (__p == this->__end_)
1742 __alloc_traits::construct(this->__alloc(),
1743 _VSTD::__to_raw_pointer(this->__end_), __x);
1748 __move_range(__p, this->__end_, __p + 1);
1749 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1750 if (__p <= __xr && __xr < this->__end_)
1754 __annotator.__done();
1758 allocator_type& __a = this->__alloc();
1759 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1761 __p = __swap_out_circular_buffer(__v, __p);
1763 return __make_iter(__p);
1766 #ifndef _LIBCPP_CXX03_LANG
1768 template <class _Tp, class _Allocator>
1769 typename vector<_Tp, _Allocator>::iterator
1770 vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1772 #if _LIBCPP_DEBUG_LEVEL >= 2
1773 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1774 "vector::insert(iterator, x) called with an iterator not"
1775 " referring to this vector");
1777 pointer __p = this->__begin_ + (__position - begin());
1778 if (this->__end_ < this->__end_cap())
1780 __RAII_IncreaseAnnotator __annotator(*this);
1781 if (__p == this->__end_)
1783 __alloc_traits::construct(this->__alloc(),
1784 _VSTD::__to_raw_pointer(this->__end_),
1790 __move_range(__p, this->__end_, __p + 1);
1791 *__p = _VSTD::move(__x);
1793 __annotator.__done();
1797 allocator_type& __a = this->__alloc();
1798 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1799 __v.push_back(_VSTD::move(__x));
1800 __p = __swap_out_circular_buffer(__v, __p);
1802 return __make_iter(__p);
1805 template <class _Tp, class _Allocator>
1806 template <class... _Args>
1807 typename vector<_Tp, _Allocator>::iterator
1808 vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1810 #if _LIBCPP_DEBUG_LEVEL >= 2
1811 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1812 "vector::emplace(iterator, x) called with an iterator not"
1813 " referring to this vector");
1815 pointer __p = this->__begin_ + (__position - begin());
1816 if (this->__end_ < this->__end_cap())
1818 __RAII_IncreaseAnnotator __annotator(*this);
1819 if (__p == this->__end_)
1821 __alloc_traits::construct(this->__alloc(),
1822 _VSTD::__to_raw_pointer(this->__end_),
1823 _VSTD::forward<_Args>(__args)...);
1828 __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
1829 __move_range(__p, this->__end_, __p + 1);
1830 *__p = _VSTD::move(__tmp.get());
1832 __annotator.__done();
1836 allocator_type& __a = this->__alloc();
1837 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1838 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1839 __p = __swap_out_circular_buffer(__v, __p);
1841 return __make_iter(__p);
1844 #endif // !_LIBCPP_CXX03_LANG
1846 template <class _Tp, class _Allocator>
1847 typename vector<_Tp, _Allocator>::iterator
1848 vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1850 #if _LIBCPP_DEBUG_LEVEL >= 2
1851 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1852 "vector::insert(iterator, n, x) called with an iterator not"
1853 " referring to this vector");
1855 pointer __p = this->__begin_ + (__position - begin());
1858 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1860 size_type __old_n = __n;
1861 pointer __old_last = this->__end_;
1862 if (__n > static_cast<size_type>(this->__end_ - __p))
1864 size_type __cx = __n - (this->__end_ - __p);
1865 __construct_at_end(__cx, __x);
1870 __RAII_IncreaseAnnotator __annotator(*this, __n);
1871 __move_range(__p, __old_last, __p + __old_n);
1872 __annotator.__done();
1873 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1874 if (__p <= __xr && __xr < this->__end_)
1876 _VSTD::fill_n(__p, __n, *__xr);
1881 allocator_type& __a = this->__alloc();
1882 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1883 __v.__construct_at_end(__n, __x);
1884 __p = __swap_out_circular_buffer(__v, __p);
1887 return __make_iter(__p);
1890 template <class _Tp, class _Allocator>
1891 template <class _InputIterator>
1894 __is_input_iterator <_InputIterator>::value &&
1895 !__is_forward_iterator<_InputIterator>::value &&
1898 typename iterator_traits<_InputIterator>::reference>::value,
1899 typename vector<_Tp, _Allocator>::iterator
1901 vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1903 #if _LIBCPP_DEBUG_LEVEL >= 2
1904 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1905 "vector::insert(iterator, range) called with an iterator not"
1906 " referring to this vector");
1908 difference_type __off = __position - begin();
1909 pointer __p = this->__begin_ + __off;
1910 allocator_type& __a = this->__alloc();
1911 pointer __old_last = this->__end_;
1912 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1914 __RAII_IncreaseAnnotator __annotator(*this);
1915 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
1918 __annotator.__done();
1920 __split_buffer<value_type, allocator_type&> __v(__a);
1921 if (__first != __last)
1923 #ifndef _LIBCPP_NO_EXCEPTIONS
1926 #endif // _LIBCPP_NO_EXCEPTIONS
1927 __v.__construct_at_end(__first, __last);
1928 difference_type __old_size = __old_last - this->__begin_;
1929 difference_type __old_p = __p - this->__begin_;
1930 reserve(__recommend(size() + __v.size()));
1931 __p = this->__begin_ + __old_p;
1932 __old_last = this->__begin_ + __old_size;
1933 #ifndef _LIBCPP_NO_EXCEPTIONS
1937 erase(__make_iter(__old_last), end());
1940 #endif // _LIBCPP_NO_EXCEPTIONS
1942 __p = _VSTD::rotate(__p, __old_last, this->__end_);
1943 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1944 make_move_iterator(__v.end()));
1945 return begin() + __off;
1948 template <class _Tp, class _Allocator>
1949 template <class _ForwardIterator>
1952 __is_forward_iterator<_ForwardIterator>::value &&
1955 typename iterator_traits<_ForwardIterator>::reference>::value,
1956 typename vector<_Tp, _Allocator>::iterator
1958 vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1960 #if _LIBCPP_DEBUG_LEVEL >= 2
1961 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1962 "vector::insert(iterator, range) called with an iterator not"
1963 " referring to this vector");
1965 pointer __p = this->__begin_ + (__position - begin());
1966 difference_type __n = _VSTD::distance(__first, __last);
1969 if (__n <= this->__end_cap() - this->__end_)
1971 size_type __old_n = __n;
1972 pointer __old_last = this->__end_;
1973 _ForwardIterator __m = __last;
1974 difference_type __dx = this->__end_ - __p;
1978 difference_type __diff = this->__end_ - __p;
1979 _VSTD::advance(__m, __diff);
1980 __construct_at_end(__m, __last, __n - __diff);
1985 __RAII_IncreaseAnnotator __annotator(*this, __n);
1986 __move_range(__p, __old_last, __p + __old_n);
1987 __annotator.__done();
1988 _VSTD::copy(__first, __m, __p);
1993 allocator_type& __a = this->__alloc();
1994 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1995 __v.__construct_at_end(__first, __last);
1996 __p = __swap_out_circular_buffer(__v, __p);
1999 return __make_iter(__p);
2002 template <class _Tp, class _Allocator>
2004 vector<_Tp, _Allocator>::resize(size_type __sz)
2006 size_type __cs = size();
2008 this->__append(__sz - __cs);
2009 else if (__cs > __sz)
2010 this->__destruct_at_end(this->__begin_ + __sz);
2013 template <class _Tp, class _Allocator>
2015 vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
2017 size_type __cs = size();
2019 this->__append(__sz - __cs, __x);
2020 else if (__cs > __sz)
2021 this->__destruct_at_end(this->__begin_ + __sz);
2024 template <class _Tp, class _Allocator>
2026 vector<_Tp, _Allocator>::swap(vector& __x)
2027 #if _LIBCPP_STD_VER >= 14
2030 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
2031 __is_nothrow_swappable<allocator_type>::value)
2034 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
2035 this->__alloc() == __x.__alloc(),
2036 "vector::swap: Either propagate_on_container_swap must be true"
2037 " or the allocators must compare equal");
2038 _VSTD::swap(this->__begin_, __x.__begin_);
2039 _VSTD::swap(this->__end_, __x.__end_);
2040 _VSTD::swap(this->__end_cap(), __x.__end_cap());
2041 __swap_allocator(this->__alloc(), __x.__alloc(),
2042 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
2043 #if _LIBCPP_DEBUG_LEVEL >= 2
2044 __get_db()->swap(this, &__x);
2045 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2048 template <class _Tp, class _Allocator>
2050 vector<_Tp, _Allocator>::__invariants() const
2052 if (this->__begin_ == nullptr)
2054 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
2059 if (this->__begin_ > this->__end_)
2061 if (this->__begin_ == this->__end_cap())
2063 if (this->__end_ > this->__end_cap())
2069 #if _LIBCPP_DEBUG_LEVEL >= 2
2071 template <class _Tp, class _Allocator>
2073 vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
2075 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
2078 template <class _Tp, class _Allocator>
2080 vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
2082 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
2085 template <class _Tp, class _Allocator>
2087 vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2089 const_pointer __p = __i->base() + __n;
2090 return this->__begin_ <= __p && __p <= this->__end_;
2093 template <class _Tp, class _Allocator>
2095 vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2097 const_pointer __p = __i->base() + __n;
2098 return this->__begin_ <= __p && __p < this->__end_;
2101 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2103 template <class _Tp, class _Allocator>
2104 inline _LIBCPP_INLINE_VISIBILITY
2106 vector<_Tp, _Allocator>::__invalidate_all_iterators()
2108 #if _LIBCPP_DEBUG_LEVEL >= 2
2109 __get_db()->__invalidate_all(this);
2110 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2114 template <class _Tp, class _Allocator>
2115 inline _LIBCPP_INLINE_VISIBILITY
2117 vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
2118 #if _LIBCPP_DEBUG_LEVEL >= 2
2119 __c_node* __c = __get_db()->__find_c_and_lock(this);
2120 for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
2122 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
2123 if (__i->base() > __new_last) {
2124 (*__p)->__c_ = nullptr;
2125 if (--__c->end_ != __p)
2126 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
2129 __get_db()->unlock();
2137 template <class _Allocator> class vector<bool, _Allocator>;
2139 template <class _Allocator> struct hash<vector<bool, _Allocator> >;
2141 template <class _Allocator>
2142 struct __has_storage_type<vector<bool, _Allocator> >
2144 static const bool value = true;
2147 template <class _Allocator>
2148 class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
2149 : private __vector_base_common<true>
2152 typedef vector __self;
2153 typedef bool value_type;
2154 typedef _Allocator allocator_type;
2155 typedef allocator_traits<allocator_type> __alloc_traits;
2156 typedef typename __alloc_traits::size_type size_type;
2157 typedef typename __alloc_traits::difference_type difference_type;
2158 typedef size_type __storage_type;
2159 typedef __bit_iterator<vector, false> pointer;
2160 typedef __bit_iterator<vector, true> const_pointer;
2161 typedef pointer iterator;
2162 typedef const_pointer const_iterator;
2163 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
2164 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
2167 typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
2168 typedef allocator_traits<__storage_allocator> __storage_traits;
2169 typedef typename __storage_traits::pointer __storage_pointer;
2170 typedef typename __storage_traits::const_pointer __const_storage_pointer;
2172 __storage_pointer __begin_;
2174 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
2176 typedef __bit_reference<vector> reference;
2177 typedef __bit_const_reference<vector> const_reference;
2179 _LIBCPP_INLINE_VISIBILITY
2180 size_type& __cap() _NOEXCEPT
2181 {return __cap_alloc_.first();}
2182 _LIBCPP_INLINE_VISIBILITY
2183 const size_type& __cap() const _NOEXCEPT
2184 {return __cap_alloc_.first();}
2185 _LIBCPP_INLINE_VISIBILITY
2186 __storage_allocator& __alloc() _NOEXCEPT
2187 {return __cap_alloc_.second();}
2188 _LIBCPP_INLINE_VISIBILITY
2189 const __storage_allocator& __alloc() const _NOEXCEPT
2190 {return __cap_alloc_.second();}
2192 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2194 _LIBCPP_INLINE_VISIBILITY
2195 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
2196 {return __n * __bits_per_word;}
2197 _LIBCPP_INLINE_VISIBILITY
2198 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
2199 {return (__n - 1) / __bits_per_word + 1;}
2202 _LIBCPP_INLINE_VISIBILITY
2203 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
2205 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
2206 #if _LIBCPP_STD_VER <= 14
2207 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
2212 explicit vector(size_type __n);
2213 #if _LIBCPP_STD_VER > 11
2214 explicit vector(size_type __n, const allocator_type& __a);
2216 vector(size_type __n, const value_type& __v);
2217 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2218 template <class _InputIterator>
2219 vector(_InputIterator __first, _InputIterator __last,
2220 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2221 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2222 template <class _InputIterator>
2223 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2224 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2225 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2226 template <class _ForwardIterator>
2227 vector(_ForwardIterator __first, _ForwardIterator __last,
2228 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2229 template <class _ForwardIterator>
2230 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2231 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2233 vector(const vector& __v);
2234 vector(const vector& __v, const allocator_type& __a);
2235 vector& operator=(const vector& __v);
2237 #ifndef _LIBCPP_CXX03_LANG
2238 vector(initializer_list<value_type> __il);
2239 vector(initializer_list<value_type> __il, const allocator_type& __a);
2241 _LIBCPP_INLINE_VISIBILITY
2242 vector(vector&& __v)
2243 #if _LIBCPP_STD_VER > 14
2246 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
2248 vector(vector&& __v, const allocator_type& __a);
2249 _LIBCPP_INLINE_VISIBILITY
2250 vector& operator=(vector&& __v)
2251 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
2253 _LIBCPP_INLINE_VISIBILITY
2254 vector& operator=(initializer_list<value_type> __il)
2255 {assign(__il.begin(), __il.end()); return *this;}
2257 #endif // !_LIBCPP_CXX03_LANG
2259 template <class _InputIterator>
2262 __is_input_iterator<_InputIterator>::value &&
2263 !__is_forward_iterator<_InputIterator>::value,
2266 assign(_InputIterator __first, _InputIterator __last);
2267 template <class _ForwardIterator>
2270 __is_forward_iterator<_ForwardIterator>::value,
2273 assign(_ForwardIterator __first, _ForwardIterator __last);
2275 void assign(size_type __n, const value_type& __x);
2277 #ifndef _LIBCPP_CXX03_LANG
2278 _LIBCPP_INLINE_VISIBILITY
2279 void assign(initializer_list<value_type> __il)
2280 {assign(__il.begin(), __il.end());}
2283 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
2284 {return allocator_type(this->__alloc());}
2286 size_type max_size() const _NOEXCEPT;
2287 _LIBCPP_INLINE_VISIBILITY
2288 size_type capacity() const _NOEXCEPT
2289 {return __internal_cap_to_external(__cap());}
2290 _LIBCPP_INLINE_VISIBILITY
2291 size_type size() const _NOEXCEPT
2293 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
2294 bool empty() const _NOEXCEPT
2295 {return __size_ == 0;}
2296 void reserve(size_type __n);
2297 void shrink_to_fit() _NOEXCEPT;
2299 _LIBCPP_INLINE_VISIBILITY
2300 iterator begin() _NOEXCEPT
2301 {return __make_iter(0);}
2302 _LIBCPP_INLINE_VISIBILITY
2303 const_iterator begin() const _NOEXCEPT
2304 {return __make_iter(0);}
2305 _LIBCPP_INLINE_VISIBILITY
2306 iterator end() _NOEXCEPT
2307 {return __make_iter(__size_);}
2308 _LIBCPP_INLINE_VISIBILITY
2309 const_iterator end() const _NOEXCEPT
2310 {return __make_iter(__size_);}
2312 _LIBCPP_INLINE_VISIBILITY
2313 reverse_iterator rbegin() _NOEXCEPT
2314 {return reverse_iterator(end());}
2315 _LIBCPP_INLINE_VISIBILITY
2316 const_reverse_iterator rbegin() const _NOEXCEPT
2317 {return const_reverse_iterator(end());}
2318 _LIBCPP_INLINE_VISIBILITY
2319 reverse_iterator rend() _NOEXCEPT
2320 {return reverse_iterator(begin());}
2321 _LIBCPP_INLINE_VISIBILITY
2322 const_reverse_iterator rend() const _NOEXCEPT
2323 {return const_reverse_iterator(begin());}
2325 _LIBCPP_INLINE_VISIBILITY
2326 const_iterator cbegin() const _NOEXCEPT
2327 {return __make_iter(0);}
2328 _LIBCPP_INLINE_VISIBILITY
2329 const_iterator cend() const _NOEXCEPT
2330 {return __make_iter(__size_);}
2331 _LIBCPP_INLINE_VISIBILITY
2332 const_reverse_iterator crbegin() const _NOEXCEPT
2334 _LIBCPP_INLINE_VISIBILITY
2335 const_reverse_iterator crend() const _NOEXCEPT
2338 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2339 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2340 reference at(size_type __n);
2341 const_reference at(size_type __n) const;
2343 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2344 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2345 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2346 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2348 void push_back(const value_type& __x);
2349 #if _LIBCPP_STD_VER > 11
2350 template <class... _Args>
2351 #if _LIBCPP_STD_VER > 14
2352 _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args)
2354 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
2357 push_back ( value_type ( _VSTD::forward<_Args>(__args)... ));
2358 #if _LIBCPP_STD_VER > 14
2359 return this->back();
2364 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2366 #if _LIBCPP_STD_VER > 11
2367 template <class... _Args>
2368 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2369 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2372 iterator insert(const_iterator __position, const value_type& __x);
2373 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2374 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2375 template <class _InputIterator>
2378 __is_input_iterator <_InputIterator>::value &&
2379 !__is_forward_iterator<_InputIterator>::value,
2382 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2383 template <class _ForwardIterator>
2386 __is_forward_iterator<_ForwardIterator>::value,
2389 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
2391 #ifndef _LIBCPP_CXX03_LANG
2392 _LIBCPP_INLINE_VISIBILITY
2393 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2394 {return insert(__position, __il.begin(), __il.end());}
2397 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
2398 iterator erase(const_iterator __first, const_iterator __last);
2400 _LIBCPP_INLINE_VISIBILITY
2401 void clear() _NOEXCEPT {__size_ = 0;}
2404 #if _LIBCPP_STD_VER >= 14
2407 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2408 __is_nothrow_swappable<allocator_type>::value);
2410 static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
2412 void resize(size_type __sz, value_type __x = false);
2413 void flip() _NOEXCEPT;
2415 bool __invariants() const;
2418 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
2419 void allocate(size_type __n);
2420 void deallocate() _NOEXCEPT;
2421 _LIBCPP_INLINE_VISIBILITY
2422 static size_type __align_it(size_type __new_size) _NOEXCEPT
2423 {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);};
2424 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2425 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
2426 template <class _ForwardIterator>
2429 __is_forward_iterator<_ForwardIterator>::value,
2432 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2433 void __append(size_type __n, const_reference __x);
2434 _LIBCPP_INLINE_VISIBILITY
2435 reference __make_ref(size_type __pos) _NOEXCEPT
2436 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2437 _LIBCPP_INLINE_VISIBILITY
2438 const_reference __make_ref(size_type __pos) const _NOEXCEPT
2439 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2440 _LIBCPP_INLINE_VISIBILITY
2441 iterator __make_iter(size_type __pos) _NOEXCEPT
2442 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2443 _LIBCPP_INLINE_VISIBILITY
2444 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
2445 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2446 _LIBCPP_INLINE_VISIBILITY
2447 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
2448 {return begin() + (__p - cbegin());}
2450 _LIBCPP_INLINE_VISIBILITY
2451 void __copy_assign_alloc(const vector& __v)
2452 {__copy_assign_alloc(__v, integral_constant<bool,
2453 __storage_traits::propagate_on_container_copy_assignment::value>());}
2454 _LIBCPP_INLINE_VISIBILITY
2455 void __copy_assign_alloc(const vector& __c, true_type)
2457 if (__alloc() != __c.__alloc())
2459 __alloc() = __c.__alloc();
2462 _LIBCPP_INLINE_VISIBILITY
2463 void __copy_assign_alloc(const vector&, false_type)
2466 void __move_assign(vector& __c, false_type);
2467 void __move_assign(vector& __c, true_type)
2468 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2469 _LIBCPP_INLINE_VISIBILITY
2470 void __move_assign_alloc(vector& __c)
2472 !__storage_traits::propagate_on_container_move_assignment::value ||
2473 is_nothrow_move_assignable<allocator_type>::value)
2474 {__move_assign_alloc(__c, integral_constant<bool,
2475 __storage_traits::propagate_on_container_move_assignment::value>());}
2476 _LIBCPP_INLINE_VISIBILITY
2477 void __move_assign_alloc(vector& __c, true_type)
2478 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2480 __alloc() = _VSTD::move(__c.__alloc());
2483 _LIBCPP_INLINE_VISIBILITY
2484 void __move_assign_alloc(vector&, false_type)
2488 size_t __hash_code() const _NOEXCEPT;
2490 friend class __bit_reference<vector>;
2491 friend class __bit_const_reference<vector>;
2492 friend class __bit_iterator<vector, false>;
2493 friend class __bit_iterator<vector, true>;
2494 friend struct __bit_array<vector>;
2495 friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
2498 template <class _Allocator>
2499 inline _LIBCPP_INLINE_VISIBILITY
2501 vector<bool, _Allocator>::__invalidate_all_iterators()
2505 // Allocate space for __n objects
2506 // throws length_error if __n > max_size()
2507 // throws (probably bad_alloc) if memory run out
2508 // Precondition: __begin_ == __end_ == __cap() == 0
2509 // Precondition: __n > 0
2510 // Postcondition: capacity() == __n
2511 // Postcondition: size() == 0
2512 template <class _Allocator>
2514 vector<bool, _Allocator>::allocate(size_type __n)
2516 if (__n > max_size())
2517 this->__throw_length_error();
2518 __n = __external_cap_to_internal(__n);
2519 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2521 this->__cap() = __n;
2524 template <class _Allocator>
2526 vector<bool, _Allocator>::deallocate() _NOEXCEPT
2528 if (this->__begin_ != nullptr)
2530 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2531 __invalidate_all_iterators();
2532 this->__begin_ = nullptr;
2533 this->__size_ = this->__cap() = 0;
2537 template <class _Allocator>
2538 typename vector<bool, _Allocator>::size_type
2539 vector<bool, _Allocator>::max_size() const _NOEXCEPT
2541 size_type __amax = __storage_traits::max_size(__alloc());
2542 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2543 if (__nmax / __bits_per_word <= __amax)
2545 return __internal_cap_to_external(__amax);
2548 // Precondition: __new_size > capacity()
2549 template <class _Allocator>
2550 inline _LIBCPP_INLINE_VISIBILITY
2551 typename vector<bool, _Allocator>::size_type
2552 vector<bool, _Allocator>::__recommend(size_type __new_size) const
2554 const size_type __ms = max_size();
2555 if (__new_size > __ms)
2556 this->__throw_length_error();
2557 const size_type __cap = capacity();
2558 if (__cap >= __ms / 2)
2560 return _VSTD::max(2*__cap, __align_it(__new_size));
2563 // Default constructs __n objects starting at __end_
2564 // Precondition: __n > 0
2565 // Precondition: size() + __n <= capacity()
2566 // Postcondition: size() == size() + __n
2567 template <class _Allocator>
2568 inline _LIBCPP_INLINE_VISIBILITY
2570 vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2572 size_type __old_size = this->__size_;
2573 this->__size_ += __n;
2574 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
2577 template <class _Allocator>
2578 template <class _ForwardIterator>
2581 __is_forward_iterator<_ForwardIterator>::value,
2584 vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2586 size_type __old_size = this->__size_;
2587 this->__size_ += _VSTD::distance(__first, __last);
2588 _VSTD::copy(__first, __last, __make_iter(__old_size));
2591 template <class _Allocator>
2592 inline _LIBCPP_INLINE_VISIBILITY
2593 vector<bool, _Allocator>::vector()
2594 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2595 : __begin_(nullptr),
2601 template <class _Allocator>
2602 inline _LIBCPP_INLINE_VISIBILITY
2603 vector<bool, _Allocator>::vector(const allocator_type& __a)
2604 #if _LIBCPP_STD_VER <= 14
2605 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
2609 : __begin_(nullptr),
2611 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2615 template <class _Allocator>
2616 vector<bool, _Allocator>::vector(size_type __n)
2617 : __begin_(nullptr),
2624 __construct_at_end(__n, false);
2628 #if _LIBCPP_STD_VER > 11
2629 template <class _Allocator>
2630 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2631 : __begin_(nullptr),
2633 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2638 __construct_at_end(__n, false);
2643 template <class _Allocator>
2644 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2645 : __begin_(nullptr),
2652 __construct_at_end(__n, __x);
2656 template <class _Allocator>
2657 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2658 : __begin_(nullptr),
2660 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2665 __construct_at_end(__n, __x);
2669 template <class _Allocator>
2670 template <class _InputIterator>
2671 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2672 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2673 !__is_forward_iterator<_InputIterator>::value>::type*)
2674 : __begin_(nullptr),
2678 #ifndef _LIBCPP_NO_EXCEPTIONS
2681 #endif // _LIBCPP_NO_EXCEPTIONS
2682 for (; __first != __last; ++__first)
2683 push_back(*__first);
2684 #ifndef _LIBCPP_NO_EXCEPTIONS
2688 if (__begin_ != nullptr)
2689 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2690 __invalidate_all_iterators();
2693 #endif // _LIBCPP_NO_EXCEPTIONS
2696 template <class _Allocator>
2697 template <class _InputIterator>
2698 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2699 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2700 !__is_forward_iterator<_InputIterator>::value>::type*)
2701 : __begin_(nullptr),
2703 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2705 #ifndef _LIBCPP_NO_EXCEPTIONS
2708 #endif // _LIBCPP_NO_EXCEPTIONS
2709 for (; __first != __last; ++__first)
2710 push_back(*__first);
2711 #ifndef _LIBCPP_NO_EXCEPTIONS
2715 if (__begin_ != nullptr)
2716 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2717 __invalidate_all_iterators();
2720 #endif // _LIBCPP_NO_EXCEPTIONS
2723 template <class _Allocator>
2724 template <class _ForwardIterator>
2725 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2726 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2727 : __begin_(nullptr),
2731 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2735 __construct_at_end(__first, __last);
2739 template <class _Allocator>
2740 template <class _ForwardIterator>
2741 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2742 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2743 : __begin_(nullptr),
2745 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2747 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2751 __construct_at_end(__first, __last);
2755 #ifndef _LIBCPP_CXX03_LANG
2757 template <class _Allocator>
2758 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2759 : __begin_(nullptr),
2763 size_type __n = static_cast<size_type>(__il.size());
2767 __construct_at_end(__il.begin(), __il.end());
2771 template <class _Allocator>
2772 vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2773 : __begin_(nullptr),
2775 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2777 size_type __n = static_cast<size_type>(__il.size());
2781 __construct_at_end(__il.begin(), __il.end());
2785 #endif // _LIBCPP_CXX03_LANG
2787 template <class _Allocator>
2788 vector<bool, _Allocator>::~vector()
2790 if (__begin_ != nullptr)
2791 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2792 __invalidate_all_iterators();
2795 template <class _Allocator>
2796 vector<bool, _Allocator>::vector(const vector& __v)
2797 : __begin_(nullptr),
2799 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2803 allocate(__v.size());
2804 __construct_at_end(__v.begin(), __v.end());
2808 template <class _Allocator>
2809 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2810 : __begin_(nullptr),
2812 __cap_alloc_(0, __a)
2816 allocate(__v.size());
2817 __construct_at_end(__v.begin(), __v.end());
2821 template <class _Allocator>
2822 vector<bool, _Allocator>&
2823 vector<bool, _Allocator>::operator=(const vector& __v)
2827 __copy_assign_alloc(__v);
2830 if (__v.__size_ > capacity())
2833 allocate(__v.__size_);
2835 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2837 __size_ = __v.__size_;
2842 #ifndef _LIBCPP_CXX03_LANG
2844 template <class _Allocator>
2845 inline _LIBCPP_INLINE_VISIBILITY
2846 vector<bool, _Allocator>::vector(vector&& __v)
2847 #if _LIBCPP_STD_VER > 14
2850 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2852 : __begin_(__v.__begin_),
2853 __size_(__v.__size_),
2854 __cap_alloc_(__v.__cap_alloc_)
2856 __v.__begin_ = nullptr;
2861 template <class _Allocator>
2862 vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2863 : __begin_(nullptr),
2865 __cap_alloc_(0, __a)
2867 if (__a == allocator_type(__v.__alloc()))
2869 this->__begin_ = __v.__begin_;
2870 this->__size_ = __v.__size_;
2871 this->__cap() = __v.__cap();
2872 __v.__begin_ = nullptr;
2873 __v.__cap() = __v.__size_ = 0;
2875 else if (__v.size() > 0)
2877 allocate(__v.size());
2878 __construct_at_end(__v.begin(), __v.end());
2882 template <class _Allocator>
2883 inline _LIBCPP_INLINE_VISIBILITY
2884 vector<bool, _Allocator>&
2885 vector<bool, _Allocator>::operator=(vector&& __v)
2886 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
2888 __move_assign(__v, integral_constant<bool,
2889 __storage_traits::propagate_on_container_move_assignment::value>());
2893 template <class _Allocator>
2895 vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2897 if (__alloc() != __c.__alloc())
2898 assign(__c.begin(), __c.end());
2900 __move_assign(__c, true_type());
2903 template <class _Allocator>
2905 vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2906 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2909 __move_assign_alloc(__c);
2910 this->__begin_ = __c.__begin_;
2911 this->__size_ = __c.__size_;
2912 this->__cap() = __c.__cap();
2913 __c.__begin_ = nullptr;
2914 __c.__cap() = __c.__size_ = 0;
2917 #endif // !_LIBCPP_CXX03_LANG
2919 template <class _Allocator>
2921 vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2926 size_type __c = capacity();
2931 vector __v(__alloc());
2932 __v.reserve(__recommend(__n));
2936 _VSTD::fill_n(begin(), __n, __x);
2938 __invalidate_all_iterators();
2941 template <class _Allocator>
2942 template <class _InputIterator>
2945 __is_input_iterator<_InputIterator>::value &&
2946 !__is_forward_iterator<_InputIterator>::value,
2949 vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2952 for (; __first != __last; ++__first)
2953 push_back(*__first);
2956 template <class _Allocator>
2957 template <class _ForwardIterator>
2960 __is_forward_iterator<_ForwardIterator>::value,
2963 vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2966 difference_type __ns = _VSTD::distance(__first, __last);
2967 _LIBCPP_ASSERT(__ns >= 0, "invalid range specified");
2968 const size_t __n = static_cast<size_type>(__ns);
2971 if (__n > capacity())
2976 __construct_at_end(__first, __last);
2980 template <class _Allocator>
2982 vector<bool, _Allocator>::reserve(size_type __n)
2984 if (__n > capacity())
2986 vector __v(this->__alloc());
2988 __v.__construct_at_end(this->begin(), this->end());
2990 __invalidate_all_iterators();
2994 template <class _Allocator>
2996 vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
2998 if (__external_cap_to_internal(size()) > __cap())
3000 #ifndef _LIBCPP_NO_EXCEPTIONS
3003 #endif // _LIBCPP_NO_EXCEPTIONS
3004 vector(*this, allocator_type(__alloc())).swap(*this);
3005 #ifndef _LIBCPP_NO_EXCEPTIONS
3010 #endif // _LIBCPP_NO_EXCEPTIONS
3014 template <class _Allocator>
3015 typename vector<bool, _Allocator>::reference
3016 vector<bool, _Allocator>::at(size_type __n)
3019 this->__throw_out_of_range();
3020 return (*this)[__n];
3023 template <class _Allocator>
3024 typename vector<bool, _Allocator>::const_reference
3025 vector<bool, _Allocator>::at(size_type __n) const
3028 this->__throw_out_of_range();
3029 return (*this)[__n];
3032 template <class _Allocator>
3034 vector<bool, _Allocator>::push_back(const value_type& __x)
3036 if (this->__size_ == this->capacity())
3037 reserve(__recommend(this->__size_ + 1));
3042 template <class _Allocator>
3043 typename vector<bool, _Allocator>::iterator
3044 vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
3047 if (size() < capacity())
3049 const_iterator __old_end = end();
3051 _VSTD::copy_backward(__position, __old_end, end());
3052 __r = __const_iterator_cast(__position);
3056 vector __v(__alloc());
3057 __v.reserve(__recommend(__size_ + 1));
3058 __v.__size_ = __size_ + 1;
3059 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3060 _VSTD::copy_backward(__position, cend(), __v.end());
3067 template <class _Allocator>
3068 typename vector<bool, _Allocator>::iterator
3069 vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
3072 size_type __c = capacity();
3073 if (__n <= __c && size() <= __c - __n)
3075 const_iterator __old_end = end();
3077 _VSTD::copy_backward(__position, __old_end, end());
3078 __r = __const_iterator_cast(__position);
3082 vector __v(__alloc());
3083 __v.reserve(__recommend(__size_ + __n));
3084 __v.__size_ = __size_ + __n;
3085 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3086 _VSTD::copy_backward(__position, cend(), __v.end());
3089 _VSTD::fill_n(__r, __n, __x);
3093 template <class _Allocator>
3094 template <class _InputIterator>
3097 __is_input_iterator <_InputIterator>::value &&
3098 !__is_forward_iterator<_InputIterator>::value,
3099 typename vector<bool, _Allocator>::iterator
3101 vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
3103 difference_type __off = __position - begin();
3104 iterator __p = __const_iterator_cast(__position);
3105 iterator __old_end = end();
3106 for (; size() != capacity() && __first != __last; ++__first)
3111 vector __v(__alloc());
3112 if (__first != __last)
3114 #ifndef _LIBCPP_NO_EXCEPTIONS
3117 #endif // _LIBCPP_NO_EXCEPTIONS
3118 __v.assign(__first, __last);
3119 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
3120 difference_type __old_p = __p - begin();
3121 reserve(__recommend(size() + __v.size()));
3122 __p = begin() + __old_p;
3123 __old_end = begin() + __old_size;
3124 #ifndef _LIBCPP_NO_EXCEPTIONS
3128 erase(__old_end, end());
3131 #endif // _LIBCPP_NO_EXCEPTIONS
3133 __p = _VSTD::rotate(__p, __old_end, end());
3134 insert(__p, __v.begin(), __v.end());
3135 return begin() + __off;
3138 template <class _Allocator>
3139 template <class _ForwardIterator>
3142 __is_forward_iterator<_ForwardIterator>::value,
3143 typename vector<bool, _Allocator>::iterator
3145 vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
3147 const difference_type __n_signed = _VSTD::distance(__first, __last);
3148 _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified");
3149 const size_type __n = static_cast<size_type>(__n_signed);
3151 size_type __c = capacity();
3152 if (__n <= __c && size() <= __c - __n)
3154 const_iterator __old_end = end();
3156 _VSTD::copy_backward(__position, __old_end, end());
3157 __r = __const_iterator_cast(__position);
3161 vector __v(__alloc());
3162 __v.reserve(__recommend(__size_ + __n));
3163 __v.__size_ = __size_ + __n;
3164 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3165 _VSTD::copy_backward(__position, cend(), __v.end());
3168 _VSTD::copy(__first, __last, __r);
3172 template <class _Allocator>
3173 inline _LIBCPP_INLINE_VISIBILITY
3174 typename vector<bool, _Allocator>::iterator
3175 vector<bool, _Allocator>::erase(const_iterator __position)
3177 iterator __r = __const_iterator_cast(__position);
3178 _VSTD::copy(__position + 1, this->cend(), __r);
3183 template <class _Allocator>
3184 typename vector<bool, _Allocator>::iterator
3185 vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3187 iterator __r = __const_iterator_cast(__first);
3188 difference_type __d = __last - __first;
3189 _VSTD::copy(__last, this->cend(), __r);
3194 template <class _Allocator>
3196 vector<bool, _Allocator>::swap(vector& __x)
3197 #if _LIBCPP_STD_VER >= 14
3200 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3201 __is_nothrow_swappable<allocator_type>::value)
3204 _VSTD::swap(this->__begin_, __x.__begin_);
3205 _VSTD::swap(this->__size_, __x.__size_);
3206 _VSTD::swap(this->__cap(), __x.__cap());
3207 __swap_allocator(this->__alloc(), __x.__alloc(),
3208 integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
3211 template <class _Allocator>
3213 vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3215 size_type __cs = size();
3219 size_type __c = capacity();
3220 size_type __n = __sz - __cs;
3221 if (__n <= __c && __cs <= __c - __n)
3228 vector __v(__alloc());
3229 __v.reserve(__recommend(__size_ + __n));
3230 __v.__size_ = __size_ + __n;
3231 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
3234 _VSTD::fill_n(__r, __n, __x);
3240 template <class _Allocator>
3242 vector<bool, _Allocator>::flip() _NOEXCEPT
3244 // do middle whole words
3245 size_type __n = __size_;
3246 __storage_pointer __p = __begin_;
3247 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3249 // do last partial word
3252 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3253 __storage_type __b = *__p & __m;
3259 template <class _Allocator>
3261 vector<bool, _Allocator>::__invariants() const
3263 if (this->__begin_ == nullptr)
3265 if (this->__size_ != 0 || this->__cap() != 0)
3270 if (this->__cap() == 0)
3272 if (this->__size_ > this->capacity())
3278 template <class _Allocator>
3280 vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
3283 // do middle whole words
3284 size_type __n = __size_;
3285 __storage_pointer __p = __begin_;
3286 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3288 // do last partial word
3291 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3297 template <class _Allocator>
3298 struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
3299 : public unary_function<vector<bool, _Allocator>, size_t>
3301 _LIBCPP_INLINE_VISIBILITY
3302 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
3303 {return __vec.__hash_code();}
3306 template <class _Tp, class _Allocator>
3307 inline _LIBCPP_INLINE_VISIBILITY
3309 operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3311 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
3312 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3315 template <class _Tp, class _Allocator>
3316 inline _LIBCPP_INLINE_VISIBILITY
3318 operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3320 return !(__x == __y);
3323 template <class _Tp, class _Allocator>
3324 inline _LIBCPP_INLINE_VISIBILITY
3326 operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3328 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
3331 template <class _Tp, class _Allocator>
3332 inline _LIBCPP_INLINE_VISIBILITY
3334 operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3339 template <class _Tp, class _Allocator>
3340 inline _LIBCPP_INLINE_VISIBILITY
3342 operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3344 return !(__x < __y);
3347 template <class _Tp, class _Allocator>
3348 inline _LIBCPP_INLINE_VISIBILITY
3350 operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3352 return !(__y < __x);
3355 template <class _Tp, class _Allocator>
3356 inline _LIBCPP_INLINE_VISIBILITY
3358 swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
3359 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
3364 _LIBCPP_END_NAMESPACE_STD
3368 #endif // _LIBCPP_VECTOR