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 is_nothrow_move_assignable<allocator_type>::value);
56 vector& operator=(initializer_list<value_type> il);
57 template <class InputIterator>
58 void assign(InputIterator first, InputIterator last);
59 void assign(size_type n, const value_type& u);
60 void assign(initializer_list<value_type> il);
62 allocator_type get_allocator() const noexcept;
64 iterator begin() noexcept;
65 const_iterator begin() const noexcept;
66 iterator end() noexcept;
67 const_iterator end() const noexcept;
69 reverse_iterator rbegin() noexcept;
70 const_reverse_iterator rbegin() const noexcept;
71 reverse_iterator rend() noexcept;
72 const_reverse_iterator rend() const noexcept;
74 const_iterator cbegin() const noexcept;
75 const_iterator cend() const noexcept;
76 const_reverse_iterator crbegin() const noexcept;
77 const_reverse_iterator crend() const noexcept;
79 size_type size() const noexcept;
80 size_type max_size() const noexcept;
81 size_type capacity() const noexcept;
82 bool empty() const noexcept;
83 void reserve(size_type n);
84 void shrink_to_fit() noexcept;
86 reference operator[](size_type n);
87 const_reference operator[](size_type n) const;
88 reference at(size_type n);
89 const_reference at(size_type n) const;
92 const_reference front() const;
94 const_reference back() const;
96 value_type* data() noexcept;
97 const value_type* data() const noexcept;
99 void push_back(const value_type& x);
100 void push_back(value_type&& x);
101 template <class... Args>
102 void emplace_back(Args&&... args);
105 template <class... Args> iterator emplace(const_iterator position, Args&&... args);
106 iterator insert(const_iterator position, const value_type& x);
107 iterator insert(const_iterator position, value_type&& x);
108 iterator insert(const_iterator position, size_type n, const value_type& x);
109 template <class InputIterator>
110 iterator insert(const_iterator position, InputIterator first, InputIterator last);
111 iterator insert(const_iterator position, initializer_list<value_type> il);
113 iterator erase(const_iterator position);
114 iterator erase(const_iterator first, const_iterator last);
116 void clear() noexcept;
118 void resize(size_type sz);
119 void resize(size_type sz, const value_type& c);
122 noexcept(!allocator_type::propagate_on_container_swap::value ||
123 __is_nothrow_swappable<allocator_type>::value);
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 is_nothrow_move_assignable<allocator_type>::value);
180 vector& operator=(initializer_list<value_type> il);
181 template <class InputIterator>
182 void assign(InputIterator first, InputIterator last);
183 void assign(size_type n, const value_type& u);
184 void assign(initializer_list<value_type> il);
186 allocator_type get_allocator() const noexcept;
188 iterator begin() noexcept;
189 const_iterator begin() const noexcept;
190 iterator end() noexcept;
191 const_iterator end() const noexcept;
193 reverse_iterator rbegin() noexcept;
194 const_reverse_iterator rbegin() const noexcept;
195 reverse_iterator rend() noexcept;
196 const_reverse_iterator rend() const noexcept;
198 const_iterator cbegin() const noexcept;
199 const_iterator cend() const noexcept;
200 const_reverse_iterator crbegin() const noexcept;
201 const_reverse_iterator crend() const noexcept;
203 size_type size() const noexcept;
204 size_type max_size() const noexcept;
205 size_type capacity() const noexcept;
206 bool empty() const noexcept;
207 void reserve(size_type n);
208 void shrink_to_fit() noexcept;
210 reference operator[](size_type n);
211 const_reference operator[](size_type n) const;
212 reference at(size_type n);
213 const_reference at(size_type n) const;
216 const_reference front() const;
218 const_reference back() const;
220 void push_back(const value_type& x);
221 template <class... Args> void emplace_back(Args&&... args); // C++14
224 template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
225 iterator insert(const_iterator position, const value_type& x);
226 iterator insert(const_iterator position, size_type n, const value_type& x);
227 template <class InputIterator>
228 iterator insert(const_iterator position, InputIterator first, InputIterator last);
229 iterator insert(const_iterator position, initializer_list<value_type> il);
231 iterator erase(const_iterator position);
232 iterator erase(const_iterator first, const_iterator last);
234 void clear() noexcept;
236 void resize(size_type sz);
237 void resize(size_type sz, value_type x);
240 noexcept(!allocator_type::propagate_on_container_swap::value ||
241 __is_nothrow_swappable<allocator_type>::value);
242 void flip() noexcept;
244 bool __invariants() const;
247 template <class Allocator> struct hash<std::vector<bool, Allocator>>;
249 template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
250 template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
251 template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
252 template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
253 template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
254 template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
256 template <class T, class Allocator>
257 void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
258 noexcept(noexcept(x.swap(y)));
265 #include <__bit_reference>
266 #include <type_traits>
269 #include <initializer_list>
274 #include <__split_buffer>
275 #include <__functional_base>
277 #include <__undef_min_max>
281 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
282 #pragma GCC system_header
285 _LIBCPP_BEGIN_NAMESPACE_STD
288 class __vector_base_common
291 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
292 void __throw_length_error() const;
293 void __throw_out_of_range() const;
298 __vector_base_common<__b>::__throw_length_error() const
300 #ifndef _LIBCPP_NO_EXCEPTIONS
301 throw length_error("vector");
303 assert(!"vector length_error");
309 __vector_base_common<__b>::__throw_out_of_range() const
311 #ifndef _LIBCPP_NO_EXCEPTIONS
312 throw out_of_range("vector");
314 assert(!"vector out_of_range");
319 #pragma warning( push )
320 #pragma warning( disable: 4231 )
321 #endif // _LIBCPP_MSVC
322 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common<true>)
324 #pragma warning( pop )
325 #endif // _LIBCPP_MSVC
327 template <class _Tp, class _Allocator>
329 : protected __vector_base_common<true>
332 typedef _Tp value_type;
333 typedef _Allocator allocator_type;
334 typedef allocator_traits<allocator_type> __alloc_traits;
335 typedef value_type& reference;
336 typedef const value_type& const_reference;
337 typedef typename __alloc_traits::size_type size_type;
338 typedef typename __alloc_traits::difference_type difference_type;
339 typedef typename __alloc_traits::pointer pointer;
340 typedef typename __alloc_traits::const_pointer const_pointer;
341 typedef pointer iterator;
342 typedef const_pointer const_iterator;
346 __compressed_pair<pointer, allocator_type> __end_cap_;
348 _LIBCPP_INLINE_VISIBILITY
349 allocator_type& __alloc() _NOEXCEPT
350 {return __end_cap_.second();}
351 _LIBCPP_INLINE_VISIBILITY
352 const allocator_type& __alloc() const _NOEXCEPT
353 {return __end_cap_.second();}
354 _LIBCPP_INLINE_VISIBILITY
355 pointer& __end_cap() _NOEXCEPT
356 {return __end_cap_.first();}
357 _LIBCPP_INLINE_VISIBILITY
358 const pointer& __end_cap() const _NOEXCEPT
359 {return __end_cap_.first();}
361 _LIBCPP_INLINE_VISIBILITY
363 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
364 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
367 _LIBCPP_INLINE_VISIBILITY
368 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
369 _LIBCPP_INLINE_VISIBILITY
370 size_type capacity() const _NOEXCEPT
371 {return static_cast<size_type>(__end_cap() - __begin_);}
373 _LIBCPP_INLINE_VISIBILITY
374 void __destruct_at_end(pointer __new_last) _NOEXCEPT;
376 _LIBCPP_INLINE_VISIBILITY
377 void __copy_assign_alloc(const __vector_base& __c)
378 {__copy_assign_alloc(__c, integral_constant<bool,
379 __alloc_traits::propagate_on_container_copy_assignment::value>());}
381 _LIBCPP_INLINE_VISIBILITY
382 void __move_assign_alloc(__vector_base& __c)
384 !__alloc_traits::propagate_on_container_move_assignment::value ||
385 is_nothrow_move_assignable<allocator_type>::value)
386 {__move_assign_alloc(__c, integral_constant<bool,
387 __alloc_traits::propagate_on_container_move_assignment::value>());}
389 _LIBCPP_INLINE_VISIBILITY
390 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
392 !__alloc_traits::propagate_on_container_swap::value ||
393 __is_nothrow_swappable<allocator_type>::value)
394 {__swap_alloc(__x, __y, integral_constant<bool,
395 __alloc_traits::propagate_on_container_swap::value>());}
397 _LIBCPP_INLINE_VISIBILITY
398 void __copy_assign_alloc(const __vector_base& __c, true_type)
400 if (__alloc() != __c.__alloc())
403 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
404 __begin_ = __end_ = __end_cap() = nullptr;
406 __alloc() = __c.__alloc();
409 _LIBCPP_INLINE_VISIBILITY
410 void __copy_assign_alloc(const __vector_base&, false_type)
413 _LIBCPP_INLINE_VISIBILITY
414 void __move_assign_alloc(__vector_base& __c, true_type)
415 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
417 __alloc() = _VSTD::move(__c.__alloc());
420 _LIBCPP_INLINE_VISIBILITY
421 void __move_assign_alloc(__vector_base&, false_type)
425 _LIBCPP_INLINE_VISIBILITY
426 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
427 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
432 _LIBCPP_INLINE_VISIBILITY
433 static void __swap_alloc(allocator_type&, allocator_type&, false_type)
438 template <class _Tp, class _Allocator>
439 inline _LIBCPP_INLINE_VISIBILITY
441 __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
443 while (__new_last != __end_)
444 __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
447 template <class _Tp, class _Allocator>
448 inline _LIBCPP_INLINE_VISIBILITY
449 __vector_base<_Tp, _Allocator>::__vector_base()
450 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
457 template <class _Tp, class _Allocator>
458 inline _LIBCPP_INLINE_VISIBILITY
459 __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
462 __end_cap_(nullptr, __a)
466 template <class _Tp, class _Allocator>
467 __vector_base<_Tp, _Allocator>::~__vector_base()
469 if (__begin_ != nullptr)
472 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
476 template <class _Tp, class _Allocator = allocator<_Tp> >
477 class _LIBCPP_TYPE_VIS_ONLY vector
478 : private __vector_base<_Tp, _Allocator>
481 typedef __vector_base<_Tp, _Allocator> __base;
482 typedef allocator<_Tp> __default_allocator_type;
484 typedef vector __self;
485 typedef _Tp value_type;
486 typedef _Allocator allocator_type;
487 typedef typename __base::__alloc_traits __alloc_traits;
488 typedef typename __base::reference reference;
489 typedef typename __base::const_reference const_reference;
490 typedef typename __base::size_type size_type;
491 typedef typename __base::difference_type difference_type;
492 typedef typename __base::pointer pointer;
493 typedef typename __base::const_pointer const_pointer;
494 typedef __wrap_iter<pointer> iterator;
495 typedef __wrap_iter<const_pointer> const_iterator;
496 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
497 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
499 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
500 "Allocator::value_type must be same type as value_type");
502 _LIBCPP_INLINE_VISIBILITY
504 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
506 #if _LIBCPP_DEBUG_LEVEL >= 2
507 __get_db()->__insert_c(this);
510 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
513 #if _LIBCPP_DEBUG_LEVEL >= 2
514 __get_db()->__insert_c(this);
517 explicit vector(size_type __n);
518 #if _LIBCPP_STD_VER > 11
519 explicit vector(size_type __n, const allocator_type& __a);
521 vector(size_type __n, const_reference __x);
522 vector(size_type __n, const_reference __x, const allocator_type& __a);
523 template <class _InputIterator>
524 vector(_InputIterator __first,
525 typename enable_if<__is_input_iterator <_InputIterator>::value &&
526 !__is_forward_iterator<_InputIterator>::value &&
529 typename iterator_traits<_InputIterator>::reference>::value,
530 _InputIterator>::type __last);
531 template <class _InputIterator>
532 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
533 typename enable_if<__is_input_iterator <_InputIterator>::value &&
534 !__is_forward_iterator<_InputIterator>::value &&
537 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
538 template <class _ForwardIterator>
539 vector(_ForwardIterator __first,
540 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
543 typename iterator_traits<_ForwardIterator>::reference>::value,
544 _ForwardIterator>::type __last);
545 template <class _ForwardIterator>
546 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
547 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
550 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
551 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
552 _LIBCPP_INLINE_VISIBILITY
553 vector(initializer_list<value_type> __il);
554 _LIBCPP_INLINE_VISIBILITY
555 vector(initializer_list<value_type> __il, const allocator_type& __a);
556 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
557 #if _LIBCPP_DEBUG_LEVEL >= 2
558 _LIBCPP_INLINE_VISIBILITY
561 __get_db()->__erase_c(this);
565 vector(const vector& __x);
566 vector(const vector& __x, const allocator_type& __a);
567 _LIBCPP_INLINE_VISIBILITY
568 vector& operator=(const vector& __x);
569 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
570 _LIBCPP_INLINE_VISIBILITY
572 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
573 _LIBCPP_INLINE_VISIBILITY
574 vector(vector&& __x, const allocator_type& __a);
575 _LIBCPP_INLINE_VISIBILITY
576 vector& operator=(vector&& __x)
578 __alloc_traits::propagate_on_container_move_assignment::value &&
579 is_nothrow_move_assignable<allocator_type>::value);
580 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
581 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
582 _LIBCPP_INLINE_VISIBILITY
583 vector& operator=(initializer_list<value_type> __il)
584 {assign(__il.begin(), __il.end()); return *this;}
585 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
587 template <class _InputIterator>
590 __is_input_iterator <_InputIterator>::value &&
591 !__is_forward_iterator<_InputIterator>::value &&
594 typename iterator_traits<_InputIterator>::reference>::value,
597 assign(_InputIterator __first, _InputIterator __last);
598 template <class _ForwardIterator>
601 __is_forward_iterator<_ForwardIterator>::value &&
604 typename iterator_traits<_ForwardIterator>::reference>::value,
607 assign(_ForwardIterator __first, _ForwardIterator __last);
609 void assign(size_type __n, const_reference __u);
610 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
611 _LIBCPP_INLINE_VISIBILITY
612 void assign(initializer_list<value_type> __il)
613 {assign(__il.begin(), __il.end());}
614 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
616 _LIBCPP_INLINE_VISIBILITY
617 allocator_type get_allocator() const _NOEXCEPT
618 {return this->__alloc();}
620 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
621 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
622 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
623 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
625 _LIBCPP_INLINE_VISIBILITY
626 reverse_iterator rbegin() _NOEXCEPT
627 {return reverse_iterator(end());}
628 _LIBCPP_INLINE_VISIBILITY
629 const_reverse_iterator rbegin() const _NOEXCEPT
630 {return const_reverse_iterator(end());}
631 _LIBCPP_INLINE_VISIBILITY
632 reverse_iterator rend() _NOEXCEPT
633 {return reverse_iterator(begin());}
634 _LIBCPP_INLINE_VISIBILITY
635 const_reverse_iterator rend() const _NOEXCEPT
636 {return const_reverse_iterator(begin());}
638 _LIBCPP_INLINE_VISIBILITY
639 const_iterator cbegin() const _NOEXCEPT
641 _LIBCPP_INLINE_VISIBILITY
642 const_iterator cend() const _NOEXCEPT
644 _LIBCPP_INLINE_VISIBILITY
645 const_reverse_iterator crbegin() const _NOEXCEPT
647 _LIBCPP_INLINE_VISIBILITY
648 const_reverse_iterator crend() const _NOEXCEPT
651 _LIBCPP_INLINE_VISIBILITY
652 size_type size() const _NOEXCEPT
653 {return static_cast<size_type>(this->__end_ - this->__begin_);}
654 _LIBCPP_INLINE_VISIBILITY
655 size_type capacity() const _NOEXCEPT
656 {return __base::capacity();}
657 _LIBCPP_INLINE_VISIBILITY
658 bool empty() const _NOEXCEPT
659 {return this->__begin_ == this->__end_;}
660 size_type max_size() const _NOEXCEPT;
661 void reserve(size_type __n);
662 void shrink_to_fit() _NOEXCEPT;
664 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
665 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
666 reference at(size_type __n);
667 const_reference at(size_type __n) const;
669 _LIBCPP_INLINE_VISIBILITY reference front()
671 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
672 return *this->__begin_;
674 _LIBCPP_INLINE_VISIBILITY const_reference front() const
676 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
677 return *this->__begin_;
679 _LIBCPP_INLINE_VISIBILITY reference back()
681 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
682 return *(this->__end_ - 1);
684 _LIBCPP_INLINE_VISIBILITY const_reference back() const
686 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
687 return *(this->__end_ - 1);
690 _LIBCPP_INLINE_VISIBILITY
691 value_type* data() _NOEXCEPT
692 {return _VSTD::__to_raw_pointer(this->__begin_);}
693 _LIBCPP_INLINE_VISIBILITY
694 const value_type* data() const _NOEXCEPT
695 {return _VSTD::__to_raw_pointer(this->__begin_);}
697 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
698 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
699 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
700 #ifndef _LIBCPP_HAS_NO_VARIADICS
701 template <class... _Args>
702 void emplace_back(_Args&&... __args);
703 #endif // _LIBCPP_HAS_NO_VARIADICS
704 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
707 iterator insert(const_iterator __position, const_reference __x);
708 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
709 iterator insert(const_iterator __position, value_type&& __x);
710 #ifndef _LIBCPP_HAS_NO_VARIADICS
711 template <class... _Args>
712 iterator emplace(const_iterator __position, _Args&&... __args);
713 #endif // _LIBCPP_HAS_NO_VARIADICS
714 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
715 iterator insert(const_iterator __position, size_type __n, const_reference __x);
716 template <class _InputIterator>
719 __is_input_iterator <_InputIterator>::value &&
720 !__is_forward_iterator<_InputIterator>::value &&
723 typename iterator_traits<_InputIterator>::reference>::value,
726 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
727 template <class _ForwardIterator>
730 __is_forward_iterator<_ForwardIterator>::value &&
733 typename iterator_traits<_ForwardIterator>::reference>::value,
736 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
737 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
738 _LIBCPP_INLINE_VISIBILITY
739 iterator insert(const_iterator __position, initializer_list<value_type> __il)
740 {return insert(__position, __il.begin(), __il.end());}
741 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
743 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
744 iterator erase(const_iterator __first, const_iterator __last);
746 _LIBCPP_INLINE_VISIBILITY
747 void clear() _NOEXCEPT
749 size_type __old_size = size();
751 __annotate_shrink(__old_size);
752 __invalidate_all_iterators();
755 void resize(size_type __sz);
756 void resize(size_type __sz, const_reference __x);
759 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
760 __is_nothrow_swappable<allocator_type>::value);
762 bool __invariants() const;
764 #if _LIBCPP_DEBUG_LEVEL >= 2
766 bool __dereferenceable(const const_iterator* __i) const;
767 bool __decrementable(const const_iterator* __i) const;
768 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
769 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
771 #endif // _LIBCPP_DEBUG_LEVEL >= 2
774 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
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 void __construct_at_end(size_type __n, const_reference __x);
780 template <class _ForwardIterator>
783 __is_forward_iterator<_ForwardIterator>::value,
786 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
787 void __append(size_type __n);
788 void __append(size_type __n, const_reference __x);
789 _LIBCPP_INLINE_VISIBILITY
790 iterator __make_iter(pointer __p) _NOEXCEPT;
791 _LIBCPP_INLINE_VISIBILITY
792 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
793 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
794 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
795 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
796 void __move_assign(vector& __c, true_type)
797 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
798 void __move_assign(vector& __c, false_type);
799 _LIBCPP_INLINE_VISIBILITY
800 void __destruct_at_end(pointer __new_last) _NOEXCEPT
802 #if _LIBCPP_DEBUG_LEVEL >= 2
803 __c_node* __c = __get_db()->__find_c_and_lock(this);
804 for (__i_node** __p = __c->end_; __p != __c->beg_; )
807 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
808 if (__i->base() > __new_last)
810 (*__p)->__c_ = nullptr;
811 if (--__c->end_ != __p)
812 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
815 __get_db()->unlock();
817 size_type __old_size = size();
818 __base::__destruct_at_end(__new_last);
819 __annotate_shrink(__old_size);
823 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
824 __push_back_slow_path(_Up&& __x);
826 __push_back_slow_path(_Up& __x);
828 #if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
829 template <class... _Args>
831 __emplace_back_slow_path(_Args&&... __args);
833 // The following functions are no-ops outside of AddressSanitizer mode.
834 // We call annotatations only for the default Allocator because other allocators
835 // may not meet the AddressSanitizer alignment constraints.
836 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
837 void __annotate_contiguous_container
838 (const void *__beg, const void *__end, const void *__old_mid, const void *__new_mid) const
840 #ifndef _LIBCPP_HAS_NO_ASAN
841 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
842 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
846 void __annotate_new(size_type __current_size) const
848 __annotate_contiguous_container(data(), data() + capacity(),
849 data() + capacity(), data() + __current_size);
851 void __annotate_delete() const
853 __annotate_contiguous_container(data(), data() + capacity(),
854 data() + size(), data() + capacity());
856 void __annotate_increase(size_type __n) const
858 __annotate_contiguous_container(data(), data() + capacity(),
859 data() + size(), data() + size() + __n);
861 void __annotate_shrink(size_type __old_size) const
863 __annotate_contiguous_container(data(), data() + capacity(),
864 data() + __old_size, data() + size());
866 #ifndef _LIBCPP_HAS_NO_ASAN
867 // The annotation for size increase should happen before the actual increase,
868 // but if an exception is thrown after that the annotation has to be undone.
869 struct __RAII_IncreaseAnnotator {
870 __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1)
871 : __commit(false), __v(__v), __n(__n) {
872 __v.__annotate_increase(__n);
874 void __done() { __commit = true; }
875 ~__RAII_IncreaseAnnotator() {
876 if (__commit) return;
877 __v.__annotate_shrink(__v.size() + __n);
884 struct __RAII_IncreaseAnnotator {
885 inline __RAII_IncreaseAnnotator(const vector &, size_type __n = 1) {}
886 inline void __done() {}
892 template <class _Tp, class _Allocator>
894 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
897 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
898 _VSTD::swap(this->__begin_, __v.__begin_);
899 _VSTD::swap(this->__end_, __v.__end_);
900 _VSTD::swap(this->__end_cap(), __v.__end_cap());
901 __v.__first_ = __v.__begin_;
902 __annotate_new(size());
903 __invalidate_all_iterators();
906 template <class _Tp, class _Allocator>
907 typename vector<_Tp, _Allocator>::pointer
908 vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
911 pointer __r = __v.__begin_;
912 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
913 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
914 _VSTD::swap(this->__begin_, __v.__begin_);
915 _VSTD::swap(this->__end_, __v.__end_);
916 _VSTD::swap(this->__end_cap(), __v.__end_cap());
917 __v.__first_ = __v.__begin_;
918 __annotate_new(size());
919 __invalidate_all_iterators();
923 // Allocate space for __n objects
924 // throws length_error if __n > max_size()
925 // throws (probably bad_alloc) if memory run out
926 // Precondition: __begin_ == __end_ == __end_cap() == 0
927 // Precondition: __n > 0
928 // Postcondition: capacity() == __n
929 // Postcondition: size() == 0
930 template <class _Tp, class _Allocator>
932 vector<_Tp, _Allocator>::allocate(size_type __n)
934 if (__n > max_size())
935 this->__throw_length_error();
936 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
937 this->__end_cap() = this->__begin_ + __n;
941 template <class _Tp, class _Allocator>
943 vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
945 if (this->__begin_ != nullptr)
948 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
949 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
953 template <class _Tp, class _Allocator>
954 typename vector<_Tp, _Allocator>::size_type
955 vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
957 return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2); // end() >= begin(), always
960 // Precondition: __new_size > capacity()
961 template <class _Tp, class _Allocator>
962 inline _LIBCPP_INLINE_VISIBILITY
963 typename vector<_Tp, _Allocator>::size_type
964 vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
966 const size_type __ms = max_size();
967 if (__new_size > __ms)
968 this->__throw_length_error();
969 const size_type __cap = capacity();
970 if (__cap >= __ms / 2)
972 return _VSTD::max<size_type>(2*__cap, __new_size);
975 // Default constructs __n objects starting at __end_
976 // throws if construction throws
977 // Precondition: __n > 0
978 // Precondition: size() + __n <= capacity()
979 // Postcondition: size() == size() + __n
980 template <class _Tp, class _Allocator>
982 vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
984 allocator_type& __a = this->__alloc();
987 __RAII_IncreaseAnnotator __annotator(*this);
988 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
991 __annotator.__done();
995 // Copy constructs __n objects starting at __end_ from __x
996 // throws if construction throws
997 // Precondition: __n > 0
998 // Precondition: size() + __n <= capacity()
999 // Postcondition: size() == old size() + __n
1000 // Postcondition: [i] == __x for all i in [size() - __n, __n)
1001 template <class _Tp, class _Allocator>
1002 inline _LIBCPP_INLINE_VISIBILITY
1004 vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
1006 allocator_type& __a = this->__alloc();
1009 __RAII_IncreaseAnnotator __annotator(*this);
1010 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
1013 __annotator.__done();
1017 template <class _Tp, class _Allocator>
1018 template <class _ForwardIterator>
1021 __is_forward_iterator<_ForwardIterator>::value,
1024 vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
1026 allocator_type& __a = this->__alloc();
1027 for (; __first != __last; ++__first)
1029 __RAII_IncreaseAnnotator __annotator(*this);
1030 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
1031 __annotator.__done();
1036 // Default constructs __n objects starting at __end_
1037 // throws if construction throws
1038 // Postcondition: size() == size() + __n
1039 // Exception safety: strong.
1040 template <class _Tp, class _Allocator>
1042 vector<_Tp, _Allocator>::__append(size_type __n)
1044 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1045 this->__construct_at_end(__n);
1048 allocator_type& __a = this->__alloc();
1049 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1050 __v.__construct_at_end(__n);
1051 __swap_out_circular_buffer(__v);
1055 // Default constructs __n objects starting at __end_
1056 // throws if construction throws
1057 // Postcondition: size() == size() + __n
1058 // Exception safety: strong.
1059 template <class _Tp, class _Allocator>
1061 vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1063 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1064 this->__construct_at_end(__n, __x);
1067 allocator_type& __a = this->__alloc();
1068 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1069 __v.__construct_at_end(__n, __x);
1070 __swap_out_circular_buffer(__v);
1074 template <class _Tp, class _Allocator>
1075 vector<_Tp, _Allocator>::vector(size_type __n)
1077 #if _LIBCPP_DEBUG_LEVEL >= 2
1078 __get_db()->__insert_c(this);
1083 __construct_at_end(__n);
1087 #if _LIBCPP_STD_VER > 11
1088 template <class _Tp, class _Allocator>
1089 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1092 #if _LIBCPP_DEBUG_LEVEL >= 2
1093 __get_db()->__insert_c(this);
1098 __construct_at_end(__n);
1103 template <class _Tp, class _Allocator>
1104 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1106 #if _LIBCPP_DEBUG_LEVEL >= 2
1107 __get_db()->__insert_c(this);
1112 __construct_at_end(__n, __x);
1116 template <class _Tp, class _Allocator>
1117 vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1120 #if _LIBCPP_DEBUG_LEVEL >= 2
1121 __get_db()->__insert_c(this);
1126 __construct_at_end(__n, __x);
1130 template <class _Tp, class _Allocator>
1131 template <class _InputIterator>
1132 vector<_Tp, _Allocator>::vector(_InputIterator __first,
1133 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1134 !__is_forward_iterator<_InputIterator>::value &&
1137 typename iterator_traits<_InputIterator>::reference>::value,
1138 _InputIterator>::type __last)
1140 #if _LIBCPP_DEBUG_LEVEL >= 2
1141 __get_db()->__insert_c(this);
1143 for (; __first != __last; ++__first)
1144 push_back(*__first);
1147 template <class _Tp, class _Allocator>
1148 template <class _InputIterator>
1149 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1150 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1151 !__is_forward_iterator<_InputIterator>::value &&
1154 typename iterator_traits<_InputIterator>::reference>::value>::type*)
1157 #if _LIBCPP_DEBUG_LEVEL >= 2
1158 __get_db()->__insert_c(this);
1160 for (; __first != __last; ++__first)
1161 push_back(*__first);
1164 template <class _Tp, class _Allocator>
1165 template <class _ForwardIterator>
1166 vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
1167 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1170 typename iterator_traits<_ForwardIterator>::reference>::value,
1171 _ForwardIterator>::type __last)
1173 #if _LIBCPP_DEBUG_LEVEL >= 2
1174 __get_db()->__insert_c(this);
1176 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1180 __construct_at_end(__first, __last);
1184 template <class _Tp, class _Allocator>
1185 template <class _ForwardIterator>
1186 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1187 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1190 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1193 #if _LIBCPP_DEBUG_LEVEL >= 2
1194 __get_db()->__insert_c(this);
1196 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1200 __construct_at_end(__first, __last);
1204 template <class _Tp, class _Allocator>
1205 vector<_Tp, _Allocator>::vector(const vector& __x)
1206 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1208 #if _LIBCPP_DEBUG_LEVEL >= 2
1209 __get_db()->__insert_c(this);
1211 size_type __n = __x.size();
1215 __construct_at_end(__x.__begin_, __x.__end_);
1219 template <class _Tp, class _Allocator>
1220 vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1223 #if _LIBCPP_DEBUG_LEVEL >= 2
1224 __get_db()->__insert_c(this);
1226 size_type __n = __x.size();
1230 __construct_at_end(__x.__begin_, __x.__end_);
1234 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1236 template <class _Tp, class _Allocator>
1237 inline _LIBCPP_INLINE_VISIBILITY
1238 vector<_Tp, _Allocator>::vector(vector&& __x)
1239 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1240 : __base(_VSTD::move(__x.__alloc()))
1242 #if _LIBCPP_DEBUG_LEVEL >= 2
1243 __get_db()->__insert_c(this);
1244 __get_db()->swap(this, &__x);
1246 this->__begin_ = __x.__begin_;
1247 this->__end_ = __x.__end_;
1248 this->__end_cap() = __x.__end_cap();
1249 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1252 template <class _Tp, class _Allocator>
1253 inline _LIBCPP_INLINE_VISIBILITY
1254 vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1257 #if _LIBCPP_DEBUG_LEVEL >= 2
1258 __get_db()->__insert_c(this);
1260 if (__a == __x.__alloc())
1262 this->__begin_ = __x.__begin_;
1263 this->__end_ = __x.__end_;
1264 this->__end_cap() = __x.__end_cap();
1265 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1266 #if _LIBCPP_DEBUG_LEVEL >= 2
1267 __get_db()->swap(this, &__x);
1272 typedef move_iterator<iterator> _Ip;
1273 assign(_Ip(__x.begin()), _Ip(__x.end()));
1277 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1279 template <class _Tp, class _Allocator>
1280 inline _LIBCPP_INLINE_VISIBILITY
1281 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1283 #if _LIBCPP_DEBUG_LEVEL >= 2
1284 __get_db()->__insert_c(this);
1286 if (__il.size() > 0)
1288 allocate(__il.size());
1289 __construct_at_end(__il.begin(), __il.end());
1293 template <class _Tp, class _Allocator>
1294 inline _LIBCPP_INLINE_VISIBILITY
1295 vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1298 #if _LIBCPP_DEBUG_LEVEL >= 2
1299 __get_db()->__insert_c(this);
1301 if (__il.size() > 0)
1303 allocate(__il.size());
1304 __construct_at_end(__il.begin(), __il.end());
1308 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1310 template <class _Tp, class _Allocator>
1311 inline _LIBCPP_INLINE_VISIBILITY
1312 vector<_Tp, _Allocator>&
1313 vector<_Tp, _Allocator>::operator=(vector&& __x)
1315 __alloc_traits::propagate_on_container_move_assignment::value &&
1316 is_nothrow_move_assignable<allocator_type>::value)
1318 __move_assign(__x, integral_constant<bool,
1319 __alloc_traits::propagate_on_container_move_assignment::value>());
1323 template <class _Tp, class _Allocator>
1325 vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1327 if (__base::__alloc() != __c.__alloc())
1329 typedef move_iterator<iterator> _Ip;
1330 assign(_Ip(__c.begin()), _Ip(__c.end()));
1333 __move_assign(__c, true_type());
1336 template <class _Tp, class _Allocator>
1338 vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1339 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1342 __base::__move_assign_alloc(__c); // this can throw
1343 this->__begin_ = __c.__begin_;
1344 this->__end_ = __c.__end_;
1345 this->__end_cap() = __c.__end_cap();
1346 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1347 #if _LIBCPP_DEBUG_LEVEL >= 2
1348 __get_db()->swap(this, &__c);
1352 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1354 template <class _Tp, class _Allocator>
1355 inline _LIBCPP_INLINE_VISIBILITY
1356 vector<_Tp, _Allocator>&
1357 vector<_Tp, _Allocator>::operator=(const vector& __x)
1361 __base::__copy_assign_alloc(__x);
1362 assign(__x.__begin_, __x.__end_);
1367 template <class _Tp, class _Allocator>
1368 template <class _InputIterator>
1371 __is_input_iterator <_InputIterator>::value &&
1372 !__is_forward_iterator<_InputIterator>::value &&
1375 typename iterator_traits<_InputIterator>::reference>::value,
1378 vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1381 for (; __first != __last; ++__first)
1382 push_back(*__first);
1385 template <class _Tp, class _Allocator>
1386 template <class _ForwardIterator>
1389 __is_forward_iterator<_ForwardIterator>::value &&
1392 typename iterator_traits<_ForwardIterator>::reference>::value,
1395 vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1397 typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last);
1398 if (static_cast<size_type>(__new_size) <= capacity())
1400 _ForwardIterator __mid = __last;
1401 bool __growing = false;
1402 if (static_cast<size_type>(__new_size) > size())
1406 _VSTD::advance(__mid, size());
1408 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
1410 __construct_at_end(__mid, __last);
1412 this->__destruct_at_end(__m);
1417 allocate(__recommend(static_cast<size_type>(__new_size)));
1418 __construct_at_end(__first, __last);
1422 template <class _Tp, class _Allocator>
1424 vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1426 if (__n <= capacity())
1428 size_type __s = size();
1429 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
1431 __construct_at_end(__n - __s, __u);
1433 this->__destruct_at_end(this->__begin_ + __n);
1438 allocate(__recommend(static_cast<size_type>(__n)));
1439 __construct_at_end(__n, __u);
1443 template <class _Tp, class _Allocator>
1444 inline _LIBCPP_INLINE_VISIBILITY
1445 typename vector<_Tp, _Allocator>::iterator
1446 vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
1448 #if _LIBCPP_DEBUG_LEVEL >= 2
1449 return iterator(this, __p);
1451 return iterator(__p);
1455 template <class _Tp, class _Allocator>
1456 inline _LIBCPP_INLINE_VISIBILITY
1457 typename vector<_Tp, _Allocator>::const_iterator
1458 vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
1460 #if _LIBCPP_DEBUG_LEVEL >= 2
1461 return const_iterator(this, __p);
1463 return const_iterator(__p);
1467 template <class _Tp, class _Allocator>
1468 inline _LIBCPP_INLINE_VISIBILITY
1469 typename vector<_Tp, _Allocator>::iterator
1470 vector<_Tp, _Allocator>::begin() _NOEXCEPT
1472 return __make_iter(this->__begin_);
1475 template <class _Tp, class _Allocator>
1476 inline _LIBCPP_INLINE_VISIBILITY
1477 typename vector<_Tp, _Allocator>::const_iterator
1478 vector<_Tp, _Allocator>::begin() const _NOEXCEPT
1480 return __make_iter(this->__begin_);
1483 template <class _Tp, class _Allocator>
1484 inline _LIBCPP_INLINE_VISIBILITY
1485 typename vector<_Tp, _Allocator>::iterator
1486 vector<_Tp, _Allocator>::end() _NOEXCEPT
1488 return __make_iter(this->__end_);
1491 template <class _Tp, class _Allocator>
1492 inline _LIBCPP_INLINE_VISIBILITY
1493 typename vector<_Tp, _Allocator>::const_iterator
1494 vector<_Tp, _Allocator>::end() const _NOEXCEPT
1496 return __make_iter(this->__end_);
1499 template <class _Tp, class _Allocator>
1500 inline _LIBCPP_INLINE_VISIBILITY
1501 typename vector<_Tp, _Allocator>::reference
1502 vector<_Tp, _Allocator>::operator[](size_type __n)
1504 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1505 return this->__begin_[__n];
1508 template <class _Tp, class _Allocator>
1509 inline _LIBCPP_INLINE_VISIBILITY
1510 typename vector<_Tp, _Allocator>::const_reference
1511 vector<_Tp, _Allocator>::operator[](size_type __n) const
1513 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1514 return this->__begin_[__n];
1517 template <class _Tp, class _Allocator>
1518 typename vector<_Tp, _Allocator>::reference
1519 vector<_Tp, _Allocator>::at(size_type __n)
1522 this->__throw_out_of_range();
1523 return this->__begin_[__n];
1526 template <class _Tp, class _Allocator>
1527 typename vector<_Tp, _Allocator>::const_reference
1528 vector<_Tp, _Allocator>::at(size_type __n) const
1531 this->__throw_out_of_range();
1532 return this->__begin_[__n];
1535 template <class _Tp, class _Allocator>
1537 vector<_Tp, _Allocator>::reserve(size_type __n)
1539 if (__n > capacity())
1541 allocator_type& __a = this->__alloc();
1542 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
1543 __swap_out_circular_buffer(__v);
1547 template <class _Tp, class _Allocator>
1549 vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1551 if (capacity() > size())
1553 #ifndef _LIBCPP_NO_EXCEPTIONS
1556 #endif // _LIBCPP_NO_EXCEPTIONS
1557 allocator_type& __a = this->__alloc();
1558 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1559 __swap_out_circular_buffer(__v);
1560 #ifndef _LIBCPP_NO_EXCEPTIONS
1565 #endif // _LIBCPP_NO_EXCEPTIONS
1569 template <class _Tp, class _Allocator>
1570 template <class _Up>
1572 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1573 vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1575 vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1578 allocator_type& __a = this->__alloc();
1579 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1580 // __v.push_back(_VSTD::forward<_Up>(__x));
1581 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
1583 __swap_out_circular_buffer(__v);
1586 template <class _Tp, class _Allocator>
1587 inline _LIBCPP_INLINE_VISIBILITY
1589 vector<_Tp, _Allocator>::push_back(const_reference __x)
1591 if (this->__end_ != this->__end_cap())
1593 __RAII_IncreaseAnnotator __annotator(*this);
1594 __alloc_traits::construct(this->__alloc(),
1595 _VSTD::__to_raw_pointer(this->__end_), __x);
1596 __annotator.__done();
1600 __push_back_slow_path(__x);
1603 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1605 template <class _Tp, class _Allocator>
1606 inline _LIBCPP_INLINE_VISIBILITY
1608 vector<_Tp, _Allocator>::push_back(value_type&& __x)
1610 if (this->__end_ < this->__end_cap())
1612 __RAII_IncreaseAnnotator __annotator(*this);
1613 __alloc_traits::construct(this->__alloc(),
1614 _VSTD::__to_raw_pointer(this->__end_),
1616 __annotator.__done();
1620 __push_back_slow_path(_VSTD::move(__x));
1623 #ifndef _LIBCPP_HAS_NO_VARIADICS
1625 template <class _Tp, class _Allocator>
1626 template <class... _Args>
1628 vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1630 allocator_type& __a = this->__alloc();
1631 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1632 // __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1633 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
1635 __swap_out_circular_buffer(__v);
1638 template <class _Tp, class _Allocator>
1639 template <class... _Args>
1640 inline _LIBCPP_INLINE_VISIBILITY
1642 vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1644 if (this->__end_ < this->__end_cap())
1646 __RAII_IncreaseAnnotator __annotator(*this);
1647 __alloc_traits::construct(this->__alloc(),
1648 _VSTD::__to_raw_pointer(this->__end_),
1649 _VSTD::forward<_Args>(__args)...);
1650 __annotator.__done();
1654 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
1657 #endif // _LIBCPP_HAS_NO_VARIADICS
1658 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1660 template <class _Tp, class _Allocator>
1661 inline _LIBCPP_INLINE_VISIBILITY
1663 vector<_Tp, _Allocator>::pop_back()
1665 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
1666 this->__destruct_at_end(this->__end_ - 1);
1669 template <class _Tp, class _Allocator>
1670 inline _LIBCPP_INLINE_VISIBILITY
1671 typename vector<_Tp, _Allocator>::iterator
1672 vector<_Tp, _Allocator>::erase(const_iterator __position)
1674 #if _LIBCPP_DEBUG_LEVEL >= 2
1675 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1676 "vector::erase(iterator) called with an iterator not"
1677 " referring to this vector");
1679 _LIBCPP_ASSERT(__position != end(),
1680 "vector::erase(iterator) called with a non-dereferenceable iterator");
1681 difference_type __ps = __position - cbegin();
1682 pointer __p = this->__begin_ + __ps;
1683 iterator __r = __make_iter(__p);
1684 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __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");
1697 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
1698 pointer __p = this->__begin_ + (__first - begin());
1699 iterator __r = __make_iter(__p);
1700 if (__first != __last)
1701 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1705 template <class _Tp, class _Allocator>
1707 vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1709 pointer __old_last = this->__end_;
1710 difference_type __n = __old_last - __to;
1711 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1712 __alloc_traits::construct(this->__alloc(),
1713 _VSTD::__to_raw_pointer(this->__end_),
1715 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
1718 template <class _Tp, class _Allocator>
1719 typename vector<_Tp, _Allocator>::iterator
1720 vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1722 #if _LIBCPP_DEBUG_LEVEL >= 2
1723 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1724 "vector::insert(iterator, x) called with an iterator not"
1725 " referring to this vector");
1727 pointer __p = this->__begin_ + (__position - begin());
1728 if (this->__end_ < this->__end_cap())
1730 __RAII_IncreaseAnnotator __annotator(*this);
1731 if (__p == this->__end_)
1733 __alloc_traits::construct(this->__alloc(),
1734 _VSTD::__to_raw_pointer(this->__end_), __x);
1739 __move_range(__p, this->__end_, __p + 1);
1740 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1741 if (__p <= __xr && __xr < this->__end_)
1745 __annotator.__done();
1749 allocator_type& __a = this->__alloc();
1750 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1752 __p = __swap_out_circular_buffer(__v, __p);
1754 return __make_iter(__p);
1757 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1759 template <class _Tp, class _Allocator>
1760 typename vector<_Tp, _Allocator>::iterator
1761 vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1763 #if _LIBCPP_DEBUG_LEVEL >= 2
1764 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1765 "vector::insert(iterator, x) called with an iterator not"
1766 " referring to this vector");
1768 pointer __p = this->__begin_ + (__position - begin());
1769 if (this->__end_ < this->__end_cap())
1771 __RAII_IncreaseAnnotator __annotator(*this);
1772 if (__p == this->__end_)
1774 __alloc_traits::construct(this->__alloc(),
1775 _VSTD::__to_raw_pointer(this->__end_),
1781 __move_range(__p, this->__end_, __p + 1);
1782 *__p = _VSTD::move(__x);
1784 __annotator.__done();
1788 allocator_type& __a = this->__alloc();
1789 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1790 __v.push_back(_VSTD::move(__x));
1791 __p = __swap_out_circular_buffer(__v, __p);
1793 return __make_iter(__p);
1796 #ifndef _LIBCPP_HAS_NO_VARIADICS
1798 template <class _Tp, class _Allocator>
1799 template <class... _Args>
1800 typename vector<_Tp, _Allocator>::iterator
1801 vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1803 #if _LIBCPP_DEBUG_LEVEL >= 2
1804 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1805 "vector::emplace(iterator, x) called with an iterator not"
1806 " referring to this vector");
1808 pointer __p = this->__begin_ + (__position - begin());
1809 if (this->__end_ < this->__end_cap())
1811 __RAII_IncreaseAnnotator __annotator(*this);
1812 if (__p == this->__end_)
1814 __alloc_traits::construct(this->__alloc(),
1815 _VSTD::__to_raw_pointer(this->__end_),
1816 _VSTD::forward<_Args>(__args)...);
1821 value_type __tmp(_VSTD::forward<_Args>(__args)...);
1822 __move_range(__p, this->__end_, __p + 1);
1823 *__p = _VSTD::move(__tmp);
1825 __annotator.__done();
1829 allocator_type& __a = this->__alloc();
1830 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1831 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1832 __p = __swap_out_circular_buffer(__v, __p);
1834 return __make_iter(__p);
1837 #endif // _LIBCPP_HAS_NO_VARIADICS
1838 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1840 template <class _Tp, class _Allocator>
1841 typename vector<_Tp, _Allocator>::iterator
1842 vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1844 #if _LIBCPP_DEBUG_LEVEL >= 2
1845 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1846 "vector::insert(iterator, n, x) called with an iterator not"
1847 " referring to this vector");
1849 pointer __p = this->__begin_ + (__position - begin());
1852 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1854 size_type __old_n = __n;
1855 pointer __old_last = this->__end_;
1856 if (__n > static_cast<size_type>(this->__end_ - __p))
1858 size_type __cx = __n - (this->__end_ - __p);
1859 __construct_at_end(__cx, __x);
1864 __RAII_IncreaseAnnotator __annotator(*this, __n);
1865 __move_range(__p, __old_last, __p + __old_n);
1866 __annotator.__done();
1867 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1868 if (__p <= __xr && __xr < this->__end_)
1870 _VSTD::fill_n(__p, __n, *__xr);
1875 allocator_type& __a = this->__alloc();
1876 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1877 __v.__construct_at_end(__n, __x);
1878 __p = __swap_out_circular_buffer(__v, __p);
1881 return __make_iter(__p);
1884 template <class _Tp, class _Allocator>
1885 template <class _InputIterator>
1888 __is_input_iterator <_InputIterator>::value &&
1889 !__is_forward_iterator<_InputIterator>::value &&
1892 typename iterator_traits<_InputIterator>::reference>::value,
1893 typename vector<_Tp, _Allocator>::iterator
1895 vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1897 #if _LIBCPP_DEBUG_LEVEL >= 2
1898 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1899 "vector::insert(iterator, range) called with an iterator not"
1900 " referring to this vector");
1902 difference_type __off = __position - begin();
1903 pointer __p = this->__begin_ + __off;
1904 allocator_type& __a = this->__alloc();
1905 pointer __old_last = this->__end_;
1906 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1908 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
1912 __split_buffer<value_type, allocator_type&> __v(__a);
1913 if (__first != __last)
1915 #ifndef _LIBCPP_NO_EXCEPTIONS
1918 #endif // _LIBCPP_NO_EXCEPTIONS
1919 __v.__construct_at_end(__first, __last);
1920 difference_type __old_size = __old_last - this->__begin_;
1921 difference_type __old_p = __p - this->__begin_;
1922 reserve(__recommend(size() + __v.size()));
1923 __p = this->__begin_ + __old_p;
1924 __old_last = this->__begin_ + __old_size;
1925 #ifndef _LIBCPP_NO_EXCEPTIONS
1929 erase(__make_iter(__old_last), end());
1932 #endif // _LIBCPP_NO_EXCEPTIONS
1934 __p = _VSTD::rotate(__p, __old_last, this->__end_);
1935 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1936 make_move_iterator(__v.end()));
1937 return begin() + __off;
1940 template <class _Tp, class _Allocator>
1941 template <class _ForwardIterator>
1944 __is_forward_iterator<_ForwardIterator>::value &&
1947 typename iterator_traits<_ForwardIterator>::reference>::value,
1948 typename vector<_Tp, _Allocator>::iterator
1950 vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1952 #if _LIBCPP_DEBUG_LEVEL >= 2
1953 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1954 "vector::insert(iterator, range) called with an iterator not"
1955 " referring to this vector");
1957 pointer __p = this->__begin_ + (__position - begin());
1958 difference_type __n = _VSTD::distance(__first, __last);
1961 if (__n <= this->__end_cap() - this->__end_)
1963 size_type __old_n = __n;
1964 pointer __old_last = this->__end_;
1965 _ForwardIterator __m = __last;
1966 difference_type __dx = this->__end_ - __p;
1970 _VSTD::advance(__m, this->__end_ - __p);
1971 __construct_at_end(__m, __last);
1976 __RAII_IncreaseAnnotator __annotator(*this, __n);
1977 __move_range(__p, __old_last, __p + __old_n);
1978 __annotator.__done();
1979 _VSTD::copy(__first, __m, __p);
1984 allocator_type& __a = this->__alloc();
1985 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1986 __v.__construct_at_end(__first, __last);
1987 __p = __swap_out_circular_buffer(__v, __p);
1990 return __make_iter(__p);
1993 template <class _Tp, class _Allocator>
1995 vector<_Tp, _Allocator>::resize(size_type __sz)
1997 size_type __cs = size();
1999 this->__append(__sz - __cs);
2000 else if (__cs > __sz)
2001 this->__destruct_at_end(this->__begin_ + __sz);
2004 template <class _Tp, class _Allocator>
2006 vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
2008 size_type __cs = size();
2010 this->__append(__sz - __cs, __x);
2011 else if (__cs > __sz)
2012 this->__destruct_at_end(this->__begin_ + __sz);
2015 template <class _Tp, class _Allocator>
2017 vector<_Tp, _Allocator>::swap(vector& __x)
2018 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2019 __is_nothrow_swappable<allocator_type>::value)
2021 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
2022 this->__alloc() == __x.__alloc(),
2023 "vector::swap: Either propagate_on_container_swap must be true"
2024 " or the allocators must compare equal");
2025 _VSTD::swap(this->__begin_, __x.__begin_);
2026 _VSTD::swap(this->__end_, __x.__end_);
2027 _VSTD::swap(this->__end_cap(), __x.__end_cap());
2028 __base::__swap_alloc(this->__alloc(), __x.__alloc());
2029 #if _LIBCPP_DEBUG_LEVEL >= 2
2030 __get_db()->swap(this, &__x);
2031 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2034 template <class _Tp, class _Allocator>
2036 vector<_Tp, _Allocator>::__invariants() const
2038 if (this->__begin_ == nullptr)
2040 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
2045 if (this->__begin_ > this->__end_)
2047 if (this->__begin_ == this->__end_cap())
2049 if (this->__end_ > this->__end_cap())
2055 #if _LIBCPP_DEBUG_LEVEL >= 2
2057 template <class _Tp, class _Allocator>
2059 vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
2061 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
2064 template <class _Tp, class _Allocator>
2066 vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
2068 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
2071 template <class _Tp, class _Allocator>
2073 vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2075 const_pointer __p = __i->base() + __n;
2076 return this->__begin_ <= __p && __p <= this->__end_;
2079 template <class _Tp, class _Allocator>
2081 vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2083 const_pointer __p = __i->base() + __n;
2084 return this->__begin_ <= __p && __p < this->__end_;
2087 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2089 template <class _Tp, class _Allocator>
2090 inline _LIBCPP_INLINE_VISIBILITY
2092 vector<_Tp, _Allocator>::__invalidate_all_iterators()
2094 #if _LIBCPP_DEBUG_LEVEL >= 2
2095 __get_db()->__invalidate_all(this);
2096 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2101 template <class _Allocator> class vector<bool, _Allocator>;
2103 template <class _Allocator> struct hash<vector<bool, _Allocator> >;
2105 template <class _Allocator>
2106 struct __has_storage_type<vector<bool, _Allocator> >
2108 static const bool value = true;
2111 template <class _Allocator>
2112 class _LIBCPP_TYPE_VIS_ONLY vector<bool, _Allocator>
2113 : private __vector_base_common<true>
2116 typedef vector __self;
2117 typedef bool value_type;
2118 typedef _Allocator allocator_type;
2119 typedef allocator_traits<allocator_type> __alloc_traits;
2120 typedef typename __alloc_traits::size_type size_type;
2121 typedef typename __alloc_traits::difference_type difference_type;
2122 typedef size_type __storage_type;
2123 typedef __bit_iterator<vector, false> pointer;
2124 typedef __bit_iterator<vector, true> const_pointer;
2125 typedef pointer iterator;
2126 typedef const_pointer const_iterator;
2127 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
2128 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
2131 typedef typename __alloc_traits::template
2132 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
2133 rebind_alloc<__storage_type>
2135 rebind_alloc<__storage_type>::other
2137 __storage_allocator;
2138 typedef allocator_traits<__storage_allocator> __storage_traits;
2139 typedef typename __storage_traits::pointer __storage_pointer;
2140 typedef typename __storage_traits::const_pointer __const_storage_pointer;
2142 __storage_pointer __begin_;
2144 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
2146 typedef __bit_reference<vector> reference;
2147 typedef __bit_const_reference<vector> const_reference;
2149 _LIBCPP_INLINE_VISIBILITY
2150 size_type& __cap() _NOEXCEPT
2151 {return __cap_alloc_.first();}
2152 _LIBCPP_INLINE_VISIBILITY
2153 const size_type& __cap() const _NOEXCEPT
2154 {return __cap_alloc_.first();}
2155 _LIBCPP_INLINE_VISIBILITY
2156 __storage_allocator& __alloc() _NOEXCEPT
2157 {return __cap_alloc_.second();}
2158 _LIBCPP_INLINE_VISIBILITY
2159 const __storage_allocator& __alloc() const _NOEXCEPT
2160 {return __cap_alloc_.second();}
2162 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2164 _LIBCPP_INLINE_VISIBILITY
2165 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
2166 {return __n * __bits_per_word;}
2167 _LIBCPP_INLINE_VISIBILITY
2168 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
2169 {return (__n - 1) / __bits_per_word + 1;}
2172 _LIBCPP_INLINE_VISIBILITY
2174 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
2175 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a);
2177 explicit vector(size_type __n);
2178 #if _LIBCPP_STD_VER > 11
2179 explicit vector(size_type __n, const allocator_type& __a);
2181 vector(size_type __n, const value_type& __v);
2182 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2183 template <class _InputIterator>
2184 vector(_InputIterator __first, _InputIterator __last,
2185 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2186 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2187 template <class _InputIterator>
2188 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2189 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2190 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2191 template <class _ForwardIterator>
2192 vector(_ForwardIterator __first, _ForwardIterator __last,
2193 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2194 template <class _ForwardIterator>
2195 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2196 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2198 vector(const vector& __v);
2199 vector(const vector& __v, const allocator_type& __a);
2200 vector& operator=(const vector& __v);
2201 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2202 vector(initializer_list<value_type> __il);
2203 vector(initializer_list<value_type> __il, const allocator_type& __a);
2204 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2206 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2207 _LIBCPP_INLINE_VISIBILITY
2208 vector(vector&& __v)
2209 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
2210 vector(vector&& __v, const allocator_type& __a);
2211 _LIBCPP_INLINE_VISIBILITY
2212 vector& operator=(vector&& __v)
2214 __alloc_traits::propagate_on_container_move_assignment::value &&
2215 is_nothrow_move_assignable<allocator_type>::value);
2216 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2217 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2218 _LIBCPP_INLINE_VISIBILITY
2219 vector& operator=(initializer_list<value_type> __il)
2220 {assign(__il.begin(), __il.end()); return *this;}
2221 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2223 template <class _InputIterator>
2226 __is_input_iterator<_InputIterator>::value &&
2227 !__is_forward_iterator<_InputIterator>::value,
2230 assign(_InputIterator __first, _InputIterator __last);
2231 template <class _ForwardIterator>
2234 __is_forward_iterator<_ForwardIterator>::value,
2237 assign(_ForwardIterator __first, _ForwardIterator __last);
2239 void assign(size_type __n, const value_type& __x);
2240 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2241 _LIBCPP_INLINE_VISIBILITY
2242 void assign(initializer_list<value_type> __il)
2243 {assign(__il.begin(), __il.end());}
2244 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2246 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
2247 {return allocator_type(this->__alloc());}
2249 size_type max_size() const _NOEXCEPT;
2250 _LIBCPP_INLINE_VISIBILITY
2251 size_type capacity() const _NOEXCEPT
2252 {return __internal_cap_to_external(__cap());}
2253 _LIBCPP_INLINE_VISIBILITY
2254 size_type size() const _NOEXCEPT
2256 _LIBCPP_INLINE_VISIBILITY
2257 bool empty() const _NOEXCEPT
2258 {return __size_ == 0;}
2259 void reserve(size_type __n);
2260 void shrink_to_fit() _NOEXCEPT;
2262 _LIBCPP_INLINE_VISIBILITY
2263 iterator begin() _NOEXCEPT
2264 {return __make_iter(0);}
2265 _LIBCPP_INLINE_VISIBILITY
2266 const_iterator begin() const _NOEXCEPT
2267 {return __make_iter(0);}
2268 _LIBCPP_INLINE_VISIBILITY
2269 iterator end() _NOEXCEPT
2270 {return __make_iter(__size_);}
2271 _LIBCPP_INLINE_VISIBILITY
2272 const_iterator end() const _NOEXCEPT
2273 {return __make_iter(__size_);}
2275 _LIBCPP_INLINE_VISIBILITY
2276 reverse_iterator rbegin() _NOEXCEPT
2277 {return reverse_iterator(end());}
2278 _LIBCPP_INLINE_VISIBILITY
2279 const_reverse_iterator rbegin() const _NOEXCEPT
2280 {return const_reverse_iterator(end());}
2281 _LIBCPP_INLINE_VISIBILITY
2282 reverse_iterator rend() _NOEXCEPT
2283 {return reverse_iterator(begin());}
2284 _LIBCPP_INLINE_VISIBILITY
2285 const_reverse_iterator rend() const _NOEXCEPT
2286 {return const_reverse_iterator(begin());}
2288 _LIBCPP_INLINE_VISIBILITY
2289 const_iterator cbegin() const _NOEXCEPT
2290 {return __make_iter(0);}
2291 _LIBCPP_INLINE_VISIBILITY
2292 const_iterator cend() const _NOEXCEPT
2293 {return __make_iter(__size_);}
2294 _LIBCPP_INLINE_VISIBILITY
2295 const_reverse_iterator crbegin() const _NOEXCEPT
2297 _LIBCPP_INLINE_VISIBILITY
2298 const_reverse_iterator crend() const _NOEXCEPT
2301 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2302 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2303 reference at(size_type __n);
2304 const_reference at(size_type __n) const;
2306 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2307 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2308 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2309 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2311 void push_back(const value_type& __x);
2312 #if _LIBCPP_STD_VER > 11
2313 template <class... _Args>
2314 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
2315 { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); }
2318 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2320 #if _LIBCPP_STD_VER > 11
2321 template <class... _Args>
2322 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2323 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2326 iterator insert(const_iterator __position, const value_type& __x);
2327 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2328 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2329 template <class _InputIterator>
2332 __is_input_iterator <_InputIterator>::value &&
2333 !__is_forward_iterator<_InputIterator>::value,
2336 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2337 template <class _ForwardIterator>
2340 __is_forward_iterator<_ForwardIterator>::value,
2343 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
2344 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2345 _LIBCPP_INLINE_VISIBILITY
2346 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2347 {return insert(__position, __il.begin(), __il.end());}
2348 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2350 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
2351 iterator erase(const_iterator __first, const_iterator __last);
2353 _LIBCPP_INLINE_VISIBILITY
2354 void clear() _NOEXCEPT {__size_ = 0;}
2357 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2358 __is_nothrow_swappable<allocator_type>::value);
2360 void resize(size_type __sz, value_type __x = false);
2361 void flip() _NOEXCEPT;
2363 bool __invariants() const;
2366 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
2367 void allocate(size_type __n);
2368 void deallocate() _NOEXCEPT;
2369 _LIBCPP_INLINE_VISIBILITY
2370 static size_type __align_it(size_type __new_size) _NOEXCEPT
2371 {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);};
2372 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2373 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
2374 template <class _ForwardIterator>
2377 __is_forward_iterator<_ForwardIterator>::value,
2380 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2381 void __append(size_type __n, const_reference __x);
2382 _LIBCPP_INLINE_VISIBILITY
2383 reference __make_ref(size_type __pos) _NOEXCEPT
2384 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2385 _LIBCPP_INLINE_VISIBILITY
2386 const_reference __make_ref(size_type __pos) const _NOEXCEPT
2387 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2388 _LIBCPP_INLINE_VISIBILITY
2389 iterator __make_iter(size_type __pos) _NOEXCEPT
2390 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2391 _LIBCPP_INLINE_VISIBILITY
2392 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
2393 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2394 _LIBCPP_INLINE_VISIBILITY
2395 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
2396 {return begin() + (__p - cbegin());}
2398 _LIBCPP_INLINE_VISIBILITY
2399 void __copy_assign_alloc(const vector& __v)
2400 {__copy_assign_alloc(__v, integral_constant<bool,
2401 __storage_traits::propagate_on_container_copy_assignment::value>());}
2402 _LIBCPP_INLINE_VISIBILITY
2403 void __copy_assign_alloc(const vector& __c, true_type)
2405 if (__alloc() != __c.__alloc())
2407 __alloc() = __c.__alloc();
2410 _LIBCPP_INLINE_VISIBILITY
2411 void __copy_assign_alloc(const vector&, false_type)
2414 void __move_assign(vector& __c, false_type);
2415 void __move_assign(vector& __c, true_type)
2416 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2417 _LIBCPP_INLINE_VISIBILITY
2418 void __move_assign_alloc(vector& __c)
2420 !__storage_traits::propagate_on_container_move_assignment::value ||
2421 is_nothrow_move_assignable<allocator_type>::value)
2422 {__move_assign_alloc(__c, integral_constant<bool,
2423 __storage_traits::propagate_on_container_move_assignment::value>());}
2424 _LIBCPP_INLINE_VISIBILITY
2425 void __move_assign_alloc(vector& __c, true_type)
2426 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2428 __alloc() = _VSTD::move(__c.__alloc());
2431 _LIBCPP_INLINE_VISIBILITY
2432 void __move_assign_alloc(vector&, false_type)
2436 _LIBCPP_INLINE_VISIBILITY
2437 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
2439 !__storage_traits::propagate_on_container_swap::value ||
2440 __is_nothrow_swappable<allocator_type>::value)
2441 {__swap_alloc(__x, __y, integral_constant<bool,
2442 __storage_traits::propagate_on_container_swap::value>());}
2444 _LIBCPP_INLINE_VISIBILITY
2445 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
2446 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
2451 _LIBCPP_INLINE_VISIBILITY
2452 static void __swap_alloc(__storage_allocator&, __storage_allocator&, false_type)
2456 size_t __hash_code() const _NOEXCEPT;
2458 friend class __bit_reference<vector>;
2459 friend class __bit_const_reference<vector>;
2460 friend class __bit_iterator<vector, false>;
2461 friend class __bit_iterator<vector, true>;
2462 friend struct __bit_array<vector>;
2463 friend struct _LIBCPP_TYPE_VIS_ONLY hash<vector>;
2466 template <class _Allocator>
2467 inline _LIBCPP_INLINE_VISIBILITY
2469 vector<bool, _Allocator>::__invalidate_all_iterators()
2473 // Allocate space for __n objects
2474 // throws length_error if __n > max_size()
2475 // throws (probably bad_alloc) if memory run out
2476 // Precondition: __begin_ == __end_ == __cap() == 0
2477 // Precondition: __n > 0
2478 // Postcondition: capacity() == __n
2479 // Postcondition: size() == 0
2480 template <class _Allocator>
2482 vector<bool, _Allocator>::allocate(size_type __n)
2484 if (__n > max_size())
2485 this->__throw_length_error();
2486 __n = __external_cap_to_internal(__n);
2487 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2489 this->__cap() = __n;
2492 template <class _Allocator>
2494 vector<bool, _Allocator>::deallocate() _NOEXCEPT
2496 if (this->__begin_ != nullptr)
2498 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2499 __invalidate_all_iterators();
2500 this->__begin_ = nullptr;
2501 this->__size_ = this->__cap() = 0;
2505 template <class _Allocator>
2506 typename vector<bool, _Allocator>::size_type
2507 vector<bool, _Allocator>::max_size() const _NOEXCEPT
2509 size_type __amax = __storage_traits::max_size(__alloc());
2510 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2511 if (__nmax / __bits_per_word <= __amax)
2513 return __internal_cap_to_external(__amax);
2516 // Precondition: __new_size > capacity()
2517 template <class _Allocator>
2518 inline _LIBCPP_INLINE_VISIBILITY
2519 typename vector<bool, _Allocator>::size_type
2520 vector<bool, _Allocator>::__recommend(size_type __new_size) const
2522 const size_type __ms = max_size();
2523 if (__new_size > __ms)
2524 this->__throw_length_error();
2525 const size_type __cap = capacity();
2526 if (__cap >= __ms / 2)
2528 return _VSTD::max(2*__cap, __align_it(__new_size));
2531 // Default constructs __n objects starting at __end_
2532 // Precondition: __n > 0
2533 // Precondition: size() + __n <= capacity()
2534 // Postcondition: size() == size() + __n
2535 template <class _Allocator>
2536 inline _LIBCPP_INLINE_VISIBILITY
2538 vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2540 size_type __old_size = this->__size_;
2541 this->__size_ += __n;
2542 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
2545 template <class _Allocator>
2546 template <class _ForwardIterator>
2549 __is_forward_iterator<_ForwardIterator>::value,
2552 vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2554 size_type __old_size = this->__size_;
2555 this->__size_ += _VSTD::distance(__first, __last);
2556 _VSTD::copy(__first, __last, __make_iter(__old_size));
2559 template <class _Allocator>
2560 inline _LIBCPP_INLINE_VISIBILITY
2561 vector<bool, _Allocator>::vector()
2562 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2563 : __begin_(nullptr),
2569 template <class _Allocator>
2570 inline _LIBCPP_INLINE_VISIBILITY
2571 vector<bool, _Allocator>::vector(const allocator_type& __a)
2572 : __begin_(nullptr),
2574 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2578 template <class _Allocator>
2579 vector<bool, _Allocator>::vector(size_type __n)
2580 : __begin_(nullptr),
2587 __construct_at_end(__n, false);
2591 #if _LIBCPP_STD_VER > 11
2592 template <class _Allocator>
2593 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2594 : __begin_(nullptr),
2596 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2601 __construct_at_end(__n, false);
2606 template <class _Allocator>
2607 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2608 : __begin_(nullptr),
2615 __construct_at_end(__n, __x);
2619 template <class _Allocator>
2620 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2621 : __begin_(nullptr),
2623 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2628 __construct_at_end(__n, __x);
2632 template <class _Allocator>
2633 template <class _InputIterator>
2634 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2635 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2636 !__is_forward_iterator<_InputIterator>::value>::type*)
2637 : __begin_(nullptr),
2641 #ifndef _LIBCPP_NO_EXCEPTIONS
2644 #endif // _LIBCPP_NO_EXCEPTIONS
2645 for (; __first != __last; ++__first)
2646 push_back(*__first);
2647 #ifndef _LIBCPP_NO_EXCEPTIONS
2651 if (__begin_ != nullptr)
2652 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2653 __invalidate_all_iterators();
2656 #endif // _LIBCPP_NO_EXCEPTIONS
2659 template <class _Allocator>
2660 template <class _InputIterator>
2661 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2662 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2663 !__is_forward_iterator<_InputIterator>::value>::type*)
2664 : __begin_(nullptr),
2666 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2668 #ifndef _LIBCPP_NO_EXCEPTIONS
2671 #endif // _LIBCPP_NO_EXCEPTIONS
2672 for (; __first != __last; ++__first)
2673 push_back(*__first);
2674 #ifndef _LIBCPP_NO_EXCEPTIONS
2678 if (__begin_ != nullptr)
2679 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2680 __invalidate_all_iterators();
2683 #endif // _LIBCPP_NO_EXCEPTIONS
2686 template <class _Allocator>
2687 template <class _ForwardIterator>
2688 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2689 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2690 : __begin_(nullptr),
2694 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2698 __construct_at_end(__first, __last);
2702 template <class _Allocator>
2703 template <class _ForwardIterator>
2704 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2705 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2706 : __begin_(nullptr),
2708 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2710 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2714 __construct_at_end(__first, __last);
2718 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2720 template <class _Allocator>
2721 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2722 : __begin_(nullptr),
2726 size_type __n = static_cast<size_type>(__il.size());
2730 __construct_at_end(__il.begin(), __il.end());
2734 template <class _Allocator>
2735 vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2736 : __begin_(nullptr),
2738 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2740 size_type __n = static_cast<size_type>(__il.size());
2744 __construct_at_end(__il.begin(), __il.end());
2748 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2750 template <class _Allocator>
2751 vector<bool, _Allocator>::~vector()
2753 if (__begin_ != nullptr)
2754 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2755 __invalidate_all_iterators();
2758 template <class _Allocator>
2759 vector<bool, _Allocator>::vector(const vector& __v)
2760 : __begin_(nullptr),
2762 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2766 allocate(__v.size());
2767 __construct_at_end(__v.begin(), __v.end());
2771 template <class _Allocator>
2772 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2773 : __begin_(nullptr),
2775 __cap_alloc_(0, __a)
2779 allocate(__v.size());
2780 __construct_at_end(__v.begin(), __v.end());
2784 template <class _Allocator>
2785 vector<bool, _Allocator>&
2786 vector<bool, _Allocator>::operator=(const vector& __v)
2790 __copy_assign_alloc(__v);
2793 if (__v.__size_ > capacity())
2796 allocate(__v.__size_);
2798 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2800 __size_ = __v.__size_;
2805 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2807 template <class _Allocator>
2808 inline _LIBCPP_INLINE_VISIBILITY
2809 vector<bool, _Allocator>::vector(vector&& __v)
2810 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2811 : __begin_(__v.__begin_),
2812 __size_(__v.__size_),
2813 __cap_alloc_(__v.__cap_alloc_)
2815 __v.__begin_ = nullptr;
2820 template <class _Allocator>
2821 vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2822 : __begin_(nullptr),
2824 __cap_alloc_(0, __a)
2826 if (__a == allocator_type(__v.__alloc()))
2828 this->__begin_ = __v.__begin_;
2829 this->__size_ = __v.__size_;
2830 this->__cap() = __v.__cap();
2831 __v.__begin_ = nullptr;
2832 __v.__cap() = __v.__size_ = 0;
2834 else if (__v.size() > 0)
2836 allocate(__v.size());
2837 __construct_at_end(__v.begin(), __v.end());
2841 template <class _Allocator>
2842 inline _LIBCPP_INLINE_VISIBILITY
2843 vector<bool, _Allocator>&
2844 vector<bool, _Allocator>::operator=(vector&& __v)
2846 __alloc_traits::propagate_on_container_move_assignment::value &&
2847 is_nothrow_move_assignable<allocator_type>::value)
2849 __move_assign(__v, integral_constant<bool,
2850 __storage_traits::propagate_on_container_move_assignment::value>());
2854 template <class _Allocator>
2856 vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2858 if (__alloc() != __c.__alloc())
2859 assign(__c.begin(), __c.end());
2861 __move_assign(__c, true_type());
2864 template <class _Allocator>
2866 vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2867 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2870 __move_assign_alloc(__c);
2871 this->__begin_ = __c.__begin_;
2872 this->__size_ = __c.__size_;
2873 this->__cap() = __c.__cap();
2874 __c.__begin_ = nullptr;
2875 __c.__cap() = __c.__size_ = 0;
2878 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2880 template <class _Allocator>
2882 vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2887 size_type __c = capacity();
2892 vector __v(__alloc());
2893 __v.reserve(__recommend(__n));
2897 _VSTD::fill_n(begin(), __n, __x);
2901 template <class _Allocator>
2902 template <class _InputIterator>
2905 __is_input_iterator<_InputIterator>::value &&
2906 !__is_forward_iterator<_InputIterator>::value,
2909 vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2912 for (; __first != __last; ++__first)
2913 push_back(*__first);
2916 template <class _Allocator>
2917 template <class _ForwardIterator>
2920 __is_forward_iterator<_ForwardIterator>::value,
2923 vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2926 difference_type __n = _VSTD::distance(__first, __last);
2929 if (__n > capacity())
2934 __construct_at_end(__first, __last);
2938 template <class _Allocator>
2940 vector<bool, _Allocator>::reserve(size_type __n)
2942 if (__n > capacity())
2944 vector __v(this->__alloc());
2946 __v.__construct_at_end(this->begin(), this->end());
2948 __invalidate_all_iterators();
2952 template <class _Allocator>
2954 vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
2956 if (__external_cap_to_internal(size()) > __cap())
2958 #ifndef _LIBCPP_NO_EXCEPTIONS
2961 #endif // _LIBCPP_NO_EXCEPTIONS
2962 vector(*this, allocator_type(__alloc())).swap(*this);
2963 #ifndef _LIBCPP_NO_EXCEPTIONS
2968 #endif // _LIBCPP_NO_EXCEPTIONS
2972 template <class _Allocator>
2973 typename vector<bool, _Allocator>::reference
2974 vector<bool, _Allocator>::at(size_type __n)
2977 this->__throw_out_of_range();
2978 return (*this)[__n];
2981 template <class _Allocator>
2982 typename vector<bool, _Allocator>::const_reference
2983 vector<bool, _Allocator>::at(size_type __n) const
2986 this->__throw_out_of_range();
2987 return (*this)[__n];
2990 template <class _Allocator>
2992 vector<bool, _Allocator>::push_back(const value_type& __x)
2994 if (this->__size_ == this->capacity())
2995 reserve(__recommend(this->__size_ + 1));
3000 template <class _Allocator>
3001 typename vector<bool, _Allocator>::iterator
3002 vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
3005 if (size() < capacity())
3007 const_iterator __old_end = end();
3009 _VSTD::copy_backward(__position, __old_end, end());
3010 __r = __const_iterator_cast(__position);
3014 vector __v(__alloc());
3015 __v.reserve(__recommend(__size_ + 1));
3016 __v.__size_ = __size_ + 1;
3017 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3018 _VSTD::copy_backward(__position, cend(), __v.end());
3025 template <class _Allocator>
3026 typename vector<bool, _Allocator>::iterator
3027 vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
3030 size_type __c = capacity();
3031 if (__n <= __c && size() <= __c - __n)
3033 const_iterator __old_end = end();
3035 _VSTD::copy_backward(__position, __old_end, end());
3036 __r = __const_iterator_cast(__position);
3040 vector __v(__alloc());
3041 __v.reserve(__recommend(__size_ + __n));
3042 __v.__size_ = __size_ + __n;
3043 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3044 _VSTD::copy_backward(__position, cend(), __v.end());
3047 _VSTD::fill_n(__r, __n, __x);
3051 template <class _Allocator>
3052 template <class _InputIterator>
3055 __is_input_iterator <_InputIterator>::value &&
3056 !__is_forward_iterator<_InputIterator>::value,
3057 typename vector<bool, _Allocator>::iterator
3059 vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
3061 difference_type __off = __position - begin();
3062 iterator __p = __const_iterator_cast(__position);
3063 iterator __old_end = end();
3064 for (; size() != capacity() && __first != __last; ++__first)
3069 vector __v(__alloc());
3070 if (__first != __last)
3072 #ifndef _LIBCPP_NO_EXCEPTIONS
3075 #endif // _LIBCPP_NO_EXCEPTIONS
3076 __v.assign(__first, __last);
3077 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
3078 difference_type __old_p = __p - begin();
3079 reserve(__recommend(size() + __v.size()));
3080 __p = begin() + __old_p;
3081 __old_end = begin() + __old_size;
3082 #ifndef _LIBCPP_NO_EXCEPTIONS
3086 erase(__old_end, end());
3089 #endif // _LIBCPP_NO_EXCEPTIONS
3091 __p = _VSTD::rotate(__p, __old_end, end());
3092 insert(__p, __v.begin(), __v.end());
3093 return begin() + __off;
3096 template <class _Allocator>
3097 template <class _ForwardIterator>
3100 __is_forward_iterator<_ForwardIterator>::value,
3101 typename vector<bool, _Allocator>::iterator
3103 vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
3105 difference_type __n = _VSTD::distance(__first, __last);
3107 size_type __c = capacity();
3108 if (__n <= __c && size() <= __c - __n)
3110 const_iterator __old_end = end();
3112 _VSTD::copy_backward(__position, __old_end, end());
3113 __r = __const_iterator_cast(__position);
3117 vector __v(__alloc());
3118 __v.reserve(__recommend(__size_ + __n));
3119 __v.__size_ = __size_ + __n;
3120 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3121 _VSTD::copy_backward(__position, cend(), __v.end());
3124 _VSTD::copy(__first, __last, __r);
3128 template <class _Allocator>
3129 inline _LIBCPP_INLINE_VISIBILITY
3130 typename vector<bool, _Allocator>::iterator
3131 vector<bool, _Allocator>::erase(const_iterator __position)
3133 iterator __r = __const_iterator_cast(__position);
3134 _VSTD::copy(__position + 1, this->cend(), __r);
3139 template <class _Allocator>
3140 typename vector<bool, _Allocator>::iterator
3141 vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3143 iterator __r = __const_iterator_cast(__first);
3144 difference_type __d = __last - __first;
3145 _VSTD::copy(__last, this->cend(), __r);
3150 template <class _Allocator>
3152 vector<bool, _Allocator>::swap(vector& __x)
3153 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3154 __is_nothrow_swappable<allocator_type>::value)
3156 _VSTD::swap(this->__begin_, __x.__begin_);
3157 _VSTD::swap(this->__size_, __x.__size_);
3158 _VSTD::swap(this->__cap(), __x.__cap());
3159 __swap_alloc(this->__alloc(), __x.__alloc());
3162 template <class _Allocator>
3164 vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3166 size_type __cs = size();
3170 size_type __c = capacity();
3171 size_type __n = __sz - __cs;
3172 if (__n <= __c && __cs <= __c - __n)
3179 vector __v(__alloc());
3180 __v.reserve(__recommend(__size_ + __n));
3181 __v.__size_ = __size_ + __n;
3182 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
3185 _VSTD::fill_n(__r, __n, __x);
3191 template <class _Allocator>
3193 vector<bool, _Allocator>::flip() _NOEXCEPT
3195 // do middle whole words
3196 size_type __n = __size_;
3197 __storage_pointer __p = __begin_;
3198 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3200 // do last partial word
3203 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3204 __storage_type __b = *__p & __m;
3210 template <class _Allocator>
3212 vector<bool, _Allocator>::__invariants() const
3214 if (this->__begin_ == nullptr)
3216 if (this->__size_ != 0 || this->__cap() != 0)
3221 if (this->__cap() == 0)
3223 if (this->__size_ > this->capacity())
3229 template <class _Allocator>
3231 vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
3234 // do middle whole words
3235 size_type __n = __size_;
3236 __storage_pointer __p = __begin_;
3237 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3239 // do last partial word
3242 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3248 template <class _Allocator>
3249 struct _LIBCPP_TYPE_VIS_ONLY hash<vector<bool, _Allocator> >
3250 : public unary_function<vector<bool, _Allocator>, size_t>
3252 _LIBCPP_INLINE_VISIBILITY
3253 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
3254 {return __vec.__hash_code();}
3257 template <class _Tp, class _Allocator>
3258 inline _LIBCPP_INLINE_VISIBILITY
3260 operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3262 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
3263 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3266 template <class _Tp, class _Allocator>
3267 inline _LIBCPP_INLINE_VISIBILITY
3269 operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3271 return !(__x == __y);
3274 template <class _Tp, class _Allocator>
3275 inline _LIBCPP_INLINE_VISIBILITY
3277 operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3279 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
3282 template <class _Tp, class _Allocator>
3283 inline _LIBCPP_INLINE_VISIBILITY
3285 operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3290 template <class _Tp, class _Allocator>
3291 inline _LIBCPP_INLINE_VISIBILITY
3293 operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3295 return !(__x < __y);
3298 template <class _Tp, class _Allocator>
3299 inline _LIBCPP_INLINE_VISIBILITY
3301 operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3303 return !(__y < __x);
3306 template <class _Tp, class _Allocator>
3307 inline _LIBCPP_INLINE_VISIBILITY
3309 swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
3310 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
3315 _LIBCPP_END_NAMESPACE_STD
3317 #endif // _LIBCPP_VECTOR