blob: 1be584d061c64bff7615b4d1863d99cc380c42b6 [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
Eric Fiselierb9536102014-08-10 23:53:08 +0000279#include <__debug>
Howard Hinnant8b00e6c2013-08-02 00:26:35 +0000280
Howard Hinnant08e17472011-10-17 20:05:10 +0000281#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000282#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000283#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000284
285_LIBCPP_BEGIN_NAMESPACE_STD
286
287template <bool>
288class __vector_base_common
289{
290protected:
291 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
292 void __throw_length_error() const;
293 void __throw_out_of_range() const;
294};
295
296template <bool __b>
297void
298__vector_base_common<__b>::__throw_length_error() const
299{
300#ifndef _LIBCPP_NO_EXCEPTIONS
301 throw length_error("vector");
302#else
303 assert(!"vector length_error");
304#endif
305}
306
307template <bool __b>
308void
309__vector_base_common<__b>::__throw_out_of_range() const
310{
311#ifndef _LIBCPP_NO_EXCEPTIONS
312 throw out_of_range("vector");
313#else
314 assert(!"vector out_of_range");
315#endif
316}
317
Howard Hinnante9df0a52013-08-01 18:17:34 +0000318#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000319#pragma warning( push )
320#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000321#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000322_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +0000323#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000324#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000325#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000326
327template <class _Tp, class _Allocator>
328class __vector_base
329 : protected __vector_base_common<true>
330{
331protected:
Howard Hinnant324bb032010-08-22 00:02:43 +0000332 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333 typedef _Allocator allocator_type;
334 typedef allocator_traits<allocator_type> __alloc_traits;
335 typedef value_type& reference;
336 typedef const value_type& const_reference;
337 typedef typename __alloc_traits::size_type size_type;
338 typedef typename __alloc_traits::difference_type difference_type;
339 typedef typename __alloc_traits::pointer pointer;
340 typedef typename __alloc_traits::const_pointer const_pointer;
341 typedef pointer iterator;
342 typedef const_pointer const_iterator;
343
344 pointer __begin_;
345 pointer __end_;
346 __compressed_pair<pointer, allocator_type> __end_cap_;
347
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000348 _LIBCPP_INLINE_VISIBILITY
349 allocator_type& __alloc() _NOEXCEPT
350 {return __end_cap_.second();}
351 _LIBCPP_INLINE_VISIBILITY
352 const allocator_type& __alloc() const _NOEXCEPT
353 {return __end_cap_.second();}
354 _LIBCPP_INLINE_VISIBILITY
355 pointer& __end_cap() _NOEXCEPT
356 {return __end_cap_.first();}
357 _LIBCPP_INLINE_VISIBILITY
358 const pointer& __end_cap() const _NOEXCEPT
359 {return __end_cap_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000360
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000361 _LIBCPP_INLINE_VISIBILITY
362 __vector_base()
363 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000364 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365 ~__vector_base();
366
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000367 _LIBCPP_INLINE_VISIBILITY
368 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
369 _LIBCPP_INLINE_VISIBILITY
370 size_type capacity() const _NOEXCEPT
371 {return static_cast<size_type>(__end_cap() - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000374 void __destruct_at_end(pointer __new_last) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000376 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377 void __copy_assign_alloc(const __vector_base& __c)
378 {__copy_assign_alloc(__c, integral_constant<bool,
379 __alloc_traits::propagate_on_container_copy_assignment::value>());}
380
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382 void __move_assign_alloc(__vector_base& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000383 _NOEXCEPT_(
384 !__alloc_traits::propagate_on_container_move_assignment::value ||
385 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386 {__move_assign_alloc(__c, integral_constant<bool,
387 __alloc_traits::propagate_on_container_move_assignment::value>());}
388
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000391 _NOEXCEPT_(
392 !__alloc_traits::propagate_on_container_swap::value ||
393 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394 {__swap_alloc(__x, __y, integral_constant<bool,
395 __alloc_traits::propagate_on_container_swap::value>());}
396private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000398 void __copy_assign_alloc(const __vector_base& __c, true_type)
399 {
400 if (__alloc() != __c.__alloc())
401 {
402 clear();
403 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
404 __begin_ = __end_ = __end_cap() = nullptr;
405 }
406 __alloc() = __c.__alloc();
407 }
408
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +0000410 void __copy_assign_alloc(const __vector_base&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411 {}
412
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000414 void __move_assign_alloc(__vector_base& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000415 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000417 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418 }
419
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +0000421 void __move_assign_alloc(__vector_base&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000422 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423 {}
424
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000427 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000429 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430 swap(__x, __y);
431 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000432 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +0000433 static void __swap_alloc(allocator_type&, allocator_type&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000434 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435 {}
436};
437
438template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000439inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440void
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000441__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442{
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000443 while (__new_last != __end_)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000444 __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445}
446
447template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000448inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449__vector_base<_Tp, _Allocator>::__vector_base()
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000450 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000451 : __begin_(nullptr),
452 __end_(nullptr),
453 __end_cap_(nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454{
455}
456
457template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000458inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000460 : __begin_(nullptr),
461 __end_(nullptr),
462 __end_cap_(nullptr, __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463{
464}
465
466template <class _Tp, class _Allocator>
467__vector_base<_Tp, _Allocator>::~__vector_base()
468{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000469 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 {
471 clear();
472 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
473 }
474}
475
476template <class _Tp, class _Allocator = allocator<_Tp> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000477class _LIBCPP_TYPE_VIS_ONLY vector
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478 : private __vector_base<_Tp, _Allocator>
479{
480private:
481 typedef __vector_base<_Tp, _Allocator> __base;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000482 typedef allocator<_Tp> __default_allocator_type;
Howard Hinnant324bb032010-08-22 00:02:43 +0000483public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +0000485 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000486 typedef _Allocator allocator_type;
487 typedef typename __base::__alloc_traits __alloc_traits;
488 typedef typename __base::reference reference;
489 typedef typename __base::const_reference const_reference;
490 typedef typename __base::size_type size_type;
491 typedef typename __base::difference_type difference_type;
492 typedef typename __base::pointer pointer;
493 typedef typename __base::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494 typedef __wrap_iter<pointer> iterator;
495 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000496 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
497 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498
Howard Hinnant02d5e182013-03-26 19:04:56 +0000499 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
500 "Allocator::value_type must be same type as value_type");
501
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000502 _LIBCPP_INLINE_VISIBILITY
503 vector()
504 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant7a563db2011-09-14 18:33:51 +0000505 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000506#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000507 __get_db()->__insert_c(this);
508#endif
509 }
510 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
511 : __base(__a)
512 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000513#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000514 __get_db()->__insert_c(this);
515#endif
516 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517 explicit vector(size_type __n);
Marshall Clowa49a2c92013-09-14 00:47:59 +0000518#if _LIBCPP_STD_VER > 11
519 explicit vector(size_type __n, const allocator_type& __a);
520#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521 vector(size_type __n, const_reference __x);
522 vector(size_type __n, const_reference __x, const allocator_type& __a);
523 template <class _InputIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +0000524 vector(_InputIterator __first,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000526 !__is_forward_iterator<_InputIterator>::value &&
527 is_constructible<
528 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +0000529 typename iterator_traits<_InputIterator>::reference>::value,
530 _InputIterator>::type __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531 template <class _InputIterator>
532 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
533 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000534 !__is_forward_iterator<_InputIterator>::value &&
535 is_constructible<
536 value_type,
537 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538 template <class _ForwardIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +0000539 vector(_ForwardIterator __first,
Howard Hinnant742fecb2013-03-28 17:44:32 +0000540 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
541 is_constructible<
542 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +0000543 typename iterator_traits<_ForwardIterator>::reference>::value,
544 _ForwardIterator>::type __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545 template <class _ForwardIterator>
546 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
Howard Hinnant742fecb2013-03-28 17:44:32 +0000547 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
548 is_constructible<
549 value_type,
550 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02 +0000551#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553 vector(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000555 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000556#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantabe26282011-09-16 17:29:17 +0000557#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a563db2011-09-14 18:33:51 +0000559 ~vector()
560 {
561 __get_db()->__erase_c(this);
562 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000563#endif
564
565 vector(const vector& __x);
566 vector(const vector& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568 vector& operator=(const vector& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000569#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000571 vector(vector&& __x)
572 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574 vector(vector&& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000576 vector& operator=(vector&& __x)
577 _NOEXCEPT_(
578 __alloc_traits::propagate_on_container_move_assignment::value &&
579 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000580#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000581#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000583 vector& operator=(initializer_list<value_type> __il)
584 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000585#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586
587 template <class _InputIterator>
588 typename enable_if
589 <
590 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000591 !__is_forward_iterator<_InputIterator>::value &&
592 is_constructible<
593 value_type,
594 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595 void
596 >::type
597 assign(_InputIterator __first, _InputIterator __last);
598 template <class _ForwardIterator>
599 typename enable_if
600 <
Howard Hinnant742fecb2013-03-28 17:44:32 +0000601 __is_forward_iterator<_ForwardIterator>::value &&
602 is_constructible<
603 value_type,
604 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000605 void
606 >::type
607 assign(_ForwardIterator __first, _ForwardIterator __last);
608
609 void assign(size_type __n, const_reference __u);
Howard Hinnante3e32912011-08-12 21:56:02 +0000610#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000612 void assign(initializer_list<value_type> __il)
613 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000614#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000615
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000616 _LIBCPP_INLINE_VISIBILITY
617 allocator_type get_allocator() const _NOEXCEPT
618 {return this->__alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000620 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
621 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
622 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
623 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000625 _LIBCPP_INLINE_VISIBILITY
626 reverse_iterator rbegin() _NOEXCEPT
627 {return reverse_iterator(end());}
628 _LIBCPP_INLINE_VISIBILITY
629 const_reverse_iterator rbegin() const _NOEXCEPT
630 {return const_reverse_iterator(end());}
631 _LIBCPP_INLINE_VISIBILITY
632 reverse_iterator rend() _NOEXCEPT
633 {return reverse_iterator(begin());}
634 _LIBCPP_INLINE_VISIBILITY
635 const_reverse_iterator rend() const _NOEXCEPT
636 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000638 _LIBCPP_INLINE_VISIBILITY
639 const_iterator cbegin() const _NOEXCEPT
640 {return begin();}
641 _LIBCPP_INLINE_VISIBILITY
642 const_iterator cend() const _NOEXCEPT
643 {return end();}
644 _LIBCPP_INLINE_VISIBILITY
645 const_reverse_iterator crbegin() const _NOEXCEPT
646 {return rbegin();}
647 _LIBCPP_INLINE_VISIBILITY
648 const_reverse_iterator crend() const _NOEXCEPT
649 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000650
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000651 _LIBCPP_INLINE_VISIBILITY
652 size_type size() const _NOEXCEPT
653 {return static_cast<size_type>(this->__end_ - this->__begin_);}
654 _LIBCPP_INLINE_VISIBILITY
655 size_type capacity() const _NOEXCEPT
656 {return __base::capacity();}
657 _LIBCPP_INLINE_VISIBILITY
658 bool empty() const _NOEXCEPT
659 {return this->__begin_ == this->__end_;}
660 size_type max_size() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000662 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663
664 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
665 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
666 reference at(size_type __n);
667 const_reference at(size_type __n) const;
668
Howard Hinnant7a563db2011-09-14 18:33:51 +0000669 _LIBCPP_INLINE_VISIBILITY reference front()
670 {
671 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
672 return *this->__begin_;
673 }
674 _LIBCPP_INLINE_VISIBILITY const_reference front() const
675 {
676 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
677 return *this->__begin_;
678 }
679 _LIBCPP_INLINE_VISIBILITY reference back()
680 {
681 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
682 return *(this->__end_ - 1);
683 }
684 _LIBCPP_INLINE_VISIBILITY const_reference back() const
685 {
686 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
687 return *(this->__end_ - 1);
688 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000690 _LIBCPP_INLINE_VISIBILITY
691 value_type* data() _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000692 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000693 _LIBCPP_INLINE_VISIBILITY
694 const value_type* data() const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000695 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000696
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000697 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000698#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000699 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000700#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000701 template <class... _Args>
702 void emplace_back(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000703#endif // _LIBCPP_HAS_NO_VARIADICS
704#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705 void pop_back();
706
707 iterator insert(const_iterator __position, const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000708#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000709 iterator insert(const_iterator __position, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000710#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 template <class... _Args>
712 iterator emplace(const_iterator __position, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000713#endif // _LIBCPP_HAS_NO_VARIADICS
714#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715 iterator insert(const_iterator __position, size_type __n, const_reference __x);
716 template <class _InputIterator>
717 typename enable_if
718 <
719 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000720 !__is_forward_iterator<_InputIterator>::value &&
721 is_constructible<
722 value_type,
723 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724 iterator
725 >::type
726 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
727 template <class _ForwardIterator>
728 typename enable_if
729 <
Howard Hinnant742fecb2013-03-28 17:44:32 +0000730 __is_forward_iterator<_ForwardIterator>::value &&
731 is_constructible<
732 value_type,
733 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734 iterator
735 >::type
736 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000737#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000738 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739 iterator insert(const_iterator __position, initializer_list<value_type> __il)
740 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000741#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000743 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744 iterator erase(const_iterator __first, const_iterator __last);
745
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000746 _LIBCPP_INLINE_VISIBILITY
747 void clear() _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +0000748 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000749 size_type __old_size = size();
Howard Hinnant7a563db2011-09-14 18:33:51 +0000750 __base::clear();
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000751 __annotate_shrink(__old_size);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000752 __invalidate_all_iterators();
753 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754
755 void resize(size_type __sz);
756 void resize(size_type __sz, const_reference __x);
757
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000758 void swap(vector&)
759 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
760 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761
762 bool __invariants() const;
763
Howard Hinnantabe26282011-09-16 17:29:17 +0000764#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000765
766 bool __dereferenceable(const const_iterator* __i) const;
767 bool __decrementable(const const_iterator* __i) const;
768 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
769 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
770
Howard Hinnantabe26282011-09-16 17:29:17 +0000771#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000772
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000773private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000774 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000776 void deallocate() _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000777 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
Howard Hinnant04240d92011-01-04 19:53:31 +0000778 void __construct_at_end(size_type __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779 void __construct_at_end(size_type __n, const_reference __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000780 template <class _ForwardIterator>
781 typename enable_if
782 <
783 __is_forward_iterator<_ForwardIterator>::value,
784 void
785 >::type
786 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
787 void __move_construct_at_end(pointer __first, pointer __last);
788 void __append(size_type __n);
789 void __append(size_type __n, const_reference __x);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000791 iterator __make_iter(pointer __p) _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000793 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
795 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
796 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000797 void __move_assign(vector& __c, true_type)
798 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799 void __move_assign(vector& __c, false_type);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000801 void __destruct_at_end(pointer __new_last) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +0000802 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000803#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000804 __c_node* __c = __get_db()->__find_c_and_lock(this);
805 for (__i_node** __p = __c->end_; __p != __c->beg_; )
806 {
807 --__p;
808 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
809 if (__i->base() > __new_last)
810 {
811 (*__p)->__c_ = nullptr;
812 if (--__c->end_ != __p)
813 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
814 }
815 }
816 __get_db()->unlock();
817#endif
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000818 size_type __old_size = size();
Howard Hinnant7a563db2011-09-14 18:33:51 +0000819 __base::__destruct_at_end(__new_last);
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000820 __annotate_shrink(__old_size);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000821 }
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000822 template <class _Up>
823 void
824#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
825 __push_back_slow_path(_Up&& __x);
826#else
827 __push_back_slow_path(_Up& __x);
828#endif
Howard Hinnant0438ea22012-02-26 15:30:12 +0000829#if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
830 template <class... _Args>
831 void
832 __emplace_back_slow_path(_Args&&... __args);
833#endif
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000834 // The following functions are no-ops outside of AddressSanitizer mode.
835 // We call annotatations only for the default Allocator because other allocators
836 // may not meet the AddressSanitizer alignment constraints.
837 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
838 void __annotate_contiguous_container
839 (const void *__beg, const void *__end, const void *__old_mid, const void *__new_mid)
840 {
841#ifndef _LIBCPP_HAS_NO_ASAN
842 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
843 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
844#endif
845 }
846
847 void __annotate_new(size_type __current_size)
848 {
849 __annotate_contiguous_container(data(), data() + capacity(),
850 data() + capacity(), data() + __current_size);
851 }
852 void __annotate_delete()
853 {
854 __annotate_contiguous_container(data(), data() + capacity(),
855 data() + size(), data() + capacity());
856 }
857 void __annotate_increase(size_type __n)
858 {
859 __annotate_contiguous_container(data(), data() + capacity(),
860 data() + size(), data() + size() + __n);
861 }
862 void __annotate_shrink(size_type __old_size)
863 {
864 __annotate_contiguous_container(data(), data() + capacity(),
865 data() + __old_size, data() + size());
866 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000867};
868
869template <class _Tp, class _Allocator>
870void
871vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
872{
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000873 __annotate_delete();
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000874 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000875 _VSTD::swap(this->__begin_, __v.__begin_);
876 _VSTD::swap(this->__end_, __v.__end_);
877 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878 __v.__first_ = __v.__begin_;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000879 __annotate_new(size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000880 __invalidate_all_iterators();
881}
882
883template <class _Tp, class _Allocator>
884typename vector<_Tp, _Allocator>::pointer
885vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
886{
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000887 __annotate_delete();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888 pointer __r = __v.__begin_;
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000889 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
890 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000891 _VSTD::swap(this->__begin_, __v.__begin_);
892 _VSTD::swap(this->__end_, __v.__end_);
893 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894 __v.__first_ = __v.__begin_;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000895 __annotate_new(size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896 __invalidate_all_iterators();
897 return __r;
898}
899
900// Allocate space for __n objects
901// throws length_error if __n > max_size()
902// throws (probably bad_alloc) if memory run out
903// Precondition: __begin_ == __end_ == __end_cap() == 0
904// Precondition: __n > 0
905// Postcondition: capacity() == __n
906// Postcondition: size() == 0
907template <class _Tp, class _Allocator>
908void
909vector<_Tp, _Allocator>::allocate(size_type __n)
910{
911 if (__n > max_size())
912 this->__throw_length_error();
913 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
914 this->__end_cap() = this->__begin_ + __n;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000915 __annotate_new(0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916}
917
918template <class _Tp, class _Allocator>
919void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000920vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000921{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000922 if (this->__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000923 {
924 clear();
925 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000926 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927 }
928}
929
930template <class _Tp, class _Allocator>
931typename vector<_Tp, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000932vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933{
Sean Hunt110b8bf2011-07-29 23:31:58 +0000934 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 +0000935}
936
937// Precondition: __new_size > capacity()
938template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000939inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000940typename vector<_Tp, _Allocator>::size_type
941vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
942{
943 const size_type __ms = max_size();
944 if (__new_size > __ms)
945 this->__throw_length_error();
946 const size_type __cap = capacity();
947 if (__cap >= __ms / 2)
948 return __ms;
Sean Hunt110b8bf2011-07-29 23:31:58 +0000949 return _VSTD::max<size_type>(2*__cap, __new_size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000950}
951
952// Default constructs __n objects starting at __end_
953// throws if construction throws
954// Precondition: __n > 0
955// Precondition: size() + __n <= capacity()
956// Postcondition: size() == size() + __n
957template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958void
959vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
960{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000961 allocator_type& __a = this->__alloc();
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000962 __annotate_increase(__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000963 do
964 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000965 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000966 ++this->__end_;
967 --__n;
968 } while (__n > 0);
969}
970
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971// Copy constructs __n objects starting at __end_ from __x
972// throws if construction throws
973// Precondition: __n > 0
974// Precondition: size() + __n <= capacity()
975// Postcondition: size() == old size() + __n
976// Postcondition: [i] == __x for all i in [size() - __n, __n)
977template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000978inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000979void
980vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
981{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982 allocator_type& __a = this->__alloc();
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000983 __annotate_increase(__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984 do
985 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000986 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987 ++this->__end_;
988 --__n;
989 } while (__n > 0);
990}
991
992template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000993template <class _ForwardIterator>
994typename enable_if
995<
996 __is_forward_iterator<_ForwardIterator>::value,
997 void
998>::type
999vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
1000{
1001 allocator_type& __a = this->__alloc();
1002 for (; __first != __last; ++__first)
1003 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001004 __annotate_increase(1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001005 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001006 ++this->__end_;
1007 }
1008}
1009
1010template <class _Tp, class _Allocator>
1011void
1012vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
1013{
1014 allocator_type& __a = this->__alloc();
1015 for (; __first != __last; ++__first)
1016 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001017 __annotate_increase(1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001018 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
1019 _VSTD::move(*__first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001020 ++this->__end_;
1021 }
1022}
1023
1024// Default constructs __n objects starting at __end_
1025// throws if construction throws
1026// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001027// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001028template <class _Tp, class _Allocator>
1029void
1030vector<_Tp, _Allocator>::__append(size_type __n)
1031{
1032 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1033 this->__construct_at_end(__n);
1034 else
1035 {
1036 allocator_type& __a = this->__alloc();
1037 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1038 __v.__construct_at_end(__n);
1039 __swap_out_circular_buffer(__v);
1040 }
1041}
1042
1043// Default constructs __n objects starting at __end_
1044// throws if construction throws
1045// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001046// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001047template <class _Tp, class _Allocator>
1048void
1049vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1050{
1051 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1052 this->__construct_at_end(__n, __x);
1053 else
1054 {
1055 allocator_type& __a = this->__alloc();
1056 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1057 __v.__construct_at_end(__n, __x);
1058 __swap_out_circular_buffer(__v);
1059 }
1060}
1061
1062template <class _Tp, class _Allocator>
1063vector<_Tp, _Allocator>::vector(size_type __n)
1064{
Howard Hinnant0442b122011-09-16 18:41:29 +00001065#if _LIBCPP_DEBUG_LEVEL >= 2
1066 __get_db()->__insert_c(this);
1067#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001068 if (__n > 0)
1069 {
1070 allocate(__n);
1071 __construct_at_end(__n);
1072 }
1073}
1074
Marshall Clowa49a2c92013-09-14 00:47:59 +00001075#if _LIBCPP_STD_VER > 11
1076template <class _Tp, class _Allocator>
1077vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1078 : __base(__a)
1079{
1080#if _LIBCPP_DEBUG_LEVEL >= 2
1081 __get_db()->__insert_c(this);
1082#endif
1083 if (__n > 0)
1084 {
1085 allocate(__n);
1086 __construct_at_end(__n);
1087 }
1088}
1089#endif
1090
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091template <class _Tp, class _Allocator>
1092vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1093{
Howard Hinnant0442b122011-09-16 18:41:29 +00001094#if _LIBCPP_DEBUG_LEVEL >= 2
1095 __get_db()->__insert_c(this);
1096#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001097 if (__n > 0)
1098 {
1099 allocate(__n);
1100 __construct_at_end(__n, __x);
1101 }
1102}
1103
1104template <class _Tp, class _Allocator>
1105vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1106 : __base(__a)
1107{
Howard Hinnant0442b122011-09-16 18:41:29 +00001108#if _LIBCPP_DEBUG_LEVEL >= 2
1109 __get_db()->__insert_c(this);
1110#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001111 if (__n > 0)
1112 {
1113 allocate(__n);
1114 __construct_at_end(__n, __x);
1115 }
1116}
1117
1118template <class _Tp, class _Allocator>
1119template <class _InputIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +00001120vector<_Tp, _Allocator>::vector(_InputIterator __first,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001121 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001122 !__is_forward_iterator<_InputIterator>::value &&
1123 is_constructible<
1124 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +00001125 typename iterator_traits<_InputIterator>::reference>::value,
1126 _InputIterator>::type __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001127{
Howard Hinnantabe26282011-09-16 17:29:17 +00001128#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001129 __get_db()->__insert_c(this);
1130#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001131 for (; __first != __last; ++__first)
1132 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133}
1134
1135template <class _Tp, class _Allocator>
1136template <class _InputIterator>
1137vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1138 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001139 !__is_forward_iterator<_InputIterator>::value &&
1140 is_constructible<
1141 value_type,
1142 typename iterator_traits<_InputIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001143 : __base(__a)
1144{
Howard Hinnantabe26282011-09-16 17:29:17 +00001145#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001146 __get_db()->__insert_c(this);
1147#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001148 for (; __first != __last; ++__first)
1149 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001150}
1151
1152template <class _Tp, class _Allocator>
1153template <class _ForwardIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +00001154vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
Howard Hinnant742fecb2013-03-28 17:44:32 +00001155 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1156 is_constructible<
1157 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +00001158 typename iterator_traits<_ForwardIterator>::reference>::value,
1159 _ForwardIterator>::type __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160{
Howard Hinnant0442b122011-09-16 18:41:29 +00001161#if _LIBCPP_DEBUG_LEVEL >= 2
1162 __get_db()->__insert_c(this);
1163#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001164 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001165 if (__n > 0)
1166 {
1167 allocate(__n);
1168 __construct_at_end(__first, __last);
1169 }
1170}
1171
1172template <class _Tp, class _Allocator>
1173template <class _ForwardIterator>
1174vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
Howard Hinnant742fecb2013-03-28 17:44:32 +00001175 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1176 is_constructible<
1177 value_type,
1178 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001179 : __base(__a)
1180{
Howard Hinnant0442b122011-09-16 18:41:29 +00001181#if _LIBCPP_DEBUG_LEVEL >= 2
1182 __get_db()->__insert_c(this);
1183#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001184 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001185 if (__n > 0)
1186 {
1187 allocate(__n);
1188 __construct_at_end(__first, __last);
1189 }
1190}
1191
1192template <class _Tp, class _Allocator>
1193vector<_Tp, _Allocator>::vector(const vector& __x)
1194 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1195{
Howard Hinnant0442b122011-09-16 18:41:29 +00001196#if _LIBCPP_DEBUG_LEVEL >= 2
1197 __get_db()->__insert_c(this);
1198#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001199 size_type __n = __x.size();
1200 if (__n > 0)
1201 {
1202 allocate(__n);
1203 __construct_at_end(__x.__begin_, __x.__end_);
1204 }
1205}
1206
1207template <class _Tp, class _Allocator>
1208vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1209 : __base(__a)
1210{
Howard Hinnant0442b122011-09-16 18:41:29 +00001211#if _LIBCPP_DEBUG_LEVEL >= 2
1212 __get_db()->__insert_c(this);
1213#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001214 size_type __n = __x.size();
1215 if (__n > 0)
1216 {
1217 allocate(__n);
1218 __construct_at_end(__x.__begin_, __x.__end_);
1219 }
1220}
1221
Howard Hinnant73d21a42010-09-04 23:28:19 +00001222#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223
1224template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001225inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001226vector<_Tp, _Allocator>::vector(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001227 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001228 : __base(_VSTD::move(__x.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001229{
Howard Hinnantabe26282011-09-16 17:29:17 +00001230#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001231 __get_db()->__insert_c(this);
Howard Hinnante6125bd2011-09-19 16:34:29 +00001232 __get_db()->swap(this, &__x);
Howard Hinnant7a563db2011-09-14 18:33:51 +00001233#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001234 this->__begin_ = __x.__begin_;
1235 this->__end_ = __x.__end_;
1236 this->__end_cap() = __x.__end_cap();
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001237 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001238}
1239
1240template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001241inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1243 : __base(__a)
1244{
Howard Hinnant0442b122011-09-16 18:41:29 +00001245#if _LIBCPP_DEBUG_LEVEL >= 2
1246 __get_db()->__insert_c(this);
1247#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001248 if (__a == __x.__alloc())
1249 {
1250 this->__begin_ = __x.__begin_;
1251 this->__end_ = __x.__end_;
1252 this->__end_cap() = __x.__end_cap();
1253 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001254#if _LIBCPP_DEBUG_LEVEL >= 2
1255 __get_db()->swap(this, &__x);
1256#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001257 }
1258 else
1259 {
Howard Hinnant99968442011-11-29 18:15:50 +00001260 typedef move_iterator<iterator> _Ip;
1261 assign(_Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262 }
1263}
1264
Howard Hinnante3e32912011-08-12 21:56:02 +00001265#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1266
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001268inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1270{
Howard Hinnant0442b122011-09-16 18:41:29 +00001271#if _LIBCPP_DEBUG_LEVEL >= 2
1272 __get_db()->__insert_c(this);
1273#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274 if (__il.size() > 0)
1275 {
1276 allocate(__il.size());
1277 __construct_at_end(__il.begin(), __il.end());
1278 }
1279}
1280
1281template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001282inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001283vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1284 : __base(__a)
1285{
Howard Hinnant0442b122011-09-16 18:41:29 +00001286#if _LIBCPP_DEBUG_LEVEL >= 2
1287 __get_db()->__insert_c(this);
1288#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001289 if (__il.size() > 0)
1290 {
1291 allocate(__il.size());
1292 __construct_at_end(__il.begin(), __il.end());
1293 }
1294}
1295
Howard Hinnante3e32912011-08-12 21:56:02 +00001296#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1297
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001299inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001300vector<_Tp, _Allocator>&
1301vector<_Tp, _Allocator>::operator=(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001302 _NOEXCEPT_(
1303 __alloc_traits::propagate_on_container_move_assignment::value &&
1304 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305{
1306 __move_assign(__x, integral_constant<bool,
1307 __alloc_traits::propagate_on_container_move_assignment::value>());
1308 return *this;
1309}
1310
1311template <class _Tp, class _Allocator>
1312void
1313vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1314{
1315 if (__base::__alloc() != __c.__alloc())
1316 {
Howard Hinnant99968442011-11-29 18:15:50 +00001317 typedef move_iterator<iterator> _Ip;
1318 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001319 }
1320 else
1321 __move_assign(__c, true_type());
1322}
1323
1324template <class _Tp, class _Allocator>
1325void
1326vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001327 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001328{
1329 deallocate();
Marshall Clow3c2eac62014-07-21 15:11:13 +00001330 __base::__move_assign_alloc(__c); // this can throw
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331 this->__begin_ = __c.__begin_;
1332 this->__end_ = __c.__end_;
1333 this->__end_cap() = __c.__end_cap();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001335#if _LIBCPP_DEBUG_LEVEL >= 2
1336 __get_db()->swap(this, &__c);
1337#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338}
1339
Howard Hinnant73d21a42010-09-04 23:28:19 +00001340#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001341
1342template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001343inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001344vector<_Tp, _Allocator>&
1345vector<_Tp, _Allocator>::operator=(const vector& __x)
1346{
1347 if (this != &__x)
1348 {
1349 __base::__copy_assign_alloc(__x);
1350 assign(__x.__begin_, __x.__end_);
1351 }
1352 return *this;
1353}
1354
1355template <class _Tp, class _Allocator>
1356template <class _InputIterator>
1357typename enable_if
1358<
1359 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001360 !__is_forward_iterator<_InputIterator>::value &&
1361 is_constructible<
1362 _Tp,
1363 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001364 void
1365>::type
1366vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1367{
1368 clear();
1369 for (; __first != __last; ++__first)
1370 push_back(*__first);
1371}
1372
1373template <class _Tp, class _Allocator>
1374template <class _ForwardIterator>
1375typename enable_if
1376<
Howard Hinnant742fecb2013-03-28 17:44:32 +00001377 __is_forward_iterator<_ForwardIterator>::value &&
1378 is_constructible<
1379 _Tp,
1380 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001381 void
1382>::type
1383vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1384{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001385 typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001386 if (static_cast<size_type>(__new_size) <= capacity())
1387 {
1388 _ForwardIterator __mid = __last;
1389 bool __growing = false;
1390 if (static_cast<size_type>(__new_size) > size())
1391 {
1392 __growing = true;
1393 __mid = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001394 _VSTD::advance(__mid, size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001395 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001396 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001397 if (__growing)
1398 __construct_at_end(__mid, __last);
1399 else
1400 this->__destruct_at_end(__m);
1401 }
1402 else
1403 {
1404 deallocate();
1405 allocate(__recommend(static_cast<size_type>(__new_size)));
1406 __construct_at_end(__first, __last);
1407 }
1408}
1409
1410template <class _Tp, class _Allocator>
1411void
1412vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1413{
1414 if (__n <= capacity())
1415 {
1416 size_type __s = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001417 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418 if (__n > __s)
1419 __construct_at_end(__n - __s, __u);
1420 else
Howard Hinnantadff4892010-05-24 17:49:41 +00001421 this->__destruct_at_end(this->__begin_ + __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422 }
1423 else
1424 {
1425 deallocate();
1426 allocate(__recommend(static_cast<size_type>(__n)));
1427 __construct_at_end(__n, __u);
1428 }
1429}
1430
Howard Hinnant324bb032010-08-22 00:02:43 +00001431template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001432inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001433typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001434vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001435{
Howard Hinnantabe26282011-09-16 17:29:17 +00001436#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437 return iterator(this, __p);
1438#else
1439 return iterator(__p);
1440#endif
1441}
1442
Howard Hinnant324bb032010-08-22 00:02:43 +00001443template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001444inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001445typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001446vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001447{
Howard Hinnantabe26282011-09-16 17:29:17 +00001448#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001449 return const_iterator(this, __p);
1450#else
1451 return const_iterator(__p);
1452#endif
1453}
1454
Howard Hinnant324bb032010-08-22 00:02:43 +00001455template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001456inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001457typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001458vector<_Tp, _Allocator>::begin() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001459{
1460 return __make_iter(this->__begin_);
1461}
1462
Howard Hinnant324bb032010-08-22 00:02:43 +00001463template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001464inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001465typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001466vector<_Tp, _Allocator>::begin() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001467{
1468 return __make_iter(this->__begin_);
1469}
1470
Howard Hinnant324bb032010-08-22 00:02:43 +00001471template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001472inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001473typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001474vector<_Tp, _Allocator>::end() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001475{
1476 return __make_iter(this->__end_);
1477}
1478
Howard Hinnant324bb032010-08-22 00:02:43 +00001479template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001480inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001481typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001482vector<_Tp, _Allocator>::end() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001483{
1484 return __make_iter(this->__end_);
1485}
1486
Howard Hinnant324bb032010-08-22 00:02:43 +00001487template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001488inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001489typename vector<_Tp, _Allocator>::reference
1490vector<_Tp, _Allocator>::operator[](size_type __n)
1491{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001492 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493 return this->__begin_[__n];
1494}
1495
Howard Hinnant324bb032010-08-22 00:02:43 +00001496template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001497inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001498typename vector<_Tp, _Allocator>::const_reference
1499vector<_Tp, _Allocator>::operator[](size_type __n) const
1500{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001501 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001502 return this->__begin_[__n];
1503}
1504
Howard Hinnant324bb032010-08-22 00:02:43 +00001505template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506typename vector<_Tp, _Allocator>::reference
1507vector<_Tp, _Allocator>::at(size_type __n)
1508{
1509 if (__n >= size())
1510 this->__throw_out_of_range();
1511 return this->__begin_[__n];
1512}
1513
Howard Hinnant324bb032010-08-22 00:02:43 +00001514template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515typename vector<_Tp, _Allocator>::const_reference
1516vector<_Tp, _Allocator>::at(size_type __n) const
1517{
1518 if (__n >= size())
1519 this->__throw_out_of_range();
1520 return this->__begin_[__n];
1521}
1522
1523template <class _Tp, class _Allocator>
1524void
1525vector<_Tp, _Allocator>::reserve(size_type __n)
1526{
1527 if (__n > capacity())
1528 {
1529 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001530 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531 __swap_out_circular_buffer(__v);
1532 }
1533}
1534
1535template <class _Tp, class _Allocator>
1536void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001537vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001538{
1539 if (capacity() > size())
1540 {
1541#ifndef _LIBCPP_NO_EXCEPTIONS
1542 try
1543 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001544#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001546 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001547 __swap_out_circular_buffer(__v);
1548#ifndef _LIBCPP_NO_EXCEPTIONS
1549 }
1550 catch (...)
1551 {
1552 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001553#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554 }
1555}
1556
1557template <class _Tp, class _Allocator>
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001558template <class _Up>
1559void
1560#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1561vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1562#else
1563vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1564#endif
1565{
1566 allocator_type& __a = this->__alloc();
1567 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1568 // __v.push_back(_VSTD::forward<_Up>(__x));
Howard Hinnantf619e232013-01-11 20:36:59 +00001569 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
1570 __v.__end_++;
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001571 __swap_out_circular_buffer(__v);
1572}
1573
1574template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001575inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001576void
1577vector<_Tp, _Allocator>::push_back(const_reference __x)
1578{
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001579 if (this->__end_ != this->__end_cap())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001581 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001582 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001583 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001584 ++this->__end_;
1585 }
1586 else
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001587 __push_back_slow_path(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001588}
1589
Howard Hinnant73d21a42010-09-04 23:28:19 +00001590#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001591
1592template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001593inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001594void
1595vector<_Tp, _Allocator>::push_back(value_type&& __x)
1596{
1597 if (this->__end_ < this->__end_cap())
1598 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001599 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001600 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001601 _VSTD::__to_raw_pointer(this->__end_),
1602 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001603 ++this->__end_;
1604 }
1605 else
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001606 __push_back_slow_path(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001607}
1608
Howard Hinnant73d21a42010-09-04 23:28:19 +00001609#ifndef _LIBCPP_HAS_NO_VARIADICS
1610
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001611template <class _Tp, class _Allocator>
1612template <class... _Args>
1613void
Howard Hinnant0438ea22012-02-26 15:30:12 +00001614vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1615{
1616 allocator_type& __a = this->__alloc();
1617 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1618// __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantf619e232013-01-11 20:36:59 +00001619 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
1620 __v.__end_++;
Howard Hinnant0438ea22012-02-26 15:30:12 +00001621 __swap_out_circular_buffer(__v);
1622}
1623
1624template <class _Tp, class _Allocator>
1625template <class... _Args>
Howard Hinnant1e564242013-10-04 22:09:00 +00001626inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0438ea22012-02-26 15:30:12 +00001627void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1629{
1630 if (this->__end_ < this->__end_cap())
1631 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001632 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001633 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001634 _VSTD::__to_raw_pointer(this->__end_),
1635 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001636 ++this->__end_;
1637 }
1638 else
Howard Hinnant0438ea22012-02-26 15:30:12 +00001639 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640}
1641
Howard Hinnant73d21a42010-09-04 23:28:19 +00001642#endif // _LIBCPP_HAS_NO_VARIADICS
1643#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644
1645template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001646inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647void
1648vector<_Tp, _Allocator>::pop_back()
1649{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001650 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651 this->__destruct_at_end(this->__end_ - 1);
1652}
1653
1654template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001655inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001656typename vector<_Tp, _Allocator>::iterator
1657vector<_Tp, _Allocator>::erase(const_iterator __position)
1658{
Howard Hinnantabe26282011-09-16 17:29:17 +00001659#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001660 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1661 "vector::erase(iterator) called with an iterator not"
1662 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001663#endif
Howard Hinnant782da332013-03-25 22:12:26 +00001664 _LIBCPP_ASSERT(__position != end(),
1665 "vector::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001666 difference_type __ps = __position - cbegin();
1667 pointer __p = this->__begin_ + __ps;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001668 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001669 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001670 return __r;
1671}
1672
1673template <class _Tp, class _Allocator>
1674typename vector<_Tp, _Allocator>::iterator
1675vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1676{
Howard Hinnantabe26282011-09-16 17:29:17 +00001677#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001678 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1679 "vector::erase(iterator, iterator) called with an iterator not"
1680 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001681#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001682 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001683 pointer __p = this->__begin_ + (__first - begin());
1684 iterator __r = __make_iter(__p);
Howard Hinnantb4e67cf2013-04-18 15:02:57 +00001685 if (__first != __last)
1686 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001687 return __r;
1688}
1689
1690template <class _Tp, class _Allocator>
1691void
1692vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1693{
1694 pointer __old_last = this->__end_;
1695 difference_type __n = __old_last - __to;
1696 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1697 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001698 _VSTD::__to_raw_pointer(this->__end_),
1699 _VSTD::move(*__i));
1700 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001701}
1702
1703template <class _Tp, class _Allocator>
1704typename vector<_Tp, _Allocator>::iterator
1705vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1706{
Howard Hinnantabe26282011-09-16 17:29:17 +00001707#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001708 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1709 "vector::insert(iterator, x) called with an iterator not"
1710 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001711#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001712 pointer __p = this->__begin_ + (__position - begin());
1713 if (this->__end_ < this->__end_cap())
1714 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001715 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001716 if (__p == this->__end_)
1717 {
1718 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001719 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001720 ++this->__end_;
1721 }
1722 else
1723 {
1724 __move_range(__p, this->__end_, __p + 1);
1725 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1726 if (__p <= __xr && __xr < this->__end_)
1727 ++__xr;
1728 *__p = *__xr;
1729 }
1730 }
1731 else
1732 {
1733 allocator_type& __a = this->__alloc();
1734 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1735 __v.push_back(__x);
1736 __p = __swap_out_circular_buffer(__v, __p);
1737 }
1738 return __make_iter(__p);
1739}
1740
Howard Hinnant73d21a42010-09-04 23:28:19 +00001741#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742
1743template <class _Tp, class _Allocator>
1744typename vector<_Tp, _Allocator>::iterator
1745vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1746{
Howard Hinnantabe26282011-09-16 17:29:17 +00001747#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001748 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1749 "vector::insert(iterator, x) called with an iterator not"
1750 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001751#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752 pointer __p = this->__begin_ + (__position - begin());
1753 if (this->__end_ < this->__end_cap())
1754 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001755 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001756 if (__p == this->__end_)
1757 {
1758 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001759 _VSTD::__to_raw_pointer(this->__end_),
1760 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001761 ++this->__end_;
1762 }
1763 else
1764 {
1765 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001766 *__p = _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001767 }
1768 }
1769 else
1770 {
1771 allocator_type& __a = this->__alloc();
1772 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001773 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001774 __p = __swap_out_circular_buffer(__v, __p);
1775 }
1776 return __make_iter(__p);
1777}
1778
Howard Hinnant73d21a42010-09-04 23:28:19 +00001779#ifndef _LIBCPP_HAS_NO_VARIADICS
1780
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001781template <class _Tp, class _Allocator>
1782template <class... _Args>
1783typename vector<_Tp, _Allocator>::iterator
1784vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1785{
Howard Hinnantabe26282011-09-16 17:29:17 +00001786#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001787 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1788 "vector::emplace(iterator, x) called with an iterator not"
1789 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001790#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001791 pointer __p = this->__begin_ + (__position - begin());
1792 if (this->__end_ < this->__end_cap())
1793 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001794 __annotate_increase(1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795 if (__p == this->__end_)
1796 {
1797 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001798 _VSTD::__to_raw_pointer(this->__end_),
1799 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800 ++this->__end_;
1801 }
1802 else
1803 {
Howard Hinnanta58402a2012-07-08 23:23:04 +00001804 value_type __tmp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001805 __move_range(__p, this->__end_, __p + 1);
Howard Hinnanta58402a2012-07-08 23:23:04 +00001806 *__p = _VSTD::move(__tmp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001807 }
1808 }
1809 else
1810 {
1811 allocator_type& __a = this->__alloc();
1812 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001813 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001814 __p = __swap_out_circular_buffer(__v, __p);
1815 }
1816 return __make_iter(__p);
1817}
1818
Howard Hinnant73d21a42010-09-04 23:28:19 +00001819#endif // _LIBCPP_HAS_NO_VARIADICS
1820#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821
1822template <class _Tp, class _Allocator>
1823typename vector<_Tp, _Allocator>::iterator
1824vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1825{
Howard Hinnantabe26282011-09-16 17:29:17 +00001826#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001827 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1828 "vector::insert(iterator, n, x) called with an iterator not"
1829 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001830#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001831 pointer __p = this->__begin_ + (__position - begin());
1832 if (__n > 0)
1833 {
1834 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1835 {
1836 size_type __old_n = __n;
1837 pointer __old_last = this->__end_;
1838 if (__n > static_cast<size_type>(this->__end_ - __p))
1839 {
1840 size_type __cx = __n - (this->__end_ - __p);
1841 __construct_at_end(__cx, __x);
1842 __n -= __cx;
1843 }
1844 if (__n > 0)
1845 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001846 __annotate_increase(__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847 __move_range(__p, __old_last, __p + __old_n);
1848 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1849 if (__p <= __xr && __xr < this->__end_)
1850 __xr += __old_n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001851 _VSTD::fill_n(__p, __n, *__xr);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852 }
1853 }
1854 else
1855 {
1856 allocator_type& __a = this->__alloc();
1857 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1858 __v.__construct_at_end(__n, __x);
1859 __p = __swap_out_circular_buffer(__v, __p);
1860 }
1861 }
1862 return __make_iter(__p);
1863}
1864
1865template <class _Tp, class _Allocator>
1866template <class _InputIterator>
1867typename enable_if
1868<
1869 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001870 !__is_forward_iterator<_InputIterator>::value &&
1871 is_constructible<
1872 _Tp,
1873 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874 typename vector<_Tp, _Allocator>::iterator
1875>::type
1876vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1877{
Howard Hinnantabe26282011-09-16 17:29:17 +00001878#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001879 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1880 "vector::insert(iterator, range) called with an iterator not"
1881 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001882#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001883 difference_type __off = __position - begin();
1884 pointer __p = this->__begin_ + __off;
1885 allocator_type& __a = this->__alloc();
1886 pointer __old_last = this->__end_;
1887 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1888 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001889 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001890 *__first);
1891 ++this->__end_;
1892 }
1893 __split_buffer<value_type, allocator_type&> __v(__a);
1894 if (__first != __last)
1895 {
1896#ifndef _LIBCPP_NO_EXCEPTIONS
1897 try
1898 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001899#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001900 __v.__construct_at_end(__first, __last);
1901 difference_type __old_size = __old_last - this->__begin_;
1902 difference_type __old_p = __p - this->__begin_;
1903 reserve(__recommend(size() + __v.size()));
1904 __p = this->__begin_ + __old_p;
1905 __old_last = this->__begin_ + __old_size;
1906#ifndef _LIBCPP_NO_EXCEPTIONS
1907 }
1908 catch (...)
1909 {
1910 erase(__make_iter(__old_last), end());
1911 throw;
1912 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001913#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001914 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001915 __p = _VSTD::rotate(__p, __old_last, this->__end_);
Howard Hinnant0442b122011-09-16 18:41:29 +00001916 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1917 make_move_iterator(__v.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001918 return begin() + __off;
1919}
1920
1921template <class _Tp, class _Allocator>
1922template <class _ForwardIterator>
1923typename enable_if
1924<
Howard Hinnant742fecb2013-03-28 17:44:32 +00001925 __is_forward_iterator<_ForwardIterator>::value &&
1926 is_constructible<
1927 _Tp,
1928 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001929 typename vector<_Tp, _Allocator>::iterator
1930>::type
1931vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1932{
Howard Hinnantabe26282011-09-16 17:29:17 +00001933#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001934 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1935 "vector::insert(iterator, range) called with an iterator not"
1936 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001937#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001938 pointer __p = this->__begin_ + (__position - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00001939 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940 if (__n > 0)
1941 {
1942 if (__n <= this->__end_cap() - this->__end_)
1943 {
1944 size_type __old_n = __n;
1945 pointer __old_last = this->__end_;
1946 _ForwardIterator __m = __last;
1947 difference_type __dx = this->__end_ - __p;
1948 if (__n > __dx)
1949 {
1950 __m = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001951 _VSTD::advance(__m, this->__end_ - __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001952 __construct_at_end(__m, __last);
1953 __n = __dx;
1954 }
1955 if (__n > 0)
1956 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +00001957 __annotate_increase(__n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958 __move_range(__p, __old_last, __p + __old_n);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001959 _VSTD::copy(__first, __m, __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001960 }
1961 }
1962 else
1963 {
1964 allocator_type& __a = this->__alloc();
1965 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1966 __v.__construct_at_end(__first, __last);
1967 __p = __swap_out_circular_buffer(__v, __p);
1968 }
1969 }
1970 return __make_iter(__p);
1971}
1972
1973template <class _Tp, class _Allocator>
1974void
1975vector<_Tp, _Allocator>::resize(size_type __sz)
1976{
1977 size_type __cs = size();
1978 if (__cs < __sz)
1979 this->__append(__sz - __cs);
1980 else if (__cs > __sz)
1981 this->__destruct_at_end(this->__begin_ + __sz);
1982}
1983
1984template <class _Tp, class _Allocator>
1985void
1986vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1987{
1988 size_type __cs = size();
1989 if (__cs < __sz)
1990 this->__append(__sz - __cs, __x);
1991 else if (__cs > __sz)
1992 this->__destruct_at_end(this->__begin_ + __sz);
1993}
1994
1995template <class _Tp, class _Allocator>
1996void
1997vector<_Tp, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001998 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1999 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002000{
Howard Hinnant7a563db2011-09-14 18:33:51 +00002001 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
2002 this->__alloc() == __x.__alloc(),
2003 "vector::swap: Either propagate_on_container_swap must be true"
2004 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19 +00002005 _VSTD::swap(this->__begin_, __x.__begin_);
2006 _VSTD::swap(this->__end_, __x.__end_);
2007 _VSTD::swap(this->__end_cap(), __x.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002008 __base::__swap_alloc(this->__alloc(), __x.__alloc());
Howard Hinnantabe26282011-09-16 17:29:17 +00002009#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002010 __get_db()->swap(this, &__x);
Howard Hinnantabe26282011-09-16 17:29:17 +00002011#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002012}
2013
Howard Hinnant324bb032010-08-22 00:02:43 +00002014template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002015bool
2016vector<_Tp, _Allocator>::__invariants() const
2017{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002018 if (this->__begin_ == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002019 {
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002020 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002021 return false;
2022 }
2023 else
2024 {
2025 if (this->__begin_ > this->__end_)
2026 return false;
2027 if (this->__begin_ == this->__end_cap())
2028 return false;
2029 if (this->__end_ > this->__end_cap())
2030 return false;
2031 }
2032 return true;
2033}
2034
Howard Hinnantabe26282011-09-16 17:29:17 +00002035#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002036
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002037template <class _Tp, class _Allocator>
Howard Hinnant7a563db2011-09-14 18:33:51 +00002038bool
2039vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
2040{
2041 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
2042}
2043
2044template <class _Tp, class _Allocator>
2045bool
2046vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
2047{
2048 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
2049}
2050
2051template <class _Tp, class _Allocator>
2052bool
2053vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2054{
2055 const_pointer __p = __i->base() + __n;
2056 return this->__begin_ <= __p && __p <= this->__end_;
2057}
2058
2059template <class _Tp, class _Allocator>
2060bool
2061vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2062{
2063 const_pointer __p = __i->base() + __n;
2064 return this->__begin_ <= __p && __p < this->__end_;
2065}
2066
Howard Hinnantabe26282011-09-16 17:29:17 +00002067#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002068
2069template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002070inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002071void
2072vector<_Tp, _Allocator>::__invalidate_all_iterators()
2073{
Howard Hinnantabe26282011-09-16 17:29:17 +00002074#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002075 __get_db()->__invalidate_all(this);
Howard Hinnantabe26282011-09-16 17:29:17 +00002076#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002077}
2078
2079// vector<bool>
2080
2081template <class _Allocator> class vector<bool, _Allocator>;
2082
2083template <class _Allocator> struct hash<vector<bool, _Allocator> >;
2084
2085template <class _Allocator>
Howard Hinnantf03c3b42011-07-02 20:33:23 +00002086struct __has_storage_type<vector<bool, _Allocator> >
2087{
2088 static const bool value = true;
2089};
2090
2091template <class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002092class _LIBCPP_TYPE_VIS_ONLY vector<bool, _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002093 : private __vector_base_common<true>
2094{
2095public:
2096 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +00002097 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002098 typedef _Allocator allocator_type;
2099 typedef allocator_traits<allocator_type> __alloc_traits;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002100 typedef typename __alloc_traits::size_type size_type;
2101 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnantf867f632012-05-07 16:50:38 +00002102 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002103 typedef __bit_iterator<vector, false> pointer;
2104 typedef __bit_iterator<vector, true> const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002105 typedef pointer iterator;
2106 typedef const_pointer const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002107 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
2108 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002109
2110private:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002111 typedef typename __alloc_traits::template
2112#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
2113 rebind_alloc<__storage_type>
2114#else
2115 rebind_alloc<__storage_type>::other
2116#endif
2117 __storage_allocator;
2118 typedef allocator_traits<__storage_allocator> __storage_traits;
2119 typedef typename __storage_traits::pointer __storage_pointer;
2120 typedef typename __storage_traits::const_pointer __const_storage_pointer;
2121
2122 __storage_pointer __begin_;
2123 size_type __size_;
2124 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00002125public:
Howard Hinnantf03c3b42011-07-02 20:33:23 +00002126 typedef __bit_reference<vector> reference;
2127 typedef __bit_const_reference<vector> const_reference;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00002128private:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002129 _LIBCPP_INLINE_VISIBILITY
2130 size_type& __cap() _NOEXCEPT
2131 {return __cap_alloc_.first();}
2132 _LIBCPP_INLINE_VISIBILITY
2133 const size_type& __cap() const _NOEXCEPT
2134 {return __cap_alloc_.first();}
2135 _LIBCPP_INLINE_VISIBILITY
2136 __storage_allocator& __alloc() _NOEXCEPT
2137 {return __cap_alloc_.second();}
2138 _LIBCPP_INLINE_VISIBILITY
2139 const __storage_allocator& __alloc() const _NOEXCEPT
2140 {return __cap_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002141
2142 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2143
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002144 _LIBCPP_INLINE_VISIBILITY
2145 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002146 {return __n * __bits_per_word;}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002147 _LIBCPP_INLINE_VISIBILITY
2148 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002149 {return (__n - 1) / __bits_per_word + 1;}
2150
2151public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002152 _LIBCPP_INLINE_VISIBILITY
2153 vector()
2154 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002155 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002156 ~vector();
2157 explicit vector(size_type __n);
Marshall Clowa49a2c92013-09-14 00:47:59 +00002158#if _LIBCPP_STD_VER > 11
2159 explicit vector(size_type __n, const allocator_type& __a);
2160#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002161 vector(size_type __n, const value_type& __v);
2162 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2163 template <class _InputIterator>
2164 vector(_InputIterator __first, _InputIterator __last,
2165 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2166 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2167 template <class _InputIterator>
2168 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2169 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2170 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2171 template <class _ForwardIterator>
2172 vector(_ForwardIterator __first, _ForwardIterator __last,
2173 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2174 template <class _ForwardIterator>
2175 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2176 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2177
2178 vector(const vector& __v);
2179 vector(const vector& __v, const allocator_type& __a);
2180 vector& operator=(const vector& __v);
Howard Hinnante3e32912011-08-12 21:56:02 +00002181#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182 vector(initializer_list<value_type> __il);
2183 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00002184#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002185
Howard Hinnant73d21a42010-09-04 23:28:19 +00002186#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002187 _LIBCPP_INLINE_VISIBILITY
2188 vector(vector&& __v)
2189 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002190 vector(vector&& __v, const allocator_type& __a);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002191 _LIBCPP_INLINE_VISIBILITY
2192 vector& operator=(vector&& __v)
2193 _NOEXCEPT_(
2194 __alloc_traits::propagate_on_container_move_assignment::value &&
2195 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002196#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00002197#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002199 vector& operator=(initializer_list<value_type> __il)
2200 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00002201#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002202
2203 template <class _InputIterator>
2204 typename enable_if
2205 <
2206 __is_input_iterator<_InputIterator>::value &&
2207 !__is_forward_iterator<_InputIterator>::value,
2208 void
2209 >::type
2210 assign(_InputIterator __first, _InputIterator __last);
2211 template <class _ForwardIterator>
2212 typename enable_if
2213 <
2214 __is_forward_iterator<_ForwardIterator>::value,
2215 void
2216 >::type
2217 assign(_ForwardIterator __first, _ForwardIterator __last);
2218
2219 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:02 +00002220#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002222 void assign(initializer_list<value_type> __il)
2223 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002224#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002225
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002226 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002227 {return allocator_type(this->__alloc());}
2228
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002229 size_type max_size() const _NOEXCEPT;
2230 _LIBCPP_INLINE_VISIBILITY
2231 size_type capacity() const _NOEXCEPT
2232 {return __internal_cap_to_external(__cap());}
2233 _LIBCPP_INLINE_VISIBILITY
2234 size_type size() const _NOEXCEPT
2235 {return __size_;}
2236 _LIBCPP_INLINE_VISIBILITY
2237 bool empty() const _NOEXCEPT
2238 {return __size_ == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002239 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002240 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002241
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002242 _LIBCPP_INLINE_VISIBILITY
2243 iterator begin() _NOEXCEPT
2244 {return __make_iter(0);}
2245 _LIBCPP_INLINE_VISIBILITY
2246 const_iterator begin() const _NOEXCEPT
2247 {return __make_iter(0);}
2248 _LIBCPP_INLINE_VISIBILITY
2249 iterator end() _NOEXCEPT
2250 {return __make_iter(__size_);}
2251 _LIBCPP_INLINE_VISIBILITY
2252 const_iterator end() const _NOEXCEPT
2253 {return __make_iter(__size_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002254
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002255 _LIBCPP_INLINE_VISIBILITY
2256 reverse_iterator rbegin() _NOEXCEPT
2257 {return reverse_iterator(end());}
2258 _LIBCPP_INLINE_VISIBILITY
2259 const_reverse_iterator rbegin() const _NOEXCEPT
2260 {return const_reverse_iterator(end());}
2261 _LIBCPP_INLINE_VISIBILITY
2262 reverse_iterator rend() _NOEXCEPT
2263 {return reverse_iterator(begin());}
2264 _LIBCPP_INLINE_VISIBILITY
2265 const_reverse_iterator rend() const _NOEXCEPT
2266 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002267
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002268 _LIBCPP_INLINE_VISIBILITY
2269 const_iterator cbegin() const _NOEXCEPT
2270 {return __make_iter(0);}
2271 _LIBCPP_INLINE_VISIBILITY
2272 const_iterator cend() const _NOEXCEPT
2273 {return __make_iter(__size_);}
2274 _LIBCPP_INLINE_VISIBILITY
2275 const_reverse_iterator crbegin() const _NOEXCEPT
2276 {return rbegin();}
2277 _LIBCPP_INLINE_VISIBILITY
2278 const_reverse_iterator crend() const _NOEXCEPT
2279 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002280
2281 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2282 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2283 reference at(size_type __n);
2284 const_reference at(size_type __n) const;
2285
2286 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2287 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2288 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2289 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2290
2291 void push_back(const value_type& __x);
Marshall Clow198a2a52013-08-13 23:54:12 +00002292#if _LIBCPP_STD_VER > 11
2293 template <class... _Args>
2294 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
2295 { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); }
2296#endif
2297
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002298 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2299
Marshall Clow198a2a52013-08-13 23:54:12 +00002300#if _LIBCPP_STD_VER > 11
2301 template <class... _Args>
2302 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2303 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2304#endif
2305
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002306 iterator insert(const_iterator __position, const value_type& __x);
2307 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2308 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2309 template <class _InputIterator>
2310 typename enable_if
2311 <
2312 __is_input_iterator <_InputIterator>::value &&
2313 !__is_forward_iterator<_InputIterator>::value,
2314 iterator
2315 >::type
2316 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2317 template <class _ForwardIterator>
2318 typename enable_if
2319 <
2320 __is_forward_iterator<_ForwardIterator>::value,
2321 iterator
2322 >::type
2323 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00002324#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002326 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2327 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002328#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002329
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002330 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002331 iterator erase(const_iterator __first, const_iterator __last);
2332
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002333 _LIBCPP_INLINE_VISIBILITY
2334 void clear() _NOEXCEPT {__size_ = 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002336 void swap(vector&)
2337 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2338 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002339
2340 void resize(size_type __sz, value_type __x = false);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002341 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002342
2343 bool __invariants() const;
2344
2345private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002346 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002347 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002348 void deallocate() _NOEXCEPT;
2349 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00002350 static size_type __align_it(size_type __new_size) _NOEXCEPT
Marshall Clow0d1965d2014-07-28 15:02:42 +00002351 {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);};
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002352 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2353 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002354 template <class _ForwardIterator>
2355 typename enable_if
2356 <
2357 __is_forward_iterator<_ForwardIterator>::value,
2358 void
2359 >::type
2360 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2361 void __append(size_type __n, const_reference __x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002362 _LIBCPP_INLINE_VISIBILITY
2363 reference __make_ref(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002364 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002365 _LIBCPP_INLINE_VISIBILITY
2366 const_reference __make_ref(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002367 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002368 _LIBCPP_INLINE_VISIBILITY
2369 iterator __make_iter(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002370 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002371 _LIBCPP_INLINE_VISIBILITY
2372 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002373 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002374 _LIBCPP_INLINE_VISIBILITY
2375 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002376 {return begin() + (__p - cbegin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002377
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002378 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002379 void __copy_assign_alloc(const vector& __v)
2380 {__copy_assign_alloc(__v, integral_constant<bool,
2381 __storage_traits::propagate_on_container_copy_assignment::value>());}
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& __c, true_type)
2384 {
2385 if (__alloc() != __c.__alloc())
2386 deallocate();
2387 __alloc() = __c.__alloc();
2388 }
2389
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002390 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00002391 void __copy_assign_alloc(const vector&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002392 {}
2393
2394 void __move_assign(vector& __c, false_type);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002395 void __move_assign(vector& __c, true_type)
2396 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002398 void __move_assign_alloc(vector& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002399 _NOEXCEPT_(
2400 !__storage_traits::propagate_on_container_move_assignment::value ||
2401 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002402 {__move_assign_alloc(__c, integral_constant<bool,
2403 __storage_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00002405 void __move_assign_alloc(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002406 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002407 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002408 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002409 }
2410
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00002412 void __move_assign_alloc(vector&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002413 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002414 {}
2415
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002416 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002417 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002418 _NOEXCEPT_(
2419 !__storage_traits::propagate_on_container_swap::value ||
2420 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002421 {__swap_alloc(__x, __y, integral_constant<bool,
2422 __storage_traits::propagate_on_container_swap::value>());}
2423
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002425 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002426 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002427 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002428 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002429 swap(__x, __y);
2430 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002431 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00002432 static void __swap_alloc(__storage_allocator&, __storage_allocator&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002433 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002434 {}
2435
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002436 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002437
2438 friend class __bit_reference<vector>;
2439 friend class __bit_const_reference<vector>;
2440 friend class __bit_iterator<vector, false>;
2441 friend class __bit_iterator<vector, true>;
Howard Hinnant4ae952a2012-08-17 17:10:18 +00002442 friend struct __bit_array<vector>;
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002443 friend struct _LIBCPP_TYPE_VIS_ONLY hash<vector>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002444};
2445
2446template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002447inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002448void
2449vector<bool, _Allocator>::__invalidate_all_iterators()
2450{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002451}
2452
2453// Allocate space for __n objects
2454// throws length_error if __n > max_size()
2455// throws (probably bad_alloc) if memory run out
2456// Precondition: __begin_ == __end_ == __cap() == 0
2457// Precondition: __n > 0
2458// Postcondition: capacity() == __n
2459// Postcondition: size() == 0
2460template <class _Allocator>
2461void
2462vector<bool, _Allocator>::allocate(size_type __n)
2463{
2464 if (__n > max_size())
2465 this->__throw_length_error();
2466 __n = __external_cap_to_internal(__n);
2467 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2468 this->__size_ = 0;
2469 this->__cap() = __n;
2470}
2471
2472template <class _Allocator>
2473void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002474vector<bool, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002475{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002476 if (this->__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002477 {
2478 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2479 __invalidate_all_iterators();
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002480 this->__begin_ = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002481 this->__size_ = this->__cap() = 0;
2482 }
2483}
2484
2485template <class _Allocator>
2486typename vector<bool, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002487vector<bool, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002488{
2489 size_type __amax = __storage_traits::max_size(__alloc());
2490 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2491 if (__nmax / __bits_per_word <= __amax)
2492 return __nmax;
2493 return __internal_cap_to_external(__amax);
2494}
2495
2496// Precondition: __new_size > capacity()
2497template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002498inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002499typename vector<bool, _Allocator>::size_type
2500vector<bool, _Allocator>::__recommend(size_type __new_size) const
2501{
2502 const size_type __ms = max_size();
2503 if (__new_size > __ms)
2504 this->__throw_length_error();
2505 const size_type __cap = capacity();
2506 if (__cap >= __ms / 2)
2507 return __ms;
Howard Hinnant7f764502013-08-14 18:00:20 +00002508 return _VSTD::max(2*__cap, __align_it(__new_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002509}
2510
2511// Default constructs __n objects starting at __end_
2512// Precondition: __n > 0
2513// Precondition: size() + __n <= capacity()
2514// Postcondition: size() == size() + __n
2515template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002516inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002517void
2518vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2519{
2520 size_type __old_size = this->__size_;
2521 this->__size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002522 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002523}
2524
2525template <class _Allocator>
2526template <class _ForwardIterator>
2527typename enable_if
2528<
2529 __is_forward_iterator<_ForwardIterator>::value,
2530 void
2531>::type
2532vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2533{
2534 size_type __old_size = this->__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002535 this->__size_ += _VSTD::distance(__first, __last);
2536 _VSTD::copy(__first, __last, __make_iter(__old_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002537}
2538
2539template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002540inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002541vector<bool, _Allocator>::vector()
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002542 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002543 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002544 __size_(0),
2545 __cap_alloc_(0)
2546{
2547}
2548
2549template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002550inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002551vector<bool, _Allocator>::vector(const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002552 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002553 __size_(0),
2554 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2555{
2556}
2557
2558template <class _Allocator>
2559vector<bool, _Allocator>::vector(size_type __n)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002560 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002561 __size_(0),
2562 __cap_alloc_(0)
2563{
2564 if (__n > 0)
2565 {
2566 allocate(__n);
2567 __construct_at_end(__n, false);
2568 }
2569}
2570
Marshall Clowa49a2c92013-09-14 00:47:59 +00002571#if _LIBCPP_STD_VER > 11
2572template <class _Allocator>
2573vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2574 : __begin_(nullptr),
2575 __size_(0),
2576 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2577{
2578 if (__n > 0)
2579 {
2580 allocate(__n);
2581 __construct_at_end(__n, false);
2582 }
2583}
2584#endif
2585
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002586template <class _Allocator>
2587vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002588 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002589 __size_(0),
2590 __cap_alloc_(0)
2591{
2592 if (__n > 0)
2593 {
2594 allocate(__n);
2595 __construct_at_end(__n, __x);
2596 }
2597}
2598
2599template <class _Allocator>
2600vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002601 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002602 __size_(0),
2603 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2604{
2605 if (__n > 0)
2606 {
2607 allocate(__n);
2608 __construct_at_end(__n, __x);
2609 }
2610}
2611
2612template <class _Allocator>
2613template <class _InputIterator>
2614vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2615 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2616 !__is_forward_iterator<_InputIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002617 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002618 __size_(0),
2619 __cap_alloc_(0)
2620{
2621#ifndef _LIBCPP_NO_EXCEPTIONS
2622 try
2623 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002624#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002625 for (; __first != __last; ++__first)
2626 push_back(*__first);
2627#ifndef _LIBCPP_NO_EXCEPTIONS
2628 }
2629 catch (...)
2630 {
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002631 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002632 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2633 __invalidate_all_iterators();
2634 throw;
2635 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002636#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002637}
2638
2639template <class _Allocator>
2640template <class _InputIterator>
2641vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2642 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2643 !__is_forward_iterator<_InputIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002644 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002645 __size_(0),
2646 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2647{
2648#ifndef _LIBCPP_NO_EXCEPTIONS
2649 try
2650 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002651#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002652 for (; __first != __last; ++__first)
2653 push_back(*__first);
2654#ifndef _LIBCPP_NO_EXCEPTIONS
2655 }
2656 catch (...)
2657 {
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002658 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002659 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2660 __invalidate_all_iterators();
2661 throw;
2662 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002663#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002664}
2665
2666template <class _Allocator>
2667template <class _ForwardIterator>
2668vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2669 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002670 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002671 __size_(0),
2672 __cap_alloc_(0)
2673{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002674 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002675 if (__n > 0)
2676 {
2677 allocate(__n);
2678 __construct_at_end(__first, __last);
2679 }
2680}
2681
2682template <class _Allocator>
2683template <class _ForwardIterator>
2684vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2685 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002686 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002687 __size_(0),
2688 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2689{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002690 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002691 if (__n > 0)
2692 {
2693 allocate(__n);
2694 __construct_at_end(__first, __last);
2695 }
2696}
2697
Howard Hinnante3e32912011-08-12 21:56:02 +00002698#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2699
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002700template <class _Allocator>
2701vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002702 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002703 __size_(0),
2704 __cap_alloc_(0)
2705{
2706 size_type __n = static_cast<size_type>(__il.size());
2707 if (__n > 0)
2708 {
2709 allocate(__n);
2710 __construct_at_end(__il.begin(), __il.end());
2711 }
2712}
2713
2714template <class _Allocator>
2715vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002716 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002717 __size_(0),
2718 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2719{
2720 size_type __n = static_cast<size_type>(__il.size());
2721 if (__n > 0)
2722 {
2723 allocate(__n);
2724 __construct_at_end(__il.begin(), __il.end());
2725 }
2726}
2727
Howard Hinnante3e32912011-08-12 21:56:02 +00002728#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2729
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002730template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002731vector<bool, _Allocator>::~vector()
2732{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002733 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002734 __storage_traits::deallocate(__alloc(), __begin_, __cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002735 __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002736}
2737
2738template <class _Allocator>
2739vector<bool, _Allocator>::vector(const vector& __v)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002740 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002741 __size_(0),
2742 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2743{
2744 if (__v.size() > 0)
2745 {
2746 allocate(__v.size());
2747 __construct_at_end(__v.begin(), __v.end());
2748 }
2749}
2750
2751template <class _Allocator>
2752vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002753 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002754 __size_(0),
2755 __cap_alloc_(0, __a)
2756{
2757 if (__v.size() > 0)
2758 {
2759 allocate(__v.size());
2760 __construct_at_end(__v.begin(), __v.end());
2761 }
2762}
2763
2764template <class _Allocator>
2765vector<bool, _Allocator>&
2766vector<bool, _Allocator>::operator=(const vector& __v)
2767{
2768 if (this != &__v)
2769 {
2770 __copy_assign_alloc(__v);
2771 if (__v.__size_)
2772 {
2773 if (__v.__size_ > capacity())
2774 {
2775 deallocate();
2776 allocate(__v.__size_);
2777 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002778 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002779 }
2780 __size_ = __v.__size_;
2781 }
2782 return *this;
2783}
2784
Howard Hinnant73d21a42010-09-04 23:28:19 +00002785#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2786
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002787template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002788inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002789vector<bool, _Allocator>::vector(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002790 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002791 : __begin_(__v.__begin_),
2792 __size_(__v.__size_),
2793 __cap_alloc_(__v.__cap_alloc_)
2794{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002795 __v.__begin_ = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002796 __v.__size_ = 0;
2797 __v.__cap() = 0;
2798}
2799
2800template <class _Allocator>
2801vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002802 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002803 __size_(0),
2804 __cap_alloc_(0, __a)
2805{
2806 if (__a == allocator_type(__v.__alloc()))
2807 {
2808 this->__begin_ = __v.__begin_;
2809 this->__size_ = __v.__size_;
2810 this->__cap() = __v.__cap();
2811 __v.__begin_ = nullptr;
2812 __v.__cap() = __v.__size_ = 0;
2813 }
2814 else if (__v.size() > 0)
2815 {
2816 allocate(__v.size());
2817 __construct_at_end(__v.begin(), __v.end());
2818 }
2819}
2820
2821template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002822inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002823vector<bool, _Allocator>&
2824vector<bool, _Allocator>::operator=(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002825 _NOEXCEPT_(
2826 __alloc_traits::propagate_on_container_move_assignment::value &&
2827 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002828{
2829 __move_assign(__v, integral_constant<bool,
2830 __storage_traits::propagate_on_container_move_assignment::value>());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002831 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002832}
2833
2834template <class _Allocator>
2835void
2836vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2837{
2838 if (__alloc() != __c.__alloc())
2839 assign(__c.begin(), __c.end());
2840 else
2841 __move_assign(__c, true_type());
2842}
2843
2844template <class _Allocator>
2845void
2846vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002847 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002848{
2849 deallocate();
Marshall Clowdb5e54d2014-07-21 15:15:15 +00002850 __move_assign_alloc(__c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002851 this->__begin_ = __c.__begin_;
2852 this->__size_ = __c.__size_;
2853 this->__cap() = __c.__cap();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002854 __c.__begin_ = nullptr;
2855 __c.__cap() = __c.__size_ = 0;
2856}
Howard Hinnant73d21a42010-09-04 23:28:19 +00002857
2858#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002859
2860template <class _Allocator>
2861void
2862vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2863{
2864 __size_ = 0;
2865 if (__n > 0)
2866 {
2867 size_type __c = capacity();
2868 if (__n <= __c)
2869 __size_ = __n;
2870 else
2871 {
2872 vector __v(__alloc());
2873 __v.reserve(__recommend(__n));
2874 __v.__size_ = __n;
2875 swap(__v);
2876 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002877 _VSTD::fill_n(begin(), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002878 }
2879}
2880
2881template <class _Allocator>
2882template <class _InputIterator>
2883typename enable_if
2884<
2885 __is_input_iterator<_InputIterator>::value &&
2886 !__is_forward_iterator<_InputIterator>::value,
2887 void
2888>::type
2889vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2890{
2891 clear();
2892 for (; __first != __last; ++__first)
2893 push_back(*__first);
2894}
2895
2896template <class _Allocator>
2897template <class _ForwardIterator>
2898typename enable_if
2899<
2900 __is_forward_iterator<_ForwardIterator>::value,
2901 void
2902>::type
2903vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2904{
2905 clear();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002906 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002907 if (__n)
2908 {
2909 if (__n > capacity())
2910 {
2911 deallocate();
2912 allocate(__n);
2913 }
2914 __construct_at_end(__first, __last);
2915 }
2916}
2917
2918template <class _Allocator>
2919void
2920vector<bool, _Allocator>::reserve(size_type __n)
2921{
2922 if (__n > capacity())
2923 {
2924 vector __v(this->__alloc());
2925 __v.allocate(__n);
2926 __v.__construct_at_end(this->begin(), this->end());
2927 swap(__v);
2928 __invalidate_all_iterators();
2929 }
2930}
2931
2932template <class _Allocator>
2933void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002934vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002935{
2936 if (__external_cap_to_internal(size()) > __cap())
2937 {
2938#ifndef _LIBCPP_NO_EXCEPTIONS
2939 try
2940 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002941#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002942 vector(*this, allocator_type(__alloc())).swap(*this);
2943#ifndef _LIBCPP_NO_EXCEPTIONS
2944 }
2945 catch (...)
2946 {
2947 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002948#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002949 }
2950}
2951
2952template <class _Allocator>
2953typename vector<bool, _Allocator>::reference
2954vector<bool, _Allocator>::at(size_type __n)
2955{
2956 if (__n >= size())
2957 this->__throw_out_of_range();
2958 return (*this)[__n];
2959}
2960
2961template <class _Allocator>
2962typename vector<bool, _Allocator>::const_reference
2963vector<bool, _Allocator>::at(size_type __n) const
2964{
2965 if (__n >= size())
2966 this->__throw_out_of_range();
2967 return (*this)[__n];
2968}
2969
2970template <class _Allocator>
2971void
2972vector<bool, _Allocator>::push_back(const value_type& __x)
2973{
2974 if (this->__size_ == this->capacity())
2975 reserve(__recommend(this->__size_ + 1));
2976 ++this->__size_;
2977 back() = __x;
2978}
2979
2980template <class _Allocator>
2981typename vector<bool, _Allocator>::iterator
2982vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2983{
2984 iterator __r;
2985 if (size() < capacity())
2986 {
2987 const_iterator __old_end = end();
2988 ++__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002989 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002990 __r = __const_iterator_cast(__position);
2991 }
2992 else
2993 {
2994 vector __v(__alloc());
2995 __v.reserve(__recommend(__size_ + 1));
2996 __v.__size_ = __size_ + 1;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002997 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2998 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002999 swap(__v);
3000 }
3001 *__r = __x;
3002 return __r;
3003}
3004
3005template <class _Allocator>
3006typename vector<bool, _Allocator>::iterator
3007vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
3008{
3009 iterator __r;
3010 size_type __c = capacity();
3011 if (__n <= __c && size() <= __c - __n)
3012 {
3013 const_iterator __old_end = end();
3014 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003015 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003016 __r = __const_iterator_cast(__position);
3017 }
3018 else
3019 {
3020 vector __v(__alloc());
3021 __v.reserve(__recommend(__size_ + __n));
3022 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003023 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3024 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003025 swap(__v);
3026 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003027 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003028 return __r;
3029}
3030
3031template <class _Allocator>
3032template <class _InputIterator>
3033typename enable_if
3034<
3035 __is_input_iterator <_InputIterator>::value &&
3036 !__is_forward_iterator<_InputIterator>::value,
3037 typename vector<bool, _Allocator>::iterator
3038>::type
3039vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
3040{
3041 difference_type __off = __position - begin();
3042 iterator __p = __const_iterator_cast(__position);
3043 iterator __old_end = end();
3044 for (; size() != capacity() && __first != __last; ++__first)
3045 {
3046 ++this->__size_;
3047 back() = *__first;
3048 }
3049 vector __v(__alloc());
3050 if (__first != __last)
3051 {
3052#ifndef _LIBCPP_NO_EXCEPTIONS
3053 try
3054 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003055#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003056 __v.assign(__first, __last);
3057 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
3058 difference_type __old_p = __p - begin();
3059 reserve(__recommend(size() + __v.size()));
3060 __p = begin() + __old_p;
3061 __old_end = begin() + __old_size;
3062#ifndef _LIBCPP_NO_EXCEPTIONS
3063 }
3064 catch (...)
3065 {
3066 erase(__old_end, end());
3067 throw;
3068 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003069#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003070 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003071 __p = _VSTD::rotate(__p, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003072 insert(__p, __v.begin(), __v.end());
3073 return begin() + __off;
3074}
3075
3076template <class _Allocator>
3077template <class _ForwardIterator>
3078typename enable_if
3079<
3080 __is_forward_iterator<_ForwardIterator>::value,
3081 typename vector<bool, _Allocator>::iterator
3082>::type
3083vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
3084{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003085 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003086 iterator __r;
3087 size_type __c = capacity();
3088 if (__n <= __c && size() <= __c - __n)
3089 {
3090 const_iterator __old_end = end();
3091 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003092 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003093 __r = __const_iterator_cast(__position);
3094 }
3095 else
3096 {
3097 vector __v(__alloc());
3098 __v.reserve(__recommend(__size_ + __n));
3099 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003100 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3101 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003102 swap(__v);
3103 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003104 _VSTD::copy(__first, __last, __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003105 return __r;
3106}
3107
3108template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003109inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003110typename vector<bool, _Allocator>::iterator
3111vector<bool, _Allocator>::erase(const_iterator __position)
3112{
3113 iterator __r = __const_iterator_cast(__position);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003114 _VSTD::copy(__position + 1, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003115 --__size_;
3116 return __r;
3117}
3118
3119template <class _Allocator>
3120typename vector<bool, _Allocator>::iterator
3121vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3122{
3123 iterator __r = __const_iterator_cast(__first);
3124 difference_type __d = __last - __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003125 _VSTD::copy(__last, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003126 __size_ -= __d;
3127 return __r;
3128}
3129
3130template <class _Allocator>
3131void
3132vector<bool, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003133 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3134 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003135{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003136 _VSTD::swap(this->__begin_, __x.__begin_);
3137 _VSTD::swap(this->__size_, __x.__size_);
3138 _VSTD::swap(this->__cap(), __x.__cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003139 __swap_alloc(this->__alloc(), __x.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003140}
3141
Howard Hinnant324bb032010-08-22 00:02:43 +00003142template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003143void
3144vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3145{
3146 size_type __cs = size();
3147 if (__cs < __sz)
3148 {
3149 iterator __r;
3150 size_type __c = capacity();
3151 size_type __n = __sz - __cs;
3152 if (__n <= __c && __cs <= __c - __n)
3153 {
3154 __r = end();
3155 __size_ += __n;
3156 }
3157 else
3158 {
3159 vector __v(__alloc());
3160 __v.reserve(__recommend(__size_ + __n));
3161 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003162 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003163 swap(__v);
3164 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003165 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003166 }
3167 else
3168 __size_ = __sz;
3169}
3170
Howard Hinnant324bb032010-08-22 00:02:43 +00003171template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003172void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003173vector<bool, _Allocator>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003174{
3175 // do middle whole words
3176 size_type __n = __size_;
3177 __storage_pointer __p = __begin_;
3178 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3179 *__p = ~*__p;
3180 // do last partial word
3181 if (__n > 0)
3182 {
3183 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3184 __storage_type __b = *__p & __m;
3185 *__p &= ~__m;
3186 *__p |= ~__b & __m;
3187 }
3188}
3189
Howard Hinnant324bb032010-08-22 00:02:43 +00003190template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003191bool
3192vector<bool, _Allocator>::__invariants() const
3193{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00003194 if (this->__begin_ == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003195 {
3196 if (this->__size_ != 0 || this->__cap() != 0)
3197 return false;
3198 }
3199 else
3200 {
3201 if (this->__cap() == 0)
3202 return false;
3203 if (this->__size_ > this->capacity())
3204 return false;
3205 }
3206 return true;
3207}
3208
Howard Hinnant324bb032010-08-22 00:02:43 +00003209template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003210size_t
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003211vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003212{
3213 size_t __h = 0;
3214 // do middle whole words
3215 size_type __n = __size_;
3216 __storage_pointer __p = __begin_;
3217 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3218 __h ^= *__p;
3219 // do last partial word
3220 if (__n > 0)
3221 {
3222 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3223 __h ^= *__p & __m;
3224 }
3225 return __h;
3226}
3227
3228template <class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003229struct _LIBCPP_TYPE_VIS_ONLY hash<vector<bool, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003230 : public unary_function<vector<bool, _Allocator>, size_t>
3231{
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003233 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003234 {return __vec.__hash_code();}
3235};
3236
3237template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003238inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003239bool
3240operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3241{
3242 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003243 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003244}
3245
3246template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003247inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003248bool
3249operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3250{
3251 return !(__x == __y);
3252}
3253
3254template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003255inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003256bool
3257operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3258{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003259 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003260}
3261
3262template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003263inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003264bool
3265operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3266{
3267 return __y < __x;
3268}
3269
3270template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003271inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003272bool
3273operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3274{
3275 return !(__x < __y);
3276}
3277
3278template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003279inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003280bool
3281operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3282{
3283 return !(__y < __x);
3284}
3285
3286template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003287inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003288void
3289swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003290 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003291{
3292 __x.swap(__y);
3293}
3294
3295_LIBCPP_END_NAMESPACE_STD
3296
3297#endif // _LIBCPP_VECTOR