blob: b334074d0b909e3116afe01307b99a0e8c9f3c74 [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);
41 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
42 template <class InputIterator>
43 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
44 vector(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +000045 vector(vector&& x)
46 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000047 vector(initializer_list<value_type> il);
48 vector(initializer_list<value_type> il, const allocator_type& a);
49 ~vector();
50 vector& operator=(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +000051 vector& operator=(vector&& x)
52 noexcept(
53 allocator_type::propagate_on_container_move_assignment::value &&
54 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000055 vector& operator=(initializer_list<value_type> il);
56 template <class InputIterator>
57 void assign(InputIterator first, InputIterator last);
58 void assign(size_type n, const value_type& u);
59 void assign(initializer_list<value_type> il);
60
Howard Hinnantd1d27a42011-06-03 19:40:40 +000061 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000062
Howard Hinnantd1d27a42011-06-03 19:40:40 +000063 iterator begin() noexcept;
64 const_iterator begin() const noexcept;
65 iterator end() noexcept;
66 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000067
Howard Hinnantd1d27a42011-06-03 19:40:40 +000068 reverse_iterator rbegin() noexcept;
69 const_reverse_iterator rbegin() const noexcept;
70 reverse_iterator rend() noexcept;
71 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072
Howard Hinnantd1d27a42011-06-03 19:40:40 +000073 const_iterator cbegin() const noexcept;
74 const_iterator cend() const noexcept;
75 const_reverse_iterator crbegin() const noexcept;
76 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000077
Howard Hinnantd1d27a42011-06-03 19:40:40 +000078 size_type size() const noexcept;
79 size_type max_size() const noexcept;
80 size_type capacity() const noexcept;
81 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000082 void reserve(size_type n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +000083 void shrink_to_fit() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000084
85 reference operator[](size_type n);
86 const_reference operator[](size_type n) const;
87 reference at(size_type n);
88 const_reference at(size_type n) const;
89
90 reference front();
91 const_reference front() const;
92 reference back();
93 const_reference back() const;
94
Howard Hinnantd1d27a42011-06-03 19:40:40 +000095 value_type* data() noexcept;
96 const value_type* data() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000097
98 void push_back(const value_type& x);
99 void push_back(value_type&& x);
100 template <class... Args>
101 void emplace_back(Args&&... args);
102 void pop_back();
103
104 template <class... Args> iterator emplace(const_iterator position, Args&&... args);
105 iterator insert(const_iterator position, const value_type& x);
106 iterator insert(const_iterator position, value_type&& x);
107 iterator insert(const_iterator position, size_type n, const value_type& x);
108 template <class InputIterator>
109 iterator insert(const_iterator position, InputIterator first, InputIterator last);
110 iterator insert(const_iterator position, initializer_list<value_type> il);
111
112 iterator erase(const_iterator position);
113 iterator erase(const_iterator first, const_iterator last);
114
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000115 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000116
117 void resize(size_type sz);
118 void resize(size_type sz, const value_type& c);
119
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000120 void swap(vector&)
121 noexcept(!allocator_type::propagate_on_container_swap::value ||
122 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000123
124 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43 +0000125};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000126
Howard Hinnant324bb032010-08-22 00:02:43 +0000127template <class Allocator = allocator<T> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000128class vector<bool, Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000129{
130public:
131 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000132 typedef Allocator allocator_type;
133 typedef implementation-defined iterator;
134 typedef implementation-defined const_iterator;
135 typedef typename allocator_type::size_type size_type;
136 typedef typename allocator_type::difference_type difference_type;
137 typedef iterator pointer;
138 typedef const_iterator const_pointer;
139 typedef std::reverse_iterator<iterator> reverse_iterator;
140 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
141
142 class reference
143 {
144 public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000145 reference(const reference&) noexcept;
146 operator bool() const noexcept;
147 reference& operator=(const bool x) noexcept;
148 reference& operator=(const reference& x) noexcept;
149 iterator operator&() const noexcept;
150 void flip() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000151 };
152
153 class const_reference
154 {
155 public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000156 const_reference(const reference&) noexcept;
157 operator bool() const noexcept;
158 const_iterator operator&() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000159 };
160
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000161 vector()
162 noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant9cbee432011-09-02 20:42:31 +0000163 explicit vector(const allocator_type&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000164 explicit vector(size_type n, const value_type& value = value_type(), const allocator_type& = allocator_type());
165 template <class InputIterator>
166 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
167 vector(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000168 vector(vector&& x)
169 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000170 vector(initializer_list<value_type> il);
171 vector(initializer_list<value_type> il, const allocator_type& a);
172 ~vector();
173 vector& operator=(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000174 vector& operator=(vector&& x)
175 noexcept(
176 allocator_type::propagate_on_container_move_assignment::value &&
177 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000178 vector& operator=(initializer_list<value_type> il);
179 template <class InputIterator>
180 void assign(InputIterator first, InputIterator last);
181 void assign(size_type n, const value_type& u);
182 void assign(initializer_list<value_type> il);
183
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000184 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000185
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000186 iterator begin() noexcept;
187 const_iterator begin() const noexcept;
188 iterator end() noexcept;
189 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000190
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000191 reverse_iterator rbegin() noexcept;
192 const_reverse_iterator rbegin() const noexcept;
193 reverse_iterator rend() noexcept;
194 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000195
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000196 const_iterator cbegin() const noexcept;
197 const_iterator cend() const noexcept;
198 const_reverse_iterator crbegin() const noexcept;
199 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000200
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000201 size_type size() const noexcept;
202 size_type max_size() const noexcept;
203 size_type capacity() const noexcept;
204 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000205 void reserve(size_type n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000206 void shrink_to_fit() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000207
208 reference operator[](size_type n);
209 const_reference operator[](size_type n) const;
210 reference at(size_type n);
211 const_reference at(size_type n) const;
212
213 reference front();
214 const_reference front() const;
215 reference back();
216 const_reference back() const;
217
218 void push_back(const value_type& x);
219 void pop_back();
220
221 iterator insert(const_iterator position, const value_type& x);
222 iterator insert(const_iterator position, size_type n, const value_type& x);
223 template <class InputIterator>
224 iterator insert(const_iterator position, InputIterator first, InputIterator last);
225 iterator insert(const_iterator position, initializer_list<value_type> il);
226
227 iterator erase(const_iterator position);
228 iterator erase(const_iterator first, const_iterator last);
229
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000230 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231
232 void resize(size_type sz);
233 void resize(size_type sz, value_type x);
234
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000235 void swap(vector&)
236 noexcept(!allocator_type::propagate_on_container_swap::value ||
237 __is_nothrow_swappable<allocator_type>::value);
238 void flip() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239
240 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43 +0000241};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000242
243template <class Allocator> struct hash<std::vector<bool, Allocator>>;
244
245template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
246template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
247template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
248template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
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);
251
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000252template <class T, class Allocator>
253void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
254 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255
256} // std
257
258*/
259
260#include <__config>
261#include <__bit_reference>
262#include <type_traits>
263#include <climits>
264#include <limits>
265#include <initializer_list>
266#include <memory>
267#include <stdexcept>
268#include <algorithm>
269#include <cstring>
270#include <__split_buffer>
271#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272
273#pragma GCC system_header
274
275_LIBCPP_BEGIN_NAMESPACE_STD
276
277template <bool>
278class __vector_base_common
279{
280protected:
281 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
282 void __throw_length_error() const;
283 void __throw_out_of_range() const;
284};
285
286template <bool __b>
287void
288__vector_base_common<__b>::__throw_length_error() const
289{
290#ifndef _LIBCPP_NO_EXCEPTIONS
291 throw length_error("vector");
292#else
293 assert(!"vector length_error");
294#endif
295}
296
297template <bool __b>
298void
299__vector_base_common<__b>::__throw_out_of_range() const
300{
301#ifndef _LIBCPP_NO_EXCEPTIONS
302 throw out_of_range("vector");
303#else
304 assert(!"vector out_of_range");
305#endif
306}
307
308extern template class __vector_base_common<true>;
309
310template <class _Tp, class _Allocator>
311class __vector_base
312 : protected __vector_base_common<true>
313{
314protected:
Howard Hinnant324bb032010-08-22 00:02:43 +0000315 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000316 typedef _Allocator allocator_type;
317 typedef allocator_traits<allocator_type> __alloc_traits;
318 typedef value_type& reference;
319 typedef const value_type& const_reference;
320 typedef typename __alloc_traits::size_type size_type;
321 typedef typename __alloc_traits::difference_type difference_type;
322 typedef typename __alloc_traits::pointer pointer;
323 typedef typename __alloc_traits::const_pointer const_pointer;
324 typedef pointer iterator;
325 typedef const_pointer const_iterator;
326
327 pointer __begin_;
328 pointer __end_;
329 __compressed_pair<pointer, allocator_type> __end_cap_;
330
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000331 _LIBCPP_INLINE_VISIBILITY
332 allocator_type& __alloc() _NOEXCEPT
333 {return __end_cap_.second();}
334 _LIBCPP_INLINE_VISIBILITY
335 const allocator_type& __alloc() const _NOEXCEPT
336 {return __end_cap_.second();}
337 _LIBCPP_INLINE_VISIBILITY
338 pointer& __end_cap() _NOEXCEPT
339 {return __end_cap_.first();}
340 _LIBCPP_INLINE_VISIBILITY
341 const pointer& __end_cap() const _NOEXCEPT
342 {return __end_cap_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000343
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000344 _LIBCPP_INLINE_VISIBILITY
345 __vector_base()
346 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000347 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348 ~__vector_base();
349
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000350 _LIBCPP_INLINE_VISIBILITY
351 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
352 _LIBCPP_INLINE_VISIBILITY
353 size_type capacity() const _NOEXCEPT
354 {return static_cast<size_type>(__end_cap() - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000356 _LIBCPP_INLINE_VISIBILITY
357 void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +0000358 {__destruct_at_end(__new_last, is_trivially_destructible<value_type>());}
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000359 _LIBCPP_INLINE_VISIBILITY
360 void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT;
361 _LIBCPP_INLINE_VISIBILITY
362 void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365 void __copy_assign_alloc(const __vector_base& __c)
366 {__copy_assign_alloc(__c, integral_constant<bool,
367 __alloc_traits::propagate_on_container_copy_assignment::value>());}
368
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370 void __move_assign_alloc(__vector_base& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000371 _NOEXCEPT_(
372 !__alloc_traits::propagate_on_container_move_assignment::value ||
373 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374 {__move_assign_alloc(__c, integral_constant<bool,
375 __alloc_traits::propagate_on_container_move_assignment::value>());}
376
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000379 _NOEXCEPT_(
380 !__alloc_traits::propagate_on_container_swap::value ||
381 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382 {__swap_alloc(__x, __y, integral_constant<bool,
383 __alloc_traits::propagate_on_container_swap::value>());}
384private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000385 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386 void __copy_assign_alloc(const __vector_base& __c, true_type)
387 {
388 if (__alloc() != __c.__alloc())
389 {
390 clear();
391 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
392 __begin_ = __end_ = __end_cap() = nullptr;
393 }
394 __alloc() = __c.__alloc();
395 }
396
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, false_type)
399 {}
400
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000402 void __move_assign_alloc(__vector_base& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000403 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000405 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000406 }
407
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000409 void __move_assign_alloc(__vector_base& __c, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000410 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411 {}
412
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414 static void __swap_alloc(allocator_type& __x, allocator_type& __y, 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 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418 swap(__x, __y);
419 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421 static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000422 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423 {}
424};
425
426template <class _Tp, class _Allocator>
427_LIBCPP_INLINE_VISIBILITY inline
428void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000429__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430{
431 while (__new_last < __end_)
432 __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_));
433}
434
435template <class _Tp, class _Allocator>
436_LIBCPP_INLINE_VISIBILITY inline
437void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000438__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439{
440 __end_ = const_cast<pointer>(__new_last);
441}
442
443template <class _Tp, class _Allocator>
444_LIBCPP_INLINE_VISIBILITY inline
445__vector_base<_Tp, _Allocator>::__vector_base()
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000446 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000447 : __begin_(0),
448 __end_(0),
449 __end_cap_(0)
450{
451}
452
453template <class _Tp, class _Allocator>
454_LIBCPP_INLINE_VISIBILITY inline
455__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
456 : __begin_(0),
457 __end_(0),
458 __end_cap_(0, __a)
459{
460}
461
462template <class _Tp, class _Allocator>
463__vector_base<_Tp, _Allocator>::~__vector_base()
464{
465 if (__begin_ != 0)
466 {
467 clear();
468 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
469 }
470}
471
472template <class _Tp, class _Allocator = allocator<_Tp> >
Howard Hinnant36cdf022010-09-10 16:42:26 +0000473class _LIBCPP_VISIBLE vector
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474 : private __vector_base<_Tp, _Allocator>
475{
476private:
477 typedef __vector_base<_Tp, _Allocator> __base;
Howard Hinnant324bb032010-08-22 00:02:43 +0000478public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000479 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +0000480 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000481 typedef _Allocator allocator_type;
482 typedef typename __base::__alloc_traits __alloc_traits;
483 typedef typename __base::reference reference;
484 typedef typename __base::const_reference const_reference;
485 typedef typename __base::size_type size_type;
486 typedef typename __base::difference_type difference_type;
487 typedef typename __base::pointer pointer;
488 typedef typename __base::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489 typedef __wrap_iter<pointer> iterator;
490 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000491 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
492 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000494 _LIBCPP_INLINE_VISIBILITY
495 vector()
496 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant7a563db2011-09-14 18:33:51 +0000497 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000498#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000499 __get_db()->__insert_c(this);
500#endif
501 }
502 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
503 : __base(__a)
504 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000505#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000506 __get_db()->__insert_c(this);
507#endif
508 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509 explicit vector(size_type __n);
510 vector(size_type __n, const_reference __x);
511 vector(size_type __n, const_reference __x, const allocator_type& __a);
512 template <class _InputIterator>
513 vector(_InputIterator __first, _InputIterator __last,
514 typename enable_if<__is_input_iterator <_InputIterator>::value &&
515 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
516 template <class _InputIterator>
517 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
518 typename enable_if<__is_input_iterator <_InputIterator>::value &&
519 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
520 template <class _ForwardIterator>
521 vector(_ForwardIterator __first, _ForwardIterator __last,
522 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
523 template <class _ForwardIterator>
524 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
525 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02 +0000526#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528 vector(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000531#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantabe26282011-09-16 17:29:17 +0000532#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a563db2011-09-14 18:33:51 +0000534 ~vector()
535 {
536 __get_db()->__erase_c(this);
537 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538#endif
539
540 vector(const vector& __x);
541 vector(const vector& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543 vector& operator=(const vector& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000544#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000546 vector(vector&& __x)
547 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549 vector(vector&& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000551 vector& operator=(vector&& __x)
552 _NOEXCEPT_(
553 __alloc_traits::propagate_on_container_move_assignment::value &&
554 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000555#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000556#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558 vector& operator=(initializer_list<value_type> __il)
559 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000560#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000561
562 template <class _InputIterator>
563 typename enable_if
564 <
565 __is_input_iterator <_InputIterator>::value &&
566 !__is_forward_iterator<_InputIterator>::value,
567 void
568 >::type
569 assign(_InputIterator __first, _InputIterator __last);
570 template <class _ForwardIterator>
571 typename enable_if
572 <
573 __is_forward_iterator<_ForwardIterator>::value,
574 void
575 >::type
576 assign(_ForwardIterator __first, _ForwardIterator __last);
577
578 void assign(size_type __n, const_reference __u);
Howard Hinnante3e32912011-08-12 21:56:02 +0000579#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581 void assign(initializer_list<value_type> __il)
582 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000583#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000585 _LIBCPP_INLINE_VISIBILITY
586 allocator_type get_allocator() const _NOEXCEPT
587 {return this->__alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000589 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
590 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
591 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
592 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000594 _LIBCPP_INLINE_VISIBILITY
595 reverse_iterator rbegin() _NOEXCEPT
596 {return reverse_iterator(end());}
597 _LIBCPP_INLINE_VISIBILITY
598 const_reverse_iterator rbegin() const _NOEXCEPT
599 {return const_reverse_iterator(end());}
600 _LIBCPP_INLINE_VISIBILITY
601 reverse_iterator rend() _NOEXCEPT
602 {return reverse_iterator(begin());}
603 _LIBCPP_INLINE_VISIBILITY
604 const_reverse_iterator rend() const _NOEXCEPT
605 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000607 _LIBCPP_INLINE_VISIBILITY
608 const_iterator cbegin() const _NOEXCEPT
609 {return begin();}
610 _LIBCPP_INLINE_VISIBILITY
611 const_iterator cend() const _NOEXCEPT
612 {return end();}
613 _LIBCPP_INLINE_VISIBILITY
614 const_reverse_iterator crbegin() const _NOEXCEPT
615 {return rbegin();}
616 _LIBCPP_INLINE_VISIBILITY
617 const_reverse_iterator crend() const _NOEXCEPT
618 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000620 _LIBCPP_INLINE_VISIBILITY
621 size_type size() const _NOEXCEPT
622 {return static_cast<size_type>(this->__end_ - this->__begin_);}
623 _LIBCPP_INLINE_VISIBILITY
624 size_type capacity() const _NOEXCEPT
625 {return __base::capacity();}
626 _LIBCPP_INLINE_VISIBILITY
627 bool empty() const _NOEXCEPT
628 {return this->__begin_ == this->__end_;}
629 size_type max_size() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000631 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632
633 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
634 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
635 reference at(size_type __n);
636 const_reference at(size_type __n) const;
637
Howard Hinnant7a563db2011-09-14 18:33:51 +0000638 _LIBCPP_INLINE_VISIBILITY reference front()
639 {
640 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
641 return *this->__begin_;
642 }
643 _LIBCPP_INLINE_VISIBILITY const_reference front() const
644 {
645 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
646 return *this->__begin_;
647 }
648 _LIBCPP_INLINE_VISIBILITY reference back()
649 {
650 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
651 return *(this->__end_ - 1);
652 }
653 _LIBCPP_INLINE_VISIBILITY const_reference back() const
654 {
655 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
656 return *(this->__end_ - 1);
657 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000658
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000659 _LIBCPP_INLINE_VISIBILITY
660 value_type* data() _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000661 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000662 _LIBCPP_INLINE_VISIBILITY
663 const value_type* data() const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000664 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000666 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000667#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668 void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000669#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 template <class... _Args>
671 void emplace_back(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000672#endif // _LIBCPP_HAS_NO_VARIADICS
673#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674 void pop_back();
675
676 iterator insert(const_iterator __position, const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000677#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678 iterator insert(const_iterator __position, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000679#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680 template <class... _Args>
681 iterator emplace(const_iterator __position, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000682#endif // _LIBCPP_HAS_NO_VARIADICS
683#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000684 iterator insert(const_iterator __position, size_type __n, const_reference __x);
685 template <class _InputIterator>
686 typename enable_if
687 <
688 __is_input_iterator <_InputIterator>::value &&
689 !__is_forward_iterator<_InputIterator>::value,
690 iterator
691 >::type
692 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
693 template <class _ForwardIterator>
694 typename enable_if
695 <
696 __is_forward_iterator<_ForwardIterator>::value,
697 iterator
698 >::type
699 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000700#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702 iterator insert(const_iterator __position, initializer_list<value_type> __il)
703 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000704#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000706 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707 iterator erase(const_iterator __first, const_iterator __last);
708
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000709 _LIBCPP_INLINE_VISIBILITY
710 void clear() _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +0000711 {
712 __base::clear();
713 __invalidate_all_iterators();
714 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715
716 void resize(size_type __sz);
717 void resize(size_type __sz, const_reference __x);
718
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000719 void swap(vector&)
720 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
721 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722
723 bool __invariants() const;
724
Howard Hinnantabe26282011-09-16 17:29:17 +0000725#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000726
727 bool __dereferenceable(const const_iterator* __i) const;
728 bool __decrementable(const const_iterator* __i) const;
729 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
730 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
731
Howard Hinnantabe26282011-09-16 17:29:17 +0000732#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000733
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000735 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000737 void deallocate() _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000738 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
Howard Hinnant04240d92011-01-04 19:53:31 +0000739 void __construct_at_end(size_type __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000740 void __construct_at_end(size_type __n, const_reference __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741 template <class _ForwardIterator>
742 typename enable_if
743 <
744 __is_forward_iterator<_ForwardIterator>::value,
745 void
746 >::type
747 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
748 void __move_construct_at_end(pointer __first, pointer __last);
749 void __append(size_type __n);
750 void __append(size_type __n, const_reference __x);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000752 iterator __make_iter(pointer __p) _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000754 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000755 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
756 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
757 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000758 void __move_assign(vector& __c, true_type)
759 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000760 void __move_assign(vector& __c, false_type);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000761 _LIBCPP_INLINE_VISIBILITY
762 void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
763 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000764#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000765 __c_node* __c = __get_db()->__find_c_and_lock(this);
766 for (__i_node** __p = __c->end_; __p != __c->beg_; )
767 {
768 --__p;
769 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
770 if (__i->base() > __new_last)
771 {
772 (*__p)->__c_ = nullptr;
773 if (--__c->end_ != __p)
774 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
775 }
776 }
777 __get_db()->unlock();
778#endif
779 __base::__destruct_at_end(__new_last);
780 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000781};
782
783template <class _Tp, class _Allocator>
784void
785vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
786{
787 for (pointer __p = this->__end_; this->__begin_ < __p;)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000788 __v.push_front(_VSTD::move_if_noexcept(*--__p));
789 _VSTD::swap(this->__begin_, __v.__begin_);
790 _VSTD::swap(this->__end_, __v.__end_);
791 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792 __v.__first_ = __v.__begin_;
793 __invalidate_all_iterators();
794}
795
796template <class _Tp, class _Allocator>
797typename vector<_Tp, _Allocator>::pointer
798vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
799{
800 pointer __r = __v.__begin_;
801 for (pointer __i = __p; this->__begin_ < __i;)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000802 __v.push_front(_VSTD::move_if_noexcept(*--__i));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 for (pointer __i = __p; __i < this->__end_; ++__i)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000804 __v.push_back(_VSTD::move_if_noexcept(*__i));
805 _VSTD::swap(this->__begin_, __v.__begin_);
806 _VSTD::swap(this->__end_, __v.__end_);
807 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808 __v.__first_ = __v.__begin_;
809 __invalidate_all_iterators();
810 return __r;
811}
812
813// Allocate space for __n objects
814// throws length_error if __n > max_size()
815// throws (probably bad_alloc) if memory run out
816// Precondition: __begin_ == __end_ == __end_cap() == 0
817// Precondition: __n > 0
818// Postcondition: capacity() == __n
819// Postcondition: size() == 0
820template <class _Tp, class _Allocator>
821void
822vector<_Tp, _Allocator>::allocate(size_type __n)
823{
824 if (__n > max_size())
825 this->__throw_length_error();
826 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
827 this->__end_cap() = this->__begin_ + __n;
828}
829
830template <class _Tp, class _Allocator>
831void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000832vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833{
834 if (this->__begin_ != 0)
835 {
836 clear();
837 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838 this->__begin_ = this->__end_ = this->__end_cap() = 0;
839 }
840}
841
842template <class _Tp, class _Allocator>
843typename vector<_Tp, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000844vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845{
Sean Hunt110b8bf2011-07-29 23:31:58 +0000846 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 +0000847}
848
849// Precondition: __new_size > capacity()
850template <class _Tp, class _Allocator>
851_LIBCPP_INLINE_VISIBILITY inline
852typename vector<_Tp, _Allocator>::size_type
853vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
854{
855 const size_type __ms = max_size();
856 if (__new_size > __ms)
857 this->__throw_length_error();
858 const size_type __cap = capacity();
859 if (__cap >= __ms / 2)
860 return __ms;
Sean Hunt110b8bf2011-07-29 23:31:58 +0000861 return _VSTD::max<size_type>(2*__cap, __new_size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862}
863
864// Default constructs __n objects starting at __end_
865// throws if construction throws
866// Precondition: __n > 0
867// Precondition: size() + __n <= capacity()
868// Postcondition: size() == size() + __n
869template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870void
871vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
872{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873 allocator_type& __a = this->__alloc();
874 do
875 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000876 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877 ++this->__end_;
878 --__n;
879 } while (__n > 0);
880}
881
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000882// Copy constructs __n objects starting at __end_ from __x
883// throws if construction throws
884// Precondition: __n > 0
885// Precondition: size() + __n <= capacity()
886// Postcondition: size() == old size() + __n
887// Postcondition: [i] == __x for all i in [size() - __n, __n)
888template <class _Tp, class _Allocator>
889_LIBCPP_INLINE_VISIBILITY inline
890void
891vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
892{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893 allocator_type& __a = this->__alloc();
894 do
895 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000896 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 ++this->__end_;
898 --__n;
899 } while (__n > 0);
900}
901
902template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903template <class _ForwardIterator>
904typename enable_if
905<
906 __is_forward_iterator<_ForwardIterator>::value,
907 void
908>::type
909vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
910{
911 allocator_type& __a = this->__alloc();
912 for (; __first != __last; ++__first)
913 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000914 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915 ++this->__end_;
916 }
917}
918
919template <class _Tp, class _Allocator>
920void
921vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
922{
923 allocator_type& __a = this->__alloc();
924 for (; __first != __last; ++__first)
925 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000926 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
927 _VSTD::move(*__first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000928 ++this->__end_;
929 }
930}
931
932// Default constructs __n objects starting at __end_
933// throws if construction throws
934// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000935// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936template <class _Tp, class _Allocator>
937void
938vector<_Tp, _Allocator>::__append(size_type __n)
939{
940 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
941 this->__construct_at_end(__n);
942 else
943 {
944 allocator_type& __a = this->__alloc();
945 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
946 __v.__construct_at_end(__n);
947 __swap_out_circular_buffer(__v);
948 }
949}
950
951// Default constructs __n objects starting at __end_
952// throws if construction throws
953// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000954// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000955template <class _Tp, class _Allocator>
956void
957vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
958{
959 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
960 this->__construct_at_end(__n, __x);
961 else
962 {
963 allocator_type& __a = this->__alloc();
964 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
965 __v.__construct_at_end(__n, __x);
966 __swap_out_circular_buffer(__v);
967 }
968}
969
970template <class _Tp, class _Allocator>
971vector<_Tp, _Allocator>::vector(size_type __n)
972{
Howard Hinnant0442b122011-09-16 18:41:29 +0000973#if _LIBCPP_DEBUG_LEVEL >= 2
974 __get_db()->__insert_c(this);
975#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 if (__n > 0)
977 {
978 allocate(__n);
979 __construct_at_end(__n);
980 }
981}
982
983template <class _Tp, class _Allocator>
984vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
985{
Howard Hinnant0442b122011-09-16 18:41:29 +0000986#if _LIBCPP_DEBUG_LEVEL >= 2
987 __get_db()->__insert_c(this);
988#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000989 if (__n > 0)
990 {
991 allocate(__n);
992 __construct_at_end(__n, __x);
993 }
994}
995
996template <class _Tp, class _Allocator>
997vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
998 : __base(__a)
999{
Howard Hinnant0442b122011-09-16 18:41:29 +00001000#if _LIBCPP_DEBUG_LEVEL >= 2
1001 __get_db()->__insert_c(this);
1002#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001003 if (__n > 0)
1004 {
1005 allocate(__n);
1006 __construct_at_end(__n, __x);
1007 }
1008}
1009
1010template <class _Tp, class _Allocator>
1011template <class _InputIterator>
1012vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
1013 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1014 !__is_forward_iterator<_InputIterator>::value>::type*)
1015{
Howard Hinnantabe26282011-09-16 17:29:17 +00001016#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001017 __get_db()->__insert_c(this);
1018#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001019 for (; __first != __last; ++__first)
1020 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001021}
1022
1023template <class _Tp, class _Allocator>
1024template <class _InputIterator>
1025vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1026 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1027 !__is_forward_iterator<_InputIterator>::value>::type*)
1028 : __base(__a)
1029{
Howard Hinnantabe26282011-09-16 17:29:17 +00001030#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001031 __get_db()->__insert_c(this);
1032#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001033 for (; __first != __last; ++__first)
1034 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035}
1036
1037template <class _Tp, class _Allocator>
1038template <class _ForwardIterator>
1039vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
1040 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1041{
Howard Hinnant0442b122011-09-16 18:41:29 +00001042#if _LIBCPP_DEBUG_LEVEL >= 2
1043 __get_db()->__insert_c(this);
1044#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001045 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046 if (__n > 0)
1047 {
1048 allocate(__n);
1049 __construct_at_end(__first, __last);
1050 }
1051}
1052
1053template <class _Tp, class _Allocator>
1054template <class _ForwardIterator>
1055vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1056 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1057 : __base(__a)
1058{
Howard Hinnant0442b122011-09-16 18:41:29 +00001059#if _LIBCPP_DEBUG_LEVEL >= 2
1060 __get_db()->__insert_c(this);
1061#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001062 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001063 if (__n > 0)
1064 {
1065 allocate(__n);
1066 __construct_at_end(__first, __last);
1067 }
1068}
1069
1070template <class _Tp, class _Allocator>
1071vector<_Tp, _Allocator>::vector(const vector& __x)
1072 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1073{
Howard Hinnant0442b122011-09-16 18:41:29 +00001074#if _LIBCPP_DEBUG_LEVEL >= 2
1075 __get_db()->__insert_c(this);
1076#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001077 size_type __n = __x.size();
1078 if (__n > 0)
1079 {
1080 allocate(__n);
1081 __construct_at_end(__x.__begin_, __x.__end_);
1082 }
1083}
1084
1085template <class _Tp, class _Allocator>
1086vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1087 : __base(__a)
1088{
Howard Hinnant0442b122011-09-16 18:41:29 +00001089#if _LIBCPP_DEBUG_LEVEL >= 2
1090 __get_db()->__insert_c(this);
1091#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001092 size_type __n = __x.size();
1093 if (__n > 0)
1094 {
1095 allocate(__n);
1096 __construct_at_end(__x.__begin_, __x.__end_);
1097 }
1098}
1099
Howard Hinnant73d21a42010-09-04 23:28:19 +00001100#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001101
1102template <class _Tp, class _Allocator>
1103_LIBCPP_INLINE_VISIBILITY inline
1104vector<_Tp, _Allocator>::vector(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001105 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001106 : __base(_VSTD::move(__x.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001107{
Howard Hinnantabe26282011-09-16 17:29:17 +00001108#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001109 __get_db()->__insert_c(this);
Howard Hinnante6125bd2011-09-19 16:34:29 +00001110 __get_db()->swap(this, &__x);
Howard Hinnant7a563db2011-09-14 18:33:51 +00001111#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001112 this->__begin_ = __x.__begin_;
1113 this->__end_ = __x.__end_;
1114 this->__end_cap() = __x.__end_cap();
1115 __x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001116}
1117
1118template <class _Tp, class _Allocator>
1119_LIBCPP_INLINE_VISIBILITY inline
1120vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1121 : __base(__a)
1122{
Howard Hinnant0442b122011-09-16 18:41:29 +00001123#if _LIBCPP_DEBUG_LEVEL >= 2
1124 __get_db()->__insert_c(this);
1125#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001126 if (__a == __x.__alloc())
1127 {
1128 this->__begin_ = __x.__begin_;
1129 this->__end_ = __x.__end_;
1130 this->__end_cap() = __x.__end_cap();
1131 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001132#if _LIBCPP_DEBUG_LEVEL >= 2
1133 __get_db()->swap(this, &__x);
1134#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001135 }
1136 else
1137 {
1138 typedef move_iterator<iterator> _I;
1139 assign(_I(__x.begin()), _I(__x.end()));
1140 }
1141}
1142
Howard Hinnante3e32912011-08-12 21:56:02 +00001143#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1144
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145template <class _Tp, class _Allocator>
1146_LIBCPP_INLINE_VISIBILITY inline
1147vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1148{
Howard Hinnant0442b122011-09-16 18:41:29 +00001149#if _LIBCPP_DEBUG_LEVEL >= 2
1150 __get_db()->__insert_c(this);
1151#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152 if (__il.size() > 0)
1153 {
1154 allocate(__il.size());
1155 __construct_at_end(__il.begin(), __il.end());
1156 }
1157}
1158
1159template <class _Tp, class _Allocator>
1160_LIBCPP_INLINE_VISIBILITY inline
1161vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1162 : __base(__a)
1163{
Howard Hinnant0442b122011-09-16 18:41:29 +00001164#if _LIBCPP_DEBUG_LEVEL >= 2
1165 __get_db()->__insert_c(this);
1166#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167 if (__il.size() > 0)
1168 {
1169 allocate(__il.size());
1170 __construct_at_end(__il.begin(), __il.end());
1171 }
1172}
1173
Howard Hinnante3e32912011-08-12 21:56:02 +00001174#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1175
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001176template <class _Tp, class _Allocator>
1177_LIBCPP_INLINE_VISIBILITY inline
1178vector<_Tp, _Allocator>&
1179vector<_Tp, _Allocator>::operator=(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001180 _NOEXCEPT_(
1181 __alloc_traits::propagate_on_container_move_assignment::value &&
1182 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183{
1184 __move_assign(__x, integral_constant<bool,
1185 __alloc_traits::propagate_on_container_move_assignment::value>());
1186 return *this;
1187}
1188
1189template <class _Tp, class _Allocator>
1190void
1191vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1192{
1193 if (__base::__alloc() != __c.__alloc())
1194 {
1195 typedef move_iterator<iterator> _I;
1196 assign(_I(__c.begin()), _I(__c.end()));
1197 }
1198 else
1199 __move_assign(__c, true_type());
1200}
1201
1202template <class _Tp, class _Allocator>
1203void
1204vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001205 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206{
1207 deallocate();
1208 this->__begin_ = __c.__begin_;
1209 this->__end_ = __c.__end_;
1210 this->__end_cap() = __c.__end_cap();
1211 __base::__move_assign_alloc(__c);
1212 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001213#if _LIBCPP_DEBUG_LEVEL >= 2
1214 __get_db()->swap(this, &__c);
1215#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001216}
1217
Howard Hinnant73d21a42010-09-04 23:28:19 +00001218#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001219
1220template <class _Tp, class _Allocator>
1221_LIBCPP_INLINE_VISIBILITY inline
1222vector<_Tp, _Allocator>&
1223vector<_Tp, _Allocator>::operator=(const vector& __x)
1224{
1225 if (this != &__x)
1226 {
1227 __base::__copy_assign_alloc(__x);
1228 assign(__x.__begin_, __x.__end_);
1229 }
1230 return *this;
1231}
1232
1233template <class _Tp, class _Allocator>
1234template <class _InputIterator>
1235typename enable_if
1236<
1237 __is_input_iterator <_InputIterator>::value &&
1238 !__is_forward_iterator<_InputIterator>::value,
1239 void
1240>::type
1241vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1242{
1243 clear();
1244 for (; __first != __last; ++__first)
1245 push_back(*__first);
1246}
1247
1248template <class _Tp, class _Allocator>
1249template <class _ForwardIterator>
1250typename enable_if
1251<
1252 __is_forward_iterator<_ForwardIterator>::value,
1253 void
1254>::type
1255vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1256{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001257 typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258 if (static_cast<size_type>(__new_size) <= capacity())
1259 {
1260 _ForwardIterator __mid = __last;
1261 bool __growing = false;
1262 if (static_cast<size_type>(__new_size) > size())
1263 {
1264 __growing = true;
1265 __mid = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001266 _VSTD::advance(__mid, size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001268 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269 if (__growing)
1270 __construct_at_end(__mid, __last);
1271 else
1272 this->__destruct_at_end(__m);
1273 }
1274 else
1275 {
1276 deallocate();
1277 allocate(__recommend(static_cast<size_type>(__new_size)));
1278 __construct_at_end(__first, __last);
1279 }
1280}
1281
1282template <class _Tp, class _Allocator>
1283void
1284vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1285{
1286 if (__n <= capacity())
1287 {
1288 size_type __s = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001289 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001290 if (__n > __s)
1291 __construct_at_end(__n - __s, __u);
1292 else
Howard Hinnantadff4892010-05-24 17:49:41 +00001293 this->__destruct_at_end(this->__begin_ + __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001294 }
1295 else
1296 {
1297 deallocate();
1298 allocate(__recommend(static_cast<size_type>(__n)));
1299 __construct_at_end(__n, __u);
1300 }
1301}
1302
Howard Hinnant324bb032010-08-22 00:02:43 +00001303template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001304_LIBCPP_INLINE_VISIBILITY inline
1305typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001306vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001307{
Howard Hinnantabe26282011-09-16 17:29:17 +00001308#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309 return iterator(this, __p);
1310#else
1311 return iterator(__p);
1312#endif
1313}
1314
Howard Hinnant324bb032010-08-22 00:02:43 +00001315template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001316_LIBCPP_INLINE_VISIBILITY inline
1317typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001318vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001319{
Howard Hinnantabe26282011-09-16 17:29:17 +00001320#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001321 return const_iterator(this, __p);
1322#else
1323 return const_iterator(__p);
1324#endif
1325}
1326
Howard Hinnant324bb032010-08-22 00:02:43 +00001327template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001328_LIBCPP_INLINE_VISIBILITY inline
1329typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001330vector<_Tp, _Allocator>::begin() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331{
1332 return __make_iter(this->__begin_);
1333}
1334
Howard Hinnant324bb032010-08-22 00:02:43 +00001335template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336_LIBCPP_INLINE_VISIBILITY inline
1337typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001338vector<_Tp, _Allocator>::begin() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001339{
1340 return __make_iter(this->__begin_);
1341}
1342
Howard Hinnant324bb032010-08-22 00:02:43 +00001343template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001344_LIBCPP_INLINE_VISIBILITY inline
1345typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001346vector<_Tp, _Allocator>::end() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001347{
1348 return __make_iter(this->__end_);
1349}
1350
Howard Hinnant324bb032010-08-22 00:02:43 +00001351template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352_LIBCPP_INLINE_VISIBILITY inline
1353typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001354vector<_Tp, _Allocator>::end() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001355{
1356 return __make_iter(this->__end_);
1357}
1358
Howard Hinnant324bb032010-08-22 00:02:43 +00001359template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001360_LIBCPP_INLINE_VISIBILITY inline
1361typename vector<_Tp, _Allocator>::reference
1362vector<_Tp, _Allocator>::operator[](size_type __n)
1363{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001364 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001365 return this->__begin_[__n];
1366}
1367
Howard Hinnant324bb032010-08-22 00:02:43 +00001368template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001369_LIBCPP_INLINE_VISIBILITY inline
1370typename vector<_Tp, _Allocator>::const_reference
1371vector<_Tp, _Allocator>::operator[](size_type __n) const
1372{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001373 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001374 return this->__begin_[__n];
1375}
1376
Howard Hinnant324bb032010-08-22 00:02:43 +00001377template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001378typename vector<_Tp, _Allocator>::reference
1379vector<_Tp, _Allocator>::at(size_type __n)
1380{
1381 if (__n >= size())
1382 this->__throw_out_of_range();
1383 return this->__begin_[__n];
1384}
1385
Howard Hinnant324bb032010-08-22 00:02:43 +00001386template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387typename vector<_Tp, _Allocator>::const_reference
1388vector<_Tp, _Allocator>::at(size_type __n) const
1389{
1390 if (__n >= size())
1391 this->__throw_out_of_range();
1392 return this->__begin_[__n];
1393}
1394
1395template <class _Tp, class _Allocator>
1396void
1397vector<_Tp, _Allocator>::reserve(size_type __n)
1398{
1399 if (__n > capacity())
1400 {
1401 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001402 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403 __swap_out_circular_buffer(__v);
1404 }
1405}
1406
1407template <class _Tp, class _Allocator>
1408void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001409vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410{
1411 if (capacity() > size())
1412 {
1413#ifndef _LIBCPP_NO_EXCEPTIONS
1414 try
1415 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001416#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001417 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001418 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001419 __swap_out_circular_buffer(__v);
1420#ifndef _LIBCPP_NO_EXCEPTIONS
1421 }
1422 catch (...)
1423 {
1424 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001425#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426 }
1427}
1428
1429template <class _Tp, class _Allocator>
1430void
1431vector<_Tp, _Allocator>::push_back(const_reference __x)
1432{
1433 if (this->__end_ < this->__end_cap())
1434 {
1435 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001436 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437 ++this->__end_;
1438 }
1439 else
1440 {
1441 allocator_type& __a = this->__alloc();
1442 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1443 __v.push_back(__x);
1444 __swap_out_circular_buffer(__v);
1445 }
1446}
1447
Howard Hinnant73d21a42010-09-04 23:28:19 +00001448#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001449
1450template <class _Tp, class _Allocator>
1451void
1452vector<_Tp, _Allocator>::push_back(value_type&& __x)
1453{
1454 if (this->__end_ < this->__end_cap())
1455 {
1456 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001457 _VSTD::__to_raw_pointer(this->__end_),
1458 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001459 ++this->__end_;
1460 }
1461 else
1462 {
1463 allocator_type& __a = this->__alloc();
1464 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001465 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001466 __swap_out_circular_buffer(__v);
1467 }
1468}
1469
Howard Hinnant73d21a42010-09-04 23:28:19 +00001470#ifndef _LIBCPP_HAS_NO_VARIADICS
1471
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001472template <class _Tp, class _Allocator>
1473template <class... _Args>
1474void
1475vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1476{
1477 if (this->__end_ < this->__end_cap())
1478 {
1479 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001480 _VSTD::__to_raw_pointer(this->__end_),
1481 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001482 ++this->__end_;
1483 }
1484 else
1485 {
1486 allocator_type& __a = this->__alloc();
1487 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001488 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001489 __swap_out_circular_buffer(__v);
1490 }
1491}
1492
Howard Hinnant73d21a42010-09-04 23:28:19 +00001493#endif // _LIBCPP_HAS_NO_VARIADICS
1494#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001495
1496template <class _Tp, class _Allocator>
1497_LIBCPP_INLINE_VISIBILITY inline
1498void
1499vector<_Tp, _Allocator>::pop_back()
1500{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001501 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001502 this->__destruct_at_end(this->__end_ - 1);
1503}
1504
1505template <class _Tp, class _Allocator>
1506_LIBCPP_INLINE_VISIBILITY inline
1507typename vector<_Tp, _Allocator>::iterator
1508vector<_Tp, _Allocator>::erase(const_iterator __position)
1509{
Howard Hinnantabe26282011-09-16 17:29:17 +00001510#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001511 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1512 "vector::erase(iterator) called with an iterator not"
1513 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001514#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515 pointer __p = const_cast<pointer>(&*__position);
1516 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001517 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518 return __r;
1519}
1520
1521template <class _Tp, class _Allocator>
1522typename vector<_Tp, _Allocator>::iterator
1523vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1524{
Howard Hinnantabe26282011-09-16 17:29:17 +00001525#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001526 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1527 "vector::erase(iterator, iterator) called with an iterator not"
1528 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001529#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001530 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531 pointer __p = this->__begin_ + (__first - begin());
1532 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001533 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534 return __r;
1535}
1536
1537template <class _Tp, class _Allocator>
1538void
1539vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1540{
1541 pointer __old_last = this->__end_;
1542 difference_type __n = __old_last - __to;
1543 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1544 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001545 _VSTD::__to_raw_pointer(this->__end_),
1546 _VSTD::move(*__i));
1547 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548}
1549
1550template <class _Tp, class _Allocator>
1551typename vector<_Tp, _Allocator>::iterator
1552vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1553{
Howard Hinnantabe26282011-09-16 17:29:17 +00001554#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001555 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1556 "vector::insert(iterator, x) called with an iterator not"
1557 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001558#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001559 pointer __p = this->__begin_ + (__position - begin());
1560 if (this->__end_ < this->__end_cap())
1561 {
1562 if (__p == this->__end_)
1563 {
1564 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001565 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001566 ++this->__end_;
1567 }
1568 else
1569 {
1570 __move_range(__p, this->__end_, __p + 1);
1571 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1572 if (__p <= __xr && __xr < this->__end_)
1573 ++__xr;
1574 *__p = *__xr;
1575 }
1576 }
1577 else
1578 {
1579 allocator_type& __a = this->__alloc();
1580 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1581 __v.push_back(__x);
1582 __p = __swap_out_circular_buffer(__v, __p);
1583 }
1584 return __make_iter(__p);
1585}
1586
Howard Hinnant73d21a42010-09-04 23:28:19 +00001587#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001588
1589template <class _Tp, class _Allocator>
1590typename vector<_Tp, _Allocator>::iterator
1591vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1592{
Howard Hinnantabe26282011-09-16 17:29:17 +00001593#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001594 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1595 "vector::insert(iterator, x) called with an iterator not"
1596 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001597#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598 pointer __p = this->__begin_ + (__position - begin());
1599 if (this->__end_ < this->__end_cap())
1600 {
1601 if (__p == this->__end_)
1602 {
1603 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001604 _VSTD::__to_raw_pointer(this->__end_),
1605 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001606 ++this->__end_;
1607 }
1608 else
1609 {
1610 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001611 *__p = _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001612 }
1613 }
1614 else
1615 {
1616 allocator_type& __a = this->__alloc();
1617 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001618 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001619 __p = __swap_out_circular_buffer(__v, __p);
1620 }
1621 return __make_iter(__p);
1622}
1623
Howard Hinnant73d21a42010-09-04 23:28:19 +00001624#ifndef _LIBCPP_HAS_NO_VARIADICS
1625
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001626template <class _Tp, class _Allocator>
1627template <class... _Args>
1628typename vector<_Tp, _Allocator>::iterator
1629vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1630{
Howard Hinnantabe26282011-09-16 17:29:17 +00001631#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001632 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1633 "vector::emplace(iterator, x) called with an iterator not"
1634 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001635#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001636 pointer __p = this->__begin_ + (__position - begin());
1637 if (this->__end_ < this->__end_cap())
1638 {
1639 if (__p == this->__end_)
1640 {
1641 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001642 _VSTD::__to_raw_pointer(this->__end_),
1643 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644 ++this->__end_;
1645 }
1646 else
1647 {
1648 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001649 *__p = value_type(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650 }
1651 }
1652 else
1653 {
1654 allocator_type& __a = this->__alloc();
1655 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001656 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001657 __p = __swap_out_circular_buffer(__v, __p);
1658 }
1659 return __make_iter(__p);
1660}
1661
Howard Hinnant73d21a42010-09-04 23:28:19 +00001662#endif // _LIBCPP_HAS_NO_VARIADICS
1663#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001664
1665template <class _Tp, class _Allocator>
1666typename vector<_Tp, _Allocator>::iterator
1667vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1668{
Howard Hinnantabe26282011-09-16 17:29:17 +00001669#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001670 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1671 "vector::insert(iterator, n, x) called with an iterator not"
1672 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001673#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001674 pointer __p = this->__begin_ + (__position - begin());
1675 if (__n > 0)
1676 {
1677 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1678 {
1679 size_type __old_n = __n;
1680 pointer __old_last = this->__end_;
1681 if (__n > static_cast<size_type>(this->__end_ - __p))
1682 {
1683 size_type __cx = __n - (this->__end_ - __p);
1684 __construct_at_end(__cx, __x);
1685 __n -= __cx;
1686 }
1687 if (__n > 0)
1688 {
1689 __move_range(__p, __old_last, __p + __old_n);
1690 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1691 if (__p <= __xr && __xr < this->__end_)
1692 __xr += __old_n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001693 _VSTD::fill_n(__p, __n, *__xr);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001694 }
1695 }
1696 else
1697 {
1698 allocator_type& __a = this->__alloc();
1699 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1700 __v.__construct_at_end(__n, __x);
1701 __p = __swap_out_circular_buffer(__v, __p);
1702 }
1703 }
1704 return __make_iter(__p);
1705}
1706
1707template <class _Tp, class _Allocator>
1708template <class _InputIterator>
1709typename enable_if
1710<
1711 __is_input_iterator <_InputIterator>::value &&
1712 !__is_forward_iterator<_InputIterator>::value,
1713 typename vector<_Tp, _Allocator>::iterator
1714>::type
1715vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1716{
Howard Hinnantabe26282011-09-16 17:29:17 +00001717#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001718 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1719 "vector::insert(iterator, range) called with an iterator not"
1720 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001721#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001722 difference_type __off = __position - begin();
1723 pointer __p = this->__begin_ + __off;
1724 allocator_type& __a = this->__alloc();
1725 pointer __old_last = this->__end_;
1726 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1727 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001728 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001729 *__first);
1730 ++this->__end_;
1731 }
1732 __split_buffer<value_type, allocator_type&> __v(__a);
1733 if (__first != __last)
1734 {
1735#ifndef _LIBCPP_NO_EXCEPTIONS
1736 try
1737 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001738#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001739 __v.__construct_at_end(__first, __last);
1740 difference_type __old_size = __old_last - this->__begin_;
1741 difference_type __old_p = __p - this->__begin_;
1742 reserve(__recommend(size() + __v.size()));
1743 __p = this->__begin_ + __old_p;
1744 __old_last = this->__begin_ + __old_size;
1745#ifndef _LIBCPP_NO_EXCEPTIONS
1746 }
1747 catch (...)
1748 {
1749 erase(__make_iter(__old_last), end());
1750 throw;
1751 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001752#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001753 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001754 __p = _VSTD::rotate(__p, __old_last, this->__end_);
Howard Hinnant0442b122011-09-16 18:41:29 +00001755 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1756 make_move_iterator(__v.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001757 return begin() + __off;
1758}
1759
1760template <class _Tp, class _Allocator>
1761template <class _ForwardIterator>
1762typename enable_if
1763<
1764 __is_forward_iterator<_ForwardIterator>::value,
1765 typename vector<_Tp, _Allocator>::iterator
1766>::type
1767vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1768{
Howard Hinnantabe26282011-09-16 17:29:17 +00001769#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001770 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1771 "vector::insert(iterator, range) called with an iterator not"
1772 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001773#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001774 pointer __p = this->__begin_ + (__position - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00001775 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001776 if (__n > 0)
1777 {
1778 if (__n <= this->__end_cap() - this->__end_)
1779 {
1780 size_type __old_n = __n;
1781 pointer __old_last = this->__end_;
1782 _ForwardIterator __m = __last;
1783 difference_type __dx = this->__end_ - __p;
1784 if (__n > __dx)
1785 {
1786 __m = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001787 _VSTD::advance(__m, this->__end_ - __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001788 __construct_at_end(__m, __last);
1789 __n = __dx;
1790 }
1791 if (__n > 0)
1792 {
1793 __move_range(__p, __old_last, __p + __old_n);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001794 _VSTD::copy(__first, __m, __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795 }
1796 }
1797 else
1798 {
1799 allocator_type& __a = this->__alloc();
1800 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1801 __v.__construct_at_end(__first, __last);
1802 __p = __swap_out_circular_buffer(__v, __p);
1803 }
1804 }
1805 return __make_iter(__p);
1806}
1807
1808template <class _Tp, class _Allocator>
1809void
1810vector<_Tp, _Allocator>::resize(size_type __sz)
1811{
1812 size_type __cs = size();
1813 if (__cs < __sz)
1814 this->__append(__sz - __cs);
1815 else if (__cs > __sz)
1816 this->__destruct_at_end(this->__begin_ + __sz);
1817}
1818
1819template <class _Tp, class _Allocator>
1820void
1821vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1822{
1823 size_type __cs = size();
1824 if (__cs < __sz)
1825 this->__append(__sz - __cs, __x);
1826 else if (__cs > __sz)
1827 this->__destruct_at_end(this->__begin_ + __sz);
1828}
1829
1830template <class _Tp, class _Allocator>
1831void
1832vector<_Tp, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001833 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1834 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001836 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
1837 this->__alloc() == __x.__alloc(),
1838 "vector::swap: Either propagate_on_container_swap must be true"
1839 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19 +00001840 _VSTD::swap(this->__begin_, __x.__begin_);
1841 _VSTD::swap(this->__end_, __x.__end_);
1842 _VSTD::swap(this->__end_cap(), __x.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001843 __base::__swap_alloc(this->__alloc(), __x.__alloc());
Howard Hinnantabe26282011-09-16 17:29:17 +00001844#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001845 __get_db()->swap(this, &__x);
Howard Hinnantabe26282011-09-16 17:29:17 +00001846#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847}
1848
Howard Hinnant324bb032010-08-22 00:02:43 +00001849template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001850bool
1851vector<_Tp, _Allocator>::__invariants() const
1852{
1853 if (this->__begin_ == 0)
1854 {
1855 if (this->__end_ != 0 || this->__end_cap() != 0)
1856 return false;
1857 }
1858 else
1859 {
1860 if (this->__begin_ > this->__end_)
1861 return false;
1862 if (this->__begin_ == this->__end_cap())
1863 return false;
1864 if (this->__end_ > this->__end_cap())
1865 return false;
1866 }
1867 return true;
1868}
1869
Howard Hinnantabe26282011-09-16 17:29:17 +00001870#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001871
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872template <class _Tp, class _Allocator>
Howard Hinnant7a563db2011-09-14 18:33:51 +00001873bool
1874vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
1875{
1876 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
1877}
1878
1879template <class _Tp, class _Allocator>
1880bool
1881vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
1882{
1883 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
1884}
1885
1886template <class _Tp, class _Allocator>
1887bool
1888vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
1889{
1890 const_pointer __p = __i->base() + __n;
1891 return this->__begin_ <= __p && __p <= this->__end_;
1892}
1893
1894template <class _Tp, class _Allocator>
1895bool
1896vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1897{
1898 const_pointer __p = __i->base() + __n;
1899 return this->__begin_ <= __p && __p < this->__end_;
1900}
1901
Howard Hinnantabe26282011-09-16 17:29:17 +00001902#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001903
1904template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001905_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001906void
1907vector<_Tp, _Allocator>::__invalidate_all_iterators()
1908{
Howard Hinnantabe26282011-09-16 17:29:17 +00001909#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001910 __get_db()->__invalidate_all(this);
Howard Hinnantabe26282011-09-16 17:29:17 +00001911#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001912}
1913
1914// vector<bool>
1915
1916template <class _Allocator> class vector<bool, _Allocator>;
1917
1918template <class _Allocator> struct hash<vector<bool, _Allocator> >;
1919
1920template <class _Allocator>
Howard Hinnantf03c3b42011-07-02 20:33:23 +00001921struct __has_storage_type<vector<bool, _Allocator> >
1922{
1923 static const bool value = true;
1924};
1925
1926template <class _Allocator>
Howard Hinnant36cdf022010-09-10 16:42:26 +00001927class _LIBCPP_VISIBLE vector<bool, _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928 : private __vector_base_common<true>
1929{
1930public:
1931 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +00001932 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001933 typedef _Allocator allocator_type;
1934 typedef allocator_traits<allocator_type> __alloc_traits;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935 typedef typename __alloc_traits::size_type size_type;
1936 typedef typename __alloc_traits::difference_type difference_type;
1937 typedef __bit_iterator<vector, false> pointer;
1938 typedef __bit_iterator<vector, true> const_pointer;
1939#ifdef _LIBCPP_DEBUG
1940 typedef __debug_iter<vector, pointer> iterator;
1941 typedef __debug_iter<vector, const_pointer> const_iterator;
1942
1943 friend class __debug_iter<vector, pointer>;
1944 friend class __debug_iter<vector, const_pointer>;
1945
1946 pair<iterator*, const_iterator*> __iterator_list_;
1947
1948 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1949 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
Howard Hinnant324bb032010-08-22 00:02:43 +00001950#else // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951 typedef pointer iterator;
1952 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001953#endif // _LIBCPP_DEBUG
Howard Hinnant0949eed2011-06-30 21:18:19 +00001954 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1955 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001956
1957private:
1958 typedef size_type __storage_type;
1959 typedef typename __alloc_traits::template
1960#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1961 rebind_alloc<__storage_type>
1962#else
1963 rebind_alloc<__storage_type>::other
1964#endif
1965 __storage_allocator;
1966 typedef allocator_traits<__storage_allocator> __storage_traits;
1967 typedef typename __storage_traits::pointer __storage_pointer;
1968 typedef typename __storage_traits::const_pointer __const_storage_pointer;
1969
1970 __storage_pointer __begin_;
1971 size_type __size_;
1972 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00001973public:
Howard Hinnantf03c3b42011-07-02 20:33:23 +00001974 typedef __bit_reference<vector> reference;
1975 typedef __bit_const_reference<vector> const_reference;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00001976private:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001977 _LIBCPP_INLINE_VISIBILITY
1978 size_type& __cap() _NOEXCEPT
1979 {return __cap_alloc_.first();}
1980 _LIBCPP_INLINE_VISIBILITY
1981 const size_type& __cap() const _NOEXCEPT
1982 {return __cap_alloc_.first();}
1983 _LIBCPP_INLINE_VISIBILITY
1984 __storage_allocator& __alloc() _NOEXCEPT
1985 {return __cap_alloc_.second();}
1986 _LIBCPP_INLINE_VISIBILITY
1987 const __storage_allocator& __alloc() const _NOEXCEPT
1988 {return __cap_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001989
1990 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
1991
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001992 _LIBCPP_INLINE_VISIBILITY
1993 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001994 {return __n * __bits_per_word;}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001995 _LIBCPP_INLINE_VISIBILITY
1996 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001997 {return (__n - 1) / __bits_per_word + 1;}
1998
1999public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002000 _LIBCPP_INLINE_VISIBILITY
2001 vector()
2002 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002003 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002004 ~vector();
2005 explicit vector(size_type __n);
2006 vector(size_type __n, const value_type& __v);
2007 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2008 template <class _InputIterator>
2009 vector(_InputIterator __first, _InputIterator __last,
2010 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2011 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2012 template <class _InputIterator>
2013 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2014 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2015 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2016 template <class _ForwardIterator>
2017 vector(_ForwardIterator __first, _ForwardIterator __last,
2018 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2019 template <class _ForwardIterator>
2020 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2021 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2022
2023 vector(const vector& __v);
2024 vector(const vector& __v, const allocator_type& __a);
2025 vector& operator=(const vector& __v);
Howard Hinnante3e32912011-08-12 21:56:02 +00002026#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002027 vector(initializer_list<value_type> __il);
2028 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00002029#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002030
Howard Hinnant73d21a42010-09-04 23:28:19 +00002031#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002032 _LIBCPP_INLINE_VISIBILITY
2033 vector(vector&& __v)
2034 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002035 vector(vector&& __v, const allocator_type& __a);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002036 _LIBCPP_INLINE_VISIBILITY
2037 vector& operator=(vector&& __v)
2038 _NOEXCEPT_(
2039 __alloc_traits::propagate_on_container_move_assignment::value &&
2040 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002041#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00002042#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002044 vector& operator=(initializer_list<value_type> __il)
2045 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00002046#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002047
2048 template <class _InputIterator>
2049 typename enable_if
2050 <
2051 __is_input_iterator<_InputIterator>::value &&
2052 !__is_forward_iterator<_InputIterator>::value,
2053 void
2054 >::type
2055 assign(_InputIterator __first, _InputIterator __last);
2056 template <class _ForwardIterator>
2057 typename enable_if
2058 <
2059 __is_forward_iterator<_ForwardIterator>::value,
2060 void
2061 >::type
2062 assign(_ForwardIterator __first, _ForwardIterator __last);
2063
2064 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:02 +00002065#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002066 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002067 void assign(initializer_list<value_type> __il)
2068 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002069#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002070
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002071 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072 {return allocator_type(this->__alloc());}
2073
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002074 size_type max_size() const _NOEXCEPT;
2075 _LIBCPP_INLINE_VISIBILITY
2076 size_type capacity() const _NOEXCEPT
2077 {return __internal_cap_to_external(__cap());}
2078 _LIBCPP_INLINE_VISIBILITY
2079 size_type size() const _NOEXCEPT
2080 {return __size_;}
2081 _LIBCPP_INLINE_VISIBILITY
2082 bool empty() const _NOEXCEPT
2083 {return __size_ == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002084 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002085 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002086
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002087 _LIBCPP_INLINE_VISIBILITY
2088 iterator begin() _NOEXCEPT
2089 {return __make_iter(0);}
2090 _LIBCPP_INLINE_VISIBILITY
2091 const_iterator begin() const _NOEXCEPT
2092 {return __make_iter(0);}
2093 _LIBCPP_INLINE_VISIBILITY
2094 iterator end() _NOEXCEPT
2095 {return __make_iter(__size_);}
2096 _LIBCPP_INLINE_VISIBILITY
2097 const_iterator end() const _NOEXCEPT
2098 {return __make_iter(__size_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002099
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002100 _LIBCPP_INLINE_VISIBILITY
2101 reverse_iterator rbegin() _NOEXCEPT
2102 {return reverse_iterator(end());}
2103 _LIBCPP_INLINE_VISIBILITY
2104 const_reverse_iterator rbegin() const _NOEXCEPT
2105 {return const_reverse_iterator(end());}
2106 _LIBCPP_INLINE_VISIBILITY
2107 reverse_iterator rend() _NOEXCEPT
2108 {return reverse_iterator(begin());}
2109 _LIBCPP_INLINE_VISIBILITY
2110 const_reverse_iterator rend() const _NOEXCEPT
2111 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002112
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002113 _LIBCPP_INLINE_VISIBILITY
2114 const_iterator cbegin() const _NOEXCEPT
2115 {return __make_iter(0);}
2116 _LIBCPP_INLINE_VISIBILITY
2117 const_iterator cend() const _NOEXCEPT
2118 {return __make_iter(__size_);}
2119 _LIBCPP_INLINE_VISIBILITY
2120 const_reverse_iterator crbegin() const _NOEXCEPT
2121 {return rbegin();}
2122 _LIBCPP_INLINE_VISIBILITY
2123 const_reverse_iterator crend() const _NOEXCEPT
2124 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002125
2126 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2127 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2128 reference at(size_type __n);
2129 const_reference at(size_type __n) const;
2130
2131 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2132 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2133 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2134 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2135
2136 void push_back(const value_type& __x);
2137 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2138
2139 iterator insert(const_iterator __position, const value_type& __x);
2140 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2141 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2142 template <class _InputIterator>
2143 typename enable_if
2144 <
2145 __is_input_iterator <_InputIterator>::value &&
2146 !__is_forward_iterator<_InputIterator>::value,
2147 iterator
2148 >::type
2149 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2150 template <class _ForwardIterator>
2151 typename enable_if
2152 <
2153 __is_forward_iterator<_ForwardIterator>::value,
2154 iterator
2155 >::type
2156 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00002157#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002159 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2160 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002161#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002162
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002163 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002164 iterator erase(const_iterator __first, const_iterator __last);
2165
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002166 _LIBCPP_INLINE_VISIBILITY
2167 void clear() _NOEXCEPT {__size_ = 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002168
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002169 void swap(vector&)
2170 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2171 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002172
2173 void resize(size_type __sz, value_type __x = false);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002174 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002175
2176 bool __invariants() const;
2177
2178private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002179 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002180 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002181 void deallocate() _NOEXCEPT;
2182 _LIBCPP_INLINE_VISIBILITY
2183 static size_type __align(size_type __new_size) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002184 {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);};
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002185 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2186 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002187 template <class _ForwardIterator>
2188 typename enable_if
2189 <
2190 __is_forward_iterator<_ForwardIterator>::value,
2191 void
2192 >::type
2193 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2194 void __append(size_type __n, const_reference __x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002195 _LIBCPP_INLINE_VISIBILITY
2196 reference __make_ref(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002198 _LIBCPP_INLINE_VISIBILITY
2199 const_reference __make_ref(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002200 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2201#ifdef _LIBCPP_DEBUG
2202 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos)
2203 {return iterator(this, pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2204 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const
2205 {return const_iterator(this, const_pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2206 _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p)
2207 {return iterator(this, pointer(const_cast<__storage_pointer>(__p.base().__seg_), __p.base().__ctz_));}
Howard Hinnant324bb032010-08-22 00:02:43 +00002208#else // _LIBCPP_DEBUG
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002209 _LIBCPP_INLINE_VISIBILITY
2210 iterator __make_iter(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002211 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002212 _LIBCPP_INLINE_VISIBILITY
2213 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002214 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002215 _LIBCPP_INLINE_VISIBILITY
2216 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002217 {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);}
Howard Hinnant324bb032010-08-22 00:02:43 +00002218#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002219
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002221 void __copy_assign_alloc(const vector& __v)
2222 {__copy_assign_alloc(__v, integral_constant<bool,
2223 __storage_traits::propagate_on_container_copy_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002225 void __copy_assign_alloc(const vector& __c, true_type)
2226 {
2227 if (__alloc() != __c.__alloc())
2228 deallocate();
2229 __alloc() = __c.__alloc();
2230 }
2231
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002233 void __copy_assign_alloc(const vector& __c, false_type)
2234 {}
2235
2236 void __move_assign(vector& __c, false_type);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002237 void __move_assign(vector& __c, true_type)
2238 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002240 void __move_assign_alloc(vector& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002241 _NOEXCEPT_(
2242 !__storage_traits::propagate_on_container_move_assignment::value ||
2243 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002244 {__move_assign_alloc(__c, integral_constant<bool,
2245 __storage_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00002247 void __move_assign_alloc(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002248 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002249 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002250 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002251 }
2252
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00002254 void __move_assign_alloc(vector& __c, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002255 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002256 {}
2257
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002259 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002260 _NOEXCEPT_(
2261 !__storage_traits::propagate_on_container_swap::value ||
2262 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002263 {__swap_alloc(__x, __y, integral_constant<bool,
2264 __storage_traits::propagate_on_container_swap::value>());}
2265
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002267 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002268 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002269 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002270 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002271 swap(__x, __y);
2272 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002274 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002275 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002276 {}
2277
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002278 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002279
2280 friend class __bit_reference<vector>;
2281 friend class __bit_const_reference<vector>;
2282 friend class __bit_iterator<vector, false>;
2283 friend class __bit_iterator<vector, true>;
2284 friend class __bit_array<vector>;
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002285 friend struct _LIBCPP_VISIBLE hash<vector>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002286};
2287
2288template <class _Allocator>
2289#ifndef _LIBCPP_DEBUG
2290_LIBCPP_INLINE_VISIBILITY inline
2291#endif
2292void
2293vector<bool, _Allocator>::__invalidate_all_iterators()
2294{
2295#ifdef _LIBCPP_DEBUG
2296 iterator::__remove_all(this);
2297 const_iterator::__remove_all(this);
Howard Hinnant324bb032010-08-22 00:02:43 +00002298#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002299}
2300
2301// Allocate space for __n objects
2302// throws length_error if __n > max_size()
2303// throws (probably bad_alloc) if memory run out
2304// Precondition: __begin_ == __end_ == __cap() == 0
2305// Precondition: __n > 0
2306// Postcondition: capacity() == __n
2307// Postcondition: size() == 0
2308template <class _Allocator>
2309void
2310vector<bool, _Allocator>::allocate(size_type __n)
2311{
2312 if (__n > max_size())
2313 this->__throw_length_error();
2314 __n = __external_cap_to_internal(__n);
2315 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2316 this->__size_ = 0;
2317 this->__cap() = __n;
2318}
2319
2320template <class _Allocator>
2321void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002322vector<bool, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002323{
2324 if (this->__begin_ != 0)
2325 {
2326 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2327 __invalidate_all_iterators();
2328 this->__begin_ = 0;
2329 this->__size_ = this->__cap() = 0;
2330 }
2331}
2332
2333template <class _Allocator>
2334typename vector<bool, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002335vector<bool, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002336{
2337 size_type __amax = __storage_traits::max_size(__alloc());
2338 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2339 if (__nmax / __bits_per_word <= __amax)
2340 return __nmax;
2341 return __internal_cap_to_external(__amax);
2342}
2343
2344// Precondition: __new_size > capacity()
2345template <class _Allocator>
2346_LIBCPP_INLINE_VISIBILITY inline
2347typename vector<bool, _Allocator>::size_type
2348vector<bool, _Allocator>::__recommend(size_type __new_size) const
2349{
2350 const size_type __ms = max_size();
2351 if (__new_size > __ms)
2352 this->__throw_length_error();
2353 const size_type __cap = capacity();
2354 if (__cap >= __ms / 2)
2355 return __ms;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002356 return _VSTD::max(2*__cap, __align(__new_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002357}
2358
2359// Default constructs __n objects starting at __end_
2360// Precondition: __n > 0
2361// Precondition: size() + __n <= capacity()
2362// Postcondition: size() == size() + __n
2363template <class _Allocator>
2364_LIBCPP_INLINE_VISIBILITY inline
2365void
2366vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2367{
2368 size_type __old_size = this->__size_;
2369 this->__size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002370 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002371}
2372
2373template <class _Allocator>
2374template <class _ForwardIterator>
2375typename enable_if
2376<
2377 __is_forward_iterator<_ForwardIterator>::value,
2378 void
2379>::type
2380vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2381{
2382 size_type __old_size = this->__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002383 this->__size_ += _VSTD::distance(__first, __last);
2384 _VSTD::copy(__first, __last, __make_iter(__old_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002385}
2386
2387template <class _Allocator>
2388_LIBCPP_INLINE_VISIBILITY inline
2389vector<bool, _Allocator>::vector()
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002390 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002391 : __begin_(0),
2392 __size_(0),
2393 __cap_alloc_(0)
2394{
2395}
2396
2397template <class _Allocator>
2398_LIBCPP_INLINE_VISIBILITY inline
2399vector<bool, _Allocator>::vector(const allocator_type& __a)
2400 : __begin_(0),
2401 __size_(0),
2402 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2403{
2404}
2405
2406template <class _Allocator>
2407vector<bool, _Allocator>::vector(size_type __n)
2408 : __begin_(0),
2409 __size_(0),
2410 __cap_alloc_(0)
2411{
2412 if (__n > 0)
2413 {
2414 allocate(__n);
2415 __construct_at_end(__n, false);
2416 }
2417}
2418
2419template <class _Allocator>
2420vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2421 : __begin_(0),
2422 __size_(0),
2423 __cap_alloc_(0)
2424{
2425 if (__n > 0)
2426 {
2427 allocate(__n);
2428 __construct_at_end(__n, __x);
2429 }
2430}
2431
2432template <class _Allocator>
2433vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2434 : __begin_(0),
2435 __size_(0),
2436 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2437{
2438 if (__n > 0)
2439 {
2440 allocate(__n);
2441 __construct_at_end(__n, __x);
2442 }
2443}
2444
2445template <class _Allocator>
2446template <class _InputIterator>
2447vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2448 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2449 !__is_forward_iterator<_InputIterator>::value>::type*)
2450 : __begin_(0),
2451 __size_(0),
2452 __cap_alloc_(0)
2453{
2454#ifndef _LIBCPP_NO_EXCEPTIONS
2455 try
2456 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002457#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002458 for (; __first != __last; ++__first)
2459 push_back(*__first);
2460#ifndef _LIBCPP_NO_EXCEPTIONS
2461 }
2462 catch (...)
2463 {
2464 if (__begin_ != 0)
2465 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2466 __invalidate_all_iterators();
2467 throw;
2468 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002469#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002470}
2471
2472template <class _Allocator>
2473template <class _InputIterator>
2474vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2475 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2476 !__is_forward_iterator<_InputIterator>::value>::type*)
2477 : __begin_(0),
2478 __size_(0),
2479 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2480{
2481#ifndef _LIBCPP_NO_EXCEPTIONS
2482 try
2483 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002484#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002485 for (; __first != __last; ++__first)
2486 push_back(*__first);
2487#ifndef _LIBCPP_NO_EXCEPTIONS
2488 }
2489 catch (...)
2490 {
2491 if (__begin_ != 0)
2492 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2493 __invalidate_all_iterators();
2494 throw;
2495 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002496#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002497}
2498
2499template <class _Allocator>
2500template <class _ForwardIterator>
2501vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2502 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2503 : __begin_(0),
2504 __size_(0),
2505 __cap_alloc_(0)
2506{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002507 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002508 if (__n > 0)
2509 {
2510 allocate(__n);
2511 __construct_at_end(__first, __last);
2512 }
2513}
2514
2515template <class _Allocator>
2516template <class _ForwardIterator>
2517vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2518 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2519 : __begin_(0),
2520 __size_(0),
2521 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2522{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002523 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002524 if (__n > 0)
2525 {
2526 allocate(__n);
2527 __construct_at_end(__first, __last);
2528 }
2529}
2530
Howard Hinnante3e32912011-08-12 21:56:02 +00002531#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2532
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002533template <class _Allocator>
2534vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2535 : __begin_(0),
2536 __size_(0),
2537 __cap_alloc_(0)
2538{
2539 size_type __n = static_cast<size_type>(__il.size());
2540 if (__n > 0)
2541 {
2542 allocate(__n);
2543 __construct_at_end(__il.begin(), __il.end());
2544 }
2545}
2546
2547template <class _Allocator>
2548vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2549 : __begin_(0),
2550 __size_(0),
2551 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2552{
2553 size_type __n = static_cast<size_type>(__il.size());
2554 if (__n > 0)
2555 {
2556 allocate(__n);
2557 __construct_at_end(__il.begin(), __il.end());
2558 }
2559}
2560
Howard Hinnante3e32912011-08-12 21:56:02 +00002561#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2562
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002563template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002564vector<bool, _Allocator>::~vector()
2565{
2566 if (__begin_ != 0)
2567 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2568#ifdef _LIBCPP_DEBUG
2569 __invalidate_all_iterators();
2570#endif
2571}
2572
2573template <class _Allocator>
2574vector<bool, _Allocator>::vector(const vector& __v)
2575 : __begin_(0),
2576 __size_(0),
2577 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2578{
2579 if (__v.size() > 0)
2580 {
2581 allocate(__v.size());
2582 __construct_at_end(__v.begin(), __v.end());
2583 }
2584}
2585
2586template <class _Allocator>
2587vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2588 : __begin_(0),
2589 __size_(0),
2590 __cap_alloc_(0, __a)
2591{
2592 if (__v.size() > 0)
2593 {
2594 allocate(__v.size());
2595 __construct_at_end(__v.begin(), __v.end());
2596 }
2597}
2598
2599template <class _Allocator>
2600vector<bool, _Allocator>&
2601vector<bool, _Allocator>::operator=(const vector& __v)
2602{
2603 if (this != &__v)
2604 {
2605 __copy_assign_alloc(__v);
2606 if (__v.__size_)
2607 {
2608 if (__v.__size_ > capacity())
2609 {
2610 deallocate();
2611 allocate(__v.__size_);
2612 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002613 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002614 }
2615 __size_ = __v.__size_;
2616 }
2617 return *this;
2618}
2619
Howard Hinnant73d21a42010-09-04 23:28:19 +00002620#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2621
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002622template <class _Allocator>
2623_LIBCPP_INLINE_VISIBILITY inline
2624vector<bool, _Allocator>::vector(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002625 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002626 : __begin_(__v.__begin_),
2627 __size_(__v.__size_),
2628 __cap_alloc_(__v.__cap_alloc_)
2629{
2630 __v.__begin_ = 0;
2631 __v.__size_ = 0;
2632 __v.__cap() = 0;
2633}
2634
2635template <class _Allocator>
2636vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2637 : __begin_(0),
2638 __size_(0),
2639 __cap_alloc_(0, __a)
2640{
2641 if (__a == allocator_type(__v.__alloc()))
2642 {
2643 this->__begin_ = __v.__begin_;
2644 this->__size_ = __v.__size_;
2645 this->__cap() = __v.__cap();
2646 __v.__begin_ = nullptr;
2647 __v.__cap() = __v.__size_ = 0;
2648 }
2649 else if (__v.size() > 0)
2650 {
2651 allocate(__v.size());
2652 __construct_at_end(__v.begin(), __v.end());
2653 }
2654}
2655
2656template <class _Allocator>
2657_LIBCPP_INLINE_VISIBILITY inline
2658vector<bool, _Allocator>&
2659vector<bool, _Allocator>::operator=(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002660 _NOEXCEPT_(
2661 __alloc_traits::propagate_on_container_move_assignment::value &&
2662 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002663{
2664 __move_assign(__v, integral_constant<bool,
2665 __storage_traits::propagate_on_container_move_assignment::value>());
2666}
2667
2668template <class _Allocator>
2669void
2670vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2671{
2672 if (__alloc() != __c.__alloc())
2673 assign(__c.begin(), __c.end());
2674 else
2675 __move_assign(__c, true_type());
2676}
2677
2678template <class _Allocator>
2679void
2680vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002681 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002682{
2683 deallocate();
2684 this->__begin_ = __c.__begin_;
2685 this->__size_ = __c.__size_;
2686 this->__cap() = __c.__cap();
2687 __move_assign_alloc(__c);
2688 __c.__begin_ = nullptr;
2689 __c.__cap() = __c.__size_ = 0;
2690}
Howard Hinnant73d21a42010-09-04 23:28:19 +00002691
2692#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002693
2694template <class _Allocator>
2695void
2696vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2697{
2698 __size_ = 0;
2699 if (__n > 0)
2700 {
2701 size_type __c = capacity();
2702 if (__n <= __c)
2703 __size_ = __n;
2704 else
2705 {
2706 vector __v(__alloc());
2707 __v.reserve(__recommend(__n));
2708 __v.__size_ = __n;
2709 swap(__v);
2710 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002711 _VSTD::fill_n(begin(), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002712 }
2713}
2714
2715template <class _Allocator>
2716template <class _InputIterator>
2717typename enable_if
2718<
2719 __is_input_iterator<_InputIterator>::value &&
2720 !__is_forward_iterator<_InputIterator>::value,
2721 void
2722>::type
2723vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2724{
2725 clear();
2726 for (; __first != __last; ++__first)
2727 push_back(*__first);
2728}
2729
2730template <class _Allocator>
2731template <class _ForwardIterator>
2732typename enable_if
2733<
2734 __is_forward_iterator<_ForwardIterator>::value,
2735 void
2736>::type
2737vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2738{
2739 clear();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002740 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002741 if (__n)
2742 {
2743 if (__n > capacity())
2744 {
2745 deallocate();
2746 allocate(__n);
2747 }
2748 __construct_at_end(__first, __last);
2749 }
2750}
2751
2752template <class _Allocator>
2753void
2754vector<bool, _Allocator>::reserve(size_type __n)
2755{
2756 if (__n > capacity())
2757 {
2758 vector __v(this->__alloc());
2759 __v.allocate(__n);
2760 __v.__construct_at_end(this->begin(), this->end());
2761 swap(__v);
2762 __invalidate_all_iterators();
2763 }
2764}
2765
2766template <class _Allocator>
2767void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002768vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002769{
2770 if (__external_cap_to_internal(size()) > __cap())
2771 {
2772#ifndef _LIBCPP_NO_EXCEPTIONS
2773 try
2774 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002775#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002776 vector(*this, allocator_type(__alloc())).swap(*this);
2777#ifndef _LIBCPP_NO_EXCEPTIONS
2778 }
2779 catch (...)
2780 {
2781 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002782#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002783 }
2784}
2785
2786template <class _Allocator>
2787typename vector<bool, _Allocator>::reference
2788vector<bool, _Allocator>::at(size_type __n)
2789{
2790 if (__n >= size())
2791 this->__throw_out_of_range();
2792 return (*this)[__n];
2793}
2794
2795template <class _Allocator>
2796typename vector<bool, _Allocator>::const_reference
2797vector<bool, _Allocator>::at(size_type __n) const
2798{
2799 if (__n >= size())
2800 this->__throw_out_of_range();
2801 return (*this)[__n];
2802}
2803
2804template <class _Allocator>
2805void
2806vector<bool, _Allocator>::push_back(const value_type& __x)
2807{
2808 if (this->__size_ == this->capacity())
2809 reserve(__recommend(this->__size_ + 1));
2810 ++this->__size_;
2811 back() = __x;
2812}
2813
2814template <class _Allocator>
2815typename vector<bool, _Allocator>::iterator
2816vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2817{
2818 iterator __r;
2819 if (size() < capacity())
2820 {
2821 const_iterator __old_end = end();
2822 ++__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002823 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002824 __r = __const_iterator_cast(__position);
2825 }
2826 else
2827 {
2828 vector __v(__alloc());
2829 __v.reserve(__recommend(__size_ + 1));
2830 __v.__size_ = __size_ + 1;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002831 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2832 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002833 swap(__v);
2834 }
2835 *__r = __x;
2836 return __r;
2837}
2838
2839template <class _Allocator>
2840typename vector<bool, _Allocator>::iterator
2841vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
2842{
2843 iterator __r;
2844 size_type __c = capacity();
2845 if (__n <= __c && size() <= __c - __n)
2846 {
2847 const_iterator __old_end = end();
2848 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002849 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002850 __r = __const_iterator_cast(__position);
2851 }
2852 else
2853 {
2854 vector __v(__alloc());
2855 __v.reserve(__recommend(__size_ + __n));
2856 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002857 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2858 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002859 swap(__v);
2860 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002861 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002862 return __r;
2863}
2864
2865template <class _Allocator>
2866template <class _InputIterator>
2867typename enable_if
2868<
2869 __is_input_iterator <_InputIterator>::value &&
2870 !__is_forward_iterator<_InputIterator>::value,
2871 typename vector<bool, _Allocator>::iterator
2872>::type
2873vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
2874{
2875 difference_type __off = __position - begin();
2876 iterator __p = __const_iterator_cast(__position);
2877 iterator __old_end = end();
2878 for (; size() != capacity() && __first != __last; ++__first)
2879 {
2880 ++this->__size_;
2881 back() = *__first;
2882 }
2883 vector __v(__alloc());
2884 if (__first != __last)
2885 {
2886#ifndef _LIBCPP_NO_EXCEPTIONS
2887 try
2888 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002889#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002890 __v.assign(__first, __last);
2891 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
2892 difference_type __old_p = __p - begin();
2893 reserve(__recommend(size() + __v.size()));
2894 __p = begin() + __old_p;
2895 __old_end = begin() + __old_size;
2896#ifndef _LIBCPP_NO_EXCEPTIONS
2897 }
2898 catch (...)
2899 {
2900 erase(__old_end, end());
2901 throw;
2902 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002903#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002904 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002905 __p = _VSTD::rotate(__p, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002906 insert(__p, __v.begin(), __v.end());
2907 return begin() + __off;
2908}
2909
2910template <class _Allocator>
2911template <class _ForwardIterator>
2912typename enable_if
2913<
2914 __is_forward_iterator<_ForwardIterator>::value,
2915 typename vector<bool, _Allocator>::iterator
2916>::type
2917vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
2918{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002919 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002920 iterator __r;
2921 size_type __c = capacity();
2922 if (__n <= __c && size() <= __c - __n)
2923 {
2924 const_iterator __old_end = end();
2925 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002926 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002927 __r = __const_iterator_cast(__position);
2928 }
2929 else
2930 {
2931 vector __v(__alloc());
2932 __v.reserve(__recommend(__size_ + __n));
2933 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002934 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2935 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002936 swap(__v);
2937 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002938 _VSTD::copy(__first, __last, __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002939 return __r;
2940}
2941
2942template <class _Allocator>
2943_LIBCPP_INLINE_VISIBILITY inline
2944typename vector<bool, _Allocator>::iterator
2945vector<bool, _Allocator>::erase(const_iterator __position)
2946{
2947 iterator __r = __const_iterator_cast(__position);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002948 _VSTD::copy(__position + 1, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002949 --__size_;
2950 return __r;
2951}
2952
2953template <class _Allocator>
2954typename vector<bool, _Allocator>::iterator
2955vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
2956{
2957 iterator __r = __const_iterator_cast(__first);
2958 difference_type __d = __last - __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002959 _VSTD::copy(__last, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002960 __size_ -= __d;
2961 return __r;
2962}
2963
2964template <class _Allocator>
2965void
2966vector<bool, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002967 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2968 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002969{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002970 _VSTD::swap(this->__begin_, __x.__begin_);
2971 _VSTD::swap(this->__size_, __x.__size_);
2972 _VSTD::swap(this->__cap(), __x.__cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002973 __swap_alloc(this->__alloc(), __x.__alloc());
2974#ifdef _LIBCPP_DEBUG
2975 iterator::swap(this, &__x);
2976 const_iterator::swap(this, &__x);
Howard Hinnant324bb032010-08-22 00:02:43 +00002977#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002978}
2979
Howard Hinnant324bb032010-08-22 00:02:43 +00002980template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002981void
2982vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
2983{
2984 size_type __cs = size();
2985 if (__cs < __sz)
2986 {
2987 iterator __r;
2988 size_type __c = capacity();
2989 size_type __n = __sz - __cs;
2990 if (__n <= __c && __cs <= __c - __n)
2991 {
2992 __r = end();
2993 __size_ += __n;
2994 }
2995 else
2996 {
2997 vector __v(__alloc());
2998 __v.reserve(__recommend(__size_ + __n));
2999 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003000 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003001 swap(__v);
3002 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003003 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003004 }
3005 else
3006 __size_ = __sz;
3007}
3008
Howard Hinnant324bb032010-08-22 00:02:43 +00003009template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003010void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003011vector<bool, _Allocator>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003012{
3013 // do middle whole words
3014 size_type __n = __size_;
3015 __storage_pointer __p = __begin_;
3016 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3017 *__p = ~*__p;
3018 // do last partial word
3019 if (__n > 0)
3020 {
3021 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3022 __storage_type __b = *__p & __m;
3023 *__p &= ~__m;
3024 *__p |= ~__b & __m;
3025 }
3026}
3027
Howard Hinnant324bb032010-08-22 00:02:43 +00003028template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003029bool
3030vector<bool, _Allocator>::__invariants() const
3031{
3032 if (this->__begin_ == 0)
3033 {
3034 if (this->__size_ != 0 || this->__cap() != 0)
3035 return false;
3036 }
3037 else
3038 {
3039 if (this->__cap() == 0)
3040 return false;
3041 if (this->__size_ > this->capacity())
3042 return false;
3043 }
3044 return true;
3045}
3046
Howard Hinnant324bb032010-08-22 00:02:43 +00003047template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003048size_t
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003049vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003050{
3051 size_t __h = 0;
3052 // do middle whole words
3053 size_type __n = __size_;
3054 __storage_pointer __p = __begin_;
3055 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3056 __h ^= *__p;
3057 // do last partial word
3058 if (__n > 0)
3059 {
3060 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3061 __h ^= *__p & __m;
3062 }
3063 return __h;
3064}
3065
3066template <class _Allocator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003067struct _LIBCPP_VISIBLE hash<vector<bool, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003068 : public unary_function<vector<bool, _Allocator>, size_t>
3069{
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003070 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003071 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003072 {return __vec.__hash_code();}
3073};
3074
3075template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003076_LIBCPP_INLINE_VISIBILITY inline
3077bool
3078operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3079{
3080 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003081 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003082}
3083
3084template <class _Tp, class _Allocator>
3085_LIBCPP_INLINE_VISIBILITY inline
3086bool
3087operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3088{
3089 return !(__x == __y);
3090}
3091
3092template <class _Tp, class _Allocator>
3093_LIBCPP_INLINE_VISIBILITY inline
3094bool
3095operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3096{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003097 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003098}
3099
3100template <class _Tp, class _Allocator>
3101_LIBCPP_INLINE_VISIBILITY inline
3102bool
3103operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3104{
3105 return __y < __x;
3106}
3107
3108template <class _Tp, class _Allocator>
3109_LIBCPP_INLINE_VISIBILITY inline
3110bool
3111operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3112{
3113 return !(__x < __y);
3114}
3115
3116template <class _Tp, class _Allocator>
3117_LIBCPP_INLINE_VISIBILITY inline
3118bool
3119operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3120{
3121 return !(__y < __x);
3122}
3123
3124template <class _Tp, class _Allocator>
3125_LIBCPP_INLINE_VISIBILITY inline
3126void
3127swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003128 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003129{
3130 __x.swap(__y);
3131}
3132
3133_LIBCPP_END_NAMESPACE_STD
3134
3135#endif // _LIBCPP_VECTOR