blob: 5f47180c4f4094568ebb45d3bd0be76f6233c213 [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
Howard Hinnant08e17472011-10-17 20:05:10 +0000273#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000274#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000275#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
277_LIBCPP_BEGIN_NAMESPACE_STD
278
279template <bool>
280class __vector_base_common
281{
282protected:
283 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
284 void __throw_length_error() const;
285 void __throw_out_of_range() const;
286};
287
288template <bool __b>
289void
290__vector_base_common<__b>::__throw_length_error() const
291{
292#ifndef _LIBCPP_NO_EXCEPTIONS
293 throw length_error("vector");
294#else
295 assert(!"vector length_error");
296#endif
297}
298
299template <bool __b>
300void
301__vector_base_common<__b>::__throw_out_of_range() const
302{
303#ifndef _LIBCPP_NO_EXCEPTIONS
304 throw out_of_range("vector");
305#else
306 assert(!"vector out_of_range");
307#endif
308}
309
310extern template class __vector_base_common<true>;
311
312template <class _Tp, class _Allocator>
313class __vector_base
314 : protected __vector_base_common<true>
315{
316protected:
Howard Hinnant324bb032010-08-22 00:02:43 +0000317 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000318 typedef _Allocator allocator_type;
319 typedef allocator_traits<allocator_type> __alloc_traits;
320 typedef value_type& reference;
321 typedef const value_type& const_reference;
322 typedef typename __alloc_traits::size_type size_type;
323 typedef typename __alloc_traits::difference_type difference_type;
324 typedef typename __alloc_traits::pointer pointer;
325 typedef typename __alloc_traits::const_pointer const_pointer;
326 typedef pointer iterator;
327 typedef const_pointer const_iterator;
328
329 pointer __begin_;
330 pointer __end_;
331 __compressed_pair<pointer, allocator_type> __end_cap_;
332
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000333 _LIBCPP_INLINE_VISIBILITY
334 allocator_type& __alloc() _NOEXCEPT
335 {return __end_cap_.second();}
336 _LIBCPP_INLINE_VISIBILITY
337 const allocator_type& __alloc() const _NOEXCEPT
338 {return __end_cap_.second();}
339 _LIBCPP_INLINE_VISIBILITY
340 pointer& __end_cap() _NOEXCEPT
341 {return __end_cap_.first();}
342 _LIBCPP_INLINE_VISIBILITY
343 const pointer& __end_cap() const _NOEXCEPT
344 {return __end_cap_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000346 _LIBCPP_INLINE_VISIBILITY
347 __vector_base()
348 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000349 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350 ~__vector_base();
351
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000352 _LIBCPP_INLINE_VISIBILITY
353 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
354 _LIBCPP_INLINE_VISIBILITY
355 size_type capacity() const _NOEXCEPT
356 {return static_cast<size_type>(__end_cap() - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000358 _LIBCPP_INLINE_VISIBILITY
359 void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +0000360 {__destruct_at_end(__new_last, is_trivially_destructible<value_type>());}
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000361 _LIBCPP_INLINE_VISIBILITY
362 void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT;
363 _LIBCPP_INLINE_VISIBILITY
364 void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367 void __copy_assign_alloc(const __vector_base& __c)
368 {__copy_assign_alloc(__c, integral_constant<bool,
369 __alloc_traits::propagate_on_container_copy_assignment::value>());}
370
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000371 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372 void __move_assign_alloc(__vector_base& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000373 _NOEXCEPT_(
374 !__alloc_traits::propagate_on_container_move_assignment::value ||
375 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376 {__move_assign_alloc(__c, integral_constant<bool,
377 __alloc_traits::propagate_on_container_move_assignment::value>());}
378
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000380 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000381 _NOEXCEPT_(
382 !__alloc_traits::propagate_on_container_swap::value ||
383 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384 {__swap_alloc(__x, __y, integral_constant<bool,
385 __alloc_traits::propagate_on_container_swap::value>());}
386private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000387 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388 void __copy_assign_alloc(const __vector_base& __c, true_type)
389 {
390 if (__alloc() != __c.__alloc())
391 {
392 clear();
393 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
394 __begin_ = __end_ = __end_cap() = nullptr;
395 }
396 __alloc() = __c.__alloc();
397 }
398
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400 void __copy_assign_alloc(const __vector_base& __c, false_type)
401 {}
402
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000404 void __move_assign_alloc(__vector_base& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000405 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000406 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000407 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408 }
409
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000411 void __move_assign_alloc(__vector_base& __c, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000412 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413 {}
414
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000417 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000419 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 swap(__x, __y);
421 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423 static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000424 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000425 {}
426};
427
428template <class _Tp, class _Allocator>
429_LIBCPP_INLINE_VISIBILITY inline
430void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000431__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432{
433 while (__new_last < __end_)
434 __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_));
435}
436
437template <class _Tp, class _Allocator>
438_LIBCPP_INLINE_VISIBILITY inline
439void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000440__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441{
442 __end_ = const_cast<pointer>(__new_last);
443}
444
445template <class _Tp, class _Allocator>
446_LIBCPP_INLINE_VISIBILITY inline
447__vector_base<_Tp, _Allocator>::__vector_base()
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000448 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449 : __begin_(0),
450 __end_(0),
451 __end_cap_(0)
452{
453}
454
455template <class _Tp, class _Allocator>
456_LIBCPP_INLINE_VISIBILITY inline
457__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
458 : __begin_(0),
459 __end_(0),
460 __end_cap_(0, __a)
461{
462}
463
464template <class _Tp, class _Allocator>
465__vector_base<_Tp, _Allocator>::~__vector_base()
466{
467 if (__begin_ != 0)
468 {
469 clear();
470 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
471 }
472}
473
474template <class _Tp, class _Allocator = allocator<_Tp> >
Howard Hinnant36cdf022010-09-10 16:42:26 +0000475class _LIBCPP_VISIBLE vector
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476 : private __vector_base<_Tp, _Allocator>
477{
478private:
479 typedef __vector_base<_Tp, _Allocator> __base;
Howard Hinnant324bb032010-08-22 00:02:43 +0000480public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000481 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +0000482 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483 typedef _Allocator allocator_type;
484 typedef typename __base::__alloc_traits __alloc_traits;
485 typedef typename __base::reference reference;
486 typedef typename __base::const_reference const_reference;
487 typedef typename __base::size_type size_type;
488 typedef typename __base::difference_type difference_type;
489 typedef typename __base::pointer pointer;
490 typedef typename __base::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491 typedef __wrap_iter<pointer> iterator;
492 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000493 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
494 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000496 _LIBCPP_INLINE_VISIBILITY
497 vector()
498 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant7a563db2011-09-14 18:33:51 +0000499 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000500#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000501 __get_db()->__insert_c(this);
502#endif
503 }
504 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
505 : __base(__a)
506 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000507#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000508 __get_db()->__insert_c(this);
509#endif
510 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511 explicit vector(size_type __n);
512 vector(size_type __n, const_reference __x);
513 vector(size_type __n, const_reference __x, const allocator_type& __a);
514 template <class _InputIterator>
515 vector(_InputIterator __first, _InputIterator __last,
516 typename enable_if<__is_input_iterator <_InputIterator>::value &&
517 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
518 template <class _InputIterator>
519 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
520 typename enable_if<__is_input_iterator <_InputIterator>::value &&
521 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
522 template <class _ForwardIterator>
523 vector(_ForwardIterator __first, _ForwardIterator __last,
524 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
525 template <class _ForwardIterator>
526 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
527 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02 +0000528#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
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);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000533#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantabe26282011-09-16 17:29:17 +0000534#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a563db2011-09-14 18:33:51 +0000536 ~vector()
537 {
538 __get_db()->__erase_c(this);
539 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540#endif
541
542 vector(const vector& __x);
543 vector(const vector& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545 vector& operator=(const vector& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000546#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000548 vector(vector&& __x)
549 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551 vector(vector&& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000553 vector& operator=(vector&& __x)
554 _NOEXCEPT_(
555 __alloc_traits::propagate_on_container_move_assignment::value &&
556 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000557#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000558#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560 vector& operator=(initializer_list<value_type> __il)
561 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000562#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000563
564 template <class _InputIterator>
565 typename enable_if
566 <
567 __is_input_iterator <_InputIterator>::value &&
568 !__is_forward_iterator<_InputIterator>::value,
569 void
570 >::type
571 assign(_InputIterator __first, _InputIterator __last);
572 template <class _ForwardIterator>
573 typename enable_if
574 <
575 __is_forward_iterator<_ForwardIterator>::value,
576 void
577 >::type
578 assign(_ForwardIterator __first, _ForwardIterator __last);
579
580 void assign(size_type __n, const_reference __u);
Howard Hinnante3e32912011-08-12 21:56:02 +0000581#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000583 void assign(initializer_list<value_type> __il)
584 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000585#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000587 _LIBCPP_INLINE_VISIBILITY
588 allocator_type get_allocator() const _NOEXCEPT
589 {return this->__alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000591 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
592 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
593 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
594 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000596 _LIBCPP_INLINE_VISIBILITY
597 reverse_iterator rbegin() _NOEXCEPT
598 {return reverse_iterator(end());}
599 _LIBCPP_INLINE_VISIBILITY
600 const_reverse_iterator rbegin() const _NOEXCEPT
601 {return const_reverse_iterator(end());}
602 _LIBCPP_INLINE_VISIBILITY
603 reverse_iterator rend() _NOEXCEPT
604 {return reverse_iterator(begin());}
605 _LIBCPP_INLINE_VISIBILITY
606 const_reverse_iterator rend() const _NOEXCEPT
607 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000609 _LIBCPP_INLINE_VISIBILITY
610 const_iterator cbegin() const _NOEXCEPT
611 {return begin();}
612 _LIBCPP_INLINE_VISIBILITY
613 const_iterator cend() const _NOEXCEPT
614 {return end();}
615 _LIBCPP_INLINE_VISIBILITY
616 const_reverse_iterator crbegin() const _NOEXCEPT
617 {return rbegin();}
618 _LIBCPP_INLINE_VISIBILITY
619 const_reverse_iterator crend() const _NOEXCEPT
620 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000622 _LIBCPP_INLINE_VISIBILITY
623 size_type size() const _NOEXCEPT
624 {return static_cast<size_type>(this->__end_ - this->__begin_);}
625 _LIBCPP_INLINE_VISIBILITY
626 size_type capacity() const _NOEXCEPT
627 {return __base::capacity();}
628 _LIBCPP_INLINE_VISIBILITY
629 bool empty() const _NOEXCEPT
630 {return this->__begin_ == this->__end_;}
631 size_type max_size() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000633 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634
635 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
636 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
637 reference at(size_type __n);
638 const_reference at(size_type __n) const;
639
Howard Hinnant7a563db2011-09-14 18:33:51 +0000640 _LIBCPP_INLINE_VISIBILITY reference front()
641 {
642 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
643 return *this->__begin_;
644 }
645 _LIBCPP_INLINE_VISIBILITY const_reference front() const
646 {
647 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
648 return *this->__begin_;
649 }
650 _LIBCPP_INLINE_VISIBILITY reference back()
651 {
652 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
653 return *(this->__end_ - 1);
654 }
655 _LIBCPP_INLINE_VISIBILITY const_reference back() const
656 {
657 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
658 return *(this->__end_ - 1);
659 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000661 _LIBCPP_INLINE_VISIBILITY
662 value_type* data() _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000663 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000664 _LIBCPP_INLINE_VISIBILITY
665 const value_type* data() const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000666 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000668 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000669#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000671#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000672 template <class... _Args>
673 void emplace_back(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000674#endif // _LIBCPP_HAS_NO_VARIADICS
675#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676 void pop_back();
677
678 iterator insert(const_iterator __position, const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000679#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680 iterator insert(const_iterator __position, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000681#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000682 template <class... _Args>
683 iterator emplace(const_iterator __position, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000684#endif // _LIBCPP_HAS_NO_VARIADICS
685#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686 iterator insert(const_iterator __position, size_type __n, const_reference __x);
687 template <class _InputIterator>
688 typename enable_if
689 <
690 __is_input_iterator <_InputIterator>::value &&
691 !__is_forward_iterator<_InputIterator>::value,
692 iterator
693 >::type
694 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
695 template <class _ForwardIterator>
696 typename enable_if
697 <
698 __is_forward_iterator<_ForwardIterator>::value,
699 iterator
700 >::type
701 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000702#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 iterator insert(const_iterator __position, initializer_list<value_type> __il)
705 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000706#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000708 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000709 iterator erase(const_iterator __first, const_iterator __last);
710
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000711 _LIBCPP_INLINE_VISIBILITY
712 void clear() _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +0000713 {
714 __base::clear();
715 __invalidate_all_iterators();
716 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717
718 void resize(size_type __sz);
719 void resize(size_type __sz, const_reference __x);
720
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000721 void swap(vector&)
722 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
723 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724
725 bool __invariants() const;
726
Howard Hinnantabe26282011-09-16 17:29:17 +0000727#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000728
729 bool __dereferenceable(const const_iterator* __i) const;
730 bool __decrementable(const const_iterator* __i) const;
731 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
732 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
733
Howard Hinnantabe26282011-09-16 17:29:17 +0000734#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000735
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000737 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000739 void deallocate() _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000740 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
Howard Hinnant04240d92011-01-04 19:53:31 +0000741 void __construct_at_end(size_type __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742 void __construct_at_end(size_type __n, const_reference __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743 template <class _ForwardIterator>
744 typename enable_if
745 <
746 __is_forward_iterator<_ForwardIterator>::value,
747 void
748 >::type
749 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
750 void __move_construct_at_end(pointer __first, pointer __last);
751 void __append(size_type __n);
752 void __append(size_type __n, const_reference __x);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000754 iterator __make_iter(pointer __p) _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000756 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000757 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
758 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
759 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000760 void __move_assign(vector& __c, true_type)
761 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762 void __move_assign(vector& __c, false_type);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000763 _LIBCPP_INLINE_VISIBILITY
764 void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
765 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000766#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000767 __c_node* __c = __get_db()->__find_c_and_lock(this);
768 for (__i_node** __p = __c->end_; __p != __c->beg_; )
769 {
770 --__p;
771 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
772 if (__i->base() > __new_last)
773 {
774 (*__p)->__c_ = nullptr;
775 if (--__c->end_ != __p)
776 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
777 }
778 }
779 __get_db()->unlock();
780#endif
781 __base::__destruct_at_end(__new_last);
782 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000783};
784
785template <class _Tp, class _Allocator>
786void
787vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
788{
789 for (pointer __p = this->__end_; this->__begin_ < __p;)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000790 __v.push_front(_VSTD::move_if_noexcept(*--__p));
791 _VSTD::swap(this->__begin_, __v.__begin_);
792 _VSTD::swap(this->__end_, __v.__end_);
793 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794 __v.__first_ = __v.__begin_;
795 __invalidate_all_iterators();
796}
797
798template <class _Tp, class _Allocator>
799typename vector<_Tp, _Allocator>::pointer
800vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
801{
802 pointer __r = __v.__begin_;
803 for (pointer __i = __p; this->__begin_ < __i;)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000804 __v.push_front(_VSTD::move_if_noexcept(*--__i));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000805 for (pointer __i = __p; __i < this->__end_; ++__i)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000806 __v.push_back(_VSTD::move_if_noexcept(*__i));
807 _VSTD::swap(this->__begin_, __v.__begin_);
808 _VSTD::swap(this->__end_, __v.__end_);
809 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000810 __v.__first_ = __v.__begin_;
811 __invalidate_all_iterators();
812 return __r;
813}
814
815// Allocate space for __n objects
816// throws length_error if __n > max_size()
817// throws (probably bad_alloc) if memory run out
818// Precondition: __begin_ == __end_ == __end_cap() == 0
819// Precondition: __n > 0
820// Postcondition: capacity() == __n
821// Postcondition: size() == 0
822template <class _Tp, class _Allocator>
823void
824vector<_Tp, _Allocator>::allocate(size_type __n)
825{
826 if (__n > max_size())
827 this->__throw_length_error();
828 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
829 this->__end_cap() = this->__begin_ + __n;
830}
831
832template <class _Tp, class _Allocator>
833void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000834vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835{
836 if (this->__begin_ != 0)
837 {
838 clear();
839 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840 this->__begin_ = this->__end_ = this->__end_cap() = 0;
841 }
842}
843
844template <class _Tp, class _Allocator>
845typename vector<_Tp, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000846vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847{
Sean Hunt110b8bf2011-07-29 23:31:58 +0000848 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 +0000849}
850
851// Precondition: __new_size > capacity()
852template <class _Tp, class _Allocator>
853_LIBCPP_INLINE_VISIBILITY inline
854typename vector<_Tp, _Allocator>::size_type
855vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
856{
857 const size_type __ms = max_size();
858 if (__new_size > __ms)
859 this->__throw_length_error();
860 const size_type __cap = capacity();
861 if (__cap >= __ms / 2)
862 return __ms;
Sean Hunt110b8bf2011-07-29 23:31:58 +0000863 return _VSTD::max<size_type>(2*__cap, __new_size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864}
865
866// Default constructs __n objects starting at __end_
867// throws if construction throws
868// Precondition: __n > 0
869// Precondition: size() + __n <= capacity()
870// Postcondition: size() == size() + __n
871template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000872void
873vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
874{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875 allocator_type& __a = this->__alloc();
876 do
877 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000878 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879 ++this->__end_;
880 --__n;
881 } while (__n > 0);
882}
883
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000884// Copy constructs __n objects starting at __end_ from __x
885// throws if construction throws
886// Precondition: __n > 0
887// Precondition: size() + __n <= capacity()
888// Postcondition: size() == old size() + __n
889// Postcondition: [i] == __x for all i in [size() - __n, __n)
890template <class _Tp, class _Allocator>
891_LIBCPP_INLINE_VISIBILITY inline
892void
893vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
894{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895 allocator_type& __a = this->__alloc();
896 do
897 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000898 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 ++this->__end_;
900 --__n;
901 } while (__n > 0);
902}
903
904template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905template <class _ForwardIterator>
906typename enable_if
907<
908 __is_forward_iterator<_ForwardIterator>::value,
909 void
910>::type
911vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
912{
913 allocator_type& __a = this->__alloc();
914 for (; __first != __last; ++__first)
915 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000916 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000917 ++this->__end_;
918 }
919}
920
921template <class _Tp, class _Allocator>
922void
923vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
924{
925 allocator_type& __a = this->__alloc();
926 for (; __first != __last; ++__first)
927 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000928 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
929 _VSTD::move(*__first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000930 ++this->__end_;
931 }
932}
933
934// Default constructs __n objects starting at __end_
935// throws if construction throws
936// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000937// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938template <class _Tp, class _Allocator>
939void
940vector<_Tp, _Allocator>::__append(size_type __n)
941{
942 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
943 this->__construct_at_end(__n);
944 else
945 {
946 allocator_type& __a = this->__alloc();
947 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
948 __v.__construct_at_end(__n);
949 __swap_out_circular_buffer(__v);
950 }
951}
952
953// Default constructs __n objects starting at __end_
954// throws if construction throws
955// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000956// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000957template <class _Tp, class _Allocator>
958void
959vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
960{
961 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
962 this->__construct_at_end(__n, __x);
963 else
964 {
965 allocator_type& __a = this->__alloc();
966 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
967 __v.__construct_at_end(__n, __x);
968 __swap_out_circular_buffer(__v);
969 }
970}
971
972template <class _Tp, class _Allocator>
973vector<_Tp, _Allocator>::vector(size_type __n)
974{
Howard Hinnant0442b122011-09-16 18:41:29 +0000975#if _LIBCPP_DEBUG_LEVEL >= 2
976 __get_db()->__insert_c(this);
977#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978 if (__n > 0)
979 {
980 allocate(__n);
981 __construct_at_end(__n);
982 }
983}
984
985template <class _Tp, class _Allocator>
986vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
987{
Howard Hinnant0442b122011-09-16 18:41:29 +0000988#if _LIBCPP_DEBUG_LEVEL >= 2
989 __get_db()->__insert_c(this);
990#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991 if (__n > 0)
992 {
993 allocate(__n);
994 __construct_at_end(__n, __x);
995 }
996}
997
998template <class _Tp, class _Allocator>
999vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1000 : __base(__a)
1001{
Howard Hinnant0442b122011-09-16 18:41:29 +00001002#if _LIBCPP_DEBUG_LEVEL >= 2
1003 __get_db()->__insert_c(this);
1004#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005 if (__n > 0)
1006 {
1007 allocate(__n);
1008 __construct_at_end(__n, __x);
1009 }
1010}
1011
1012template <class _Tp, class _Allocator>
1013template <class _InputIterator>
1014vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
1015 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1016 !__is_forward_iterator<_InputIterator>::value>::type*)
1017{
Howard Hinnantabe26282011-09-16 17:29:17 +00001018#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001019 __get_db()->__insert_c(this);
1020#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001021 for (; __first != __last; ++__first)
1022 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001023}
1024
1025template <class _Tp, class _Allocator>
1026template <class _InputIterator>
1027vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1028 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1029 !__is_forward_iterator<_InputIterator>::value>::type*)
1030 : __base(__a)
1031{
Howard Hinnantabe26282011-09-16 17:29:17 +00001032#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001033 __get_db()->__insert_c(this);
1034#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001035 for (; __first != __last; ++__first)
1036 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001037}
1038
1039template <class _Tp, class _Allocator>
1040template <class _ForwardIterator>
1041vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
1042 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1043{
Howard Hinnant0442b122011-09-16 18:41:29 +00001044#if _LIBCPP_DEBUG_LEVEL >= 2
1045 __get_db()->__insert_c(this);
1046#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001047 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001048 if (__n > 0)
1049 {
1050 allocate(__n);
1051 __construct_at_end(__first, __last);
1052 }
1053}
1054
1055template <class _Tp, class _Allocator>
1056template <class _ForwardIterator>
1057vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1058 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1059 : __base(__a)
1060{
Howard Hinnant0442b122011-09-16 18:41:29 +00001061#if _LIBCPP_DEBUG_LEVEL >= 2
1062 __get_db()->__insert_c(this);
1063#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001064 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065 if (__n > 0)
1066 {
1067 allocate(__n);
1068 __construct_at_end(__first, __last);
1069 }
1070}
1071
1072template <class _Tp, class _Allocator>
1073vector<_Tp, _Allocator>::vector(const vector& __x)
1074 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1075{
Howard Hinnant0442b122011-09-16 18:41:29 +00001076#if _LIBCPP_DEBUG_LEVEL >= 2
1077 __get_db()->__insert_c(this);
1078#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079 size_type __n = __x.size();
1080 if (__n > 0)
1081 {
1082 allocate(__n);
1083 __construct_at_end(__x.__begin_, __x.__end_);
1084 }
1085}
1086
1087template <class _Tp, class _Allocator>
1088vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1089 : __base(__a)
1090{
Howard Hinnant0442b122011-09-16 18:41:29 +00001091#if _LIBCPP_DEBUG_LEVEL >= 2
1092 __get_db()->__insert_c(this);
1093#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094 size_type __n = __x.size();
1095 if (__n > 0)
1096 {
1097 allocate(__n);
1098 __construct_at_end(__x.__begin_, __x.__end_);
1099 }
1100}
1101
Howard Hinnant73d21a42010-09-04 23:28:19 +00001102#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001103
1104template <class _Tp, class _Allocator>
1105_LIBCPP_INLINE_VISIBILITY inline
1106vector<_Tp, _Allocator>::vector(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001107 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001108 : __base(_VSTD::move(__x.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109{
Howard Hinnantabe26282011-09-16 17:29:17 +00001110#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001111 __get_db()->__insert_c(this);
Howard Hinnante6125bd2011-09-19 16:34:29 +00001112 __get_db()->swap(this, &__x);
Howard Hinnant7a563db2011-09-14 18:33:51 +00001113#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001114 this->__begin_ = __x.__begin_;
1115 this->__end_ = __x.__end_;
1116 this->__end_cap() = __x.__end_cap();
1117 __x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118}
1119
1120template <class _Tp, class _Allocator>
1121_LIBCPP_INLINE_VISIBILITY inline
1122vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1123 : __base(__a)
1124{
Howard Hinnant0442b122011-09-16 18:41:29 +00001125#if _LIBCPP_DEBUG_LEVEL >= 2
1126 __get_db()->__insert_c(this);
1127#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001128 if (__a == __x.__alloc())
1129 {
1130 this->__begin_ = __x.__begin_;
1131 this->__end_ = __x.__end_;
1132 this->__end_cap() = __x.__end_cap();
1133 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001134#if _LIBCPP_DEBUG_LEVEL >= 2
1135 __get_db()->swap(this, &__x);
1136#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001137 }
1138 else
1139 {
1140 typedef move_iterator<iterator> _I;
1141 assign(_I(__x.begin()), _I(__x.end()));
1142 }
1143}
1144
Howard Hinnante3e32912011-08-12 21:56:02 +00001145#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1146
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147template <class _Tp, class _Allocator>
1148_LIBCPP_INLINE_VISIBILITY inline
1149vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1150{
Howard Hinnant0442b122011-09-16 18:41:29 +00001151#if _LIBCPP_DEBUG_LEVEL >= 2
1152 __get_db()->__insert_c(this);
1153#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154 if (__il.size() > 0)
1155 {
1156 allocate(__il.size());
1157 __construct_at_end(__il.begin(), __il.end());
1158 }
1159}
1160
1161template <class _Tp, class _Allocator>
1162_LIBCPP_INLINE_VISIBILITY inline
1163vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1164 : __base(__a)
1165{
Howard Hinnant0442b122011-09-16 18:41:29 +00001166#if _LIBCPP_DEBUG_LEVEL >= 2
1167 __get_db()->__insert_c(this);
1168#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169 if (__il.size() > 0)
1170 {
1171 allocate(__il.size());
1172 __construct_at_end(__il.begin(), __il.end());
1173 }
1174}
1175
Howard Hinnante3e32912011-08-12 21:56:02 +00001176#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1177
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001178template <class _Tp, class _Allocator>
1179_LIBCPP_INLINE_VISIBILITY inline
1180vector<_Tp, _Allocator>&
1181vector<_Tp, _Allocator>::operator=(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001182 _NOEXCEPT_(
1183 __alloc_traits::propagate_on_container_move_assignment::value &&
1184 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001185{
1186 __move_assign(__x, integral_constant<bool,
1187 __alloc_traits::propagate_on_container_move_assignment::value>());
1188 return *this;
1189}
1190
1191template <class _Tp, class _Allocator>
1192void
1193vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1194{
1195 if (__base::__alloc() != __c.__alloc())
1196 {
1197 typedef move_iterator<iterator> _I;
1198 assign(_I(__c.begin()), _I(__c.end()));
1199 }
1200 else
1201 __move_assign(__c, true_type());
1202}
1203
1204template <class _Tp, class _Allocator>
1205void
1206vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001207 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001208{
1209 deallocate();
1210 this->__begin_ = __c.__begin_;
1211 this->__end_ = __c.__end_;
1212 this->__end_cap() = __c.__end_cap();
1213 __base::__move_assign_alloc(__c);
1214 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001215#if _LIBCPP_DEBUG_LEVEL >= 2
1216 __get_db()->swap(this, &__c);
1217#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218}
1219
Howard Hinnant73d21a42010-09-04 23:28:19 +00001220#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001221
1222template <class _Tp, class _Allocator>
1223_LIBCPP_INLINE_VISIBILITY inline
1224vector<_Tp, _Allocator>&
1225vector<_Tp, _Allocator>::operator=(const vector& __x)
1226{
1227 if (this != &__x)
1228 {
1229 __base::__copy_assign_alloc(__x);
1230 assign(__x.__begin_, __x.__end_);
1231 }
1232 return *this;
1233}
1234
1235template <class _Tp, class _Allocator>
1236template <class _InputIterator>
1237typename enable_if
1238<
1239 __is_input_iterator <_InputIterator>::value &&
1240 !__is_forward_iterator<_InputIterator>::value,
1241 void
1242>::type
1243vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1244{
1245 clear();
1246 for (; __first != __last; ++__first)
1247 push_back(*__first);
1248}
1249
1250template <class _Tp, class _Allocator>
1251template <class _ForwardIterator>
1252typename enable_if
1253<
1254 __is_forward_iterator<_ForwardIterator>::value,
1255 void
1256>::type
1257vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1258{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001259 typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260 if (static_cast<size_type>(__new_size) <= capacity())
1261 {
1262 _ForwardIterator __mid = __last;
1263 bool __growing = false;
1264 if (static_cast<size_type>(__new_size) > size())
1265 {
1266 __growing = true;
1267 __mid = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001268 _VSTD::advance(__mid, size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001270 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001271 if (__growing)
1272 __construct_at_end(__mid, __last);
1273 else
1274 this->__destruct_at_end(__m);
1275 }
1276 else
1277 {
1278 deallocate();
1279 allocate(__recommend(static_cast<size_type>(__new_size)));
1280 __construct_at_end(__first, __last);
1281 }
1282}
1283
1284template <class _Tp, class _Allocator>
1285void
1286vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1287{
1288 if (__n <= capacity())
1289 {
1290 size_type __s = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001291 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001292 if (__n > __s)
1293 __construct_at_end(__n - __s, __u);
1294 else
Howard Hinnantadff4892010-05-24 17:49:41 +00001295 this->__destruct_at_end(this->__begin_ + __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001296 }
1297 else
1298 {
1299 deallocate();
1300 allocate(__recommend(static_cast<size_type>(__n)));
1301 __construct_at_end(__n, __u);
1302 }
1303}
1304
Howard Hinnant324bb032010-08-22 00:02:43 +00001305template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001306_LIBCPP_INLINE_VISIBILITY inline
1307typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001308vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309{
Howard Hinnantabe26282011-09-16 17:29:17 +00001310#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001311 return iterator(this, __p);
1312#else
1313 return iterator(__p);
1314#endif
1315}
1316
Howard Hinnant324bb032010-08-22 00:02:43 +00001317template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318_LIBCPP_INLINE_VISIBILITY inline
1319typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001320vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001321{
Howard Hinnantabe26282011-09-16 17:29:17 +00001322#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323 return const_iterator(this, __p);
1324#else
1325 return const_iterator(__p);
1326#endif
1327}
1328
Howard Hinnant324bb032010-08-22 00:02:43 +00001329template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001330_LIBCPP_INLINE_VISIBILITY inline
1331typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001332vector<_Tp, _Allocator>::begin() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001333{
1334 return __make_iter(this->__begin_);
1335}
1336
Howard Hinnant324bb032010-08-22 00:02:43 +00001337template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338_LIBCPP_INLINE_VISIBILITY inline
1339typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001340vector<_Tp, _Allocator>::begin() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001341{
1342 return __make_iter(this->__begin_);
1343}
1344
Howard Hinnant324bb032010-08-22 00:02:43 +00001345template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001346_LIBCPP_INLINE_VISIBILITY inline
1347typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001348vector<_Tp, _Allocator>::end() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349{
1350 return __make_iter(this->__end_);
1351}
1352
Howard Hinnant324bb032010-08-22 00:02:43 +00001353template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001354_LIBCPP_INLINE_VISIBILITY inline
1355typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001356vector<_Tp, _Allocator>::end() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001357{
1358 return __make_iter(this->__end_);
1359}
1360
Howard Hinnant324bb032010-08-22 00:02:43 +00001361template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001362_LIBCPP_INLINE_VISIBILITY inline
1363typename vector<_Tp, _Allocator>::reference
1364vector<_Tp, _Allocator>::operator[](size_type __n)
1365{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001366 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367 return this->__begin_[__n];
1368}
1369
Howard Hinnant324bb032010-08-22 00:02:43 +00001370template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001371_LIBCPP_INLINE_VISIBILITY inline
1372typename vector<_Tp, _Allocator>::const_reference
1373vector<_Tp, _Allocator>::operator[](size_type __n) const
1374{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001375 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376 return this->__begin_[__n];
1377}
1378
Howard Hinnant324bb032010-08-22 00:02:43 +00001379template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380typename vector<_Tp, _Allocator>::reference
1381vector<_Tp, _Allocator>::at(size_type __n)
1382{
1383 if (__n >= size())
1384 this->__throw_out_of_range();
1385 return this->__begin_[__n];
1386}
1387
Howard Hinnant324bb032010-08-22 00:02:43 +00001388template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001389typename vector<_Tp, _Allocator>::const_reference
1390vector<_Tp, _Allocator>::at(size_type __n) const
1391{
1392 if (__n >= size())
1393 this->__throw_out_of_range();
1394 return this->__begin_[__n];
1395}
1396
1397template <class _Tp, class _Allocator>
1398void
1399vector<_Tp, _Allocator>::reserve(size_type __n)
1400{
1401 if (__n > capacity())
1402 {
1403 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001404 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001405 __swap_out_circular_buffer(__v);
1406 }
1407}
1408
1409template <class _Tp, class _Allocator>
1410void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001411vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412{
1413 if (capacity() > size())
1414 {
1415#ifndef _LIBCPP_NO_EXCEPTIONS
1416 try
1417 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001418#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001419 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001420 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001421 __swap_out_circular_buffer(__v);
1422#ifndef _LIBCPP_NO_EXCEPTIONS
1423 }
1424 catch (...)
1425 {
1426 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001427#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001428 }
1429}
1430
1431template <class _Tp, class _Allocator>
1432void
1433vector<_Tp, _Allocator>::push_back(const_reference __x)
1434{
1435 if (this->__end_ < this->__end_cap())
1436 {
1437 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001438 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001439 ++this->__end_;
1440 }
1441 else
1442 {
1443 allocator_type& __a = this->__alloc();
1444 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1445 __v.push_back(__x);
1446 __swap_out_circular_buffer(__v);
1447 }
1448}
1449
Howard Hinnant73d21a42010-09-04 23:28:19 +00001450#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001451
1452template <class _Tp, class _Allocator>
1453void
1454vector<_Tp, _Allocator>::push_back(value_type&& __x)
1455{
1456 if (this->__end_ < this->__end_cap())
1457 {
1458 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001459 _VSTD::__to_raw_pointer(this->__end_),
1460 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001461 ++this->__end_;
1462 }
1463 else
1464 {
1465 allocator_type& __a = this->__alloc();
1466 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001467 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001468 __swap_out_circular_buffer(__v);
1469 }
1470}
1471
Howard Hinnant73d21a42010-09-04 23:28:19 +00001472#ifndef _LIBCPP_HAS_NO_VARIADICS
1473
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001474template <class _Tp, class _Allocator>
1475template <class... _Args>
1476void
1477vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1478{
1479 if (this->__end_ < this->__end_cap())
1480 {
1481 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001482 _VSTD::__to_raw_pointer(this->__end_),
1483 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001484 ++this->__end_;
1485 }
1486 else
1487 {
1488 allocator_type& __a = this->__alloc();
1489 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001490 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001491 __swap_out_circular_buffer(__v);
1492 }
1493}
1494
Howard Hinnant73d21a42010-09-04 23:28:19 +00001495#endif // _LIBCPP_HAS_NO_VARIADICS
1496#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001497
1498template <class _Tp, class _Allocator>
1499_LIBCPP_INLINE_VISIBILITY inline
1500void
1501vector<_Tp, _Allocator>::pop_back()
1502{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001503 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001504 this->__destruct_at_end(this->__end_ - 1);
1505}
1506
1507template <class _Tp, class _Allocator>
1508_LIBCPP_INLINE_VISIBILITY inline
1509typename vector<_Tp, _Allocator>::iterator
1510vector<_Tp, _Allocator>::erase(const_iterator __position)
1511{
Howard Hinnantabe26282011-09-16 17:29:17 +00001512#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001513 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1514 "vector::erase(iterator) called with an iterator not"
1515 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001516#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517 pointer __p = const_cast<pointer>(&*__position);
1518 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001519 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520 return __r;
1521}
1522
1523template <class _Tp, class _Allocator>
1524typename vector<_Tp, _Allocator>::iterator
1525vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1526{
Howard Hinnantabe26282011-09-16 17:29:17 +00001527#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001528 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1529 "vector::erase(iterator, iterator) called with an iterator not"
1530 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001531#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001532 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001533 pointer __p = this->__begin_ + (__first - begin());
1534 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001535 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001536 return __r;
1537}
1538
1539template <class _Tp, class _Allocator>
1540void
1541vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1542{
1543 pointer __old_last = this->__end_;
1544 difference_type __n = __old_last - __to;
1545 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1546 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001547 _VSTD::__to_raw_pointer(this->__end_),
1548 _VSTD::move(*__i));
1549 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550}
1551
1552template <class _Tp, class _Allocator>
1553typename vector<_Tp, _Allocator>::iterator
1554vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1555{
Howard Hinnantabe26282011-09-16 17:29:17 +00001556#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001557 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1558 "vector::insert(iterator, x) called with an iterator not"
1559 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001560#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001561 pointer __p = this->__begin_ + (__position - begin());
1562 if (this->__end_ < this->__end_cap())
1563 {
1564 if (__p == this->__end_)
1565 {
1566 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001567 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001568 ++this->__end_;
1569 }
1570 else
1571 {
1572 __move_range(__p, this->__end_, __p + 1);
1573 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1574 if (__p <= __xr && __xr < this->__end_)
1575 ++__xr;
1576 *__p = *__xr;
1577 }
1578 }
1579 else
1580 {
1581 allocator_type& __a = this->__alloc();
1582 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1583 __v.push_back(__x);
1584 __p = __swap_out_circular_buffer(__v, __p);
1585 }
1586 return __make_iter(__p);
1587}
1588
Howard Hinnant73d21a42010-09-04 23:28:19 +00001589#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001590
1591template <class _Tp, class _Allocator>
1592typename vector<_Tp, _Allocator>::iterator
1593vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1594{
Howard Hinnantabe26282011-09-16 17:29:17 +00001595#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001596 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1597 "vector::insert(iterator, x) called with an iterator not"
1598 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001599#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001600 pointer __p = this->__begin_ + (__position - begin());
1601 if (this->__end_ < this->__end_cap())
1602 {
1603 if (__p == this->__end_)
1604 {
1605 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001606 _VSTD::__to_raw_pointer(this->__end_),
1607 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001608 ++this->__end_;
1609 }
1610 else
1611 {
1612 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001613 *__p = _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614 }
1615 }
1616 else
1617 {
1618 allocator_type& __a = this->__alloc();
1619 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001620 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621 __p = __swap_out_circular_buffer(__v, __p);
1622 }
1623 return __make_iter(__p);
1624}
1625
Howard Hinnant73d21a42010-09-04 23:28:19 +00001626#ifndef _LIBCPP_HAS_NO_VARIADICS
1627
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628template <class _Tp, class _Allocator>
1629template <class... _Args>
1630typename vector<_Tp, _Allocator>::iterator
1631vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1632{
Howard Hinnantabe26282011-09-16 17:29:17 +00001633#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001634 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1635 "vector::emplace(iterator, x) called with an iterator not"
1636 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001637#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001638 pointer __p = this->__begin_ + (__position - begin());
1639 if (this->__end_ < this->__end_cap())
1640 {
1641 if (__p == this->__end_)
1642 {
1643 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001644 _VSTD::__to_raw_pointer(this->__end_),
1645 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646 ++this->__end_;
1647 }
1648 else
1649 {
1650 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001651 *__p = value_type(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001652 }
1653 }
1654 else
1655 {
1656 allocator_type& __a = this->__alloc();
1657 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001658 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659 __p = __swap_out_circular_buffer(__v, __p);
1660 }
1661 return __make_iter(__p);
1662}
1663
Howard Hinnant73d21a42010-09-04 23:28:19 +00001664#endif // _LIBCPP_HAS_NO_VARIADICS
1665#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001666
1667template <class _Tp, class _Allocator>
1668typename vector<_Tp, _Allocator>::iterator
1669vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1670{
Howard Hinnantabe26282011-09-16 17:29:17 +00001671#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001672 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1673 "vector::insert(iterator, n, x) called with an iterator not"
1674 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001675#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001676 pointer __p = this->__begin_ + (__position - begin());
1677 if (__n > 0)
1678 {
1679 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1680 {
1681 size_type __old_n = __n;
1682 pointer __old_last = this->__end_;
1683 if (__n > static_cast<size_type>(this->__end_ - __p))
1684 {
1685 size_type __cx = __n - (this->__end_ - __p);
1686 __construct_at_end(__cx, __x);
1687 __n -= __cx;
1688 }
1689 if (__n > 0)
1690 {
1691 __move_range(__p, __old_last, __p + __old_n);
1692 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1693 if (__p <= __xr && __xr < this->__end_)
1694 __xr += __old_n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001695 _VSTD::fill_n(__p, __n, *__xr);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001696 }
1697 }
1698 else
1699 {
1700 allocator_type& __a = this->__alloc();
1701 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1702 __v.__construct_at_end(__n, __x);
1703 __p = __swap_out_circular_buffer(__v, __p);
1704 }
1705 }
1706 return __make_iter(__p);
1707}
1708
1709template <class _Tp, class _Allocator>
1710template <class _InputIterator>
1711typename enable_if
1712<
1713 __is_input_iterator <_InputIterator>::value &&
1714 !__is_forward_iterator<_InputIterator>::value,
1715 typename vector<_Tp, _Allocator>::iterator
1716>::type
1717vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1718{
Howard Hinnantabe26282011-09-16 17:29:17 +00001719#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001720 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1721 "vector::insert(iterator, range) called with an iterator not"
1722 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001723#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001724 difference_type __off = __position - begin();
1725 pointer __p = this->__begin_ + __off;
1726 allocator_type& __a = this->__alloc();
1727 pointer __old_last = this->__end_;
1728 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1729 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001730 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001731 *__first);
1732 ++this->__end_;
1733 }
1734 __split_buffer<value_type, allocator_type&> __v(__a);
1735 if (__first != __last)
1736 {
1737#ifndef _LIBCPP_NO_EXCEPTIONS
1738 try
1739 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001740#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001741 __v.__construct_at_end(__first, __last);
1742 difference_type __old_size = __old_last - this->__begin_;
1743 difference_type __old_p = __p - this->__begin_;
1744 reserve(__recommend(size() + __v.size()));
1745 __p = this->__begin_ + __old_p;
1746 __old_last = this->__begin_ + __old_size;
1747#ifndef _LIBCPP_NO_EXCEPTIONS
1748 }
1749 catch (...)
1750 {
1751 erase(__make_iter(__old_last), end());
1752 throw;
1753 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001754#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001755 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001756 __p = _VSTD::rotate(__p, __old_last, this->__end_);
Howard Hinnant0442b122011-09-16 18:41:29 +00001757 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1758 make_move_iterator(__v.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001759 return begin() + __off;
1760}
1761
1762template <class _Tp, class _Allocator>
1763template <class _ForwardIterator>
1764typename enable_if
1765<
1766 __is_forward_iterator<_ForwardIterator>::value,
1767 typename vector<_Tp, _Allocator>::iterator
1768>::type
1769vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1770{
Howard Hinnantabe26282011-09-16 17:29:17 +00001771#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001772 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1773 "vector::insert(iterator, range) called with an iterator not"
1774 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001775#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001776 pointer __p = this->__begin_ + (__position - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00001777 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001778 if (__n > 0)
1779 {
1780 if (__n <= this->__end_cap() - this->__end_)
1781 {
1782 size_type __old_n = __n;
1783 pointer __old_last = this->__end_;
1784 _ForwardIterator __m = __last;
1785 difference_type __dx = this->__end_ - __p;
1786 if (__n > __dx)
1787 {
1788 __m = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001789 _VSTD::advance(__m, this->__end_ - __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001790 __construct_at_end(__m, __last);
1791 __n = __dx;
1792 }
1793 if (__n > 0)
1794 {
1795 __move_range(__p, __old_last, __p + __old_n);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001796 _VSTD::copy(__first, __m, __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797 }
1798 }
1799 else
1800 {
1801 allocator_type& __a = this->__alloc();
1802 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1803 __v.__construct_at_end(__first, __last);
1804 __p = __swap_out_circular_buffer(__v, __p);
1805 }
1806 }
1807 return __make_iter(__p);
1808}
1809
1810template <class _Tp, class _Allocator>
1811void
1812vector<_Tp, _Allocator>::resize(size_type __sz)
1813{
1814 size_type __cs = size();
1815 if (__cs < __sz)
1816 this->__append(__sz - __cs);
1817 else if (__cs > __sz)
1818 this->__destruct_at_end(this->__begin_ + __sz);
1819}
1820
1821template <class _Tp, class _Allocator>
1822void
1823vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1824{
1825 size_type __cs = size();
1826 if (__cs < __sz)
1827 this->__append(__sz - __cs, __x);
1828 else if (__cs > __sz)
1829 this->__destruct_at_end(this->__begin_ + __sz);
1830}
1831
1832template <class _Tp, class _Allocator>
1833void
1834vector<_Tp, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001835 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1836 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001837{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001838 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
1839 this->__alloc() == __x.__alloc(),
1840 "vector::swap: Either propagate_on_container_swap must be true"
1841 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19 +00001842 _VSTD::swap(this->__begin_, __x.__begin_);
1843 _VSTD::swap(this->__end_, __x.__end_);
1844 _VSTD::swap(this->__end_cap(), __x.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845 __base::__swap_alloc(this->__alloc(), __x.__alloc());
Howard Hinnantabe26282011-09-16 17:29:17 +00001846#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001847 __get_db()->swap(this, &__x);
Howard Hinnantabe26282011-09-16 17:29:17 +00001848#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001849}
1850
Howard Hinnant324bb032010-08-22 00:02:43 +00001851template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852bool
1853vector<_Tp, _Allocator>::__invariants() const
1854{
1855 if (this->__begin_ == 0)
1856 {
1857 if (this->__end_ != 0 || this->__end_cap() != 0)
1858 return false;
1859 }
1860 else
1861 {
1862 if (this->__begin_ > this->__end_)
1863 return false;
1864 if (this->__begin_ == this->__end_cap())
1865 return false;
1866 if (this->__end_ > this->__end_cap())
1867 return false;
1868 }
1869 return true;
1870}
1871
Howard Hinnantabe26282011-09-16 17:29:17 +00001872#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001873
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874template <class _Tp, class _Allocator>
Howard Hinnant7a563db2011-09-14 18:33:51 +00001875bool
1876vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
1877{
1878 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
1879}
1880
1881template <class _Tp, class _Allocator>
1882bool
1883vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
1884{
1885 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
1886}
1887
1888template <class _Tp, class _Allocator>
1889bool
1890vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
1891{
1892 const_pointer __p = __i->base() + __n;
1893 return this->__begin_ <= __p && __p <= this->__end_;
1894}
1895
1896template <class _Tp, class _Allocator>
1897bool
1898vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1899{
1900 const_pointer __p = __i->base() + __n;
1901 return this->__begin_ <= __p && __p < this->__end_;
1902}
1903
Howard Hinnantabe26282011-09-16 17:29:17 +00001904#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001905
1906template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001907_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001908void
1909vector<_Tp, _Allocator>::__invalidate_all_iterators()
1910{
Howard Hinnantabe26282011-09-16 17:29:17 +00001911#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001912 __get_db()->__invalidate_all(this);
Howard Hinnantabe26282011-09-16 17:29:17 +00001913#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001914}
1915
1916// vector<bool>
1917
1918template <class _Allocator> class vector<bool, _Allocator>;
1919
1920template <class _Allocator> struct hash<vector<bool, _Allocator> >;
1921
1922template <class _Allocator>
Howard Hinnantf03c3b42011-07-02 20:33:23 +00001923struct __has_storage_type<vector<bool, _Allocator> >
1924{
1925 static const bool value = true;
1926};
1927
1928template <class _Allocator>
Howard Hinnant36cdf022010-09-10 16:42:26 +00001929class _LIBCPP_VISIBLE vector<bool, _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001930 : private __vector_base_common<true>
1931{
1932public:
1933 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +00001934 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935 typedef _Allocator allocator_type;
1936 typedef allocator_traits<allocator_type> __alloc_traits;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001937 typedef typename __alloc_traits::size_type size_type;
1938 typedef typename __alloc_traits::difference_type difference_type;
1939 typedef __bit_iterator<vector, false> pointer;
1940 typedef __bit_iterator<vector, true> const_pointer;
1941#ifdef _LIBCPP_DEBUG
1942 typedef __debug_iter<vector, pointer> iterator;
1943 typedef __debug_iter<vector, const_pointer> const_iterator;
1944
1945 friend class __debug_iter<vector, pointer>;
1946 friend class __debug_iter<vector, const_pointer>;
1947
1948 pair<iterator*, const_iterator*> __iterator_list_;
1949
1950 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1951 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
Howard Hinnant324bb032010-08-22 00:02:43 +00001952#else // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001953 typedef pointer iterator;
1954 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001955#endif // _LIBCPP_DEBUG
Howard Hinnant0949eed2011-06-30 21:18:19 +00001956 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1957 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958
1959private:
1960 typedef size_type __storage_type;
1961 typedef typename __alloc_traits::template
1962#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1963 rebind_alloc<__storage_type>
1964#else
1965 rebind_alloc<__storage_type>::other
1966#endif
1967 __storage_allocator;
1968 typedef allocator_traits<__storage_allocator> __storage_traits;
1969 typedef typename __storage_traits::pointer __storage_pointer;
1970 typedef typename __storage_traits::const_pointer __const_storage_pointer;
1971
1972 __storage_pointer __begin_;
1973 size_type __size_;
1974 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00001975public:
Howard Hinnantf03c3b42011-07-02 20:33:23 +00001976 typedef __bit_reference<vector> reference;
1977 typedef __bit_const_reference<vector> const_reference;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00001978private:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001979 _LIBCPP_INLINE_VISIBILITY
1980 size_type& __cap() _NOEXCEPT
1981 {return __cap_alloc_.first();}
1982 _LIBCPP_INLINE_VISIBILITY
1983 const size_type& __cap() const _NOEXCEPT
1984 {return __cap_alloc_.first();}
1985 _LIBCPP_INLINE_VISIBILITY
1986 __storage_allocator& __alloc() _NOEXCEPT
1987 {return __cap_alloc_.second();}
1988 _LIBCPP_INLINE_VISIBILITY
1989 const __storage_allocator& __alloc() const _NOEXCEPT
1990 {return __cap_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001991
1992 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
1993
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001994 _LIBCPP_INLINE_VISIBILITY
1995 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001996 {return __n * __bits_per_word;}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001997 _LIBCPP_INLINE_VISIBILITY
1998 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001999 {return (__n - 1) / __bits_per_word + 1;}
2000
2001public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002002 _LIBCPP_INLINE_VISIBILITY
2003 vector()
2004 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002005 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002006 ~vector();
2007 explicit vector(size_type __n);
2008 vector(size_type __n, const value_type& __v);
2009 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2010 template <class _InputIterator>
2011 vector(_InputIterator __first, _InputIterator __last,
2012 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2013 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2014 template <class _InputIterator>
2015 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2016 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2017 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2018 template <class _ForwardIterator>
2019 vector(_ForwardIterator __first, _ForwardIterator __last,
2020 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2021 template <class _ForwardIterator>
2022 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2023 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2024
2025 vector(const vector& __v);
2026 vector(const vector& __v, const allocator_type& __a);
2027 vector& operator=(const vector& __v);
Howard Hinnante3e32912011-08-12 21:56:02 +00002028#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002029 vector(initializer_list<value_type> __il);
2030 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00002031#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002032
Howard Hinnant73d21a42010-09-04 23:28:19 +00002033#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002034 _LIBCPP_INLINE_VISIBILITY
2035 vector(vector&& __v)
2036 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002037 vector(vector&& __v, const allocator_type& __a);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002038 _LIBCPP_INLINE_VISIBILITY
2039 vector& operator=(vector&& __v)
2040 _NOEXCEPT_(
2041 __alloc_traits::propagate_on_container_move_assignment::value &&
2042 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002043#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00002044#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002046 vector& operator=(initializer_list<value_type> __il)
2047 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00002048#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002049
2050 template <class _InputIterator>
2051 typename enable_if
2052 <
2053 __is_input_iterator<_InputIterator>::value &&
2054 !__is_forward_iterator<_InputIterator>::value,
2055 void
2056 >::type
2057 assign(_InputIterator __first, _InputIterator __last);
2058 template <class _ForwardIterator>
2059 typename enable_if
2060 <
2061 __is_forward_iterator<_ForwardIterator>::value,
2062 void
2063 >::type
2064 assign(_ForwardIterator __first, _ForwardIterator __last);
2065
2066 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:02 +00002067#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069 void assign(initializer_list<value_type> __il)
2070 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002071#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002073 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002074 {return allocator_type(this->__alloc());}
2075
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002076 size_type max_size() const _NOEXCEPT;
2077 _LIBCPP_INLINE_VISIBILITY
2078 size_type capacity() const _NOEXCEPT
2079 {return __internal_cap_to_external(__cap());}
2080 _LIBCPP_INLINE_VISIBILITY
2081 size_type size() const _NOEXCEPT
2082 {return __size_;}
2083 _LIBCPP_INLINE_VISIBILITY
2084 bool empty() const _NOEXCEPT
2085 {return __size_ == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002086 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002087 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002088
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002089 _LIBCPP_INLINE_VISIBILITY
2090 iterator begin() _NOEXCEPT
2091 {return __make_iter(0);}
2092 _LIBCPP_INLINE_VISIBILITY
2093 const_iterator begin() const _NOEXCEPT
2094 {return __make_iter(0);}
2095 _LIBCPP_INLINE_VISIBILITY
2096 iterator end() _NOEXCEPT
2097 {return __make_iter(__size_);}
2098 _LIBCPP_INLINE_VISIBILITY
2099 const_iterator end() const _NOEXCEPT
2100 {return __make_iter(__size_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002101
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002102 _LIBCPP_INLINE_VISIBILITY
2103 reverse_iterator rbegin() _NOEXCEPT
2104 {return reverse_iterator(end());}
2105 _LIBCPP_INLINE_VISIBILITY
2106 const_reverse_iterator rbegin() const _NOEXCEPT
2107 {return const_reverse_iterator(end());}
2108 _LIBCPP_INLINE_VISIBILITY
2109 reverse_iterator rend() _NOEXCEPT
2110 {return reverse_iterator(begin());}
2111 _LIBCPP_INLINE_VISIBILITY
2112 const_reverse_iterator rend() const _NOEXCEPT
2113 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002114
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002115 _LIBCPP_INLINE_VISIBILITY
2116 const_iterator cbegin() const _NOEXCEPT
2117 {return __make_iter(0);}
2118 _LIBCPP_INLINE_VISIBILITY
2119 const_iterator cend() const _NOEXCEPT
2120 {return __make_iter(__size_);}
2121 _LIBCPP_INLINE_VISIBILITY
2122 const_reverse_iterator crbegin() const _NOEXCEPT
2123 {return rbegin();}
2124 _LIBCPP_INLINE_VISIBILITY
2125 const_reverse_iterator crend() const _NOEXCEPT
2126 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002127
2128 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2129 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2130 reference at(size_type __n);
2131 const_reference at(size_type __n) const;
2132
2133 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2134 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2135 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2136 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2137
2138 void push_back(const value_type& __x);
2139 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2140
2141 iterator insert(const_iterator __position, const value_type& __x);
2142 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2143 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2144 template <class _InputIterator>
2145 typename enable_if
2146 <
2147 __is_input_iterator <_InputIterator>::value &&
2148 !__is_forward_iterator<_InputIterator>::value,
2149 iterator
2150 >::type
2151 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2152 template <class _ForwardIterator>
2153 typename enable_if
2154 <
2155 __is_forward_iterator<_ForwardIterator>::value,
2156 iterator
2157 >::type
2158 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00002159#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002161 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2162 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002163#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002164
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002165 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002166 iterator erase(const_iterator __first, const_iterator __last);
2167
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002168 _LIBCPP_INLINE_VISIBILITY
2169 void clear() _NOEXCEPT {__size_ = 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002170
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002171 void swap(vector&)
2172 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2173 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002174
2175 void resize(size_type __sz, value_type __x = false);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002176 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002177
2178 bool __invariants() const;
2179
2180private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002181 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002183 void deallocate() _NOEXCEPT;
2184 _LIBCPP_INLINE_VISIBILITY
2185 static size_type __align(size_type __new_size) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186 {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);};
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002187 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2188 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002189 template <class _ForwardIterator>
2190 typename enable_if
2191 <
2192 __is_forward_iterator<_ForwardIterator>::value,
2193 void
2194 >::type
2195 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2196 void __append(size_type __n, const_reference __x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002197 _LIBCPP_INLINE_VISIBILITY
2198 reference __make_ref(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002199 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002200 _LIBCPP_INLINE_VISIBILITY
2201 const_reference __make_ref(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002202 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2203#ifdef _LIBCPP_DEBUG
2204 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos)
2205 {return iterator(this, pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2206 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const
2207 {return const_iterator(this, const_pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2208 _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p)
2209 {return iterator(this, pointer(const_cast<__storage_pointer>(__p.base().__seg_), __p.base().__ctz_));}
Howard Hinnant324bb032010-08-22 00:02:43 +00002210#else // _LIBCPP_DEBUG
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002211 _LIBCPP_INLINE_VISIBILITY
2212 iterator __make_iter(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002213 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002214 _LIBCPP_INLINE_VISIBILITY
2215 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002216 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002217 _LIBCPP_INLINE_VISIBILITY
2218 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002219 {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);}
Howard Hinnant324bb032010-08-22 00:02:43 +00002220#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002221
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002222 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002223 void __copy_assign_alloc(const vector& __v)
2224 {__copy_assign_alloc(__v, integral_constant<bool,
2225 __storage_traits::propagate_on_container_copy_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002226 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002227 void __copy_assign_alloc(const vector& __c, true_type)
2228 {
2229 if (__alloc() != __c.__alloc())
2230 deallocate();
2231 __alloc() = __c.__alloc();
2232 }
2233
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002235 void __copy_assign_alloc(const vector& __c, false_type)
2236 {}
2237
2238 void __move_assign(vector& __c, false_type);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002239 void __move_assign(vector& __c, true_type)
2240 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002242 void __move_assign_alloc(vector& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002243 _NOEXCEPT_(
2244 !__storage_traits::propagate_on_container_move_assignment::value ||
2245 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002246 {__move_assign_alloc(__c, integral_constant<bool,
2247 __storage_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00002249 void __move_assign_alloc(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002250 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002251 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002252 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002253 }
2254
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00002256 void __move_assign_alloc(vector& __c, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002257 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002258 {}
2259
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002261 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002262 _NOEXCEPT_(
2263 !__storage_traits::propagate_on_container_swap::value ||
2264 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002265 {__swap_alloc(__x, __y, integral_constant<bool,
2266 __storage_traits::propagate_on_container_swap::value>());}
2267
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002269 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002270 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002271 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002272 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002273 swap(__x, __y);
2274 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002275 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002276 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002277 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002278 {}
2279
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002280 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002281
2282 friend class __bit_reference<vector>;
2283 friend class __bit_const_reference<vector>;
2284 friend class __bit_iterator<vector, false>;
2285 friend class __bit_iterator<vector, true>;
2286 friend class __bit_array<vector>;
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002287 friend struct _LIBCPP_VISIBLE hash<vector>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002288};
2289
2290template <class _Allocator>
2291#ifndef _LIBCPP_DEBUG
2292_LIBCPP_INLINE_VISIBILITY inline
2293#endif
2294void
2295vector<bool, _Allocator>::__invalidate_all_iterators()
2296{
2297#ifdef _LIBCPP_DEBUG
2298 iterator::__remove_all(this);
2299 const_iterator::__remove_all(this);
Howard Hinnant324bb032010-08-22 00:02:43 +00002300#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002301}
2302
2303// Allocate space for __n objects
2304// throws length_error if __n > max_size()
2305// throws (probably bad_alloc) if memory run out
2306// Precondition: __begin_ == __end_ == __cap() == 0
2307// Precondition: __n > 0
2308// Postcondition: capacity() == __n
2309// Postcondition: size() == 0
2310template <class _Allocator>
2311void
2312vector<bool, _Allocator>::allocate(size_type __n)
2313{
2314 if (__n > max_size())
2315 this->__throw_length_error();
2316 __n = __external_cap_to_internal(__n);
2317 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2318 this->__size_ = 0;
2319 this->__cap() = __n;
2320}
2321
2322template <class _Allocator>
2323void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002324vector<bool, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002325{
2326 if (this->__begin_ != 0)
2327 {
2328 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2329 __invalidate_all_iterators();
2330 this->__begin_ = 0;
2331 this->__size_ = this->__cap() = 0;
2332 }
2333}
2334
2335template <class _Allocator>
2336typename vector<bool, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002337vector<bool, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002338{
2339 size_type __amax = __storage_traits::max_size(__alloc());
2340 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2341 if (__nmax / __bits_per_word <= __amax)
2342 return __nmax;
2343 return __internal_cap_to_external(__amax);
2344}
2345
2346// Precondition: __new_size > capacity()
2347template <class _Allocator>
2348_LIBCPP_INLINE_VISIBILITY inline
2349typename vector<bool, _Allocator>::size_type
2350vector<bool, _Allocator>::__recommend(size_type __new_size) const
2351{
2352 const size_type __ms = max_size();
2353 if (__new_size > __ms)
2354 this->__throw_length_error();
2355 const size_type __cap = capacity();
2356 if (__cap >= __ms / 2)
2357 return __ms;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002358 return _VSTD::max(2*__cap, __align(__new_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002359}
2360
2361// Default constructs __n objects starting at __end_
2362// Precondition: __n > 0
2363// Precondition: size() + __n <= capacity()
2364// Postcondition: size() == size() + __n
2365template <class _Allocator>
2366_LIBCPP_INLINE_VISIBILITY inline
2367void
2368vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2369{
2370 size_type __old_size = this->__size_;
2371 this->__size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002372 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002373}
2374
2375template <class _Allocator>
2376template <class _ForwardIterator>
2377typename enable_if
2378<
2379 __is_forward_iterator<_ForwardIterator>::value,
2380 void
2381>::type
2382vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2383{
2384 size_type __old_size = this->__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002385 this->__size_ += _VSTD::distance(__first, __last);
2386 _VSTD::copy(__first, __last, __make_iter(__old_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387}
2388
2389template <class _Allocator>
2390_LIBCPP_INLINE_VISIBILITY inline
2391vector<bool, _Allocator>::vector()
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002392 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002393 : __begin_(0),
2394 __size_(0),
2395 __cap_alloc_(0)
2396{
2397}
2398
2399template <class _Allocator>
2400_LIBCPP_INLINE_VISIBILITY inline
2401vector<bool, _Allocator>::vector(const allocator_type& __a)
2402 : __begin_(0),
2403 __size_(0),
2404 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2405{
2406}
2407
2408template <class _Allocator>
2409vector<bool, _Allocator>::vector(size_type __n)
2410 : __begin_(0),
2411 __size_(0),
2412 __cap_alloc_(0)
2413{
2414 if (__n > 0)
2415 {
2416 allocate(__n);
2417 __construct_at_end(__n, false);
2418 }
2419}
2420
2421template <class _Allocator>
2422vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2423 : __begin_(0),
2424 __size_(0),
2425 __cap_alloc_(0)
2426{
2427 if (__n > 0)
2428 {
2429 allocate(__n);
2430 __construct_at_end(__n, __x);
2431 }
2432}
2433
2434template <class _Allocator>
2435vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2436 : __begin_(0),
2437 __size_(0),
2438 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2439{
2440 if (__n > 0)
2441 {
2442 allocate(__n);
2443 __construct_at_end(__n, __x);
2444 }
2445}
2446
2447template <class _Allocator>
2448template <class _InputIterator>
2449vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2450 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2451 !__is_forward_iterator<_InputIterator>::value>::type*)
2452 : __begin_(0),
2453 __size_(0),
2454 __cap_alloc_(0)
2455{
2456#ifndef _LIBCPP_NO_EXCEPTIONS
2457 try
2458 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002459#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002460 for (; __first != __last; ++__first)
2461 push_back(*__first);
2462#ifndef _LIBCPP_NO_EXCEPTIONS
2463 }
2464 catch (...)
2465 {
2466 if (__begin_ != 0)
2467 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2468 __invalidate_all_iterators();
2469 throw;
2470 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002471#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002472}
2473
2474template <class _Allocator>
2475template <class _InputIterator>
2476vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2477 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2478 !__is_forward_iterator<_InputIterator>::value>::type*)
2479 : __begin_(0),
2480 __size_(0),
2481 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2482{
2483#ifndef _LIBCPP_NO_EXCEPTIONS
2484 try
2485 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002486#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002487 for (; __first != __last; ++__first)
2488 push_back(*__first);
2489#ifndef _LIBCPP_NO_EXCEPTIONS
2490 }
2491 catch (...)
2492 {
2493 if (__begin_ != 0)
2494 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2495 __invalidate_all_iterators();
2496 throw;
2497 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002498#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002499}
2500
2501template <class _Allocator>
2502template <class _ForwardIterator>
2503vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2504 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2505 : __begin_(0),
2506 __size_(0),
2507 __cap_alloc_(0)
2508{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002509 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002510 if (__n > 0)
2511 {
2512 allocate(__n);
2513 __construct_at_end(__first, __last);
2514 }
2515}
2516
2517template <class _Allocator>
2518template <class _ForwardIterator>
2519vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2520 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2521 : __begin_(0),
2522 __size_(0),
2523 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2524{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002525 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002526 if (__n > 0)
2527 {
2528 allocate(__n);
2529 __construct_at_end(__first, __last);
2530 }
2531}
2532
Howard Hinnante3e32912011-08-12 21:56:02 +00002533#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2534
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002535template <class _Allocator>
2536vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2537 : __begin_(0),
2538 __size_(0),
2539 __cap_alloc_(0)
2540{
2541 size_type __n = static_cast<size_type>(__il.size());
2542 if (__n > 0)
2543 {
2544 allocate(__n);
2545 __construct_at_end(__il.begin(), __il.end());
2546 }
2547}
2548
2549template <class _Allocator>
2550vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2551 : __begin_(0),
2552 __size_(0),
2553 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2554{
2555 size_type __n = static_cast<size_type>(__il.size());
2556 if (__n > 0)
2557 {
2558 allocate(__n);
2559 __construct_at_end(__il.begin(), __il.end());
2560 }
2561}
2562
Howard Hinnante3e32912011-08-12 21:56:02 +00002563#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2564
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002565template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002566vector<bool, _Allocator>::~vector()
2567{
2568 if (__begin_ != 0)
2569 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2570#ifdef _LIBCPP_DEBUG
2571 __invalidate_all_iterators();
2572#endif
2573}
2574
2575template <class _Allocator>
2576vector<bool, _Allocator>::vector(const vector& __v)
2577 : __begin_(0),
2578 __size_(0),
2579 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2580{
2581 if (__v.size() > 0)
2582 {
2583 allocate(__v.size());
2584 __construct_at_end(__v.begin(), __v.end());
2585 }
2586}
2587
2588template <class _Allocator>
2589vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2590 : __begin_(0),
2591 __size_(0),
2592 __cap_alloc_(0, __a)
2593{
2594 if (__v.size() > 0)
2595 {
2596 allocate(__v.size());
2597 __construct_at_end(__v.begin(), __v.end());
2598 }
2599}
2600
2601template <class _Allocator>
2602vector<bool, _Allocator>&
2603vector<bool, _Allocator>::operator=(const vector& __v)
2604{
2605 if (this != &__v)
2606 {
2607 __copy_assign_alloc(__v);
2608 if (__v.__size_)
2609 {
2610 if (__v.__size_ > capacity())
2611 {
2612 deallocate();
2613 allocate(__v.__size_);
2614 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002615 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002616 }
2617 __size_ = __v.__size_;
2618 }
2619 return *this;
2620}
2621
Howard Hinnant73d21a42010-09-04 23:28:19 +00002622#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2623
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002624template <class _Allocator>
2625_LIBCPP_INLINE_VISIBILITY inline
2626vector<bool, _Allocator>::vector(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002627 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002628 : __begin_(__v.__begin_),
2629 __size_(__v.__size_),
2630 __cap_alloc_(__v.__cap_alloc_)
2631{
2632 __v.__begin_ = 0;
2633 __v.__size_ = 0;
2634 __v.__cap() = 0;
2635}
2636
2637template <class _Allocator>
2638vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2639 : __begin_(0),
2640 __size_(0),
2641 __cap_alloc_(0, __a)
2642{
2643 if (__a == allocator_type(__v.__alloc()))
2644 {
2645 this->__begin_ = __v.__begin_;
2646 this->__size_ = __v.__size_;
2647 this->__cap() = __v.__cap();
2648 __v.__begin_ = nullptr;
2649 __v.__cap() = __v.__size_ = 0;
2650 }
2651 else if (__v.size() > 0)
2652 {
2653 allocate(__v.size());
2654 __construct_at_end(__v.begin(), __v.end());
2655 }
2656}
2657
2658template <class _Allocator>
2659_LIBCPP_INLINE_VISIBILITY inline
2660vector<bool, _Allocator>&
2661vector<bool, _Allocator>::operator=(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002662 _NOEXCEPT_(
2663 __alloc_traits::propagate_on_container_move_assignment::value &&
2664 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002665{
2666 __move_assign(__v, integral_constant<bool,
2667 __storage_traits::propagate_on_container_move_assignment::value>());
2668}
2669
2670template <class _Allocator>
2671void
2672vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2673{
2674 if (__alloc() != __c.__alloc())
2675 assign(__c.begin(), __c.end());
2676 else
2677 __move_assign(__c, true_type());
2678}
2679
2680template <class _Allocator>
2681void
2682vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002683 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684{
2685 deallocate();
2686 this->__begin_ = __c.__begin_;
2687 this->__size_ = __c.__size_;
2688 this->__cap() = __c.__cap();
2689 __move_assign_alloc(__c);
2690 __c.__begin_ = nullptr;
2691 __c.__cap() = __c.__size_ = 0;
2692}
Howard Hinnant73d21a42010-09-04 23:28:19 +00002693
2694#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002695
2696template <class _Allocator>
2697void
2698vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2699{
2700 __size_ = 0;
2701 if (__n > 0)
2702 {
2703 size_type __c = capacity();
2704 if (__n <= __c)
2705 __size_ = __n;
2706 else
2707 {
2708 vector __v(__alloc());
2709 __v.reserve(__recommend(__n));
2710 __v.__size_ = __n;
2711 swap(__v);
2712 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002713 _VSTD::fill_n(begin(), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002714 }
2715}
2716
2717template <class _Allocator>
2718template <class _InputIterator>
2719typename enable_if
2720<
2721 __is_input_iterator<_InputIterator>::value &&
2722 !__is_forward_iterator<_InputIterator>::value,
2723 void
2724>::type
2725vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2726{
2727 clear();
2728 for (; __first != __last; ++__first)
2729 push_back(*__first);
2730}
2731
2732template <class _Allocator>
2733template <class _ForwardIterator>
2734typename enable_if
2735<
2736 __is_forward_iterator<_ForwardIterator>::value,
2737 void
2738>::type
2739vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2740{
2741 clear();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002742 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002743 if (__n)
2744 {
2745 if (__n > capacity())
2746 {
2747 deallocate();
2748 allocate(__n);
2749 }
2750 __construct_at_end(__first, __last);
2751 }
2752}
2753
2754template <class _Allocator>
2755void
2756vector<bool, _Allocator>::reserve(size_type __n)
2757{
2758 if (__n > capacity())
2759 {
2760 vector __v(this->__alloc());
2761 __v.allocate(__n);
2762 __v.__construct_at_end(this->begin(), this->end());
2763 swap(__v);
2764 __invalidate_all_iterators();
2765 }
2766}
2767
2768template <class _Allocator>
2769void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002770vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002771{
2772 if (__external_cap_to_internal(size()) > __cap())
2773 {
2774#ifndef _LIBCPP_NO_EXCEPTIONS
2775 try
2776 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002777#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002778 vector(*this, allocator_type(__alloc())).swap(*this);
2779#ifndef _LIBCPP_NO_EXCEPTIONS
2780 }
2781 catch (...)
2782 {
2783 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002784#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002785 }
2786}
2787
2788template <class _Allocator>
2789typename vector<bool, _Allocator>::reference
2790vector<bool, _Allocator>::at(size_type __n)
2791{
2792 if (__n >= size())
2793 this->__throw_out_of_range();
2794 return (*this)[__n];
2795}
2796
2797template <class _Allocator>
2798typename vector<bool, _Allocator>::const_reference
2799vector<bool, _Allocator>::at(size_type __n) const
2800{
2801 if (__n >= size())
2802 this->__throw_out_of_range();
2803 return (*this)[__n];
2804}
2805
2806template <class _Allocator>
2807void
2808vector<bool, _Allocator>::push_back(const value_type& __x)
2809{
2810 if (this->__size_ == this->capacity())
2811 reserve(__recommend(this->__size_ + 1));
2812 ++this->__size_;
2813 back() = __x;
2814}
2815
2816template <class _Allocator>
2817typename vector<bool, _Allocator>::iterator
2818vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2819{
2820 iterator __r;
2821 if (size() < capacity())
2822 {
2823 const_iterator __old_end = end();
2824 ++__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002825 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002826 __r = __const_iterator_cast(__position);
2827 }
2828 else
2829 {
2830 vector __v(__alloc());
2831 __v.reserve(__recommend(__size_ + 1));
2832 __v.__size_ = __size_ + 1;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002833 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2834 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002835 swap(__v);
2836 }
2837 *__r = __x;
2838 return __r;
2839}
2840
2841template <class _Allocator>
2842typename vector<bool, _Allocator>::iterator
2843vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
2844{
2845 iterator __r;
2846 size_type __c = capacity();
2847 if (__n <= __c && size() <= __c - __n)
2848 {
2849 const_iterator __old_end = end();
2850 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002851 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002852 __r = __const_iterator_cast(__position);
2853 }
2854 else
2855 {
2856 vector __v(__alloc());
2857 __v.reserve(__recommend(__size_ + __n));
2858 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002859 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2860 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002861 swap(__v);
2862 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002863 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002864 return __r;
2865}
2866
2867template <class _Allocator>
2868template <class _InputIterator>
2869typename enable_if
2870<
2871 __is_input_iterator <_InputIterator>::value &&
2872 !__is_forward_iterator<_InputIterator>::value,
2873 typename vector<bool, _Allocator>::iterator
2874>::type
2875vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
2876{
2877 difference_type __off = __position - begin();
2878 iterator __p = __const_iterator_cast(__position);
2879 iterator __old_end = end();
2880 for (; size() != capacity() && __first != __last; ++__first)
2881 {
2882 ++this->__size_;
2883 back() = *__first;
2884 }
2885 vector __v(__alloc());
2886 if (__first != __last)
2887 {
2888#ifndef _LIBCPP_NO_EXCEPTIONS
2889 try
2890 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002891#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002892 __v.assign(__first, __last);
2893 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
2894 difference_type __old_p = __p - begin();
2895 reserve(__recommend(size() + __v.size()));
2896 __p = begin() + __old_p;
2897 __old_end = begin() + __old_size;
2898#ifndef _LIBCPP_NO_EXCEPTIONS
2899 }
2900 catch (...)
2901 {
2902 erase(__old_end, end());
2903 throw;
2904 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002905#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002906 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002907 __p = _VSTD::rotate(__p, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002908 insert(__p, __v.begin(), __v.end());
2909 return begin() + __off;
2910}
2911
2912template <class _Allocator>
2913template <class _ForwardIterator>
2914typename enable_if
2915<
2916 __is_forward_iterator<_ForwardIterator>::value,
2917 typename vector<bool, _Allocator>::iterator
2918>::type
2919vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
2920{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002921 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002922 iterator __r;
2923 size_type __c = capacity();
2924 if (__n <= __c && size() <= __c - __n)
2925 {
2926 const_iterator __old_end = end();
2927 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002928 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002929 __r = __const_iterator_cast(__position);
2930 }
2931 else
2932 {
2933 vector __v(__alloc());
2934 __v.reserve(__recommend(__size_ + __n));
2935 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002936 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2937 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002938 swap(__v);
2939 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002940 _VSTD::copy(__first, __last, __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002941 return __r;
2942}
2943
2944template <class _Allocator>
2945_LIBCPP_INLINE_VISIBILITY inline
2946typename vector<bool, _Allocator>::iterator
2947vector<bool, _Allocator>::erase(const_iterator __position)
2948{
2949 iterator __r = __const_iterator_cast(__position);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002950 _VSTD::copy(__position + 1, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002951 --__size_;
2952 return __r;
2953}
2954
2955template <class _Allocator>
2956typename vector<bool, _Allocator>::iterator
2957vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
2958{
2959 iterator __r = __const_iterator_cast(__first);
2960 difference_type __d = __last - __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002961 _VSTD::copy(__last, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002962 __size_ -= __d;
2963 return __r;
2964}
2965
2966template <class _Allocator>
2967void
2968vector<bool, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002969 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2970 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002971{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002972 _VSTD::swap(this->__begin_, __x.__begin_);
2973 _VSTD::swap(this->__size_, __x.__size_);
2974 _VSTD::swap(this->__cap(), __x.__cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002975 __swap_alloc(this->__alloc(), __x.__alloc());
2976#ifdef _LIBCPP_DEBUG
2977 iterator::swap(this, &__x);
2978 const_iterator::swap(this, &__x);
Howard Hinnant324bb032010-08-22 00:02:43 +00002979#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002980}
2981
Howard Hinnant324bb032010-08-22 00:02:43 +00002982template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002983void
2984vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
2985{
2986 size_type __cs = size();
2987 if (__cs < __sz)
2988 {
2989 iterator __r;
2990 size_type __c = capacity();
2991 size_type __n = __sz - __cs;
2992 if (__n <= __c && __cs <= __c - __n)
2993 {
2994 __r = end();
2995 __size_ += __n;
2996 }
2997 else
2998 {
2999 vector __v(__alloc());
3000 __v.reserve(__recommend(__size_ + __n));
3001 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003002 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003003 swap(__v);
3004 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003005 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003006 }
3007 else
3008 __size_ = __sz;
3009}
3010
Howard Hinnant324bb032010-08-22 00:02:43 +00003011template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003012void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003013vector<bool, _Allocator>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003014{
3015 // do middle whole words
3016 size_type __n = __size_;
3017 __storage_pointer __p = __begin_;
3018 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3019 *__p = ~*__p;
3020 // do last partial word
3021 if (__n > 0)
3022 {
3023 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3024 __storage_type __b = *__p & __m;
3025 *__p &= ~__m;
3026 *__p |= ~__b & __m;
3027 }
3028}
3029
Howard Hinnant324bb032010-08-22 00:02:43 +00003030template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003031bool
3032vector<bool, _Allocator>::__invariants() const
3033{
3034 if (this->__begin_ == 0)
3035 {
3036 if (this->__size_ != 0 || this->__cap() != 0)
3037 return false;
3038 }
3039 else
3040 {
3041 if (this->__cap() == 0)
3042 return false;
3043 if (this->__size_ > this->capacity())
3044 return false;
3045 }
3046 return true;
3047}
3048
Howard Hinnant324bb032010-08-22 00:02:43 +00003049template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003050size_t
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003051vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003052{
3053 size_t __h = 0;
3054 // do middle whole words
3055 size_type __n = __size_;
3056 __storage_pointer __p = __begin_;
3057 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3058 __h ^= *__p;
3059 // do last partial word
3060 if (__n > 0)
3061 {
3062 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3063 __h ^= *__p & __m;
3064 }
3065 return __h;
3066}
3067
3068template <class _Allocator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003069struct _LIBCPP_VISIBLE hash<vector<bool, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003070 : public unary_function<vector<bool, _Allocator>, size_t>
3071{
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003073 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003074 {return __vec.__hash_code();}
3075};
3076
3077template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003078_LIBCPP_INLINE_VISIBILITY inline
3079bool
3080operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3081{
3082 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003083 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003084}
3085
3086template <class _Tp, class _Allocator>
3087_LIBCPP_INLINE_VISIBILITY inline
3088bool
3089operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3090{
3091 return !(__x == __y);
3092}
3093
3094template <class _Tp, class _Allocator>
3095_LIBCPP_INLINE_VISIBILITY inline
3096bool
3097operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3098{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003099 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003100}
3101
3102template <class _Tp, class _Allocator>
3103_LIBCPP_INLINE_VISIBILITY inline
3104bool
3105operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3106{
3107 return __y < __x;
3108}
3109
3110template <class _Tp, class _Allocator>
3111_LIBCPP_INLINE_VISIBILITY inline
3112bool
3113operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3114{
3115 return !(__x < __y);
3116}
3117
3118template <class _Tp, class _Allocator>
3119_LIBCPP_INLINE_VISIBILITY inline
3120bool
3121operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3122{
3123 return !(__y < __x);
3124}
3125
3126template <class _Tp, class _Allocator>
3127_LIBCPP_INLINE_VISIBILITY inline
3128void
3129swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003130 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003131{
3132 __x.swap(__y);
3133}
3134
3135_LIBCPP_END_NAMESPACE_STD
3136
3137#endif // _LIBCPP_VECTOR