blob: 1e638b9a4d9a749d0ecd4d12e2061ef5514327a2 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------------ vector --------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_VECTOR
12#define _LIBCPP_VECTOR
13
14/*
15 vector synopsis
16
17namespace std
18{
19
Howard Hinnant324bb032010-08-22 00:02:43 +000020template <class T, class Allocator = allocator<T> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021class vector
Howard Hinnant324bb032010-08-22 00:02:43 +000022{
23public:
24 typedef T value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000025 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;
36
Howard Hinnantd1d27a42011-06-03 19:40:40 +000037 vector()
38 noexcept(is_nothrow_default_constructible<allocator_type>::value);
39 explicit vector(const allocator_type&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000040 explicit vector(size_type n);
Marshall Clowa49a2c92013-09-14 00:47:59 +000041 explicit vector(size_type n, const allocator_type&); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000042 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);
Howard Hinnantd1d27a42011-06-03 19:40:40 +000046 vector(vector&& x)
47 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000048 vector(initializer_list<value_type> il);
49 vector(initializer_list<value_type> il, const allocator_type& a);
50 ~vector();
51 vector& operator=(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +000052 vector& operator=(vector&& x)
53 noexcept(
54 allocator_type::propagate_on_container_move_assignment::value &&
55 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056 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);
61
Howard Hinnantd1d27a42011-06-03 19:40:40 +000062 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000063
Howard Hinnantd1d27a42011-06-03 19:40:40 +000064 iterator begin() noexcept;
65 const_iterator begin() const noexcept;
66 iterator end() noexcept;
67 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000068
Howard Hinnantd1d27a42011-06-03 19:40:40 +000069 reverse_iterator rbegin() noexcept;
70 const_reverse_iterator rbegin() const noexcept;
71 reverse_iterator rend() noexcept;
72 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000073
Howard Hinnantd1d27a42011-06-03 19:40:40 +000074 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;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078
Howard Hinnantd1d27a42011-06-03 19:40:40 +000079 size_type size() const noexcept;
80 size_type max_size() const noexcept;
81 size_type capacity() const noexcept;
82 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000083 void reserve(size_type n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +000084 void shrink_to_fit() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000085
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;
90
91 reference front();
92 const_reference front() const;
93 reference back();
94 const_reference back() const;
95
Howard Hinnantd1d27a42011-06-03 19:40:40 +000096 value_type* data() noexcept;
97 const value_type* data() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098
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);
103 void pop_back();
104
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);
112
113 iterator erase(const_iterator position);
114 iterator erase(const_iterator first, const_iterator last);
115
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000116 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000117
118 void resize(size_type sz);
119 void resize(size_type sz, const value_type& c);
120
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000121 void swap(vector&)
122 noexcept(!allocator_type::propagate_on_container_swap::value ||
123 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000124
125 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43 +0000126};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000127
Howard Hinnant324bb032010-08-22 00:02:43 +0000128template <class Allocator = allocator<T> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000129class vector<bool, Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000130{
131public:
132 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000133 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;
142
143 class reference
144 {
145 public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000146 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;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000152 };
153
154 class const_reference
155 {
156 public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000157 const_reference(const reference&) noexcept;
158 operator bool() const noexcept;
159 const_iterator operator&() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000160 };
161
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000162 vector()
163 noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant9cbee432011-09-02 20:42:31 +0000164 explicit vector(const allocator_type&);
Marshall Clowa49a2c92013-09-14 00:47:59 +0000165 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());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000167 template <class InputIterator>
168 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
169 vector(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000170 vector(vector&& x)
171 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000172 vector(initializer_list<value_type> il);
173 vector(initializer_list<value_type> il, const allocator_type& a);
174 ~vector();
175 vector& operator=(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000176 vector& operator=(vector&& x)
177 noexcept(
178 allocator_type::propagate_on_container_move_assignment::value &&
179 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000180 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);
185
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000186 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000187
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000188 iterator begin() noexcept;
189 const_iterator begin() const noexcept;
190 iterator end() noexcept;
191 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000192
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000193 reverse_iterator rbegin() noexcept;
194 const_reverse_iterator rbegin() const noexcept;
195 reverse_iterator rend() noexcept;
196 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000197
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000198 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;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000202
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000203 size_type size() const noexcept;
204 size_type max_size() const noexcept;
205 size_type capacity() const noexcept;
206 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000207 void reserve(size_type n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000208 void shrink_to_fit() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209
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;
214
215 reference front();
216 const_reference front() const;
217 reference back();
218 const_reference back() const;
219
220 void push_back(const value_type& x);
Marshall Clow198a2a52013-08-13 23:54:12 +0000221 template <class... Args> void emplace_back(Args&&... args); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000222 void pop_back();
223
Marshall Clow198a2a52013-08-13 23:54:12 +0000224 template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225 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);
230
231 iterator erase(const_iterator position);
232 iterator erase(const_iterator first, const_iterator last);
233
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000234 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235
236 void resize(size_type sz);
237 void resize(size_type sz, value_type x);
238
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000239 void swap(vector&)
240 noexcept(!allocator_type::propagate_on_container_swap::value ||
241 __is_nothrow_swappable<allocator_type>::value);
242 void flip() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243
244 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43 +0000245};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000246
247template <class Allocator> struct hash<std::vector<bool, Allocator>>;
248
249template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
250template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
251template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
252template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
253template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
254template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
255
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000256template <class T, class Allocator>
257void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
258 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000259
260} // std
261
262*/
263
264#include <__config>
265#include <__bit_reference>
266#include <type_traits>
267#include <climits>
268#include <limits>
269#include <initializer_list>
270#include <memory>
271#include <stdexcept>
272#include <algorithm>
273#include <cstring>
274#include <__split_buffer>
275#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
Howard Hinnant66c6f972011-11-29 16:45:27 +0000277#include <__undef_min_max>
278
Howard Hinnant5e571422013-08-23 20:10:18 +0000279#ifdef _LIBCPP_DEBUG
Howard Hinnant8b00e6c2013-08-02 00:26:35 +0000280# include <__debug>
281#else
282# define _LIBCPP_ASSERT(x, m) ((void)0)
283#endif
284
Howard Hinnant08e17472011-10-17 20:05:10 +0000285#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000287#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000288
289_LIBCPP_BEGIN_NAMESPACE_STD
290
291template <bool>
292class __vector_base_common
293{
294protected:
295 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
296 void __throw_length_error() const;
297 void __throw_out_of_range() const;
298};
299
300template <bool __b>
301void
302__vector_base_common<__b>::__throw_length_error() const
303{
304#ifndef _LIBCPP_NO_EXCEPTIONS
305 throw length_error("vector");
306#else
307 assert(!"vector length_error");
308#endif
309}
310
311template <bool __b>
312void
313__vector_base_common<__b>::__throw_out_of_range() const
314{
315#ifndef _LIBCPP_NO_EXCEPTIONS
316 throw out_of_range("vector");
317#else
318 assert(!"vector out_of_range");
319#endif
320}
321
Howard Hinnante9df0a52013-08-01 18:17:34 +0000322#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000323#pragma warning( push )
324#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000325#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000326_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +0000327#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000328#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000329#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000330
331template <class _Tp, class _Allocator>
332class __vector_base
333 : protected __vector_base_common<true>
334{
335protected:
Howard Hinnant324bb032010-08-22 00:02:43 +0000336 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337 typedef _Allocator allocator_type;
338 typedef allocator_traits<allocator_type> __alloc_traits;
339 typedef value_type& reference;
340 typedef const value_type& const_reference;
341 typedef typename __alloc_traits::size_type size_type;
342 typedef typename __alloc_traits::difference_type difference_type;
343 typedef typename __alloc_traits::pointer pointer;
344 typedef typename __alloc_traits::const_pointer const_pointer;
345 typedef pointer iterator;
346 typedef const_pointer const_iterator;
347
348 pointer __begin_;
349 pointer __end_;
350 __compressed_pair<pointer, allocator_type> __end_cap_;
351
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000352 _LIBCPP_INLINE_VISIBILITY
353 allocator_type& __alloc() _NOEXCEPT
354 {return __end_cap_.second();}
355 _LIBCPP_INLINE_VISIBILITY
356 const allocator_type& __alloc() const _NOEXCEPT
357 {return __end_cap_.second();}
358 _LIBCPP_INLINE_VISIBILITY
359 pointer& __end_cap() _NOEXCEPT
360 {return __end_cap_.first();}
361 _LIBCPP_INLINE_VISIBILITY
362 const pointer& __end_cap() const _NOEXCEPT
363 {return __end_cap_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000365 _LIBCPP_INLINE_VISIBILITY
366 __vector_base()
367 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000368 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369 ~__vector_base();
370
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000371 _LIBCPP_INLINE_VISIBILITY
372 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
373 _LIBCPP_INLINE_VISIBILITY
374 size_type capacity() const _NOEXCEPT
375 {return static_cast<size_type>(__end_cap() - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000378 void __destruct_at_end(pointer __new_last) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000379
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000380 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381 void __copy_assign_alloc(const __vector_base& __c)
382 {__copy_assign_alloc(__c, integral_constant<bool,
383 __alloc_traits::propagate_on_container_copy_assignment::value>());}
384
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000385 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386 void __move_assign_alloc(__vector_base& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000387 _NOEXCEPT_(
388 !__alloc_traits::propagate_on_container_move_assignment::value ||
389 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390 {__move_assign_alloc(__c, integral_constant<bool,
391 __alloc_traits::propagate_on_container_move_assignment::value>());}
392
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000393 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000395 _NOEXCEPT_(
396 !__alloc_traits::propagate_on_container_swap::value ||
397 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000398 {__swap_alloc(__x, __y, integral_constant<bool,
399 __alloc_traits::propagate_on_container_swap::value>());}
400private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 void __copy_assign_alloc(const __vector_base& __c, true_type)
403 {
404 if (__alloc() != __c.__alloc())
405 {
406 clear();
407 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
408 __begin_ = __end_ = __end_cap() = nullptr;
409 }
410 __alloc() = __c.__alloc();
411 }
412
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +0000414 void __copy_assign_alloc(const __vector_base&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415 {}
416
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000418 void __move_assign_alloc(__vector_base& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000419 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000421 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422 }
423
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +0000425 void __move_assign_alloc(__vector_base&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000426 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427 {}
428
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000431 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000433 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434 swap(__x, __y);
435 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000436 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +0000437 static void __swap_alloc(allocator_type&, allocator_type&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000438 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 {}
440};
441
442template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000443inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444void
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000445__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446{
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000447 while (__new_last != __end_)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000448 __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449}
450
451template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000452inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000453__vector_base<_Tp, _Allocator>::__vector_base()
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000454 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000455 : __begin_(nullptr),
456 __end_(nullptr),
457 __end_cap_(nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000458{
459}
460
461template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000462inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000464 : __begin_(nullptr),
465 __end_(nullptr),
466 __end_cap_(nullptr, __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467{
468}
469
470template <class _Tp, class _Allocator>
471__vector_base<_Tp, _Allocator>::~__vector_base()
472{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000473 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474 {
475 clear();
476 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
477 }
478}
479
480template <class _Tp, class _Allocator = allocator<_Tp> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000481class _LIBCPP_TYPE_VIS_ONLY vector
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482 : private __vector_base<_Tp, _Allocator>
483{
484private:
485 typedef __vector_base<_Tp, _Allocator> __base;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000486 typedef allocator<_Tp> __default_allocator_type;
Howard Hinnant324bb032010-08-22 00:02:43 +0000487public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000488 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +0000489 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 typedef _Allocator allocator_type;
491 typedef typename __base::__alloc_traits __alloc_traits;
492 typedef typename __base::reference reference;
493 typedef typename __base::const_reference const_reference;
494 typedef typename __base::size_type size_type;
495 typedef typename __base::difference_type difference_type;
496 typedef typename __base::pointer pointer;
497 typedef typename __base::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498 typedef __wrap_iter<pointer> iterator;
499 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000500 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
501 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000502
Howard Hinnant02d5e182013-03-26 19:04:56 +0000503 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
504 "Allocator::value_type must be same type as value_type");
505
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000506 _LIBCPP_INLINE_VISIBILITY
507 vector()
508 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant7a563db2011-09-14 18:33:51 +0000509 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000510#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000511 __get_db()->__insert_c(this);
512#endif
513 }
514 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
515 : __base(__a)
516 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000517#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000518 __get_db()->__insert_c(this);
519#endif
520 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521 explicit vector(size_type __n);
Marshall Clowa49a2c92013-09-14 00:47:59 +0000522#if _LIBCPP_STD_VER > 11
523 explicit vector(size_type __n, const allocator_type& __a);
524#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525 vector(size_type __n, const_reference __x);
526 vector(size_type __n, const_reference __x, const allocator_type& __a);
527 template <class _InputIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +0000528 vector(_InputIterator __first,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000530 !__is_forward_iterator<_InputIterator>::value &&
531 is_constructible<
532 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +0000533 typename iterator_traits<_InputIterator>::reference>::value,
534 _InputIterator>::type __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000535 template <class _InputIterator>
536 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
537 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000538 !__is_forward_iterator<_InputIterator>::value &&
539 is_constructible<
540 value_type,
541 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000542 template <class _ForwardIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +0000543 vector(_ForwardIterator __first,
Howard Hinnant742fecb2013-03-28 17:44:32 +0000544 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
545 is_constructible<
546 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +0000547 typename iterator_traits<_ForwardIterator>::reference>::value,
548 _ForwardIterator>::type __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549 template <class _ForwardIterator>
550 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
Howard Hinnant742fecb2013-03-28 17:44:32 +0000551 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
552 is_constructible<
553 value_type,
554 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02 +0000555#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557 vector(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000560#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantabe26282011-09-16 17:29:17 +0000561#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a563db2011-09-14 18:33:51 +0000563 ~vector()
564 {
565 __get_db()->__erase_c(this);
566 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567#endif
568
569 vector(const vector& __x);
570 vector(const vector& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572 vector& operator=(const vector& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000573#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000574 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000575 vector(vector&& __x)
576 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000578 vector(vector&& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000580 vector& operator=(vector&& __x)
581 _NOEXCEPT_(
582 __alloc_traits::propagate_on_container_move_assignment::value &&
583 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000584#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000585#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000587 vector& operator=(initializer_list<value_type> __il)
588 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000589#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590
591 template <class _InputIterator>
592 typename enable_if
593 <
594 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000595 !__is_forward_iterator<_InputIterator>::value &&
596 is_constructible<
597 value_type,
598 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599 void
600 >::type
601 assign(_InputIterator __first, _InputIterator __last);
602 template <class _ForwardIterator>
603 typename enable_if
604 <
Howard Hinnant742fecb2013-03-28 17:44:32 +0000605 __is_forward_iterator<_ForwardIterator>::value &&
606 is_constructible<
607 value_type,
608 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609 void
610 >::type
611 assign(_ForwardIterator __first, _ForwardIterator __last);
612
613 void assign(size_type __n, const_reference __u);
Howard Hinnante3e32912011-08-12 21:56:02 +0000614#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616 void assign(initializer_list<value_type> __il)
617 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000618#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000620 _LIBCPP_INLINE_VISIBILITY
621 allocator_type get_allocator() const _NOEXCEPT
622 {return this->__alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000623
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000624 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
625 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
626 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
627 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000629 _LIBCPP_INLINE_VISIBILITY
630 reverse_iterator rbegin() _NOEXCEPT
631 {return reverse_iterator(end());}
632 _LIBCPP_INLINE_VISIBILITY
633 const_reverse_iterator rbegin() const _NOEXCEPT
634 {return const_reverse_iterator(end());}
635 _LIBCPP_INLINE_VISIBILITY
636 reverse_iterator rend() _NOEXCEPT
637 {return reverse_iterator(begin());}
638 _LIBCPP_INLINE_VISIBILITY
639 const_reverse_iterator rend() const _NOEXCEPT
640 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000642 _LIBCPP_INLINE_VISIBILITY
643 const_iterator cbegin() const _NOEXCEPT
644 {return begin();}
645 _LIBCPP_INLINE_VISIBILITY
646 const_iterator cend() const _NOEXCEPT
647 {return end();}
648 _LIBCPP_INLINE_VISIBILITY
649 const_reverse_iterator crbegin() const _NOEXCEPT
650 {return rbegin();}
651 _LIBCPP_INLINE_VISIBILITY
652 const_reverse_iterator crend() const _NOEXCEPT
653 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000655 _LIBCPP_INLINE_VISIBILITY
656 size_type size() const _NOEXCEPT
657 {return static_cast<size_type>(this->__end_ - this->__begin_);}
658 _LIBCPP_INLINE_VISIBILITY
659 size_type capacity() const _NOEXCEPT
660 {return __base::capacity();}
661 _LIBCPP_INLINE_VISIBILITY
662 bool empty() const _NOEXCEPT
663 {return this->__begin_ == this->__end_;}
664 size_type max_size() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000666 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667
668 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
669 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
670 reference at(size_type __n);
671 const_reference at(size_type __n) const;
672
Howard Hinnant7a563db2011-09-14 18:33:51 +0000673 _LIBCPP_INLINE_VISIBILITY reference front()
674 {
675 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
676 return *this->__begin_;
677 }
678 _LIBCPP_INLINE_VISIBILITY const_reference front() const
679 {
680 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
681 return *this->__begin_;
682 }
683 _LIBCPP_INLINE_VISIBILITY reference back()
684 {
685 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
686 return *(this->__end_ - 1);
687 }
688 _LIBCPP_INLINE_VISIBILITY const_reference back() const
689 {
690 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
691 return *(this->__end_ - 1);
692 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000694 _LIBCPP_INLINE_VISIBILITY
695 value_type* data() _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000696 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000697 _LIBCPP_INLINE_VISIBILITY
698 const value_type* data() const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000699 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000700
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000701 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000702#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000703 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000704#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705 template <class... _Args>
706 void emplace_back(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000707#endif // _LIBCPP_HAS_NO_VARIADICS
708#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000709 void pop_back();
710
711 iterator insert(const_iterator __position, const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000712#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 iterator insert(const_iterator __position, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000714#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715 template <class... _Args>
716 iterator emplace(const_iterator __position, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000717#endif // _LIBCPP_HAS_NO_VARIADICS
718#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000719 iterator insert(const_iterator __position, size_type __n, const_reference __x);
720 template <class _InputIterator>
721 typename enable_if
722 <
723 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000724 !__is_forward_iterator<_InputIterator>::value &&
725 is_constructible<
726 value_type,
727 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728 iterator
729 >::type
730 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
731 template <class _ForwardIterator>
732 typename enable_if
733 <
Howard Hinnant742fecb2013-03-28 17:44:32 +0000734 __is_forward_iterator<_ForwardIterator>::value &&
735 is_constructible<
736 value_type,
737 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738 iterator
739 >::type
740 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000741#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743 iterator insert(const_iterator __position, initializer_list<value_type> __il)
744 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000745#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000747 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000748 iterator erase(const_iterator __first, const_iterator __last);
749
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000750 _LIBCPP_INLINE_VISIBILITY
751 void clear() _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +0000752 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000753 size_type __old_size = size();
Howard Hinnant7a563db2011-09-14 18:33:51 +0000754 __base::clear();
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000755 __annotate_shrink(__old_size);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000756 __invalidate_all_iterators();
757 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000758
759 void resize(size_type __sz);
760 void resize(size_type __sz, const_reference __x);
761
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000762 void swap(vector&)
763 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
764 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765
766 bool __invariants() const;
767
Howard Hinnantabe26282011-09-16 17:29:17 +0000768#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000769
770 bool __dereferenceable(const const_iterator* __i) const;
771 bool __decrementable(const const_iterator* __i) const;
772 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
773 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
774
Howard Hinnantabe26282011-09-16 17:29:17 +0000775#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000776
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000778 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000780 void deallocate() _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000781 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
Howard Hinnant04240d92011-01-04 19:53:31 +0000782 void __construct_at_end(size_type __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000783 void __construct_at_end(size_type __n, const_reference __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784 template <class _ForwardIterator>
785 typename enable_if
786 <
787 __is_forward_iterator<_ForwardIterator>::value,
788 void
789 >::type
790 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
791 void __move_construct_at_end(pointer __first, pointer __last);
792 void __append(size_type __n);
793 void __append(size_type __n, const_reference __x);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000795 iterator __make_iter(pointer __p) _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000797 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000798 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
799 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
800 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000801 void __move_assign(vector& __c, true_type)
802 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 void __move_assign(vector& __c, false_type);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000804 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000805 void __destruct_at_end(pointer __new_last) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +0000806 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000807#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000808 __c_node* __c = __get_db()->__find_c_and_lock(this);
809 for (__i_node** __p = __c->end_; __p != __c->beg_; )
810 {
811 --__p;
812 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
813 if (__i->base() > __new_last)
814 {
815 (*__p)->__c_ = nullptr;
816 if (--__c->end_ != __p)
817 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
818 }
819 }
820 __get_db()->unlock();
821#endif
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000822 size_type __old_size = size();
Howard Hinnant7a563db2011-09-14 18:33:51 +0000823 __base::__destruct_at_end(__new_last);
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000824 __annotate_shrink(__old_size);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000825 }
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000826 template <class _Up>
827 void
828#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
829 __push_back_slow_path(_Up&& __x);
830#else
831 __push_back_slow_path(_Up& __x);
832#endif
Howard Hinnant0438ea22012-02-26 15:30:12 +0000833#if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
834 template <class... _Args>
835 void
836 __emplace_back_slow_path(_Args&&... __args);
837#endif
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000838 // The following functions are no-ops outside of AddressSanitizer mode.
839 // We call annotatations only for the default Allocator because other allocators
840 // may not meet the AddressSanitizer alignment constraints.
841 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
842 void __annotate_contiguous_container
843 (const void *__beg, const void *__end, const void *__old_mid, const void *__new_mid)
844 {
845#ifndef _LIBCPP_HAS_NO_ASAN
846 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
847 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
848#endif
849 }
850
851 void __annotate_new(size_type __current_size)
852 {
853 __annotate_contiguous_container(data(), data() + capacity(),
854 data() + capacity(), data() + __current_size);
855 }
856 void __annotate_delete()
857 {
858 __annotate_contiguous_container(data(), data() + capacity(),
859 data() + size(), data() + capacity());
860 }
861 void __annotate_increase(size_type __n)
862 {
863 __annotate_contiguous_container(data(), data() + capacity(),
864 data() + size(), data() + size() + __n);
865 }
866 void __annotate_shrink(size_type __old_size)
867 {
868 __annotate_contiguous_container(data(), data() + capacity(),
869 data() + __old_size, data() + size());
870 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871};
872
873template <class _Tp, class _Allocator>
874void
875vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
876{
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000877 __annotate_delete();
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000878 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000879 _VSTD::swap(this->__begin_, __v.__begin_);
880 _VSTD::swap(this->__end_, __v.__end_);
881 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000882 __v.__first_ = __v.__begin_;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000883 __annotate_new(size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000884 __invalidate_all_iterators();
885}
886
887template <class _Tp, class _Allocator>
888typename vector<_Tp, _Allocator>::pointer
889vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
890{
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000891 __annotate_delete();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892 pointer __r = __v.__begin_;
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000893 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
894 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000895 _VSTD::swap(this->__begin_, __v.__begin_);
896 _VSTD::swap(this->__end_, __v.__end_);
897 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000898 __v.__first_ = __v.__begin_;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000899 __annotate_new(size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000900 __invalidate_all_iterators();
901 return __r;
902}
903
904// Allocate space for __n objects
905// throws length_error if __n > max_size()
906// throws (probably bad_alloc) if memory run out
907// Precondition: __begin_ == __end_ == __end_cap() == 0
908// Precondition: __n > 0
909// Postcondition: capacity() == __n
910// Postcondition: size() == 0
911template <class _Tp, class _Allocator>
912void
913vector<_Tp, _Allocator>::allocate(size_type __n)
914{
915 if (__n > max_size())
916 this->__throw_length_error();
917 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
918 this->__end_cap() = this->__begin_ + __n;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000919 __annotate_new(0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920}
921
922template <class _Tp, class _Allocator>
923void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000924vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000926 if (this->__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927 {
928 clear();
929 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000930 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000931 }
932}
933
934template <class _Tp, class _Allocator>
935typename vector<_Tp, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000936vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000937{
Sean Hunt110b8bf2011-07-29 23:31:58 +0000938 return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2); // end() >= begin(), always
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000939}
940
941// Precondition: __new_size > capacity()
942template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000944typename vector<_Tp, _Allocator>::size_type
945vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
946{
947 const size_type __ms = max_size();
948 if (__new_size > __ms)
949 this->__throw_length_error();
950 const size_type __cap = capacity();
951 if (__cap >= __ms / 2)
952 return __ms;
Sean Hunt110b8bf2011-07-29 23:31:58 +0000953 return _VSTD::max<size_type>(2*__cap, __new_size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954}
955
956// Default constructs __n objects starting at __end_
957// throws if construction throws
958// Precondition: __n > 0
959// Precondition: size() + __n <= capacity()
960// Postcondition: size() == size() + __n
961template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000962void
963vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
964{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965 allocator_type& __a = this->__alloc();
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000966 __annotate_increase(__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967 do
968 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000969 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000970 ++this->__end_;
971 --__n;
972 } while (__n > 0);
973}
974
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000975// Copy constructs __n objects starting at __end_ from __x
976// throws if construction throws
977// Precondition: __n > 0
978// Precondition: size() + __n <= capacity()
979// Postcondition: size() == old size() + __n
980// Postcondition: [i] == __x for all i in [size() - __n, __n)
981template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000982inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983void
984vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
985{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986 allocator_type& __a = this->__alloc();
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000987 __annotate_increase(__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000988 do
989 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000990 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991 ++this->__end_;
992 --__n;
993 } while (__n > 0);
994}
995
996template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000997template <class _ForwardIterator>
998typename enable_if
999<
1000 __is_forward_iterator<_ForwardIterator>::value,
1001 void
1002>::type
1003vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
1004{
1005 allocator_type& __a = this->__alloc();
1006 for (; __first != __last; ++__first)
1007 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001008 __annotate_increase(1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001009 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010 ++this->__end_;
1011 }
1012}
1013
1014template <class _Tp, class _Allocator>
1015void
1016vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
1017{
1018 allocator_type& __a = this->__alloc();
1019 for (; __first != __last; ++__first)
1020 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001021 __annotate_increase(1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001022 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
1023 _VSTD::move(*__first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001024 ++this->__end_;
1025 }
1026}
1027
1028// Default constructs __n objects starting at __end_
1029// throws if construction throws
1030// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001031// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001032template <class _Tp, class _Allocator>
1033void
1034vector<_Tp, _Allocator>::__append(size_type __n)
1035{
1036 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1037 this->__construct_at_end(__n);
1038 else
1039 {
1040 allocator_type& __a = this->__alloc();
1041 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1042 __v.__construct_at_end(__n);
1043 __swap_out_circular_buffer(__v);
1044 }
1045}
1046
1047// Default constructs __n objects starting at __end_
1048// throws if construction throws
1049// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001050// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001051template <class _Tp, class _Allocator>
1052void
1053vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1054{
1055 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1056 this->__construct_at_end(__n, __x);
1057 else
1058 {
1059 allocator_type& __a = this->__alloc();
1060 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1061 __v.__construct_at_end(__n, __x);
1062 __swap_out_circular_buffer(__v);
1063 }
1064}
1065
1066template <class _Tp, class _Allocator>
1067vector<_Tp, _Allocator>::vector(size_type __n)
1068{
Howard Hinnant0442b122011-09-16 18:41:29 +00001069#if _LIBCPP_DEBUG_LEVEL >= 2
1070 __get_db()->__insert_c(this);
1071#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072 if (__n > 0)
1073 {
1074 allocate(__n);
1075 __construct_at_end(__n);
1076 }
1077}
1078
Marshall Clowa49a2c92013-09-14 00:47:59 +00001079#if _LIBCPP_STD_VER > 11
1080template <class _Tp, class _Allocator>
1081vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1082 : __base(__a)
1083{
1084#if _LIBCPP_DEBUG_LEVEL >= 2
1085 __get_db()->__insert_c(this);
1086#endif
1087 if (__n > 0)
1088 {
1089 allocate(__n);
1090 __construct_at_end(__n);
1091 }
1092}
1093#endif
1094
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001095template <class _Tp, class _Allocator>
1096vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1097{
Howard Hinnant0442b122011-09-16 18:41:29 +00001098#if _LIBCPP_DEBUG_LEVEL >= 2
1099 __get_db()->__insert_c(this);
1100#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001101 if (__n > 0)
1102 {
1103 allocate(__n);
1104 __construct_at_end(__n, __x);
1105 }
1106}
1107
1108template <class _Tp, class _Allocator>
1109vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1110 : __base(__a)
1111{
Howard Hinnant0442b122011-09-16 18:41:29 +00001112#if _LIBCPP_DEBUG_LEVEL >= 2
1113 __get_db()->__insert_c(this);
1114#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001115 if (__n > 0)
1116 {
1117 allocate(__n);
1118 __construct_at_end(__n, __x);
1119 }
1120}
1121
1122template <class _Tp, class _Allocator>
1123template <class _InputIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +00001124vector<_Tp, _Allocator>::vector(_InputIterator __first,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001125 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001126 !__is_forward_iterator<_InputIterator>::value &&
1127 is_constructible<
1128 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +00001129 typename iterator_traits<_InputIterator>::reference>::value,
1130 _InputIterator>::type __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131{
Howard Hinnantabe26282011-09-16 17:29:17 +00001132#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001133 __get_db()->__insert_c(this);
1134#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001135 for (; __first != __last; ++__first)
1136 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001137}
1138
1139template <class _Tp, class _Allocator>
1140template <class _InputIterator>
1141vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1142 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001143 !__is_forward_iterator<_InputIterator>::value &&
1144 is_constructible<
1145 value_type,
1146 typename iterator_traits<_InputIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147 : __base(__a)
1148{
Howard Hinnantabe26282011-09-16 17:29:17 +00001149#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001150 __get_db()->__insert_c(this);
1151#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001152 for (; __first != __last; ++__first)
1153 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154}
1155
1156template <class _Tp, class _Allocator>
1157template <class _ForwardIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +00001158vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
Howard Hinnant742fecb2013-03-28 17:44:32 +00001159 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1160 is_constructible<
1161 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +00001162 typename iterator_traits<_ForwardIterator>::reference>::value,
1163 _ForwardIterator>::type __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001164{
Howard Hinnant0442b122011-09-16 18:41:29 +00001165#if _LIBCPP_DEBUG_LEVEL >= 2
1166 __get_db()->__insert_c(this);
1167#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001168 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169 if (__n > 0)
1170 {
1171 allocate(__n);
1172 __construct_at_end(__first, __last);
1173 }
1174}
1175
1176template <class _Tp, class _Allocator>
1177template <class _ForwardIterator>
1178vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
Howard Hinnant742fecb2013-03-28 17:44:32 +00001179 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1180 is_constructible<
1181 value_type,
1182 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183 : __base(__a)
1184{
Howard Hinnant0442b122011-09-16 18:41:29 +00001185#if _LIBCPP_DEBUG_LEVEL >= 2
1186 __get_db()->__insert_c(this);
1187#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001188 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001189 if (__n > 0)
1190 {
1191 allocate(__n);
1192 __construct_at_end(__first, __last);
1193 }
1194}
1195
1196template <class _Tp, class _Allocator>
1197vector<_Tp, _Allocator>::vector(const vector& __x)
1198 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1199{
Howard Hinnant0442b122011-09-16 18:41:29 +00001200#if _LIBCPP_DEBUG_LEVEL >= 2
1201 __get_db()->__insert_c(this);
1202#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001203 size_type __n = __x.size();
1204 if (__n > 0)
1205 {
1206 allocate(__n);
1207 __construct_at_end(__x.__begin_, __x.__end_);
1208 }
1209}
1210
1211template <class _Tp, class _Allocator>
1212vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1213 : __base(__a)
1214{
Howard Hinnant0442b122011-09-16 18:41:29 +00001215#if _LIBCPP_DEBUG_LEVEL >= 2
1216 __get_db()->__insert_c(this);
1217#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218 size_type __n = __x.size();
1219 if (__n > 0)
1220 {
1221 allocate(__n);
1222 __construct_at_end(__x.__begin_, __x.__end_);
1223 }
1224}
1225
Howard Hinnant73d21a42010-09-04 23:28:19 +00001226#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227
1228template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001229inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230vector<_Tp, _Allocator>::vector(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001231 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001232 : __base(_VSTD::move(__x.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001233{
Howard Hinnantabe26282011-09-16 17:29:17 +00001234#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001235 __get_db()->__insert_c(this);
Howard Hinnante6125bd2011-09-19 16:34:29 +00001236 __get_db()->swap(this, &__x);
Howard Hinnant7a563db2011-09-14 18:33:51 +00001237#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001238 this->__begin_ = __x.__begin_;
1239 this->__end_ = __x.__end_;
1240 this->__end_cap() = __x.__end_cap();
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001241 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242}
1243
1244template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001245inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1247 : __base(__a)
1248{
Howard Hinnant0442b122011-09-16 18:41:29 +00001249#if _LIBCPP_DEBUG_LEVEL >= 2
1250 __get_db()->__insert_c(this);
1251#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001252 if (__a == __x.__alloc())
1253 {
1254 this->__begin_ = __x.__begin_;
1255 this->__end_ = __x.__end_;
1256 this->__end_cap() = __x.__end_cap();
1257 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001258#if _LIBCPP_DEBUG_LEVEL >= 2
1259 __get_db()->swap(this, &__x);
1260#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001261 }
1262 else
1263 {
Howard Hinnant99968442011-11-29 18:15:50 +00001264 typedef move_iterator<iterator> _Ip;
1265 assign(_Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266 }
1267}
1268
Howard Hinnante3e32912011-08-12 21:56:02 +00001269#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1270
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001271template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001272inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1274{
Howard Hinnant0442b122011-09-16 18:41:29 +00001275#if _LIBCPP_DEBUG_LEVEL >= 2
1276 __get_db()->__insert_c(this);
1277#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001278 if (__il.size() > 0)
1279 {
1280 allocate(__il.size());
1281 __construct_at_end(__il.begin(), __il.end());
1282 }
1283}
1284
1285template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001286inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1288 : __base(__a)
1289{
Howard Hinnant0442b122011-09-16 18:41:29 +00001290#if _LIBCPP_DEBUG_LEVEL >= 2
1291 __get_db()->__insert_c(this);
1292#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001293 if (__il.size() > 0)
1294 {
1295 allocate(__il.size());
1296 __construct_at_end(__il.begin(), __il.end());
1297 }
1298}
1299
Howard Hinnante3e32912011-08-12 21:56:02 +00001300#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1301
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001302template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001303inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001304vector<_Tp, _Allocator>&
1305vector<_Tp, _Allocator>::operator=(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001306 _NOEXCEPT_(
1307 __alloc_traits::propagate_on_container_move_assignment::value &&
1308 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309{
1310 __move_assign(__x, integral_constant<bool,
1311 __alloc_traits::propagate_on_container_move_assignment::value>());
1312 return *this;
1313}
1314
1315template <class _Tp, class _Allocator>
1316void
1317vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1318{
1319 if (__base::__alloc() != __c.__alloc())
1320 {
Howard Hinnant99968442011-11-29 18:15:50 +00001321 typedef move_iterator<iterator> _Ip;
1322 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323 }
1324 else
1325 __move_assign(__c, true_type());
1326}
1327
1328template <class _Tp, class _Allocator>
1329void
1330vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001331 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332{
1333 deallocate();
Marshall Clow3c2eac62014-07-21 15:11:13 +00001334 __base::__move_assign_alloc(__c); // this can throw
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001335 this->__begin_ = __c.__begin_;
1336 this->__end_ = __c.__end_;
1337 this->__end_cap() = __c.__end_cap();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001339#if _LIBCPP_DEBUG_LEVEL >= 2
1340 __get_db()->swap(this, &__c);
1341#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001342}
1343
Howard Hinnant73d21a42010-09-04 23:28:19 +00001344#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345
1346template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001347inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001348vector<_Tp, _Allocator>&
1349vector<_Tp, _Allocator>::operator=(const vector& __x)
1350{
1351 if (this != &__x)
1352 {
1353 __base::__copy_assign_alloc(__x);
1354 assign(__x.__begin_, __x.__end_);
1355 }
1356 return *this;
1357}
1358
1359template <class _Tp, class _Allocator>
1360template <class _InputIterator>
1361typename enable_if
1362<
1363 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001364 !__is_forward_iterator<_InputIterator>::value &&
1365 is_constructible<
1366 _Tp,
1367 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001368 void
1369>::type
1370vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1371{
1372 clear();
1373 for (; __first != __last; ++__first)
1374 push_back(*__first);
1375}
1376
1377template <class _Tp, class _Allocator>
1378template <class _ForwardIterator>
1379typename enable_if
1380<
Howard Hinnant742fecb2013-03-28 17:44:32 +00001381 __is_forward_iterator<_ForwardIterator>::value &&
1382 is_constructible<
1383 _Tp,
1384 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001385 void
1386>::type
1387vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1388{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001389 typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001390 if (static_cast<size_type>(__new_size) <= capacity())
1391 {
1392 _ForwardIterator __mid = __last;
1393 bool __growing = false;
1394 if (static_cast<size_type>(__new_size) > size())
1395 {
1396 __growing = true;
1397 __mid = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001398 _VSTD::advance(__mid, size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001399 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001400 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001401 if (__growing)
1402 __construct_at_end(__mid, __last);
1403 else
1404 this->__destruct_at_end(__m);
1405 }
1406 else
1407 {
1408 deallocate();
1409 allocate(__recommend(static_cast<size_type>(__new_size)));
1410 __construct_at_end(__first, __last);
1411 }
1412}
1413
1414template <class _Tp, class _Allocator>
1415void
1416vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1417{
1418 if (__n <= capacity())
1419 {
1420 size_type __s = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001421 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422 if (__n > __s)
1423 __construct_at_end(__n - __s, __u);
1424 else
Howard Hinnantadff4892010-05-24 17:49:41 +00001425 this->__destruct_at_end(this->__begin_ + __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426 }
1427 else
1428 {
1429 deallocate();
1430 allocate(__recommend(static_cast<size_type>(__n)));
1431 __construct_at_end(__n, __u);
1432 }
1433}
1434
Howard Hinnant324bb032010-08-22 00:02:43 +00001435template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001436inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001438vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001439{
Howard Hinnantabe26282011-09-16 17:29:17 +00001440#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001441 return iterator(this, __p);
1442#else
1443 return iterator(__p);
1444#endif
1445}
1446
Howard Hinnant324bb032010-08-22 00:02:43 +00001447template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001448inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001449typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001450vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001451{
Howard Hinnantabe26282011-09-16 17:29:17 +00001452#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453 return const_iterator(this, __p);
1454#else
1455 return const_iterator(__p);
1456#endif
1457}
1458
Howard Hinnant324bb032010-08-22 00:02:43 +00001459template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001460inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001461typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001462vector<_Tp, _Allocator>::begin() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001463{
1464 return __make_iter(this->__begin_);
1465}
1466
Howard Hinnant324bb032010-08-22 00:02:43 +00001467template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001468inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001469typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001470vector<_Tp, _Allocator>::begin() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471{
1472 return __make_iter(this->__begin_);
1473}
1474
Howard Hinnant324bb032010-08-22 00:02:43 +00001475template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001476inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001478vector<_Tp, _Allocator>::end() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001479{
1480 return __make_iter(this->__end_);
1481}
1482
Howard Hinnant324bb032010-08-22 00:02:43 +00001483template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001484inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001485typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001486vector<_Tp, _Allocator>::end() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487{
1488 return __make_iter(this->__end_);
1489}
1490
Howard Hinnant324bb032010-08-22 00:02:43 +00001491template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001492inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493typename vector<_Tp, _Allocator>::reference
1494vector<_Tp, _Allocator>::operator[](size_type __n)
1495{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001496 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001497 return this->__begin_[__n];
1498}
1499
Howard Hinnant324bb032010-08-22 00:02:43 +00001500template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001501inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001502typename vector<_Tp, _Allocator>::const_reference
1503vector<_Tp, _Allocator>::operator[](size_type __n) const
1504{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001505 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506 return this->__begin_[__n];
1507}
1508
Howard Hinnant324bb032010-08-22 00:02:43 +00001509template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001510typename vector<_Tp, _Allocator>::reference
1511vector<_Tp, _Allocator>::at(size_type __n)
1512{
1513 if (__n >= size())
1514 this->__throw_out_of_range();
1515 return this->__begin_[__n];
1516}
1517
Howard Hinnant324bb032010-08-22 00:02:43 +00001518template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001519typename vector<_Tp, _Allocator>::const_reference
1520vector<_Tp, _Allocator>::at(size_type __n) const
1521{
1522 if (__n >= size())
1523 this->__throw_out_of_range();
1524 return this->__begin_[__n];
1525}
1526
1527template <class _Tp, class _Allocator>
1528void
1529vector<_Tp, _Allocator>::reserve(size_type __n)
1530{
1531 if (__n > capacity())
1532 {
1533 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001534 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001535 __swap_out_circular_buffer(__v);
1536 }
1537}
1538
1539template <class _Tp, class _Allocator>
1540void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001541vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001542{
1543 if (capacity() > size())
1544 {
1545#ifndef _LIBCPP_NO_EXCEPTIONS
1546 try
1547 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001548#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001549 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001550 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551 __swap_out_circular_buffer(__v);
1552#ifndef _LIBCPP_NO_EXCEPTIONS
1553 }
1554 catch (...)
1555 {
1556 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001557#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001558 }
1559}
1560
1561template <class _Tp, class _Allocator>
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001562template <class _Up>
1563void
1564#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1565vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1566#else
1567vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1568#endif
1569{
1570 allocator_type& __a = this->__alloc();
1571 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1572 // __v.push_back(_VSTD::forward<_Up>(__x));
Howard Hinnantf619e232013-01-11 20:36:59 +00001573 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
1574 __v.__end_++;
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001575 __swap_out_circular_buffer(__v);
1576}
1577
1578template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001579inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580void
1581vector<_Tp, _Allocator>::push_back(const_reference __x)
1582{
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001583 if (this->__end_ != this->__end_cap())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001584 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001585 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001586 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001587 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001588 ++this->__end_;
1589 }
1590 else
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001591 __push_back_slow_path(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001592}
1593
Howard Hinnant73d21a42010-09-04 23:28:19 +00001594#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001595
1596template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001597inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598void
1599vector<_Tp, _Allocator>::push_back(value_type&& __x)
1600{
1601 if (this->__end_ < this->__end_cap())
1602 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001603 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001604 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001605 _VSTD::__to_raw_pointer(this->__end_),
1606 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001607 ++this->__end_;
1608 }
1609 else
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001610 __push_back_slow_path(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001611}
1612
Howard Hinnant73d21a42010-09-04 23:28:19 +00001613#ifndef _LIBCPP_HAS_NO_VARIADICS
1614
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001615template <class _Tp, class _Allocator>
1616template <class... _Args>
1617void
Howard Hinnant0438ea22012-02-26 15:30:12 +00001618vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1619{
1620 allocator_type& __a = this->__alloc();
1621 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1622// __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantf619e232013-01-11 20:36:59 +00001623 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
1624 __v.__end_++;
Howard Hinnant0438ea22012-02-26 15:30:12 +00001625 __swap_out_circular_buffer(__v);
1626}
1627
1628template <class _Tp, class _Allocator>
1629template <class... _Args>
Howard Hinnant1e564242013-10-04 22:09:00 +00001630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0438ea22012-02-26 15:30:12 +00001631void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1633{
1634 if (this->__end_ < this->__end_cap())
1635 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001636 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001637 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001638 _VSTD::__to_raw_pointer(this->__end_),
1639 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640 ++this->__end_;
1641 }
1642 else
Howard Hinnant0438ea22012-02-26 15:30:12 +00001643 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644}
1645
Howard Hinnant73d21a42010-09-04 23:28:19 +00001646#endif // _LIBCPP_HAS_NO_VARIADICS
1647#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648
1649template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001650inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651void
1652vector<_Tp, _Allocator>::pop_back()
1653{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001654 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655 this->__destruct_at_end(this->__end_ - 1);
1656}
1657
1658template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001659inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001660typename vector<_Tp, _Allocator>::iterator
1661vector<_Tp, _Allocator>::erase(const_iterator __position)
1662{
Howard Hinnantabe26282011-09-16 17:29:17 +00001663#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001664 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1665 "vector::erase(iterator) called with an iterator not"
1666 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001667#endif
Howard Hinnant782da332013-03-25 22:12:26 +00001668 _LIBCPP_ASSERT(__position != end(),
1669 "vector::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001670 difference_type __ps = __position - cbegin();
1671 pointer __p = this->__begin_ + __ps;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001673 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001674 return __r;
1675}
1676
1677template <class _Tp, class _Allocator>
1678typename vector<_Tp, _Allocator>::iterator
1679vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1680{
Howard Hinnantabe26282011-09-16 17:29:17 +00001681#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001682 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1683 "vector::erase(iterator, iterator) called with an iterator not"
1684 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001685#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001686 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001687 pointer __p = this->__begin_ + (__first - begin());
1688 iterator __r = __make_iter(__p);
Howard Hinnantb4e67cf2013-04-18 15:02:57 +00001689 if (__first != __last)
1690 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001691 return __r;
1692}
1693
1694template <class _Tp, class _Allocator>
1695void
1696vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1697{
1698 pointer __old_last = this->__end_;
1699 difference_type __n = __old_last - __to;
1700 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1701 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001702 _VSTD::__to_raw_pointer(this->__end_),
1703 _VSTD::move(*__i));
1704 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001705}
1706
1707template <class _Tp, class _Allocator>
1708typename vector<_Tp, _Allocator>::iterator
1709vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1710{
Howard Hinnantabe26282011-09-16 17:29:17 +00001711#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001712 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1713 "vector::insert(iterator, x) called with an iterator not"
1714 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001715#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001716 pointer __p = this->__begin_ + (__position - begin());
1717 if (this->__end_ < this->__end_cap())
1718 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001719 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001720 if (__p == this->__end_)
1721 {
1722 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001723 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001724 ++this->__end_;
1725 }
1726 else
1727 {
1728 __move_range(__p, this->__end_, __p + 1);
1729 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1730 if (__p <= __xr && __xr < this->__end_)
1731 ++__xr;
1732 *__p = *__xr;
1733 }
1734 }
1735 else
1736 {
1737 allocator_type& __a = this->__alloc();
1738 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1739 __v.push_back(__x);
1740 __p = __swap_out_circular_buffer(__v, __p);
1741 }
1742 return __make_iter(__p);
1743}
1744
Howard Hinnant73d21a42010-09-04 23:28:19 +00001745#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746
1747template <class _Tp, class _Allocator>
1748typename vector<_Tp, _Allocator>::iterator
1749vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1750{
Howard Hinnantabe26282011-09-16 17:29:17 +00001751#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001752 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1753 "vector::insert(iterator, x) called with an iterator not"
1754 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001755#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001756 pointer __p = this->__begin_ + (__position - begin());
1757 if (this->__end_ < this->__end_cap())
1758 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001759 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001760 if (__p == this->__end_)
1761 {
1762 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001763 _VSTD::__to_raw_pointer(this->__end_),
1764 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001765 ++this->__end_;
1766 }
1767 else
1768 {
1769 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001770 *__p = _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001771 }
1772 }
1773 else
1774 {
1775 allocator_type& __a = this->__alloc();
1776 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001777 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001778 __p = __swap_out_circular_buffer(__v, __p);
1779 }
1780 return __make_iter(__p);
1781}
1782
Howard Hinnant73d21a42010-09-04 23:28:19 +00001783#ifndef _LIBCPP_HAS_NO_VARIADICS
1784
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785template <class _Tp, class _Allocator>
1786template <class... _Args>
1787typename vector<_Tp, _Allocator>::iterator
1788vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1789{
Howard Hinnantabe26282011-09-16 17:29:17 +00001790#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001791 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1792 "vector::emplace(iterator, x) called with an iterator not"
1793 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001794#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795 pointer __p = this->__begin_ + (__position - begin());
1796 if (this->__end_ < this->__end_cap())
1797 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001798 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799 if (__p == this->__end_)
1800 {
1801 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001802 _VSTD::__to_raw_pointer(this->__end_),
1803 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804 ++this->__end_;
1805 }
1806 else
1807 {
Howard Hinnanta58402a2012-07-08 23:23:04 +00001808 value_type __tmp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001809 __move_range(__p, this->__end_, __p + 1);
Howard Hinnanta58402a2012-07-08 23:23:04 +00001810 *__p = _VSTD::move(__tmp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001811 }
1812 }
1813 else
1814 {
1815 allocator_type& __a = this->__alloc();
1816 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001817 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818 __p = __swap_out_circular_buffer(__v, __p);
1819 }
1820 return __make_iter(__p);
1821}
1822
Howard Hinnant73d21a42010-09-04 23:28:19 +00001823#endif // _LIBCPP_HAS_NO_VARIADICS
1824#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001825
1826template <class _Tp, class _Allocator>
1827typename vector<_Tp, _Allocator>::iterator
1828vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1829{
Howard Hinnantabe26282011-09-16 17:29:17 +00001830#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001831 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1832 "vector::insert(iterator, n, x) called with an iterator not"
1833 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001834#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835 pointer __p = this->__begin_ + (__position - begin());
1836 if (__n > 0)
1837 {
1838 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1839 {
1840 size_type __old_n = __n;
1841 pointer __old_last = this->__end_;
1842 if (__n > static_cast<size_type>(this->__end_ - __p))
1843 {
1844 size_type __cx = __n - (this->__end_ - __p);
1845 __construct_at_end(__cx, __x);
1846 __n -= __cx;
1847 }
1848 if (__n > 0)
1849 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001850 __annotate_increase(__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001851 __move_range(__p, __old_last, __p + __old_n);
1852 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1853 if (__p <= __xr && __xr < this->__end_)
1854 __xr += __old_n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001855 _VSTD::fill_n(__p, __n, *__xr);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001856 }
1857 }
1858 else
1859 {
1860 allocator_type& __a = this->__alloc();
1861 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1862 __v.__construct_at_end(__n, __x);
1863 __p = __swap_out_circular_buffer(__v, __p);
1864 }
1865 }
1866 return __make_iter(__p);
1867}
1868
1869template <class _Tp, class _Allocator>
1870template <class _InputIterator>
1871typename enable_if
1872<
1873 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001874 !__is_forward_iterator<_InputIterator>::value &&
1875 is_constructible<
1876 _Tp,
1877 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001878 typename vector<_Tp, _Allocator>::iterator
1879>::type
1880vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1881{
Howard Hinnantabe26282011-09-16 17:29:17 +00001882#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001883 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1884 "vector::insert(iterator, range) called with an iterator not"
1885 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001886#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001887 difference_type __off = __position - begin();
1888 pointer __p = this->__begin_ + __off;
1889 allocator_type& __a = this->__alloc();
1890 pointer __old_last = this->__end_;
1891 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1892 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001893 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001894 *__first);
1895 ++this->__end_;
1896 }
1897 __split_buffer<value_type, allocator_type&> __v(__a);
1898 if (__first != __last)
1899 {
1900#ifndef _LIBCPP_NO_EXCEPTIONS
1901 try
1902 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001903#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001904 __v.__construct_at_end(__first, __last);
1905 difference_type __old_size = __old_last - this->__begin_;
1906 difference_type __old_p = __p - this->__begin_;
1907 reserve(__recommend(size() + __v.size()));
1908 __p = this->__begin_ + __old_p;
1909 __old_last = this->__begin_ + __old_size;
1910#ifndef _LIBCPP_NO_EXCEPTIONS
1911 }
1912 catch (...)
1913 {
1914 erase(__make_iter(__old_last), end());
1915 throw;
1916 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001917#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001918 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001919 __p = _VSTD::rotate(__p, __old_last, this->__end_);
Howard Hinnant0442b122011-09-16 18:41:29 +00001920 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1921 make_move_iterator(__v.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922 return begin() + __off;
1923}
1924
1925template <class _Tp, class _Allocator>
1926template <class _ForwardIterator>
1927typename enable_if
1928<
Howard Hinnant742fecb2013-03-28 17:44:32 +00001929 __is_forward_iterator<_ForwardIterator>::value &&
1930 is_constructible<
1931 _Tp,
1932 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001933 typename vector<_Tp, _Allocator>::iterator
1934>::type
1935vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1936{
Howard Hinnantabe26282011-09-16 17:29:17 +00001937#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001938 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1939 "vector::insert(iterator, range) called with an iterator not"
1940 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001941#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001942 pointer __p = this->__begin_ + (__position - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00001943 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001944 if (__n > 0)
1945 {
1946 if (__n <= this->__end_cap() - this->__end_)
1947 {
1948 size_type __old_n = __n;
1949 pointer __old_last = this->__end_;
1950 _ForwardIterator __m = __last;
1951 difference_type __dx = this->__end_ - __p;
1952 if (__n > __dx)
1953 {
1954 __m = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001955 _VSTD::advance(__m, this->__end_ - __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001956 __construct_at_end(__m, __last);
1957 __n = __dx;
1958 }
1959 if (__n > 0)
1960 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001961 __annotate_increase(__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962 __move_range(__p, __old_last, __p + __old_n);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001963 _VSTD::copy(__first, __m, __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001964 }
1965 }
1966 else
1967 {
1968 allocator_type& __a = this->__alloc();
1969 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1970 __v.__construct_at_end(__first, __last);
1971 __p = __swap_out_circular_buffer(__v, __p);
1972 }
1973 }
1974 return __make_iter(__p);
1975}
1976
1977template <class _Tp, class _Allocator>
1978void
1979vector<_Tp, _Allocator>::resize(size_type __sz)
1980{
1981 size_type __cs = size();
1982 if (__cs < __sz)
1983 this->__append(__sz - __cs);
1984 else if (__cs > __sz)
1985 this->__destruct_at_end(this->__begin_ + __sz);
1986}
1987
1988template <class _Tp, class _Allocator>
1989void
1990vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1991{
1992 size_type __cs = size();
1993 if (__cs < __sz)
1994 this->__append(__sz - __cs, __x);
1995 else if (__cs > __sz)
1996 this->__destruct_at_end(this->__begin_ + __sz);
1997}
1998
1999template <class _Tp, class _Allocator>
2000void
2001vector<_Tp, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002002 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2003 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002004{
Howard Hinnant7a563db2011-09-14 18:33:51 +00002005 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
2006 this->__alloc() == __x.__alloc(),
2007 "vector::swap: Either propagate_on_container_swap must be true"
2008 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19 +00002009 _VSTD::swap(this->__begin_, __x.__begin_);
2010 _VSTD::swap(this->__end_, __x.__end_);
2011 _VSTD::swap(this->__end_cap(), __x.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002012 __base::__swap_alloc(this->__alloc(), __x.__alloc());
Howard Hinnantabe26282011-09-16 17:29:17 +00002013#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002014 __get_db()->swap(this, &__x);
Howard Hinnantabe26282011-09-16 17:29:17 +00002015#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016}
2017
Howard Hinnant324bb032010-08-22 00:02:43 +00002018template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002019bool
2020vector<_Tp, _Allocator>::__invariants() const
2021{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002022 if (this->__begin_ == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002023 {
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002024 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002025 return false;
2026 }
2027 else
2028 {
2029 if (this->__begin_ > this->__end_)
2030 return false;
2031 if (this->__begin_ == this->__end_cap())
2032 return false;
2033 if (this->__end_ > this->__end_cap())
2034 return false;
2035 }
2036 return true;
2037}
2038
Howard Hinnantabe26282011-09-16 17:29:17 +00002039#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002040
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002041template <class _Tp, class _Allocator>
Howard Hinnant7a563db2011-09-14 18:33:51 +00002042bool
2043vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
2044{
2045 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
2046}
2047
2048template <class _Tp, class _Allocator>
2049bool
2050vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
2051{
2052 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
2053}
2054
2055template <class _Tp, class _Allocator>
2056bool
2057vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2058{
2059 const_pointer __p = __i->base() + __n;
2060 return this->__begin_ <= __p && __p <= this->__end_;
2061}
2062
2063template <class _Tp, class _Allocator>
2064bool
2065vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2066{
2067 const_pointer __p = __i->base() + __n;
2068 return this->__begin_ <= __p && __p < this->__end_;
2069}
2070
Howard Hinnantabe26282011-09-16 17:29:17 +00002071#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002072
2073template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002075void
2076vector<_Tp, _Allocator>::__invalidate_all_iterators()
2077{
Howard Hinnantabe26282011-09-16 17:29:17 +00002078#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002079 __get_db()->__invalidate_all(this);
Howard Hinnantabe26282011-09-16 17:29:17 +00002080#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002081}
2082
2083// vector<bool>
2084
2085template <class _Allocator> class vector<bool, _Allocator>;
2086
2087template <class _Allocator> struct hash<vector<bool, _Allocator> >;
2088
2089template <class _Allocator>
Howard Hinnantf03c3b42011-07-02 20:33:23 +00002090struct __has_storage_type<vector<bool, _Allocator> >
2091{
2092 static const bool value = true;
2093};
2094
2095template <class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002096class _LIBCPP_TYPE_VIS_ONLY vector<bool, _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002097 : private __vector_base_common<true>
2098{
2099public:
2100 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +00002101 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002102 typedef _Allocator allocator_type;
2103 typedef allocator_traits<allocator_type> __alloc_traits;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002104 typedef typename __alloc_traits::size_type size_type;
2105 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnantf867f632012-05-07 16:50:38 +00002106 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002107 typedef __bit_iterator<vector, false> pointer;
2108 typedef __bit_iterator<vector, true> const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002109 typedef pointer iterator;
2110 typedef const_pointer const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002111 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
2112 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113
2114private:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115 typedef typename __alloc_traits::template
2116#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
2117 rebind_alloc<__storage_type>
2118#else
2119 rebind_alloc<__storage_type>::other
2120#endif
2121 __storage_allocator;
2122 typedef allocator_traits<__storage_allocator> __storage_traits;
2123 typedef typename __storage_traits::pointer __storage_pointer;
2124 typedef typename __storage_traits::const_pointer __const_storage_pointer;
2125
2126 __storage_pointer __begin_;
2127 size_type __size_;
2128 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00002129public:
Howard Hinnantf03c3b42011-07-02 20:33:23 +00002130 typedef __bit_reference<vector> reference;
2131 typedef __bit_const_reference<vector> const_reference;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00002132private:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002133 _LIBCPP_INLINE_VISIBILITY
2134 size_type& __cap() _NOEXCEPT
2135 {return __cap_alloc_.first();}
2136 _LIBCPP_INLINE_VISIBILITY
2137 const size_type& __cap() const _NOEXCEPT
2138 {return __cap_alloc_.first();}
2139 _LIBCPP_INLINE_VISIBILITY
2140 __storage_allocator& __alloc() _NOEXCEPT
2141 {return __cap_alloc_.second();}
2142 _LIBCPP_INLINE_VISIBILITY
2143 const __storage_allocator& __alloc() const _NOEXCEPT
2144 {return __cap_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002145
2146 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2147
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002148 _LIBCPP_INLINE_VISIBILITY
2149 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002150 {return __n * __bits_per_word;}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002151 _LIBCPP_INLINE_VISIBILITY
2152 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002153 {return (__n - 1) / __bits_per_word + 1;}
2154
2155public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002156 _LIBCPP_INLINE_VISIBILITY
2157 vector()
2158 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002159 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002160 ~vector();
2161 explicit vector(size_type __n);
Marshall Clowa49a2c92013-09-14 00:47:59 +00002162#if _LIBCPP_STD_VER > 11
2163 explicit vector(size_type __n, const allocator_type& __a);
2164#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002165 vector(size_type __n, const value_type& __v);
2166 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2167 template <class _InputIterator>
2168 vector(_InputIterator __first, _InputIterator __last,
2169 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2170 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2171 template <class _InputIterator>
2172 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2173 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2174 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2175 template <class _ForwardIterator>
2176 vector(_ForwardIterator __first, _ForwardIterator __last,
2177 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2178 template <class _ForwardIterator>
2179 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2180 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2181
2182 vector(const vector& __v);
2183 vector(const vector& __v, const allocator_type& __a);
2184 vector& operator=(const vector& __v);
Howard Hinnante3e32912011-08-12 21:56:02 +00002185#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186 vector(initializer_list<value_type> __il);
2187 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00002188#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002189
Howard Hinnant73d21a42010-09-04 23:28:19 +00002190#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002191 _LIBCPP_INLINE_VISIBILITY
2192 vector(vector&& __v)
2193 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002194 vector(vector&& __v, const allocator_type& __a);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002195 _LIBCPP_INLINE_VISIBILITY
2196 vector& operator=(vector&& __v)
2197 _NOEXCEPT_(
2198 __alloc_traits::propagate_on_container_move_assignment::value &&
2199 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002200#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00002201#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002203 vector& operator=(initializer_list<value_type> __il)
2204 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00002205#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002206
2207 template <class _InputIterator>
2208 typename enable_if
2209 <
2210 __is_input_iterator<_InputIterator>::value &&
2211 !__is_forward_iterator<_InputIterator>::value,
2212 void
2213 >::type
2214 assign(_InputIterator __first, _InputIterator __last);
2215 template <class _ForwardIterator>
2216 typename enable_if
2217 <
2218 __is_forward_iterator<_ForwardIterator>::value,
2219 void
2220 >::type
2221 assign(_ForwardIterator __first, _ForwardIterator __last);
2222
2223 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:02 +00002224#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002226 void assign(initializer_list<value_type> __il)
2227 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002228#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002229
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002230 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002231 {return allocator_type(this->__alloc());}
2232
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002233 size_type max_size() const _NOEXCEPT;
2234 _LIBCPP_INLINE_VISIBILITY
2235 size_type capacity() const _NOEXCEPT
2236 {return __internal_cap_to_external(__cap());}
2237 _LIBCPP_INLINE_VISIBILITY
2238 size_type size() const _NOEXCEPT
2239 {return __size_;}
2240 _LIBCPP_INLINE_VISIBILITY
2241 bool empty() const _NOEXCEPT
2242 {return __size_ == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002243 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002244 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002245
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002246 _LIBCPP_INLINE_VISIBILITY
2247 iterator begin() _NOEXCEPT
2248 {return __make_iter(0);}
2249 _LIBCPP_INLINE_VISIBILITY
2250 const_iterator begin() const _NOEXCEPT
2251 {return __make_iter(0);}
2252 _LIBCPP_INLINE_VISIBILITY
2253 iterator end() _NOEXCEPT
2254 {return __make_iter(__size_);}
2255 _LIBCPP_INLINE_VISIBILITY
2256 const_iterator end() const _NOEXCEPT
2257 {return __make_iter(__size_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002258
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002259 _LIBCPP_INLINE_VISIBILITY
2260 reverse_iterator rbegin() _NOEXCEPT
2261 {return reverse_iterator(end());}
2262 _LIBCPP_INLINE_VISIBILITY
2263 const_reverse_iterator rbegin() const _NOEXCEPT
2264 {return const_reverse_iterator(end());}
2265 _LIBCPP_INLINE_VISIBILITY
2266 reverse_iterator rend() _NOEXCEPT
2267 {return reverse_iterator(begin());}
2268 _LIBCPP_INLINE_VISIBILITY
2269 const_reverse_iterator rend() const _NOEXCEPT
2270 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002271
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002272 _LIBCPP_INLINE_VISIBILITY
2273 const_iterator cbegin() const _NOEXCEPT
2274 {return __make_iter(0);}
2275 _LIBCPP_INLINE_VISIBILITY
2276 const_iterator cend() const _NOEXCEPT
2277 {return __make_iter(__size_);}
2278 _LIBCPP_INLINE_VISIBILITY
2279 const_reverse_iterator crbegin() const _NOEXCEPT
2280 {return rbegin();}
2281 _LIBCPP_INLINE_VISIBILITY
2282 const_reverse_iterator crend() const _NOEXCEPT
2283 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002284
2285 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2286 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2287 reference at(size_type __n);
2288 const_reference at(size_type __n) const;
2289
2290 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2291 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2292 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2293 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2294
2295 void push_back(const value_type& __x);
Marshall Clow198a2a52013-08-13 23:54:12 +00002296#if _LIBCPP_STD_VER > 11
2297 template <class... _Args>
2298 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
2299 { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); }
2300#endif
2301
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002302 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2303
Marshall Clow198a2a52013-08-13 23:54:12 +00002304#if _LIBCPP_STD_VER > 11
2305 template <class... _Args>
2306 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2307 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2308#endif
2309
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002310 iterator insert(const_iterator __position, const value_type& __x);
2311 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2312 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2313 template <class _InputIterator>
2314 typename enable_if
2315 <
2316 __is_input_iterator <_InputIterator>::value &&
2317 !__is_forward_iterator<_InputIterator>::value,
2318 iterator
2319 >::type
2320 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2321 template <class _ForwardIterator>
2322 typename enable_if
2323 <
2324 __is_forward_iterator<_ForwardIterator>::value,
2325 iterator
2326 >::type
2327 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00002328#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002330 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2331 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002332#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002333
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002334 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335 iterator erase(const_iterator __first, const_iterator __last);
2336
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002337 _LIBCPP_INLINE_VISIBILITY
2338 void clear() _NOEXCEPT {__size_ = 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002339
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002340 void swap(vector&)
2341 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2342 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002343
2344 void resize(size_type __sz, value_type __x = false);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002345 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002346
2347 bool __invariants() const;
2348
2349private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002350 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002351 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002352 void deallocate() _NOEXCEPT;
2353 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00002354 static size_type __align_it(size_type __new_size) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002355 {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);};
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002356 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2357 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358 template <class _ForwardIterator>
2359 typename enable_if
2360 <
2361 __is_forward_iterator<_ForwardIterator>::value,
2362 void
2363 >::type
2364 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2365 void __append(size_type __n, const_reference __x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002366 _LIBCPP_INLINE_VISIBILITY
2367 reference __make_ref(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002368 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002369 _LIBCPP_INLINE_VISIBILITY
2370 const_reference __make_ref(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002371 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002372 _LIBCPP_INLINE_VISIBILITY
2373 iterator __make_iter(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002374 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002375 _LIBCPP_INLINE_VISIBILITY
2376 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002377 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002378 _LIBCPP_INLINE_VISIBILITY
2379 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002380 {return begin() + (__p - cbegin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002381
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002383 void __copy_assign_alloc(const vector& __v)
2384 {__copy_assign_alloc(__v, integral_constant<bool,
2385 __storage_traits::propagate_on_container_copy_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002386 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387 void __copy_assign_alloc(const vector& __c, true_type)
2388 {
2389 if (__alloc() != __c.__alloc())
2390 deallocate();
2391 __alloc() = __c.__alloc();
2392 }
2393
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00002395 void __copy_assign_alloc(const vector&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002396 {}
2397
2398 void __move_assign(vector& __c, false_type);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002399 void __move_assign(vector& __c, true_type)
2400 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002402 void __move_assign_alloc(vector& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002403 _NOEXCEPT_(
2404 !__storage_traits::propagate_on_container_move_assignment::value ||
2405 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002406 {__move_assign_alloc(__c, integral_constant<bool,
2407 __storage_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00002409 void __move_assign_alloc(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002410 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002411 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002412 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002413 }
2414
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00002416 void __move_assign_alloc(vector&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002417 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002418 {}
2419
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002421 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002422 _NOEXCEPT_(
2423 !__storage_traits::propagate_on_container_swap::value ||
2424 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002425 {__swap_alloc(__x, __y, integral_constant<bool,
2426 __storage_traits::propagate_on_container_swap::value>());}
2427
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002429 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002430 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002431 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002432 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002433 swap(__x, __y);
2434 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00002436 static void __swap_alloc(__storage_allocator&, __storage_allocator&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002437 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002438 {}
2439
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002440 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002441
2442 friend class __bit_reference<vector>;
2443 friend class __bit_const_reference<vector>;
2444 friend class __bit_iterator<vector, false>;
2445 friend class __bit_iterator<vector, true>;
Howard Hinnant4ae952a2012-08-17 17:10:18 +00002446 friend struct __bit_array<vector>;
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002447 friend struct _LIBCPP_TYPE_VIS_ONLY hash<vector>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002448};
2449
2450template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002451inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002452void
2453vector<bool, _Allocator>::__invalidate_all_iterators()
2454{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002455}
2456
2457// Allocate space for __n objects
2458// throws length_error if __n > max_size()
2459// throws (probably bad_alloc) if memory run out
2460// Precondition: __begin_ == __end_ == __cap() == 0
2461// Precondition: __n > 0
2462// Postcondition: capacity() == __n
2463// Postcondition: size() == 0
2464template <class _Allocator>
2465void
2466vector<bool, _Allocator>::allocate(size_type __n)
2467{
2468 if (__n > max_size())
2469 this->__throw_length_error();
2470 __n = __external_cap_to_internal(__n);
2471 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2472 this->__size_ = 0;
2473 this->__cap() = __n;
2474}
2475
2476template <class _Allocator>
2477void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002478vector<bool, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002479{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002480 if (this->__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002481 {
2482 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2483 __invalidate_all_iterators();
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002484 this->__begin_ = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002485 this->__size_ = this->__cap() = 0;
2486 }
2487}
2488
2489template <class _Allocator>
2490typename vector<bool, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002491vector<bool, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002492{
2493 size_type __amax = __storage_traits::max_size(__alloc());
2494 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2495 if (__nmax / __bits_per_word <= __amax)
2496 return __nmax;
2497 return __internal_cap_to_external(__amax);
2498}
2499
2500// Precondition: __new_size > capacity()
2501template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002502inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002503typename vector<bool, _Allocator>::size_type
2504vector<bool, _Allocator>::__recommend(size_type __new_size) const
2505{
2506 const size_type __ms = max_size();
2507 if (__new_size > __ms)
2508 this->__throw_length_error();
2509 const size_type __cap = capacity();
2510 if (__cap >= __ms / 2)
2511 return __ms;
Howard Hinnant7f764502013-08-14 18:00:20 +00002512 return _VSTD::max(2*__cap, __align_it(__new_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002513}
2514
2515// Default constructs __n objects starting at __end_
2516// Precondition: __n > 0
2517// Precondition: size() + __n <= capacity()
2518// Postcondition: size() == size() + __n
2519template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002520inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002521void
2522vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2523{
2524 size_type __old_size = this->__size_;
2525 this->__size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002526 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002527}
2528
2529template <class _Allocator>
2530template <class _ForwardIterator>
2531typename enable_if
2532<
2533 __is_forward_iterator<_ForwardIterator>::value,
2534 void
2535>::type
2536vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2537{
2538 size_type __old_size = this->__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002539 this->__size_ += _VSTD::distance(__first, __last);
2540 _VSTD::copy(__first, __last, __make_iter(__old_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002541}
2542
2543template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002544inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002545vector<bool, _Allocator>::vector()
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002546 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002547 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002548 __size_(0),
2549 __cap_alloc_(0)
2550{
2551}
2552
2553template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002554inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002555vector<bool, _Allocator>::vector(const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002556 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002557 __size_(0),
2558 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2559{
2560}
2561
2562template <class _Allocator>
2563vector<bool, _Allocator>::vector(size_type __n)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002564 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002565 __size_(0),
2566 __cap_alloc_(0)
2567{
2568 if (__n > 0)
2569 {
2570 allocate(__n);
2571 __construct_at_end(__n, false);
2572 }
2573}
2574
Marshall Clowa49a2c92013-09-14 00:47:59 +00002575#if _LIBCPP_STD_VER > 11
2576template <class _Allocator>
2577vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2578 : __begin_(nullptr),
2579 __size_(0),
2580 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2581{
2582 if (__n > 0)
2583 {
2584 allocate(__n);
2585 __construct_at_end(__n, false);
2586 }
2587}
2588#endif
2589
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002590template <class _Allocator>
2591vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002592 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002593 __size_(0),
2594 __cap_alloc_(0)
2595{
2596 if (__n > 0)
2597 {
2598 allocate(__n);
2599 __construct_at_end(__n, __x);
2600 }
2601}
2602
2603template <class _Allocator>
2604vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002605 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002606 __size_(0),
2607 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2608{
2609 if (__n > 0)
2610 {
2611 allocate(__n);
2612 __construct_at_end(__n, __x);
2613 }
2614}
2615
2616template <class _Allocator>
2617template <class _InputIterator>
2618vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2619 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2620 !__is_forward_iterator<_InputIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002621 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002622 __size_(0),
2623 __cap_alloc_(0)
2624{
2625#ifndef _LIBCPP_NO_EXCEPTIONS
2626 try
2627 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002628#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002629 for (; __first != __last; ++__first)
2630 push_back(*__first);
2631#ifndef _LIBCPP_NO_EXCEPTIONS
2632 }
2633 catch (...)
2634 {
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002635 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002636 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2637 __invalidate_all_iterators();
2638 throw;
2639 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002640#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002641}
2642
2643template <class _Allocator>
2644template <class _InputIterator>
2645vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2646 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2647 !__is_forward_iterator<_InputIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002648 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002649 __size_(0),
2650 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2651{
2652#ifndef _LIBCPP_NO_EXCEPTIONS
2653 try
2654 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002655#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002656 for (; __first != __last; ++__first)
2657 push_back(*__first);
2658#ifndef _LIBCPP_NO_EXCEPTIONS
2659 }
2660 catch (...)
2661 {
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002662 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002663 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2664 __invalidate_all_iterators();
2665 throw;
2666 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002667#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002668}
2669
2670template <class _Allocator>
2671template <class _ForwardIterator>
2672vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2673 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002674 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002675 __size_(0),
2676 __cap_alloc_(0)
2677{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002678 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002679 if (__n > 0)
2680 {
2681 allocate(__n);
2682 __construct_at_end(__first, __last);
2683 }
2684}
2685
2686template <class _Allocator>
2687template <class _ForwardIterator>
2688vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2689 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002690 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002691 __size_(0),
2692 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2693{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002694 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002695 if (__n > 0)
2696 {
2697 allocate(__n);
2698 __construct_at_end(__first, __last);
2699 }
2700}
2701
Howard Hinnante3e32912011-08-12 21:56:02 +00002702#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2703
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002704template <class _Allocator>
2705vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002706 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002707 __size_(0),
2708 __cap_alloc_(0)
2709{
2710 size_type __n = static_cast<size_type>(__il.size());
2711 if (__n > 0)
2712 {
2713 allocate(__n);
2714 __construct_at_end(__il.begin(), __il.end());
2715 }
2716}
2717
2718template <class _Allocator>
2719vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002720 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002721 __size_(0),
2722 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2723{
2724 size_type __n = static_cast<size_type>(__il.size());
2725 if (__n > 0)
2726 {
2727 allocate(__n);
2728 __construct_at_end(__il.begin(), __il.end());
2729 }
2730}
2731
Howard Hinnante3e32912011-08-12 21:56:02 +00002732#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2733
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002734template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002735vector<bool, _Allocator>::~vector()
2736{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002737 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002738 __storage_traits::deallocate(__alloc(), __begin_, __cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002739 __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002740}
2741
2742template <class _Allocator>
2743vector<bool, _Allocator>::vector(const vector& __v)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002744 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002745 __size_(0),
2746 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2747{
2748 if (__v.size() > 0)
2749 {
2750 allocate(__v.size());
2751 __construct_at_end(__v.begin(), __v.end());
2752 }
2753}
2754
2755template <class _Allocator>
2756vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002757 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002758 __size_(0),
2759 __cap_alloc_(0, __a)
2760{
2761 if (__v.size() > 0)
2762 {
2763 allocate(__v.size());
2764 __construct_at_end(__v.begin(), __v.end());
2765 }
2766}
2767
2768template <class _Allocator>
2769vector<bool, _Allocator>&
2770vector<bool, _Allocator>::operator=(const vector& __v)
2771{
2772 if (this != &__v)
2773 {
2774 __copy_assign_alloc(__v);
2775 if (__v.__size_)
2776 {
2777 if (__v.__size_ > capacity())
2778 {
2779 deallocate();
2780 allocate(__v.__size_);
2781 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002782 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002783 }
2784 __size_ = __v.__size_;
2785 }
2786 return *this;
2787}
2788
Howard Hinnant73d21a42010-09-04 23:28:19 +00002789#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2790
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002791template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002792inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002793vector<bool, _Allocator>::vector(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002794 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002795 : __begin_(__v.__begin_),
2796 __size_(__v.__size_),
2797 __cap_alloc_(__v.__cap_alloc_)
2798{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002799 __v.__begin_ = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002800 __v.__size_ = 0;
2801 __v.__cap() = 0;
2802}
2803
2804template <class _Allocator>
2805vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002806 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002807 __size_(0),
2808 __cap_alloc_(0, __a)
2809{
2810 if (__a == allocator_type(__v.__alloc()))
2811 {
2812 this->__begin_ = __v.__begin_;
2813 this->__size_ = __v.__size_;
2814 this->__cap() = __v.__cap();
2815 __v.__begin_ = nullptr;
2816 __v.__cap() = __v.__size_ = 0;
2817 }
2818 else if (__v.size() > 0)
2819 {
2820 allocate(__v.size());
2821 __construct_at_end(__v.begin(), __v.end());
2822 }
2823}
2824
2825template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002826inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002827vector<bool, _Allocator>&
2828vector<bool, _Allocator>::operator=(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002829 _NOEXCEPT_(
2830 __alloc_traits::propagate_on_container_move_assignment::value &&
2831 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002832{
2833 __move_assign(__v, integral_constant<bool,
2834 __storage_traits::propagate_on_container_move_assignment::value>());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002835 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002836}
2837
2838template <class _Allocator>
2839void
2840vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2841{
2842 if (__alloc() != __c.__alloc())
2843 assign(__c.begin(), __c.end());
2844 else
2845 __move_assign(__c, true_type());
2846}
2847
2848template <class _Allocator>
2849void
2850vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002851 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002852{
2853 deallocate();
Marshall Clowdb5e54d2014-07-21 15:15:15 +00002854 __move_assign_alloc(__c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002855 this->__begin_ = __c.__begin_;
2856 this->__size_ = __c.__size_;
2857 this->__cap() = __c.__cap();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002858 __c.__begin_ = nullptr;
2859 __c.__cap() = __c.__size_ = 0;
2860}
Howard Hinnant73d21a42010-09-04 23:28:19 +00002861
2862#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002863
2864template <class _Allocator>
2865void
2866vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2867{
2868 __size_ = 0;
2869 if (__n > 0)
2870 {
2871 size_type __c = capacity();
2872 if (__n <= __c)
2873 __size_ = __n;
2874 else
2875 {
2876 vector __v(__alloc());
2877 __v.reserve(__recommend(__n));
2878 __v.__size_ = __n;
2879 swap(__v);
2880 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002881 _VSTD::fill_n(begin(), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002882 }
2883}
2884
2885template <class _Allocator>
2886template <class _InputIterator>
2887typename enable_if
2888<
2889 __is_input_iterator<_InputIterator>::value &&
2890 !__is_forward_iterator<_InputIterator>::value,
2891 void
2892>::type
2893vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2894{
2895 clear();
2896 for (; __first != __last; ++__first)
2897 push_back(*__first);
2898}
2899
2900template <class _Allocator>
2901template <class _ForwardIterator>
2902typename enable_if
2903<
2904 __is_forward_iterator<_ForwardIterator>::value,
2905 void
2906>::type
2907vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2908{
2909 clear();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002910 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002911 if (__n)
2912 {
2913 if (__n > capacity())
2914 {
2915 deallocate();
2916 allocate(__n);
2917 }
2918 __construct_at_end(__first, __last);
2919 }
2920}
2921
2922template <class _Allocator>
2923void
2924vector<bool, _Allocator>::reserve(size_type __n)
2925{
2926 if (__n > capacity())
2927 {
2928 vector __v(this->__alloc());
2929 __v.allocate(__n);
2930 __v.__construct_at_end(this->begin(), this->end());
2931 swap(__v);
2932 __invalidate_all_iterators();
2933 }
2934}
2935
2936template <class _Allocator>
2937void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002938vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002939{
2940 if (__external_cap_to_internal(size()) > __cap())
2941 {
2942#ifndef _LIBCPP_NO_EXCEPTIONS
2943 try
2944 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002945#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002946 vector(*this, allocator_type(__alloc())).swap(*this);
2947#ifndef _LIBCPP_NO_EXCEPTIONS
2948 }
2949 catch (...)
2950 {
2951 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002952#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002953 }
2954}
2955
2956template <class _Allocator>
2957typename vector<bool, _Allocator>::reference
2958vector<bool, _Allocator>::at(size_type __n)
2959{
2960 if (__n >= size())
2961 this->__throw_out_of_range();
2962 return (*this)[__n];
2963}
2964
2965template <class _Allocator>
2966typename vector<bool, _Allocator>::const_reference
2967vector<bool, _Allocator>::at(size_type __n) const
2968{
2969 if (__n >= size())
2970 this->__throw_out_of_range();
2971 return (*this)[__n];
2972}
2973
2974template <class _Allocator>
2975void
2976vector<bool, _Allocator>::push_back(const value_type& __x)
2977{
2978 if (this->__size_ == this->capacity())
2979 reserve(__recommend(this->__size_ + 1));
2980 ++this->__size_;
2981 back() = __x;
2982}
2983
2984template <class _Allocator>
2985typename vector<bool, _Allocator>::iterator
2986vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2987{
2988 iterator __r;
2989 if (size() < capacity())
2990 {
2991 const_iterator __old_end = end();
2992 ++__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002993 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002994 __r = __const_iterator_cast(__position);
2995 }
2996 else
2997 {
2998 vector __v(__alloc());
2999 __v.reserve(__recommend(__size_ + 1));
3000 __v.__size_ = __size_ + 1;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003001 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3002 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003003 swap(__v);
3004 }
3005 *__r = __x;
3006 return __r;
3007}
3008
3009template <class _Allocator>
3010typename vector<bool, _Allocator>::iterator
3011vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
3012{
3013 iterator __r;
3014 size_type __c = capacity();
3015 if (__n <= __c && size() <= __c - __n)
3016 {
3017 const_iterator __old_end = end();
3018 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003019 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003020 __r = __const_iterator_cast(__position);
3021 }
3022 else
3023 {
3024 vector __v(__alloc());
3025 __v.reserve(__recommend(__size_ + __n));
3026 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003027 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3028 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003029 swap(__v);
3030 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003031 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003032 return __r;
3033}
3034
3035template <class _Allocator>
3036template <class _InputIterator>
3037typename enable_if
3038<
3039 __is_input_iterator <_InputIterator>::value &&
3040 !__is_forward_iterator<_InputIterator>::value,
3041 typename vector<bool, _Allocator>::iterator
3042>::type
3043vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
3044{
3045 difference_type __off = __position - begin();
3046 iterator __p = __const_iterator_cast(__position);
3047 iterator __old_end = end();
3048 for (; size() != capacity() && __first != __last; ++__first)
3049 {
3050 ++this->__size_;
3051 back() = *__first;
3052 }
3053 vector __v(__alloc());
3054 if (__first != __last)
3055 {
3056#ifndef _LIBCPP_NO_EXCEPTIONS
3057 try
3058 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003059#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003060 __v.assign(__first, __last);
3061 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
3062 difference_type __old_p = __p - begin();
3063 reserve(__recommend(size() + __v.size()));
3064 __p = begin() + __old_p;
3065 __old_end = begin() + __old_size;
3066#ifndef _LIBCPP_NO_EXCEPTIONS
3067 }
3068 catch (...)
3069 {
3070 erase(__old_end, end());
3071 throw;
3072 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003073#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003074 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003075 __p = _VSTD::rotate(__p, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003076 insert(__p, __v.begin(), __v.end());
3077 return begin() + __off;
3078}
3079
3080template <class _Allocator>
3081template <class _ForwardIterator>
3082typename enable_if
3083<
3084 __is_forward_iterator<_ForwardIterator>::value,
3085 typename vector<bool, _Allocator>::iterator
3086>::type
3087vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
3088{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003089 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003090 iterator __r;
3091 size_type __c = capacity();
3092 if (__n <= __c && size() <= __c - __n)
3093 {
3094 const_iterator __old_end = end();
3095 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003096 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003097 __r = __const_iterator_cast(__position);
3098 }
3099 else
3100 {
3101 vector __v(__alloc());
3102 __v.reserve(__recommend(__size_ + __n));
3103 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003104 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3105 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003106 swap(__v);
3107 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003108 _VSTD::copy(__first, __last, __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003109 return __r;
3110}
3111
3112template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003113inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003114typename vector<bool, _Allocator>::iterator
3115vector<bool, _Allocator>::erase(const_iterator __position)
3116{
3117 iterator __r = __const_iterator_cast(__position);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003118 _VSTD::copy(__position + 1, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003119 --__size_;
3120 return __r;
3121}
3122
3123template <class _Allocator>
3124typename vector<bool, _Allocator>::iterator
3125vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3126{
3127 iterator __r = __const_iterator_cast(__first);
3128 difference_type __d = __last - __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003129 _VSTD::copy(__last, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003130 __size_ -= __d;
3131 return __r;
3132}
3133
3134template <class _Allocator>
3135void
3136vector<bool, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003137 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3138 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003139{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003140 _VSTD::swap(this->__begin_, __x.__begin_);
3141 _VSTD::swap(this->__size_, __x.__size_);
3142 _VSTD::swap(this->__cap(), __x.__cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003143 __swap_alloc(this->__alloc(), __x.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003144}
3145
Howard Hinnant324bb032010-08-22 00:02:43 +00003146template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003147void
3148vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3149{
3150 size_type __cs = size();
3151 if (__cs < __sz)
3152 {
3153 iterator __r;
3154 size_type __c = capacity();
3155 size_type __n = __sz - __cs;
3156 if (__n <= __c && __cs <= __c - __n)
3157 {
3158 __r = end();
3159 __size_ += __n;
3160 }
3161 else
3162 {
3163 vector __v(__alloc());
3164 __v.reserve(__recommend(__size_ + __n));
3165 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003166 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003167 swap(__v);
3168 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003169 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003170 }
3171 else
3172 __size_ = __sz;
3173}
3174
Howard Hinnant324bb032010-08-22 00:02:43 +00003175template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003176void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003177vector<bool, _Allocator>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003178{
3179 // do middle whole words
3180 size_type __n = __size_;
3181 __storage_pointer __p = __begin_;
3182 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3183 *__p = ~*__p;
3184 // do last partial word
3185 if (__n > 0)
3186 {
3187 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3188 __storage_type __b = *__p & __m;
3189 *__p &= ~__m;
3190 *__p |= ~__b & __m;
3191 }
3192}
3193
Howard Hinnant324bb032010-08-22 00:02:43 +00003194template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003195bool
3196vector<bool, _Allocator>::__invariants() const
3197{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00003198 if (this->__begin_ == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003199 {
3200 if (this->__size_ != 0 || this->__cap() != 0)
3201 return false;
3202 }
3203 else
3204 {
3205 if (this->__cap() == 0)
3206 return false;
3207 if (this->__size_ > this->capacity())
3208 return false;
3209 }
3210 return true;
3211}
3212
Howard Hinnant324bb032010-08-22 00:02:43 +00003213template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003214size_t
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003215vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003216{
3217 size_t __h = 0;
3218 // do middle whole words
3219 size_type __n = __size_;
3220 __storage_pointer __p = __begin_;
3221 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3222 __h ^= *__p;
3223 // do last partial word
3224 if (__n > 0)
3225 {
3226 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3227 __h ^= *__p & __m;
3228 }
3229 return __h;
3230}
3231
3232template <class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003233struct _LIBCPP_TYPE_VIS_ONLY hash<vector<bool, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003234 : public unary_function<vector<bool, _Allocator>, size_t>
3235{
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003237 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003238 {return __vec.__hash_code();}
3239};
3240
3241template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003242inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003243bool
3244operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3245{
3246 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003247 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003248}
3249
3250template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003251inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003252bool
3253operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3254{
3255 return !(__x == __y);
3256}
3257
3258template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003259inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003260bool
3261operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3262{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003263 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003264}
3265
3266template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003267inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003268bool
3269operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3270{
3271 return __y < __x;
3272}
3273
3274template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003275inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003276bool
3277operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3278{
3279 return !(__x < __y);
3280}
3281
3282template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003283inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003284bool
3285operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3286{
3287 return !(__y < __x);
3288}
3289
3290template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003291inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003292void
3293swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003294 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003295{
3296 __x.swap(__y);
3297}
3298
3299_LIBCPP_END_NAMESPACE_STD
3300
3301#endif // _LIBCPP_VECTOR