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");
314 #pragma warning( push )
315 #pragma warning( disable: 4231 )
316 #endif // _LIBCPP_MSVC
317 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>)
319 #pragma warning( pop )
320 #endif // _LIBCPP_MSVC
322 template <class _Tp, class _Allocator>
324 : protected __vector_base_common<true>
327 typedef _Tp value_type;
328 typedef _Allocator allocator_type;
329 typedef allocator_traits<allocator_type> __alloc_traits;
330 typedef value_type& reference;
331 typedef const value_type& const_reference;
332 typedef typename __alloc_traits::size_type size_type;
333 typedef typename __alloc_traits::difference_type difference_type;
334 typedef typename __alloc_traits::pointer pointer;
335 typedef typename __alloc_traits::const_pointer const_pointer;
336 typedef pointer iterator;
337 typedef const_pointer const_iterator;
341 __compressed_pair<pointer, allocator_type> __end_cap_;
343 _LIBCPP_INLINE_VISIBILITY
344 allocator_type& __alloc() _NOEXCEPT
345 {return __end_cap_.second();}
346 _LIBCPP_INLINE_VISIBILITY
347 const allocator_type& __alloc() const _NOEXCEPT
348 {return __end_cap_.second();}
349 _LIBCPP_INLINE_VISIBILITY
350 pointer& __end_cap() _NOEXCEPT
351 {return __end_cap_.first();}
352 _LIBCPP_INLINE_VISIBILITY
353 const pointer& __end_cap() const _NOEXCEPT
354 {return __end_cap_.first();}
356 _LIBCPP_INLINE_VISIBILITY
358 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
359 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
362 _LIBCPP_INLINE_VISIBILITY
363 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
364 _LIBCPP_INLINE_VISIBILITY
365 size_type capacity() const _NOEXCEPT
366 {return static_cast<size_type>(__end_cap() - __begin_);}
368 _LIBCPP_INLINE_VISIBILITY
369 void __destruct_at_end(pointer __new_last) _NOEXCEPT;
371 _LIBCPP_INLINE_VISIBILITY
372 void __copy_assign_alloc(const __vector_base& __c)
373 {__copy_assign_alloc(__c, integral_constant<bool,
374 __alloc_traits::propagate_on_container_copy_assignment::value>());}
376 _LIBCPP_INLINE_VISIBILITY
377 void __move_assign_alloc(__vector_base& __c)
379 !__alloc_traits::propagate_on_container_move_assignment::value ||
380 is_nothrow_move_assignable<allocator_type>::value)
381 {__move_assign_alloc(__c, integral_constant<bool,
382 __alloc_traits::propagate_on_container_move_assignment::value>());}
384 _LIBCPP_INLINE_VISIBILITY
385 void __copy_assign_alloc(const __vector_base& __c, true_type)
387 if (__alloc() != __c.__alloc())
390 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
391 __begin_ = __end_ = __end_cap() = nullptr;
393 __alloc() = __c.__alloc();
396 _LIBCPP_INLINE_VISIBILITY
397 void __copy_assign_alloc(const __vector_base&, false_type)
400 _LIBCPP_INLINE_VISIBILITY
401 void __move_assign_alloc(__vector_base& __c, true_type)
402 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
404 __alloc() = _VSTD::move(__c.__alloc());
407 _LIBCPP_INLINE_VISIBILITY
408 void __move_assign_alloc(__vector_base&, false_type)
413 template <class _Tp, class _Allocator>
414 inline _LIBCPP_INLINE_VISIBILITY
416 __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
418 pointer __soon_to_be_end = __end_;
419 while (__new_last != __soon_to_be_end)
420 __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__soon_to_be_end));
424 template <class _Tp, class _Allocator>
425 inline _LIBCPP_INLINE_VISIBILITY
426 __vector_base<_Tp, _Allocator>::__vector_base()
427 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
434 template <class _Tp, class _Allocator>
435 inline _LIBCPP_INLINE_VISIBILITY
436 __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
439 __end_cap_(nullptr, __a)
443 template <class _Tp, class _Allocator>
444 __vector_base<_Tp, _Allocator>::~__vector_base()
446 if (__begin_ != nullptr)
449 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
453 template <class _Tp, class _Allocator /* = allocator<_Tp> */>
454 class _LIBCPP_TEMPLATE_VIS vector
455 : private __vector_base<_Tp, _Allocator>
458 typedef __vector_base<_Tp, _Allocator> __base;
459 typedef allocator<_Tp> __default_allocator_type;
461 typedef vector __self;
462 typedef _Tp value_type;
463 typedef _Allocator allocator_type;
464 typedef typename __base::__alloc_traits __alloc_traits;
465 typedef typename __base::reference reference;
466 typedef typename __base::const_reference const_reference;
467 typedef typename __base::size_type size_type;
468 typedef typename __base::difference_type difference_type;
469 typedef typename __base::pointer pointer;
470 typedef typename __base::const_pointer const_pointer;
471 typedef __wrap_iter<pointer> iterator;
472 typedef __wrap_iter<const_pointer> const_iterator;
473 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
474 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
476 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
477 "Allocator::value_type must be same type as value_type");
479 _LIBCPP_INLINE_VISIBILITY
480 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
482 #if _LIBCPP_DEBUG_LEVEL >= 2
483 __get_db()->__insert_c(this);
486 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
487 #if _LIBCPP_STD_VER <= 14
488 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
494 #if _LIBCPP_DEBUG_LEVEL >= 2
495 __get_db()->__insert_c(this);
498 explicit vector(size_type __n);
499 #if _LIBCPP_STD_VER > 11
500 explicit vector(size_type __n, const allocator_type& __a);
502 vector(size_type __n, const_reference __x);
503 vector(size_type __n, const_reference __x, const allocator_type& __a);
504 template <class _InputIterator>
505 vector(_InputIterator __first,
506 typename enable_if<__is_input_iterator <_InputIterator>::value &&
507 !__is_forward_iterator<_InputIterator>::value &&
510 typename iterator_traits<_InputIterator>::reference>::value,
511 _InputIterator>::type __last);
512 template <class _InputIterator>
513 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
514 typename enable_if<__is_input_iterator <_InputIterator>::value &&
515 !__is_forward_iterator<_InputIterator>::value &&
518 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
519 template <class _ForwardIterator>
520 vector(_ForwardIterator __first,
521 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
524 typename iterator_traits<_ForwardIterator>::reference>::value,
525 _ForwardIterator>::type __last);
526 template <class _ForwardIterator>
527 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
528 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
531 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
533 #if _LIBCPP_DEBUG_LEVEL >= 2
534 _LIBCPP_INLINE_VISIBILITY
537 __get_db()->__erase_c(this);
541 vector(const vector& __x);
542 vector(const vector& __x, const allocator_type& __a);
543 _LIBCPP_INLINE_VISIBILITY
544 vector& operator=(const vector& __x);
546 #ifndef _LIBCPP_CXX03_LANG
547 _LIBCPP_INLINE_VISIBILITY
548 vector(initializer_list<value_type> __il);
550 _LIBCPP_INLINE_VISIBILITY
551 vector(initializer_list<value_type> __il, const allocator_type& __a);
553 _LIBCPP_INLINE_VISIBILITY
555 #if _LIBCPP_STD_VER > 14
558 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
561 _LIBCPP_INLINE_VISIBILITY
562 vector(vector&& __x, const allocator_type& __a);
563 _LIBCPP_INLINE_VISIBILITY
564 vector& operator=(vector&& __x)
565 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
567 _LIBCPP_INLINE_VISIBILITY
568 vector& operator=(initializer_list<value_type> __il)
569 {assign(__il.begin(), __il.end()); return *this;}
571 #endif // !_LIBCPP_CXX03_LANG
573 template <class _InputIterator>
576 __is_input_iterator <_InputIterator>::value &&
577 !__is_forward_iterator<_InputIterator>::value &&
580 typename iterator_traits<_InputIterator>::reference>::value,
583 assign(_InputIterator __first, _InputIterator __last);
584 template <class _ForwardIterator>
587 __is_forward_iterator<_ForwardIterator>::value &&
590 typename iterator_traits<_ForwardIterator>::reference>::value,
593 assign(_ForwardIterator __first, _ForwardIterator __last);
595 void assign(size_type __n, const_reference __u);
597 #ifndef _LIBCPP_CXX03_LANG
598 _LIBCPP_INLINE_VISIBILITY
599 void assign(initializer_list<value_type> __il)
600 {assign(__il.begin(), __il.end());}
603 _LIBCPP_INLINE_VISIBILITY
604 allocator_type get_allocator() const _NOEXCEPT
605 {return this->__alloc();}
607 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
608 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
609 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
610 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
612 _LIBCPP_INLINE_VISIBILITY
613 reverse_iterator rbegin() _NOEXCEPT
614 {return reverse_iterator(end());}
615 _LIBCPP_INLINE_VISIBILITY
616 const_reverse_iterator rbegin() const _NOEXCEPT
617 {return const_reverse_iterator(end());}
618 _LIBCPP_INLINE_VISIBILITY
619 reverse_iterator rend() _NOEXCEPT
620 {return reverse_iterator(begin());}
621 _LIBCPP_INLINE_VISIBILITY
622 const_reverse_iterator rend() const _NOEXCEPT
623 {return const_reverse_iterator(begin());}
625 _LIBCPP_INLINE_VISIBILITY
626 const_iterator cbegin() const _NOEXCEPT
628 _LIBCPP_INLINE_VISIBILITY
629 const_iterator cend() const _NOEXCEPT
631 _LIBCPP_INLINE_VISIBILITY
632 const_reverse_iterator crbegin() const _NOEXCEPT
634 _LIBCPP_INLINE_VISIBILITY
635 const_reverse_iterator crend() const _NOEXCEPT
638 _LIBCPP_INLINE_VISIBILITY
639 size_type size() const _NOEXCEPT
640 {return static_cast<size_type>(this->__end_ - this->__begin_);}
641 _LIBCPP_INLINE_VISIBILITY
642 size_type capacity() const _NOEXCEPT
643 {return __base::capacity();}
644 _LIBCPP_INLINE_VISIBILITY
645 bool empty() const _NOEXCEPT
646 {return this->__begin_ == this->__end_;}
647 size_type max_size() const _NOEXCEPT;
648 void reserve(size_type __n);
649 void shrink_to_fit() _NOEXCEPT;
651 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
652 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
653 reference at(size_type __n);
654 const_reference at(size_type __n) const;
656 _LIBCPP_INLINE_VISIBILITY reference front()
658 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
659 return *this->__begin_;
661 _LIBCPP_INLINE_VISIBILITY const_reference front() const
663 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
664 return *this->__begin_;
666 _LIBCPP_INLINE_VISIBILITY reference back()
668 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
669 return *(this->__end_ - 1);
671 _LIBCPP_INLINE_VISIBILITY const_reference back() const
673 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
674 return *(this->__end_ - 1);
677 _LIBCPP_INLINE_VISIBILITY
678 value_type* data() _NOEXCEPT
679 {return _VSTD::__to_raw_pointer(this->__begin_);}
680 _LIBCPP_INLINE_VISIBILITY
681 const value_type* data() const _NOEXCEPT
682 {return _VSTD::__to_raw_pointer(this->__begin_);}
684 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
686 #ifndef _LIBCPP_CXX03_LANG
687 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
689 template <class... _Args>
690 _LIBCPP_INLINE_VISIBILITY
691 #if _LIBCPP_STD_VER > 14
692 reference emplace_back(_Args&&... __args);
694 void emplace_back(_Args&&... __args);
696 #endif // !_LIBCPP_CXX03_LANG
698 _LIBCPP_INLINE_VISIBILITY
701 iterator insert(const_iterator __position, const_reference __x);
703 #ifndef _LIBCPP_CXX03_LANG
704 iterator insert(const_iterator __position, value_type&& __x);
705 template <class... _Args>
706 iterator emplace(const_iterator __position, _Args&&... __args);
707 #endif // !_LIBCPP_CXX03_LANG
709 iterator insert(const_iterator __position, size_type __n, const_reference __x);
710 template <class _InputIterator>
713 __is_input_iterator <_InputIterator>::value &&
714 !__is_forward_iterator<_InputIterator>::value &&
717 typename iterator_traits<_InputIterator>::reference>::value,
720 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
721 template <class _ForwardIterator>
724 __is_forward_iterator<_ForwardIterator>::value &&
727 typename iterator_traits<_ForwardIterator>::reference>::value,
730 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
732 #ifndef _LIBCPP_CXX03_LANG
733 _LIBCPP_INLINE_VISIBILITY
734 iterator insert(const_iterator __position, initializer_list<value_type> __il)
735 {return insert(__position, __il.begin(), __il.end());}
738 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
739 iterator erase(const_iterator __first, const_iterator __last);
741 _LIBCPP_INLINE_VISIBILITY
742 void clear() _NOEXCEPT
744 size_type __old_size = size();
746 __annotate_shrink(__old_size);
747 __invalidate_all_iterators();
750 void resize(size_type __sz);
751 void resize(size_type __sz, const_reference __x);
754 #if _LIBCPP_STD_VER >= 14
757 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
758 __is_nothrow_swappable<allocator_type>::value);
761 bool __invariants() const;
763 #if _LIBCPP_DEBUG_LEVEL >= 2
765 bool __dereferenceable(const const_iterator* __i) const;
766 bool __decrementable(const const_iterator* __i) const;
767 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
768 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
770 #endif // _LIBCPP_DEBUG_LEVEL >= 2
773 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
774 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
775 void allocate(size_type __n);
776 void deallocate() _NOEXCEPT;
777 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
778 void __construct_at_end(size_type __n);
779 _LIBCPP_INLINE_VISIBILITY
780 void __construct_at_end(size_type __n, const_reference __x);
781 template <class _ForwardIterator>
784 __is_forward_iterator<_ForwardIterator>::value,
787 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
788 void __append(size_type __n);
789 void __append(size_type __n, const_reference __x);
790 _LIBCPP_INLINE_VISIBILITY
791 iterator __make_iter(pointer __p) _NOEXCEPT;
792 _LIBCPP_INLINE_VISIBILITY
793 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
794 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
795 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
796 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
797 void __move_assign(vector& __c, true_type)
798 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
799 void __move_assign(vector& __c, false_type)
800 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
801 _LIBCPP_INLINE_VISIBILITY
802 void __destruct_at_end(pointer __new_last) _NOEXCEPT
804 __invalidate_iterators_past(__new_last);
805 size_type __old_size = size();
806 __base::__destruct_at_end(__new_last);
807 __annotate_shrink(__old_size);
810 #ifndef _LIBCPP_CXX03_LANG
811 template <class _Up> void __push_back_slow_path(_Up&& __x);
813 template <class... _Args>
814 void __emplace_back_slow_path(_Args&&... __args);
816 template <class _Up> void __push_back_slow_path(_Up& __x);
819 // The following functions are no-ops outside of AddressSanitizer mode.
820 // We call annotatations only for the default Allocator because other allocators
821 // may not meet the AddressSanitizer alignment constraints.
822 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
823 #ifndef _LIBCPP_HAS_NO_ASAN
824 void __annotate_contiguous_container(const void *__beg, const void *__end,
825 const void *__old_mid,
826 const void *__new_mid) const
829 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
830 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
833 _LIBCPP_INLINE_VISIBILITY
834 void __annotate_contiguous_container(const void*, const void*, const void*,
835 const void*) const {}
837 _LIBCPP_INLINE_VISIBILITY
838 void __annotate_new(size_type __current_size) const {
839 __annotate_contiguous_container(data(), data() + capacity(),
840 data() + capacity(), data() + __current_size);
843 _LIBCPP_INLINE_VISIBILITY
844 void __annotate_delete() const {
845 __annotate_contiguous_container(data(), data() + capacity(),
846 data() + size(), data() + capacity());
849 _LIBCPP_INLINE_VISIBILITY
850 void __annotate_increase(size_type __n) const
852 __annotate_contiguous_container(data(), data() + capacity(),
853 data() + size(), data() + size() + __n);
856 _LIBCPP_INLINE_VISIBILITY
857 void __annotate_shrink(size_type __old_size) const
859 __annotate_contiguous_container(data(), data() + capacity(),
860 data() + __old_size, data() + size());
862 #ifndef _LIBCPP_HAS_NO_ASAN
863 // The annotation for size increase should happen before the actual increase,
864 // but if an exception is thrown after that the annotation has to be undone.
865 struct __RAII_IncreaseAnnotator {
866 __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1)
867 : __commit(false), __v(__v), __old_size(__v.size() + __n) {
868 __v.__annotate_increase(__n);
870 void __done() { __commit = true; }
871 ~__RAII_IncreaseAnnotator() {
872 if (__commit) return;
873 __v.__annotate_shrink(__old_size);
877 size_type __old_size;
880 struct __RAII_IncreaseAnnotator {
881 _LIBCPP_INLINE_VISIBILITY
882 __RAII_IncreaseAnnotator(const vector &, size_type = 1) {}
883 _LIBCPP_INLINE_VISIBILITY void __done() {}
889 template <class _Tp, class _Allocator>
891 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
894 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
895 _VSTD::swap(this->__begin_, __v.__begin_);
896 _VSTD::swap(this->__end_, __v.__end_);
897 _VSTD::swap(this->__end_cap(), __v.__end_cap());
898 __v.__first_ = __v.__begin_;
899 __annotate_new(size());
900 __invalidate_all_iterators();
903 template <class _Tp, class _Allocator>
904 typename vector<_Tp, _Allocator>::pointer
905 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
908 pointer __r = __v.__begin_;
909 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
910 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
911 _VSTD::swap(this->__begin_, __v.__begin_);
912 _VSTD::swap(this->__end_, __v.__end_);
913 _VSTD::swap(this->__end_cap(), __v.__end_cap());
914 __v.__first_ = __v.__begin_;
915 __annotate_new(size());
916 __invalidate_all_iterators();
920 // Allocate space for __n objects
921 // throws length_error if __n > max_size()
922 // throws (probably bad_alloc) if memory run out
923 // Precondition: __begin_ == __end_ == __end_cap() == 0
924 // Precondition: __n > 0
925 // Postcondition: capacity() == __n
926 // Postcondition: size() == 0
927 template <class _Tp, class _Allocator>
929 vector<_Tp, _Allocator>::allocate(size_type __n)
931 if (__n > max_size())
932 this->__throw_length_error();
933 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
934 this->__end_cap() = this->__begin_ + __n;
938 template <class _Tp, class _Allocator>
940 vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
942 if (this->__begin_ != nullptr)
945 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
946 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
950 template <class _Tp, class _Allocator>
951 typename vector<_Tp, _Allocator>::size_type
952 vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
954 return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()),
955 numeric_limits<difference_type>::max());
958 // Precondition: __new_size > capacity()
959 template <class _Tp, class _Allocator>
960 inline _LIBCPP_INLINE_VISIBILITY
961 typename vector<_Tp, _Allocator>::size_type
962 vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
964 const size_type __ms = max_size();
965 if (__new_size > __ms)
966 this->__throw_length_error();
967 const size_type __cap = capacity();
968 if (__cap >= __ms / 2)
970 return _VSTD::max<size_type>(2*__cap, __new_size);
973 // Default constructs __n objects starting at __end_
974 // throws if construction throws
975 // Precondition: __n > 0
976 // Precondition: size() + __n <= capacity()
977 // Postcondition: size() == size() + __n
978 template <class _Tp, class _Allocator>
980 vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
982 allocator_type& __a = this->__alloc();
985 __RAII_IncreaseAnnotator __annotator(*this);
986 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
989 __annotator.__done();
993 // Copy constructs __n objects starting at __end_ from __x
994 // throws if construction throws
995 // Precondition: __n > 0
996 // Precondition: size() + __n <= capacity()
997 // Postcondition: size() == old size() + __n
998 // Postcondition: [i] == __x for all i in [size() - __n, __n)
999 template <class _Tp, class _Allocator>
1002 vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
1004 allocator_type& __a = this->__alloc();
1007 __RAII_IncreaseAnnotator __annotator(*this);
1008 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
1011 __annotator.__done();
1015 template <class _Tp, class _Allocator>
1016 template <class _ForwardIterator>
1019 __is_forward_iterator<_ForwardIterator>::value,
1022 vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
1024 allocator_type& __a = this->__alloc();
1025 __RAII_IncreaseAnnotator __annotator(*this, __n);
1026 __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_);
1027 __annotator.__done();
1030 // Default constructs __n objects starting at __end_
1031 // throws if construction throws
1032 // Postcondition: size() == size() + __n
1033 // Exception safety: strong.
1034 template <class _Tp, class _Allocator>
1036 vector<_Tp, _Allocator>::__append(size_type __n)
1038 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1039 this->__construct_at_end(__n);
1042 allocator_type& __a = this->__alloc();
1043 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1044 __v.__construct_at_end(__n);
1045 __swap_out_circular_buffer(__v);
1049 // Default constructs __n objects starting at __end_
1050 // throws if construction throws
1051 // Postcondition: size() == size() + __n
1052 // Exception safety: strong.
1053 template <class _Tp, class _Allocator>
1055 vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1057 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1058 this->__construct_at_end(__n, __x);
1061 allocator_type& __a = this->__alloc();
1062 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1063 __v.__construct_at_end(__n, __x);
1064 __swap_out_circular_buffer(__v);
1068 template <class _Tp, class _Allocator>
1069 vector<_Tp, _Allocator>::vector(size_type __n)
1071 #if _LIBCPP_DEBUG_LEVEL >= 2
1072 __get_db()->__insert_c(this);
1077 __construct_at_end(__n);
1081 #if _LIBCPP_STD_VER > 11
1082 template <class _Tp, class _Allocator>
1083 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1086 #if _LIBCPP_DEBUG_LEVEL >= 2
1087 __get_db()->__insert_c(this);
1092 __construct_at_end(__n);
1097 template <class _Tp, class _Allocator>
1098 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1100 #if _LIBCPP_DEBUG_LEVEL >= 2
1101 __get_db()->__insert_c(this);
1106 __construct_at_end(__n, __x);
1110 template <class _Tp, class _Allocator>
1111 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1114 #if _LIBCPP_DEBUG_LEVEL >= 2
1115 __get_db()->__insert_c(this);
1120 __construct_at_end(__n, __x);
1124 template <class _Tp, class _Allocator>
1125 template <class _InputIterator>
1126 vector<_Tp, _Allocator>::vector(_InputIterator __first,
1127 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1128 !__is_forward_iterator<_InputIterator>::value &&
1131 typename iterator_traits<_InputIterator>::reference>::value,
1132 _InputIterator>::type __last)
1134 #if _LIBCPP_DEBUG_LEVEL >= 2
1135 __get_db()->__insert_c(this);
1137 for (; __first != __last; ++__first)
1138 push_back(*__first);
1141 template <class _Tp, class _Allocator>
1142 template <class _InputIterator>
1143 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1144 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1145 !__is_forward_iterator<_InputIterator>::value &&
1148 typename iterator_traits<_InputIterator>::reference>::value>::type*)
1151 #if _LIBCPP_DEBUG_LEVEL >= 2
1152 __get_db()->__insert_c(this);
1154 for (; __first != __last; ++__first)
1155 push_back(*__first);
1158 template <class _Tp, class _Allocator>
1159 template <class _ForwardIterator>
1160 vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
1161 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1164 typename iterator_traits<_ForwardIterator>::reference>::value,
1165 _ForwardIterator>::type __last)
1167 #if _LIBCPP_DEBUG_LEVEL >= 2
1168 __get_db()->__insert_c(this);
1170 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1174 __construct_at_end(__first, __last, __n);
1178 template <class _Tp, class _Allocator>
1179 template <class _ForwardIterator>
1180 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1181 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1184 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1187 #if _LIBCPP_DEBUG_LEVEL >= 2
1188 __get_db()->__insert_c(this);
1190 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1194 __construct_at_end(__first, __last, __n);
1198 template <class _Tp, class _Allocator>
1199 vector<_Tp, _Allocator>::vector(const vector& __x)
1200 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1202 #if _LIBCPP_DEBUG_LEVEL >= 2
1203 __get_db()->__insert_c(this);
1205 size_type __n = __x.size();
1209 __construct_at_end(__x.__begin_, __x.__end_, __n);
1213 template <class _Tp, class _Allocator>
1214 vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1217 #if _LIBCPP_DEBUG_LEVEL >= 2
1218 __get_db()->__insert_c(this);
1220 size_type __n = __x.size();
1224 __construct_at_end(__x.__begin_, __x.__end_, __n);
1228 #ifndef _LIBCPP_CXX03_LANG
1230 template <class _Tp, class _Allocator>
1231 inline _LIBCPP_INLINE_VISIBILITY
1232 vector<_Tp, _Allocator>::vector(vector&& __x)
1233 #if _LIBCPP_STD_VER > 14
1236 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1238 : __base(_VSTD::move(__x.__alloc()))
1240 #if _LIBCPP_DEBUG_LEVEL >= 2
1241 __get_db()->__insert_c(this);
1242 __get_db()->swap(this, &__x);
1244 this->__begin_ = __x.__begin_;
1245 this->__end_ = __x.__end_;
1246 this->__end_cap() = __x.__end_cap();
1247 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1250 template <class _Tp, class _Allocator>
1251 inline _LIBCPP_INLINE_VISIBILITY
1252 vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1255 #if _LIBCPP_DEBUG_LEVEL >= 2
1256 __get_db()->__insert_c(this);
1258 if (__a == __x.__alloc())
1260 this->__begin_ = __x.__begin_;
1261 this->__end_ = __x.__end_;
1262 this->__end_cap() = __x.__end_cap();
1263 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1264 #if _LIBCPP_DEBUG_LEVEL >= 2
1265 __get_db()->swap(this, &__x);
1270 typedef move_iterator<iterator> _Ip;
1271 assign(_Ip(__x.begin()), _Ip(__x.end()));
1275 template <class _Tp, class _Allocator>
1276 inline _LIBCPP_INLINE_VISIBILITY
1277 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1279 #if _LIBCPP_DEBUG_LEVEL >= 2
1280 __get_db()->__insert_c(this);
1282 if (__il.size() > 0)
1284 allocate(__il.size());
1285 __construct_at_end(__il.begin(), __il.end(), __il.size());
1289 template <class _Tp, class _Allocator>
1290 inline _LIBCPP_INLINE_VISIBILITY
1291 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1294 #if _LIBCPP_DEBUG_LEVEL >= 2
1295 __get_db()->__insert_c(this);
1297 if (__il.size() > 0)
1299 allocate(__il.size());
1300 __construct_at_end(__il.begin(), __il.end(), __il.size());
1304 template <class _Tp, class _Allocator>
1305 inline _LIBCPP_INLINE_VISIBILITY
1306 vector<_Tp, _Allocator>&
1307 vector<_Tp, _Allocator>::operator=(vector&& __x)
1308 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
1310 __move_assign(__x, integral_constant<bool,
1311 __alloc_traits::propagate_on_container_move_assignment::value>());
1315 template <class _Tp, class _Allocator>
1317 vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1318 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
1320 if (__base::__alloc() != __c.__alloc())
1322 typedef move_iterator<iterator> _Ip;
1323 assign(_Ip(__c.begin()), _Ip(__c.end()));
1326 __move_assign(__c, true_type());
1329 template <class _Tp, class _Allocator>
1331 vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1332 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1335 __base::__move_assign_alloc(__c); // this can throw
1336 this->__begin_ = __c.__begin_;
1337 this->__end_ = __c.__end_;
1338 this->__end_cap() = __c.__end_cap();
1339 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1340 #if _LIBCPP_DEBUG_LEVEL >= 2
1341 __get_db()->swap(this, &__c);
1345 #endif // !_LIBCPP_CXX03_LANG
1347 template <class _Tp, class _Allocator>
1348 inline _LIBCPP_INLINE_VISIBILITY
1349 vector<_Tp, _Allocator>&
1350 vector<_Tp, _Allocator>::operator=(const vector& __x)
1354 __base::__copy_assign_alloc(__x);
1355 assign(__x.__begin_, __x.__end_);
1360 template <class _Tp, class _Allocator>
1361 template <class _InputIterator>
1364 __is_input_iterator <_InputIterator>::value &&
1365 !__is_forward_iterator<_InputIterator>::value &&
1368 typename iterator_traits<_InputIterator>::reference>::value,
1371 vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1374 for (; __first != __last; ++__first)
1375 push_back(*__first);
1378 template <class _Tp, class _Allocator>
1379 template <class _ForwardIterator>
1382 __is_forward_iterator<_ForwardIterator>::value &&
1385 typename iterator_traits<_ForwardIterator>::reference>::value,
1388 vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1390 size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
1391 if (__new_size <= capacity())
1393 _ForwardIterator __mid = __last;
1394 bool __growing = false;
1395 if (__new_size > size())
1399 _VSTD::advance(__mid, size());
1401 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
1403 __construct_at_end(__mid, __last, __new_size - size());
1405 this->__destruct_at_end(__m);
1410 allocate(__recommend(__new_size));
1411 __construct_at_end(__first, __last, __new_size);
1413 __invalidate_all_iterators();
1416 template <class _Tp, class _Allocator>
1418 vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1420 if (__n <= capacity())
1422 size_type __s = size();
1423 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
1425 __construct_at_end(__n - __s, __u);
1427 this->__destruct_at_end(this->__begin_ + __n);
1432 allocate(__recommend(static_cast<size_type>(__n)));
1433 __construct_at_end(__n, __u);
1435 __invalidate_all_iterators();
1438 template <class _Tp, class _Allocator>
1439 inline _LIBCPP_INLINE_VISIBILITY
1440 typename vector<_Tp, _Allocator>::iterator
1441 vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
1443 #if _LIBCPP_DEBUG_LEVEL >= 2
1444 return iterator(this, __p);
1446 return iterator(__p);
1450 template <class _Tp, class _Allocator>
1451 inline _LIBCPP_INLINE_VISIBILITY
1452 typename vector<_Tp, _Allocator>::const_iterator
1453 vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
1455 #if _LIBCPP_DEBUG_LEVEL >= 2
1456 return const_iterator(this, __p);
1458 return const_iterator(__p);
1462 template <class _Tp, class _Allocator>
1463 inline _LIBCPP_INLINE_VISIBILITY
1464 typename vector<_Tp, _Allocator>::iterator
1465 vector<_Tp, _Allocator>::begin() _NOEXCEPT
1467 return __make_iter(this->__begin_);
1470 template <class _Tp, class _Allocator>
1471 inline _LIBCPP_INLINE_VISIBILITY
1472 typename vector<_Tp, _Allocator>::const_iterator
1473 vector<_Tp, _Allocator>::begin() const _NOEXCEPT
1475 return __make_iter(this->__begin_);
1478 template <class _Tp, class _Allocator>
1479 inline _LIBCPP_INLINE_VISIBILITY
1480 typename vector<_Tp, _Allocator>::iterator
1481 vector<_Tp, _Allocator>::end() _NOEXCEPT
1483 return __make_iter(this->__end_);
1486 template <class _Tp, class _Allocator>
1487 inline _LIBCPP_INLINE_VISIBILITY
1488 typename vector<_Tp, _Allocator>::const_iterator
1489 vector<_Tp, _Allocator>::end() const _NOEXCEPT
1491 return __make_iter(this->__end_);
1494 template <class _Tp, class _Allocator>
1495 inline _LIBCPP_INLINE_VISIBILITY
1496 typename vector<_Tp, _Allocator>::reference
1497 vector<_Tp, _Allocator>::operator[](size_type __n)
1499 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1500 return this->__begin_[__n];
1503 template <class _Tp, class _Allocator>
1504 inline _LIBCPP_INLINE_VISIBILITY
1505 typename vector<_Tp, _Allocator>::const_reference
1506 vector<_Tp, _Allocator>::operator[](size_type __n) const
1508 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1509 return this->__begin_[__n];
1512 template <class _Tp, class _Allocator>
1513 typename vector<_Tp, _Allocator>::reference
1514 vector<_Tp, _Allocator>::at(size_type __n)
1517 this->__throw_out_of_range();
1518 return this->__begin_[__n];
1521 template <class _Tp, class _Allocator>
1522 typename vector<_Tp, _Allocator>::const_reference
1523 vector<_Tp, _Allocator>::at(size_type __n) const
1526 this->__throw_out_of_range();
1527 return this->__begin_[__n];
1530 template <class _Tp, class _Allocator>
1532 vector<_Tp, _Allocator>::reserve(size_type __n)
1534 if (__n > capacity())
1536 allocator_type& __a = this->__alloc();
1537 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
1538 __swap_out_circular_buffer(__v);
1542 template <class _Tp, class _Allocator>
1544 vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1546 if (capacity() > size())
1548 #ifndef _LIBCPP_NO_EXCEPTIONS
1551 #endif // _LIBCPP_NO_EXCEPTIONS
1552 allocator_type& __a = this->__alloc();
1553 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1554 __swap_out_circular_buffer(__v);
1555 #ifndef _LIBCPP_NO_EXCEPTIONS
1560 #endif // _LIBCPP_NO_EXCEPTIONS
1564 template <class _Tp, class _Allocator>
1565 template <class _Up>
1567 #ifndef _LIBCPP_CXX03_LANG
1568 vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1570 vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1573 allocator_type& __a = this->__alloc();
1574 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1575 // __v.push_back(_VSTD::forward<_Up>(__x));
1576 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
1578 __swap_out_circular_buffer(__v);
1581 template <class _Tp, class _Allocator>
1582 inline _LIBCPP_INLINE_VISIBILITY
1584 vector<_Tp, _Allocator>::push_back(const_reference __x)
1586 if (this->__end_ != this->__end_cap())
1588 __RAII_IncreaseAnnotator __annotator(*this);
1589 __alloc_traits::construct(this->__alloc(),
1590 _VSTD::__to_raw_pointer(this->__end_), __x);
1591 __annotator.__done();
1595 __push_back_slow_path(__x);
1598 #ifndef _LIBCPP_CXX03_LANG
1600 template <class _Tp, class _Allocator>
1601 inline _LIBCPP_INLINE_VISIBILITY
1603 vector<_Tp, _Allocator>::push_back(value_type&& __x)
1605 if (this->__end_ < this->__end_cap())
1607 __RAII_IncreaseAnnotator __annotator(*this);
1608 __alloc_traits::construct(this->__alloc(),
1609 _VSTD::__to_raw_pointer(this->__end_),
1611 __annotator.__done();
1615 __push_back_slow_path(_VSTD::move(__x));
1618 template <class _Tp, class _Allocator>
1619 template <class... _Args>
1621 vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1623 allocator_type& __a = this->__alloc();
1624 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1625 // __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1626 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
1628 __swap_out_circular_buffer(__v);
1631 template <class _Tp, class _Allocator>
1632 template <class... _Args>
1634 #if _LIBCPP_STD_VER > 14
1635 typename vector<_Tp, _Allocator>::reference
1639 vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1641 if (this->__end_ < this->__end_cap())
1643 __RAII_IncreaseAnnotator __annotator(*this);
1644 __alloc_traits::construct(this->__alloc(),
1645 _VSTD::__to_raw_pointer(this->__end_),
1646 _VSTD::forward<_Args>(__args)...);
1647 __annotator.__done();
1651 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
1652 #if _LIBCPP_STD_VER > 14
1653 return this->back();
1657 #endif // !_LIBCPP_CXX03_LANG
1659 template <class _Tp, class _Allocator>
1662 vector<_Tp, _Allocator>::pop_back()
1664 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
1665 this->__destruct_at_end(this->__end_ - 1);
1668 template <class _Tp, class _Allocator>
1669 inline _LIBCPP_INLINE_VISIBILITY
1670 typename vector<_Tp, _Allocator>::iterator
1671 vector<_Tp, _Allocator>::erase(const_iterator __position)
1673 #if _LIBCPP_DEBUG_LEVEL >= 2
1674 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1675 "vector::erase(iterator) called with an iterator not"
1676 " referring to this vector");
1678 _LIBCPP_ASSERT(__position != end(),
1679 "vector::erase(iterator) called with a non-dereferenceable iterator");
1680 difference_type __ps = __position - cbegin();
1681 pointer __p = this->__begin_ + __ps;
1682 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
1683 this->__invalidate_iterators_past(__p-1);
1684 iterator __r = __make_iter(__p);
1688 template <class _Tp, class _Allocator>
1689 typename vector<_Tp, _Allocator>::iterator
1690 vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1692 #if _LIBCPP_DEBUG_LEVEL >= 2
1693 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1694 "vector::erase(iterator, iterator) called with an iterator not"
1695 " referring to this vector");
1696 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
1697 "vector::erase(iterator, iterator) called with an iterator not"
1698 " referring to this vector");
1700 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
1701 pointer __p = this->__begin_ + (__first - begin());
1702 if (__first != __last) {
1703 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1704 this->__invalidate_iterators_past(__p - 1);
1706 iterator __r = __make_iter(__p);
1710 template <class _Tp, class _Allocator>
1712 vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1714 pointer __old_last = this->__end_;
1715 difference_type __n = __old_last - __to;
1716 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1717 __alloc_traits::construct(this->__alloc(),
1718 _VSTD::__to_raw_pointer(this->__end_),
1720 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
1723 template <class _Tp, class _Allocator>
1724 typename vector<_Tp, _Allocator>::iterator
1725 vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1727 #if _LIBCPP_DEBUG_LEVEL >= 2
1728 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1729 "vector::insert(iterator, x) called with an iterator not"
1730 " referring to this vector");
1732 pointer __p = this->__begin_ + (__position - begin());
1733 if (this->__end_ < this->__end_cap())
1735 __RAII_IncreaseAnnotator __annotator(*this);
1736 if (__p == this->__end_)
1738 __alloc_traits::construct(this->__alloc(),
1739 _VSTD::__to_raw_pointer(this->__end_), __x);
1744 __move_range(__p, this->__end_, __p + 1);
1745 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1746 if (__p <= __xr && __xr < this->__end_)
1750 __annotator.__done();
1754 allocator_type& __a = this->__alloc();
1755 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1757 __p = __swap_out_circular_buffer(__v, __p);
1759 return __make_iter(__p);
1762 #ifndef _LIBCPP_CXX03_LANG
1764 template <class _Tp, class _Allocator>
1765 typename vector<_Tp, _Allocator>::iterator
1766 vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1768 #if _LIBCPP_DEBUG_LEVEL >= 2
1769 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1770 "vector::insert(iterator, x) called with an iterator not"
1771 " referring to this vector");
1773 pointer __p = this->__begin_ + (__position - begin());
1774 if (this->__end_ < this->__end_cap())
1776 __RAII_IncreaseAnnotator __annotator(*this);
1777 if (__p == this->__end_)
1779 __alloc_traits::construct(this->__alloc(),
1780 _VSTD::__to_raw_pointer(this->__end_),
1786 __move_range(__p, this->__end_, __p + 1);
1787 *__p = _VSTD::move(__x);
1789 __annotator.__done();
1793 allocator_type& __a = this->__alloc();
1794 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1795 __v.push_back(_VSTD::move(__x));
1796 __p = __swap_out_circular_buffer(__v, __p);
1798 return __make_iter(__p);
1801 template <class _Tp, class _Allocator>
1802 template <class... _Args>
1803 typename vector<_Tp, _Allocator>::iterator
1804 vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1806 #if _LIBCPP_DEBUG_LEVEL >= 2
1807 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1808 "vector::emplace(iterator, x) called with an iterator not"
1809 " referring to this vector");
1811 pointer __p = this->__begin_ + (__position - begin());
1812 if (this->__end_ < this->__end_cap())
1814 __RAII_IncreaseAnnotator __annotator(*this);
1815 if (__p == this->__end_)
1817 __alloc_traits::construct(this->__alloc(),
1818 _VSTD::__to_raw_pointer(this->__end_),
1819 _VSTD::forward<_Args>(__args)...);
1824 __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
1825 __move_range(__p, this->__end_, __p + 1);
1826 *__p = _VSTD::move(__tmp.get());
1828 __annotator.__done();
1832 allocator_type& __a = this->__alloc();
1833 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1834 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1835 __p = __swap_out_circular_buffer(__v, __p);
1837 return __make_iter(__p);
1840 #endif // !_LIBCPP_CXX03_LANG
1842 template <class _Tp, class _Allocator>
1843 typename vector<_Tp, _Allocator>::iterator
1844 vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1846 #if _LIBCPP_DEBUG_LEVEL >= 2
1847 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1848 "vector::insert(iterator, n, x) called with an iterator not"
1849 " referring to this vector");
1851 pointer __p = this->__begin_ + (__position - begin());
1854 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1856 size_type __old_n = __n;
1857 pointer __old_last = this->__end_;
1858 if (__n > static_cast<size_type>(this->__end_ - __p))
1860 size_type __cx = __n - (this->__end_ - __p);
1861 __construct_at_end(__cx, __x);
1866 __RAII_IncreaseAnnotator __annotator(*this, __n);
1867 __move_range(__p, __old_last, __p + __old_n);
1868 __annotator.__done();
1869 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1870 if (__p <= __xr && __xr < this->__end_)
1872 _VSTD::fill_n(__p, __n, *__xr);
1877 allocator_type& __a = this->__alloc();
1878 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1879 __v.__construct_at_end(__n, __x);
1880 __p = __swap_out_circular_buffer(__v, __p);
1883 return __make_iter(__p);
1886 template <class _Tp, class _Allocator>
1887 template <class _InputIterator>
1890 __is_input_iterator <_InputIterator>::value &&
1891 !__is_forward_iterator<_InputIterator>::value &&
1894 typename iterator_traits<_InputIterator>::reference>::value,
1895 typename vector<_Tp, _Allocator>::iterator
1897 vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1899 #if _LIBCPP_DEBUG_LEVEL >= 2
1900 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1901 "vector::insert(iterator, range) called with an iterator not"
1902 " referring to this vector");
1904 difference_type __off = __position - begin();
1905 pointer __p = this->__begin_ + __off;
1906 allocator_type& __a = this->__alloc();
1907 pointer __old_last = this->__end_;
1908 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1910 __RAII_IncreaseAnnotator __annotator(*this);
1911 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
1914 __annotator.__done();
1916 __split_buffer<value_type, allocator_type&> __v(__a);
1917 if (__first != __last)
1919 #ifndef _LIBCPP_NO_EXCEPTIONS
1922 #endif // _LIBCPP_NO_EXCEPTIONS
1923 __v.__construct_at_end(__first, __last);
1924 difference_type __old_size = __old_last - this->__begin_;
1925 difference_type __old_p = __p - this->__begin_;
1926 reserve(__recommend(size() + __v.size()));
1927 __p = this->__begin_ + __old_p;
1928 __old_last = this->__begin_ + __old_size;
1929 #ifndef _LIBCPP_NO_EXCEPTIONS
1933 erase(__make_iter(__old_last), end());
1936 #endif // _LIBCPP_NO_EXCEPTIONS
1938 __p = _VSTD::rotate(__p, __old_last, this->__end_);
1939 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1940 make_move_iterator(__v.end()));
1941 return begin() + __off;
1944 template <class _Tp, class _Allocator>
1945 template <class _ForwardIterator>
1948 __is_forward_iterator<_ForwardIterator>::value &&
1951 typename iterator_traits<_ForwardIterator>::reference>::value,
1952 typename vector<_Tp, _Allocator>::iterator
1954 vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1956 #if _LIBCPP_DEBUG_LEVEL >= 2
1957 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1958 "vector::insert(iterator, range) called with an iterator not"
1959 " referring to this vector");
1961 pointer __p = this->__begin_ + (__position - begin());
1962 difference_type __n = _VSTD::distance(__first, __last);
1965 if (__n <= this->__end_cap() - this->__end_)
1967 size_type __old_n = __n;
1968 pointer __old_last = this->__end_;
1969 _ForwardIterator __m = __last;
1970 difference_type __dx = this->__end_ - __p;
1974 difference_type __diff = this->__end_ - __p;
1975 _VSTD::advance(__m, __diff);
1976 __construct_at_end(__m, __last, __n - __diff);
1981 __RAII_IncreaseAnnotator __annotator(*this, __n);
1982 __move_range(__p, __old_last, __p + __old_n);
1983 __annotator.__done();
1984 _VSTD::copy(__first, __m, __p);
1989 allocator_type& __a = this->__alloc();
1990 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1991 __v.__construct_at_end(__first, __last);
1992 __p = __swap_out_circular_buffer(__v, __p);
1995 return __make_iter(__p);
1998 template <class _Tp, class _Allocator>
2000 vector<_Tp, _Allocator>::resize(size_type __sz)
2002 size_type __cs = size();
2004 this->__append(__sz - __cs);
2005 else if (__cs > __sz)
2006 this->__destruct_at_end(this->__begin_ + __sz);
2009 template <class _Tp, class _Allocator>
2011 vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
2013 size_type __cs = size();
2015 this->__append(__sz - __cs, __x);
2016 else if (__cs > __sz)
2017 this->__destruct_at_end(this->__begin_ + __sz);
2020 template <class _Tp, class _Allocator>
2022 vector<_Tp, _Allocator>::swap(vector& __x)
2023 #if _LIBCPP_STD_VER >= 14
2026 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
2027 __is_nothrow_swappable<allocator_type>::value)
2030 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
2031 this->__alloc() == __x.__alloc(),
2032 "vector::swap: Either propagate_on_container_swap must be true"
2033 " or the allocators must compare equal");
2034 _VSTD::swap(this->__begin_, __x.__begin_);
2035 _VSTD::swap(this->__end_, __x.__end_);
2036 _VSTD::swap(this->__end_cap(), __x.__end_cap());
2037 __swap_allocator(this->__alloc(), __x.__alloc(),
2038 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
2039 #if _LIBCPP_DEBUG_LEVEL >= 2
2040 __get_db()->swap(this, &__x);
2041 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2044 template <class _Tp, class _Allocator>
2046 vector<_Tp, _Allocator>::__invariants() const
2048 if (this->__begin_ == nullptr)
2050 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
2055 if (this->__begin_ > this->__end_)
2057 if (this->__begin_ == this->__end_cap())
2059 if (this->__end_ > this->__end_cap())
2065 #if _LIBCPP_DEBUG_LEVEL >= 2
2067 template <class _Tp, class _Allocator>
2069 vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
2071 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
2074 template <class _Tp, class _Allocator>
2076 vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
2078 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
2081 template <class _Tp, class _Allocator>
2083 vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2085 const_pointer __p = __i->base() + __n;
2086 return this->__begin_ <= __p && __p <= this->__end_;
2089 template <class _Tp, class _Allocator>
2091 vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2093 const_pointer __p = __i->base() + __n;
2094 return this->__begin_ <= __p && __p < this->__end_;
2097 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2099 template <class _Tp, class _Allocator>
2100 inline _LIBCPP_INLINE_VISIBILITY
2102 vector<_Tp, _Allocator>::__invalidate_all_iterators()
2104 #if _LIBCPP_DEBUG_LEVEL >= 2
2105 __get_db()->__invalidate_all(this);
2106 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2110 template <class _Tp, class _Allocator>
2111 inline _LIBCPP_INLINE_VISIBILITY
2113 vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
2114 #if _LIBCPP_DEBUG_LEVEL >= 2
2115 __c_node* __c = __get_db()->__find_c_and_lock(this);
2116 for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
2118 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
2119 if (__i->base() > __new_last) {
2120 (*__p)->__c_ = nullptr;
2121 if (--__c->end_ != __p)
2122 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
2125 __get_db()->unlock();
2133 template <class _Allocator> class vector<bool, _Allocator>;
2135 template <class _Allocator> struct hash<vector<bool, _Allocator> >;
2137 template <class _Allocator>
2138 struct __has_storage_type<vector<bool, _Allocator> >
2140 static const bool value = true;
2143 template <class _Allocator>
2144 class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
2145 : private __vector_base_common<true>
2148 typedef vector __self;
2149 typedef bool value_type;
2150 typedef _Allocator allocator_type;
2151 typedef allocator_traits<allocator_type> __alloc_traits;
2152 typedef typename __alloc_traits::size_type size_type;
2153 typedef typename __alloc_traits::difference_type difference_type;
2154 typedef size_type __storage_type;
2155 typedef __bit_iterator<vector, false> pointer;
2156 typedef __bit_iterator<vector, true> const_pointer;
2157 typedef pointer iterator;
2158 typedef const_pointer const_iterator;
2159 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
2160 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
2163 typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
2164 typedef allocator_traits<__storage_allocator> __storage_traits;
2165 typedef typename __storage_traits::pointer __storage_pointer;
2166 typedef typename __storage_traits::const_pointer __const_storage_pointer;
2168 __storage_pointer __begin_;
2170 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
2172 typedef __bit_reference<vector> reference;
2173 typedef __bit_const_reference<vector> const_reference;
2175 _LIBCPP_INLINE_VISIBILITY
2176 size_type& __cap() _NOEXCEPT
2177 {return __cap_alloc_.first();}
2178 _LIBCPP_INLINE_VISIBILITY
2179 const size_type& __cap() const _NOEXCEPT
2180 {return __cap_alloc_.first();}
2181 _LIBCPP_INLINE_VISIBILITY
2182 __storage_allocator& __alloc() _NOEXCEPT
2183 {return __cap_alloc_.second();}
2184 _LIBCPP_INLINE_VISIBILITY
2185 const __storage_allocator& __alloc() const _NOEXCEPT
2186 {return __cap_alloc_.second();}
2188 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2190 _LIBCPP_INLINE_VISIBILITY
2191 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
2192 {return __n * __bits_per_word;}
2193 _LIBCPP_INLINE_VISIBILITY
2194 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
2195 {return (__n - 1) / __bits_per_word + 1;}
2198 _LIBCPP_INLINE_VISIBILITY
2199 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
2201 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
2202 #if _LIBCPP_STD_VER <= 14
2203 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
2208 explicit vector(size_type __n);
2209 #if _LIBCPP_STD_VER > 11
2210 explicit vector(size_type __n, const allocator_type& __a);
2212 vector(size_type __n, const value_type& __v);
2213 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2214 template <class _InputIterator>
2215 vector(_InputIterator __first, _InputIterator __last,
2216 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2217 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2218 template <class _InputIterator>
2219 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2220 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2221 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2222 template <class _ForwardIterator>
2223 vector(_ForwardIterator __first, _ForwardIterator __last,
2224 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2225 template <class _ForwardIterator>
2226 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2227 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2229 vector(const vector& __v);
2230 vector(const vector& __v, const allocator_type& __a);
2231 vector& operator=(const vector& __v);
2233 #ifndef _LIBCPP_CXX03_LANG
2234 vector(initializer_list<value_type> __il);
2235 vector(initializer_list<value_type> __il, const allocator_type& __a);
2237 _LIBCPP_INLINE_VISIBILITY
2238 vector(vector&& __v)
2239 #if _LIBCPP_STD_VER > 14
2242 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
2244 vector(vector&& __v, const allocator_type& __a);
2245 _LIBCPP_INLINE_VISIBILITY
2246 vector& operator=(vector&& __v)
2247 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
2249 _LIBCPP_INLINE_VISIBILITY
2250 vector& operator=(initializer_list<value_type> __il)
2251 {assign(__il.begin(), __il.end()); return *this;}
2253 #endif // !_LIBCPP_CXX03_LANG
2255 template <class _InputIterator>
2258 __is_input_iterator<_InputIterator>::value &&
2259 !__is_forward_iterator<_InputIterator>::value,
2262 assign(_InputIterator __first, _InputIterator __last);
2263 template <class _ForwardIterator>
2266 __is_forward_iterator<_ForwardIterator>::value,
2269 assign(_ForwardIterator __first, _ForwardIterator __last);
2271 void assign(size_type __n, const value_type& __x);
2273 #ifndef _LIBCPP_CXX03_LANG
2274 _LIBCPP_INLINE_VISIBILITY
2275 void assign(initializer_list<value_type> __il)
2276 {assign(__il.begin(), __il.end());}
2279 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
2280 {return allocator_type(this->__alloc());}
2282 size_type max_size() const _NOEXCEPT;
2283 _LIBCPP_INLINE_VISIBILITY
2284 size_type capacity() const _NOEXCEPT
2285 {return __internal_cap_to_external(__cap());}
2286 _LIBCPP_INLINE_VISIBILITY
2287 size_type size() const _NOEXCEPT
2289 _LIBCPP_INLINE_VISIBILITY
2290 bool empty() const _NOEXCEPT
2291 {return __size_ == 0;}
2292 void reserve(size_type __n);
2293 void shrink_to_fit() _NOEXCEPT;
2295 _LIBCPP_INLINE_VISIBILITY
2296 iterator begin() _NOEXCEPT
2297 {return __make_iter(0);}
2298 _LIBCPP_INLINE_VISIBILITY
2299 const_iterator begin() const _NOEXCEPT
2300 {return __make_iter(0);}
2301 _LIBCPP_INLINE_VISIBILITY
2302 iterator end() _NOEXCEPT
2303 {return __make_iter(__size_);}
2304 _LIBCPP_INLINE_VISIBILITY
2305 const_iterator end() const _NOEXCEPT
2306 {return __make_iter(__size_);}
2308 _LIBCPP_INLINE_VISIBILITY
2309 reverse_iterator rbegin() _NOEXCEPT
2310 {return reverse_iterator(end());}
2311 _LIBCPP_INLINE_VISIBILITY
2312 const_reverse_iterator rbegin() const _NOEXCEPT
2313 {return const_reverse_iterator(end());}
2314 _LIBCPP_INLINE_VISIBILITY
2315 reverse_iterator rend() _NOEXCEPT
2316 {return reverse_iterator(begin());}
2317 _LIBCPP_INLINE_VISIBILITY
2318 const_reverse_iterator rend() const _NOEXCEPT
2319 {return const_reverse_iterator(begin());}
2321 _LIBCPP_INLINE_VISIBILITY
2322 const_iterator cbegin() const _NOEXCEPT
2323 {return __make_iter(0);}
2324 _LIBCPP_INLINE_VISIBILITY
2325 const_iterator cend() const _NOEXCEPT
2326 {return __make_iter(__size_);}
2327 _LIBCPP_INLINE_VISIBILITY
2328 const_reverse_iterator crbegin() const _NOEXCEPT
2330 _LIBCPP_INLINE_VISIBILITY
2331 const_reverse_iterator crend() const _NOEXCEPT
2334 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2335 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2336 reference at(size_type __n);
2337 const_reference at(size_type __n) const;
2339 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2340 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2341 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2342 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2344 void push_back(const value_type& __x);
2345 #if _LIBCPP_STD_VER > 11
2346 template <class... _Args>
2347 #if _LIBCPP_STD_VER > 14
2348 _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args)
2350 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
2353 push_back ( value_type ( _VSTD::forward<_Args>(__args)... ));
2354 #if _LIBCPP_STD_VER > 14
2355 return this->back();
2360 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2362 #if _LIBCPP_STD_VER > 11
2363 template <class... _Args>
2364 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2365 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2368 iterator insert(const_iterator __position, const value_type& __x);
2369 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2370 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2371 template <class _InputIterator>
2374 __is_input_iterator <_InputIterator>::value &&
2375 !__is_forward_iterator<_InputIterator>::value,
2378 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2379 template <class _ForwardIterator>
2382 __is_forward_iterator<_ForwardIterator>::value,
2385 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
2387 #ifndef _LIBCPP_CXX03_LANG
2388 _LIBCPP_INLINE_VISIBILITY
2389 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2390 {return insert(__position, __il.begin(), __il.end());}
2393 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
2394 iterator erase(const_iterator __first, const_iterator __last);
2396 _LIBCPP_INLINE_VISIBILITY
2397 void clear() _NOEXCEPT {__size_ = 0;}
2400 #if _LIBCPP_STD_VER >= 14
2403 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2404 __is_nothrow_swappable<allocator_type>::value);
2406 static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
2408 void resize(size_type __sz, value_type __x = false);
2409 void flip() _NOEXCEPT;
2411 bool __invariants() const;
2414 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
2415 void allocate(size_type __n);
2416 void deallocate() _NOEXCEPT;
2417 _LIBCPP_INLINE_VISIBILITY
2418 static size_type __align_it(size_type __new_size) _NOEXCEPT
2419 {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);};
2420 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2421 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
2422 template <class _ForwardIterator>
2425 __is_forward_iterator<_ForwardIterator>::value,
2428 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2429 void __append(size_type __n, const_reference __x);
2430 _LIBCPP_INLINE_VISIBILITY
2431 reference __make_ref(size_type __pos) _NOEXCEPT
2432 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2433 _LIBCPP_INLINE_VISIBILITY
2434 const_reference __make_ref(size_type __pos) const _NOEXCEPT
2435 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2436 _LIBCPP_INLINE_VISIBILITY
2437 iterator __make_iter(size_type __pos) _NOEXCEPT
2438 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2439 _LIBCPP_INLINE_VISIBILITY
2440 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
2441 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2442 _LIBCPP_INLINE_VISIBILITY
2443 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
2444 {return begin() + (__p - cbegin());}
2446 _LIBCPP_INLINE_VISIBILITY
2447 void __copy_assign_alloc(const vector& __v)
2448 {__copy_assign_alloc(__v, integral_constant<bool,
2449 __storage_traits::propagate_on_container_copy_assignment::value>());}
2450 _LIBCPP_INLINE_VISIBILITY
2451 void __copy_assign_alloc(const vector& __c, true_type)
2453 if (__alloc() != __c.__alloc())
2455 __alloc() = __c.__alloc();
2458 _LIBCPP_INLINE_VISIBILITY
2459 void __copy_assign_alloc(const vector&, false_type)
2462 void __move_assign(vector& __c, false_type);
2463 void __move_assign(vector& __c, true_type)
2464 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2465 _LIBCPP_INLINE_VISIBILITY
2466 void __move_assign_alloc(vector& __c)
2468 !__storage_traits::propagate_on_container_move_assignment::value ||
2469 is_nothrow_move_assignable<allocator_type>::value)
2470 {__move_assign_alloc(__c, integral_constant<bool,
2471 __storage_traits::propagate_on_container_move_assignment::value>());}
2472 _LIBCPP_INLINE_VISIBILITY
2473 void __move_assign_alloc(vector& __c, true_type)
2474 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2476 __alloc() = _VSTD::move(__c.__alloc());
2479 _LIBCPP_INLINE_VISIBILITY
2480 void __move_assign_alloc(vector&, false_type)
2484 size_t __hash_code() const _NOEXCEPT;
2486 friend class __bit_reference<vector>;
2487 friend class __bit_const_reference<vector>;
2488 friend class __bit_iterator<vector, false>;
2489 friend class __bit_iterator<vector, true>;
2490 friend struct __bit_array<vector>;
2491 friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
2494 template <class _Allocator>
2495 inline _LIBCPP_INLINE_VISIBILITY
2497 vector<bool, _Allocator>::__invalidate_all_iterators()
2501 // Allocate space for __n objects
2502 // throws length_error if __n > max_size()
2503 // throws (probably bad_alloc) if memory run out
2504 // Precondition: __begin_ == __end_ == __cap() == 0
2505 // Precondition: __n > 0
2506 // Postcondition: capacity() == __n
2507 // Postcondition: size() == 0
2508 template <class _Allocator>
2510 vector<bool, _Allocator>::allocate(size_type __n)
2512 if (__n > max_size())
2513 this->__throw_length_error();
2514 __n = __external_cap_to_internal(__n);
2515 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2517 this->__cap() = __n;
2520 template <class _Allocator>
2522 vector<bool, _Allocator>::deallocate() _NOEXCEPT
2524 if (this->__begin_ != nullptr)
2526 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2527 __invalidate_all_iterators();
2528 this->__begin_ = nullptr;
2529 this->__size_ = this->__cap() = 0;
2533 template <class _Allocator>
2534 typename vector<bool, _Allocator>::size_type
2535 vector<bool, _Allocator>::max_size() const _NOEXCEPT
2537 size_type __amax = __storage_traits::max_size(__alloc());
2538 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2539 if (__nmax / __bits_per_word <= __amax)
2541 return __internal_cap_to_external(__amax);
2544 // Precondition: __new_size > capacity()
2545 template <class _Allocator>
2546 inline _LIBCPP_INLINE_VISIBILITY
2547 typename vector<bool, _Allocator>::size_type
2548 vector<bool, _Allocator>::__recommend(size_type __new_size) const
2550 const size_type __ms = max_size();
2551 if (__new_size > __ms)
2552 this->__throw_length_error();
2553 const size_type __cap = capacity();
2554 if (__cap >= __ms / 2)
2556 return _VSTD::max(2*__cap, __align_it(__new_size));
2559 // Default constructs __n objects starting at __end_
2560 // Precondition: __n > 0
2561 // Precondition: size() + __n <= capacity()
2562 // Postcondition: size() == size() + __n
2563 template <class _Allocator>
2564 inline _LIBCPP_INLINE_VISIBILITY
2566 vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2568 size_type __old_size = this->__size_;
2569 this->__size_ += __n;
2570 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
2573 template <class _Allocator>
2574 template <class _ForwardIterator>
2577 __is_forward_iterator<_ForwardIterator>::value,
2580 vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2582 size_type __old_size = this->__size_;
2583 this->__size_ += _VSTD::distance(__first, __last);
2584 _VSTD::copy(__first, __last, __make_iter(__old_size));
2587 template <class _Allocator>
2588 inline _LIBCPP_INLINE_VISIBILITY
2589 vector<bool, _Allocator>::vector()
2590 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2591 : __begin_(nullptr),
2597 template <class _Allocator>
2598 inline _LIBCPP_INLINE_VISIBILITY
2599 vector<bool, _Allocator>::vector(const allocator_type& __a)
2600 #if _LIBCPP_STD_VER <= 14
2601 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
2605 : __begin_(nullptr),
2607 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2611 template <class _Allocator>
2612 vector<bool, _Allocator>::vector(size_type __n)
2613 : __begin_(nullptr),
2620 __construct_at_end(__n, false);
2624 #if _LIBCPP_STD_VER > 11
2625 template <class _Allocator>
2626 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2627 : __begin_(nullptr),
2629 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2634 __construct_at_end(__n, false);
2639 template <class _Allocator>
2640 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2641 : __begin_(nullptr),
2648 __construct_at_end(__n, __x);
2652 template <class _Allocator>
2653 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2654 : __begin_(nullptr),
2656 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2661 __construct_at_end(__n, __x);
2665 template <class _Allocator>
2666 template <class _InputIterator>
2667 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2668 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2669 !__is_forward_iterator<_InputIterator>::value>::type*)
2670 : __begin_(nullptr),
2674 #ifndef _LIBCPP_NO_EXCEPTIONS
2677 #endif // _LIBCPP_NO_EXCEPTIONS
2678 for (; __first != __last; ++__first)
2679 push_back(*__first);
2680 #ifndef _LIBCPP_NO_EXCEPTIONS
2684 if (__begin_ != nullptr)
2685 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2686 __invalidate_all_iterators();
2689 #endif // _LIBCPP_NO_EXCEPTIONS
2692 template <class _Allocator>
2693 template <class _InputIterator>
2694 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2695 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2696 !__is_forward_iterator<_InputIterator>::value>::type*)
2697 : __begin_(nullptr),
2699 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2701 #ifndef _LIBCPP_NO_EXCEPTIONS
2704 #endif // _LIBCPP_NO_EXCEPTIONS
2705 for (; __first != __last; ++__first)
2706 push_back(*__first);
2707 #ifndef _LIBCPP_NO_EXCEPTIONS
2711 if (__begin_ != nullptr)
2712 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2713 __invalidate_all_iterators();
2716 #endif // _LIBCPP_NO_EXCEPTIONS
2719 template <class _Allocator>
2720 template <class _ForwardIterator>
2721 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2722 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2723 : __begin_(nullptr),
2727 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2731 __construct_at_end(__first, __last);
2735 template <class _Allocator>
2736 template <class _ForwardIterator>
2737 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2738 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2739 : __begin_(nullptr),
2741 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2743 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2747 __construct_at_end(__first, __last);
2751 #ifndef _LIBCPP_CXX03_LANG
2753 template <class _Allocator>
2754 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2755 : __begin_(nullptr),
2759 size_type __n = static_cast<size_type>(__il.size());
2763 __construct_at_end(__il.begin(), __il.end());
2767 template <class _Allocator>
2768 vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2769 : __begin_(nullptr),
2771 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2773 size_type __n = static_cast<size_type>(__il.size());
2777 __construct_at_end(__il.begin(), __il.end());
2781 #endif // _LIBCPP_CXX03_LANG
2783 template <class _Allocator>
2784 vector<bool, _Allocator>::~vector()
2786 if (__begin_ != nullptr)
2787 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2788 __invalidate_all_iterators();
2791 template <class _Allocator>
2792 vector<bool, _Allocator>::vector(const vector& __v)
2793 : __begin_(nullptr),
2795 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2799 allocate(__v.size());
2800 __construct_at_end(__v.begin(), __v.end());
2804 template <class _Allocator>
2805 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2806 : __begin_(nullptr),
2808 __cap_alloc_(0, __a)
2812 allocate(__v.size());
2813 __construct_at_end(__v.begin(), __v.end());
2817 template <class _Allocator>
2818 vector<bool, _Allocator>&
2819 vector<bool, _Allocator>::operator=(const vector& __v)
2823 __copy_assign_alloc(__v);
2826 if (__v.__size_ > capacity())
2829 allocate(__v.__size_);
2831 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2833 __size_ = __v.__size_;
2838 #ifndef _LIBCPP_CXX03_LANG
2840 template <class _Allocator>
2841 inline _LIBCPP_INLINE_VISIBILITY
2842 vector<bool, _Allocator>::vector(vector&& __v)
2843 #if _LIBCPP_STD_VER > 14
2846 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2848 : __begin_(__v.__begin_),
2849 __size_(__v.__size_),
2850 __cap_alloc_(__v.__cap_alloc_)
2852 __v.__begin_ = nullptr;
2857 template <class _Allocator>
2858 vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2859 : __begin_(nullptr),
2861 __cap_alloc_(0, __a)
2863 if (__a == allocator_type(__v.__alloc()))
2865 this->__begin_ = __v.__begin_;
2866 this->__size_ = __v.__size_;
2867 this->__cap() = __v.__cap();
2868 __v.__begin_ = nullptr;
2869 __v.__cap() = __v.__size_ = 0;
2871 else if (__v.size() > 0)
2873 allocate(__v.size());
2874 __construct_at_end(__v.begin(), __v.end());
2878 template <class _Allocator>
2879 inline _LIBCPP_INLINE_VISIBILITY
2880 vector<bool, _Allocator>&
2881 vector<bool, _Allocator>::operator=(vector&& __v)
2882 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
2884 __move_assign(__v, integral_constant<bool,
2885 __storage_traits::propagate_on_container_move_assignment::value>());
2889 template <class _Allocator>
2891 vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2893 if (__alloc() != __c.__alloc())
2894 assign(__c.begin(), __c.end());
2896 __move_assign(__c, true_type());
2899 template <class _Allocator>
2901 vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2902 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2905 __move_assign_alloc(__c);
2906 this->__begin_ = __c.__begin_;
2907 this->__size_ = __c.__size_;
2908 this->__cap() = __c.__cap();
2909 __c.__begin_ = nullptr;
2910 __c.__cap() = __c.__size_ = 0;
2913 #endif // !_LIBCPP_CXX03_LANG
2915 template <class _Allocator>
2917 vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2922 size_type __c = capacity();
2927 vector __v(__alloc());
2928 __v.reserve(__recommend(__n));
2932 _VSTD::fill_n(begin(), __n, __x);
2934 __invalidate_all_iterators();
2937 template <class _Allocator>
2938 template <class _InputIterator>
2941 __is_input_iterator<_InputIterator>::value &&
2942 !__is_forward_iterator<_InputIterator>::value,
2945 vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2948 for (; __first != __last; ++__first)
2949 push_back(*__first);
2952 template <class _Allocator>
2953 template <class _ForwardIterator>
2956 __is_forward_iterator<_ForwardIterator>::value,
2959 vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2962 difference_type __ns = _VSTD::distance(__first, __last);
2963 _LIBCPP_ASSERT(__ns >= 0, "invalid range specified");
2964 const size_t __n = static_cast<size_type>(__ns);
2967 if (__n > capacity())
2972 __construct_at_end(__first, __last);
2976 template <class _Allocator>
2978 vector<bool, _Allocator>::reserve(size_type __n)
2980 if (__n > capacity())
2982 vector __v(this->__alloc());
2984 __v.__construct_at_end(this->begin(), this->end());
2986 __invalidate_all_iterators();
2990 template <class _Allocator>
2992 vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
2994 if (__external_cap_to_internal(size()) > __cap())
2996 #ifndef _LIBCPP_NO_EXCEPTIONS
2999 #endif // _LIBCPP_NO_EXCEPTIONS
3000 vector(*this, allocator_type(__alloc())).swap(*this);
3001 #ifndef _LIBCPP_NO_EXCEPTIONS
3006 #endif // _LIBCPP_NO_EXCEPTIONS
3010 template <class _Allocator>
3011 typename vector<bool, _Allocator>::reference
3012 vector<bool, _Allocator>::at(size_type __n)
3015 this->__throw_out_of_range();
3016 return (*this)[__n];
3019 template <class _Allocator>
3020 typename vector<bool, _Allocator>::const_reference
3021 vector<bool, _Allocator>::at(size_type __n) const
3024 this->__throw_out_of_range();
3025 return (*this)[__n];
3028 template <class _Allocator>
3030 vector<bool, _Allocator>::push_back(const value_type& __x)
3032 if (this->__size_ == this->capacity())
3033 reserve(__recommend(this->__size_ + 1));
3038 template <class _Allocator>
3039 typename vector<bool, _Allocator>::iterator
3040 vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
3043 if (size() < capacity())
3045 const_iterator __old_end = end();
3047 _VSTD::copy_backward(__position, __old_end, end());
3048 __r = __const_iterator_cast(__position);
3052 vector __v(__alloc());
3053 __v.reserve(__recommend(__size_ + 1));
3054 __v.__size_ = __size_ + 1;
3055 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3056 _VSTD::copy_backward(__position, cend(), __v.end());
3063 template <class _Allocator>
3064 typename vector<bool, _Allocator>::iterator
3065 vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
3068 size_type __c = capacity();
3069 if (__n <= __c && size() <= __c - __n)
3071 const_iterator __old_end = end();
3073 _VSTD::copy_backward(__position, __old_end, end());
3074 __r = __const_iterator_cast(__position);
3078 vector __v(__alloc());
3079 __v.reserve(__recommend(__size_ + __n));
3080 __v.__size_ = __size_ + __n;
3081 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3082 _VSTD::copy_backward(__position, cend(), __v.end());
3085 _VSTD::fill_n(__r, __n, __x);
3089 template <class _Allocator>
3090 template <class _InputIterator>
3093 __is_input_iterator <_InputIterator>::value &&
3094 !__is_forward_iterator<_InputIterator>::value,
3095 typename vector<bool, _Allocator>::iterator
3097 vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
3099 difference_type __off = __position - begin();
3100 iterator __p = __const_iterator_cast(__position);
3101 iterator __old_end = end();
3102 for (; size() != capacity() && __first != __last; ++__first)
3107 vector __v(__alloc());
3108 if (__first != __last)
3110 #ifndef _LIBCPP_NO_EXCEPTIONS
3113 #endif // _LIBCPP_NO_EXCEPTIONS
3114 __v.assign(__first, __last);
3115 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
3116 difference_type __old_p = __p - begin();
3117 reserve(__recommend(size() + __v.size()));
3118 __p = begin() + __old_p;
3119 __old_end = begin() + __old_size;
3120 #ifndef _LIBCPP_NO_EXCEPTIONS
3124 erase(__old_end, end());
3127 #endif // _LIBCPP_NO_EXCEPTIONS
3129 __p = _VSTD::rotate(__p, __old_end, end());
3130 insert(__p, __v.begin(), __v.end());
3131 return begin() + __off;
3134 template <class _Allocator>
3135 template <class _ForwardIterator>
3138 __is_forward_iterator<_ForwardIterator>::value,
3139 typename vector<bool, _Allocator>::iterator
3141 vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
3143 const difference_type __n_signed = _VSTD::distance(__first, __last);
3144 _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified");
3145 const size_type __n = static_cast<size_type>(__n_signed);
3147 size_type __c = capacity();
3148 if (__n <= __c && size() <= __c - __n)
3150 const_iterator __old_end = end();
3152 _VSTD::copy_backward(__position, __old_end, end());
3153 __r = __const_iterator_cast(__position);
3157 vector __v(__alloc());
3158 __v.reserve(__recommend(__size_ + __n));
3159 __v.__size_ = __size_ + __n;
3160 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3161 _VSTD::copy_backward(__position, cend(), __v.end());
3164 _VSTD::copy(__first, __last, __r);
3168 template <class _Allocator>
3169 inline _LIBCPP_INLINE_VISIBILITY
3170 typename vector<bool, _Allocator>::iterator
3171 vector<bool, _Allocator>::erase(const_iterator __position)
3173 iterator __r = __const_iterator_cast(__position);
3174 _VSTD::copy(__position + 1, this->cend(), __r);
3179 template <class _Allocator>
3180 typename vector<bool, _Allocator>::iterator
3181 vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3183 iterator __r = __const_iterator_cast(__first);
3184 difference_type __d = __last - __first;
3185 _VSTD::copy(__last, this->cend(), __r);
3190 template <class _Allocator>
3192 vector<bool, _Allocator>::swap(vector& __x)
3193 #if _LIBCPP_STD_VER >= 14
3196 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3197 __is_nothrow_swappable<allocator_type>::value)
3200 _VSTD::swap(this->__begin_, __x.__begin_);
3201 _VSTD::swap(this->__size_, __x.__size_);
3202 _VSTD::swap(this->__cap(), __x.__cap());
3203 __swap_allocator(this->__alloc(), __x.__alloc(),
3204 integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
3207 template <class _Allocator>
3209 vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3211 size_type __cs = size();
3215 size_type __c = capacity();
3216 size_type __n = __sz - __cs;
3217 if (__n <= __c && __cs <= __c - __n)
3224 vector __v(__alloc());
3225 __v.reserve(__recommend(__size_ + __n));
3226 __v.__size_ = __size_ + __n;
3227 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
3230 _VSTD::fill_n(__r, __n, __x);
3236 template <class _Allocator>
3238 vector<bool, _Allocator>::flip() _NOEXCEPT
3240 // do middle whole words
3241 size_type __n = __size_;
3242 __storage_pointer __p = __begin_;
3243 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3245 // do last partial word
3248 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3249 __storage_type __b = *__p & __m;
3255 template <class _Allocator>
3257 vector<bool, _Allocator>::__invariants() const
3259 if (this->__begin_ == nullptr)
3261 if (this->__size_ != 0 || this->__cap() != 0)
3266 if (this->__cap() == 0)
3268 if (this->__size_ > this->capacity())
3274 template <class _Allocator>
3276 vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
3279 // do middle whole words
3280 size_type __n = __size_;
3281 __storage_pointer __p = __begin_;
3282 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3284 // do last partial word
3287 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3293 template <class _Allocator>
3294 struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
3295 : public unary_function<vector<bool, _Allocator>, size_t>
3297 _LIBCPP_INLINE_VISIBILITY
3298 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
3299 {return __vec.__hash_code();}
3302 template <class _Tp, class _Allocator>
3303 inline _LIBCPP_INLINE_VISIBILITY
3305 operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3307 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
3308 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3311 template <class _Tp, class _Allocator>
3312 inline _LIBCPP_INLINE_VISIBILITY
3314 operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3316 return !(__x == __y);
3319 template <class _Tp, class _Allocator>
3320 inline _LIBCPP_INLINE_VISIBILITY
3322 operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3324 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
3327 template <class _Tp, class _Allocator>
3328 inline _LIBCPP_INLINE_VISIBILITY
3330 operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3335 template <class _Tp, class _Allocator>
3336 inline _LIBCPP_INLINE_VISIBILITY
3338 operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3340 return !(__x < __y);
3343 template <class _Tp, class _Allocator>
3344 inline _LIBCPP_INLINE_VISIBILITY
3346 operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3348 return !(__y < __x);
3351 template <class _Tp, class _Allocator>
3352 inline _LIBCPP_INLINE_VISIBILITY
3354 swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
3355 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
3360 _LIBCPP_END_NAMESPACE_STD
3364 #endif // _LIBCPP_VECTOR