blob: 1fb6f5919716935ede18a1b1b13024cc04866ac0 [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 Hinnant66c6f972011-11-29 16:45:27 +0000273#include <__undef_min_max>
274
Howard Hinnant08e17472011-10-17 20:05:10 +0000275#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000277#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278
279_LIBCPP_BEGIN_NAMESPACE_STD
280
281template <bool>
282class __vector_base_common
283{
284protected:
285 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
286 void __throw_length_error() const;
287 void __throw_out_of_range() const;
288};
289
290template <bool __b>
291void
292__vector_base_common<__b>::__throw_length_error() const
293{
294#ifndef _LIBCPP_NO_EXCEPTIONS
295 throw length_error("vector");
296#else
297 assert(!"vector length_error");
298#endif
299}
300
301template <bool __b>
302void
303__vector_base_common<__b>::__throw_out_of_range() const
304{
305#ifndef _LIBCPP_NO_EXCEPTIONS
306 throw out_of_range("vector");
307#else
308 assert(!"vector out_of_range");
309#endif
310}
311
Howard Hinnant78b68282011-10-22 20:59:45 +0000312#ifdef _MSC_VER
313#pragma warning( push )
314#pragma warning( disable: 4231 )
315#endif // _MSC_VER
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000316extern template class __vector_base_common<true>;
Howard Hinnant78b68282011-10-22 20:59:45 +0000317#ifdef _MSC_VER
318#pragma warning( pop )
319#endif // _MSC_VER
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320
321template <class _Tp, class _Allocator>
322class __vector_base
323 : protected __vector_base_common<true>
324{
325protected:
Howard Hinnant324bb032010-08-22 00:02:43 +0000326 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 typedef _Allocator allocator_type;
328 typedef allocator_traits<allocator_type> __alloc_traits;
329 typedef value_type& reference;
330 typedef const value_type& const_reference;
331 typedef typename __alloc_traits::size_type size_type;
332 typedef typename __alloc_traits::difference_type difference_type;
333 typedef typename __alloc_traits::pointer pointer;
334 typedef typename __alloc_traits::const_pointer const_pointer;
335 typedef pointer iterator;
336 typedef const_pointer const_iterator;
337
338 pointer __begin_;
339 pointer __end_;
340 __compressed_pair<pointer, allocator_type> __end_cap_;
341
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000342 _LIBCPP_INLINE_VISIBILITY
343 allocator_type& __alloc() _NOEXCEPT
344 {return __end_cap_.second();}
345 _LIBCPP_INLINE_VISIBILITY
346 const allocator_type& __alloc() const _NOEXCEPT
347 {return __end_cap_.second();}
348 _LIBCPP_INLINE_VISIBILITY
349 pointer& __end_cap() _NOEXCEPT
350 {return __end_cap_.first();}
351 _LIBCPP_INLINE_VISIBILITY
352 const pointer& __end_cap() const _NOEXCEPT
353 {return __end_cap_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000355 _LIBCPP_INLINE_VISIBILITY
356 __vector_base()
357 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000358 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359 ~__vector_base();
360
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000361 _LIBCPP_INLINE_VISIBILITY
362 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
363 _LIBCPP_INLINE_VISIBILITY
364 size_type capacity() const _NOEXCEPT
365 {return static_cast<size_type>(__end_cap() - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000366
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000367 _LIBCPP_INLINE_VISIBILITY
368 void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +0000369 {__destruct_at_end(__new_last, is_trivially_destructible<value_type>());}
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000370 _LIBCPP_INLINE_VISIBILITY
371 void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT;
372 _LIBCPP_INLINE_VISIBILITY
373 void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000375 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376 void __copy_assign_alloc(const __vector_base& __c)
377 {__copy_assign_alloc(__c, integral_constant<bool,
378 __alloc_traits::propagate_on_container_copy_assignment::value>());}
379
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000380 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381 void __move_assign_alloc(__vector_base& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000382 _NOEXCEPT_(
383 !__alloc_traits::propagate_on_container_move_assignment::value ||
384 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385 {__move_assign_alloc(__c, integral_constant<bool,
386 __alloc_traits::propagate_on_container_move_assignment::value>());}
387
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000388 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000390 _NOEXCEPT_(
391 !__alloc_traits::propagate_on_container_swap::value ||
392 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000393 {__swap_alloc(__x, __y, integral_constant<bool,
394 __alloc_traits::propagate_on_container_swap::value>());}
395private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397 void __copy_assign_alloc(const __vector_base& __c, true_type)
398 {
399 if (__alloc() != __c.__alloc())
400 {
401 clear();
402 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
403 __begin_ = __end_ = __end_cap() = nullptr;
404 }
405 __alloc() = __c.__alloc();
406 }
407
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000409 void __copy_assign_alloc(const __vector_base& __c, false_type)
410 {}
411
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000413 void __move_assign_alloc(__vector_base& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000414 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000416 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417 }
418
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000420 void __move_assign_alloc(__vector_base& __c, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000421 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422 {}
423
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000425 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000426 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000428 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429 swap(__x, __y);
430 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000431 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432 static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000433 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434 {}
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, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441{
442 while (__new_last < __end_)
443 __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_));
444}
445
446template <class _Tp, class _Allocator>
447_LIBCPP_INLINE_VISIBILITY inline
448void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000449__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000450{
451 __end_ = const_cast<pointer>(__new_last);
452}
453
454template <class _Tp, class _Allocator>
455_LIBCPP_INLINE_VISIBILITY inline
456__vector_base<_Tp, _Allocator>::__vector_base()
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000457 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000458 : __begin_(0),
459 __end_(0),
460 __end_cap_(0)
461{
462}
463
464template <class _Tp, class _Allocator>
465_LIBCPP_INLINE_VISIBILITY inline
466__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
467 : __begin_(0),
468 __end_(0),
469 __end_cap_(0, __a)
470{
471}
472
473template <class _Tp, class _Allocator>
474__vector_base<_Tp, _Allocator>::~__vector_base()
475{
476 if (__begin_ != 0)
477 {
478 clear();
479 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
480 }
481}
482
483template <class _Tp, class _Allocator = allocator<_Tp> >
Howard Hinnant36cdf022010-09-10 16:42:26 +0000484class _LIBCPP_VISIBLE vector
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000485 : private __vector_base<_Tp, _Allocator>
486{
487private:
488 typedef __vector_base<_Tp, _Allocator> __base;
Howard Hinnant324bb032010-08-22 00:02:43 +0000489public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +0000491 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000492 typedef _Allocator allocator_type;
493 typedef typename __base::__alloc_traits __alloc_traits;
494 typedef typename __base::reference reference;
495 typedef typename __base::const_reference const_reference;
496 typedef typename __base::size_type size_type;
497 typedef typename __base::difference_type difference_type;
498 typedef typename __base::pointer pointer;
499 typedef typename __base::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500 typedef __wrap_iter<pointer> iterator;
501 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000502 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
503 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000505 _LIBCPP_INLINE_VISIBILITY
506 vector()
507 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant7a563db2011-09-14 18:33:51 +0000508 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000509#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000510 __get_db()->__insert_c(this);
511#endif
512 }
513 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
514 : __base(__a)
515 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000516#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000517 __get_db()->__insert_c(this);
518#endif
519 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520 explicit vector(size_type __n);
521 vector(size_type __n, const_reference __x);
522 vector(size_type __n, const_reference __x, const allocator_type& __a);
523 template <class _InputIterator>
524 vector(_InputIterator __first, _InputIterator __last,
525 typename enable_if<__is_input_iterator <_InputIterator>::value &&
526 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
527 template <class _InputIterator>
528 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
529 typename enable_if<__is_input_iterator <_InputIterator>::value &&
530 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
531 template <class _ForwardIterator>
532 vector(_ForwardIterator __first, _ForwardIterator __last,
533 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
534 template <class _ForwardIterator>
535 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
536 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02 +0000537#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539 vector(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000542#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantabe26282011-09-16 17:29:17 +0000543#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a563db2011-09-14 18:33:51 +0000545 ~vector()
546 {
547 __get_db()->__erase_c(this);
548 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549#endif
550
551 vector(const vector& __x);
552 vector(const vector& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000554 vector& operator=(const vector& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000555#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000557 vector(vector&& __x)
558 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560 vector(vector&& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000562 vector& operator=(vector&& __x)
563 _NOEXCEPT_(
564 __alloc_traits::propagate_on_container_move_assignment::value &&
565 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000566#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000567#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000569 vector& operator=(initializer_list<value_type> __il)
570 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000571#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572
573 template <class _InputIterator>
574 typename enable_if
575 <
576 __is_input_iterator <_InputIterator>::value &&
577 !__is_forward_iterator<_InputIterator>::value,
578 void
579 >::type
580 assign(_InputIterator __first, _InputIterator __last);
581 template <class _ForwardIterator>
582 typename enable_if
583 <
584 __is_forward_iterator<_ForwardIterator>::value,
585 void
586 >::type
587 assign(_ForwardIterator __first, _ForwardIterator __last);
588
589 void assign(size_type __n, const_reference __u);
Howard Hinnante3e32912011-08-12 21:56:02 +0000590#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000592 void assign(initializer_list<value_type> __il)
593 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000594#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000596 _LIBCPP_INLINE_VISIBILITY
597 allocator_type get_allocator() const _NOEXCEPT
598 {return this->__alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000600 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
601 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
602 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
603 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000605 _LIBCPP_INLINE_VISIBILITY
606 reverse_iterator rbegin() _NOEXCEPT
607 {return reverse_iterator(end());}
608 _LIBCPP_INLINE_VISIBILITY
609 const_reverse_iterator rbegin() const _NOEXCEPT
610 {return const_reverse_iterator(end());}
611 _LIBCPP_INLINE_VISIBILITY
612 reverse_iterator rend() _NOEXCEPT
613 {return reverse_iterator(begin());}
614 _LIBCPP_INLINE_VISIBILITY
615 const_reverse_iterator rend() const _NOEXCEPT
616 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000618 _LIBCPP_INLINE_VISIBILITY
619 const_iterator cbegin() const _NOEXCEPT
620 {return begin();}
621 _LIBCPP_INLINE_VISIBILITY
622 const_iterator cend() const _NOEXCEPT
623 {return end();}
624 _LIBCPP_INLINE_VISIBILITY
625 const_reverse_iterator crbegin() const _NOEXCEPT
626 {return rbegin();}
627 _LIBCPP_INLINE_VISIBILITY
628 const_reverse_iterator crend() const _NOEXCEPT
629 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000631 _LIBCPP_INLINE_VISIBILITY
632 size_type size() const _NOEXCEPT
633 {return static_cast<size_type>(this->__end_ - this->__begin_);}
634 _LIBCPP_INLINE_VISIBILITY
635 size_type capacity() const _NOEXCEPT
636 {return __base::capacity();}
637 _LIBCPP_INLINE_VISIBILITY
638 bool empty() const _NOEXCEPT
639 {return this->__begin_ == this->__end_;}
640 size_type max_size() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000642 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643
644 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
645 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
646 reference at(size_type __n);
647 const_reference at(size_type __n) const;
648
Howard Hinnant7a563db2011-09-14 18:33:51 +0000649 _LIBCPP_INLINE_VISIBILITY reference front()
650 {
651 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
652 return *this->__begin_;
653 }
654 _LIBCPP_INLINE_VISIBILITY const_reference front() const
655 {
656 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
657 return *this->__begin_;
658 }
659 _LIBCPP_INLINE_VISIBILITY reference back()
660 {
661 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
662 return *(this->__end_ - 1);
663 }
664 _LIBCPP_INLINE_VISIBILITY const_reference back() const
665 {
666 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
667 return *(this->__end_ - 1);
668 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000669
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000670 _LIBCPP_INLINE_VISIBILITY
671 value_type* data() _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000672 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000673 _LIBCPP_INLINE_VISIBILITY
674 const value_type* data() const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000675 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000677 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000678#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000680#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000681 template <class... _Args>
682 void emplace_back(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000683#endif // _LIBCPP_HAS_NO_VARIADICS
684#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000685 void pop_back();
686
687 iterator insert(const_iterator __position, const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000688#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689 iterator insert(const_iterator __position, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000690#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691 template <class... _Args>
692 iterator emplace(const_iterator __position, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000693#endif // _LIBCPP_HAS_NO_VARIADICS
694#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695 iterator insert(const_iterator __position, size_type __n, const_reference __x);
696 template <class _InputIterator>
697 typename enable_if
698 <
699 __is_input_iterator <_InputIterator>::value &&
700 !__is_forward_iterator<_InputIterator>::value,
701 iterator
702 >::type
703 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
704 template <class _ForwardIterator>
705 typename enable_if
706 <
707 __is_forward_iterator<_ForwardIterator>::value,
708 iterator
709 >::type
710 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000711#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 iterator insert(const_iterator __position, initializer_list<value_type> __il)
714 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000715#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000717 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 iterator erase(const_iterator __first, const_iterator __last);
719
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000720 _LIBCPP_INLINE_VISIBILITY
721 void clear() _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +0000722 {
723 __base::clear();
724 __invalidate_all_iterators();
725 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726
727 void resize(size_type __sz);
728 void resize(size_type __sz, const_reference __x);
729
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000730 void swap(vector&)
731 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
732 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000733
734 bool __invariants() const;
735
Howard Hinnantabe26282011-09-16 17:29:17 +0000736#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000737
738 bool __dereferenceable(const const_iterator* __i) const;
739 bool __decrementable(const const_iterator* __i) const;
740 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
741 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
742
Howard Hinnantabe26282011-09-16 17:29:17 +0000743#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000744
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000746 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000748 void deallocate() _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000749 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
Howard Hinnant04240d92011-01-04 19:53:31 +0000750 void __construct_at_end(size_type __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000751 void __construct_at_end(size_type __n, const_reference __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000752 template <class _ForwardIterator>
753 typename enable_if
754 <
755 __is_forward_iterator<_ForwardIterator>::value,
756 void
757 >::type
758 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
759 void __move_construct_at_end(pointer __first, pointer __last);
760 void __append(size_type __n);
761 void __append(size_type __n, const_reference __x);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000763 iterator __make_iter(pointer __p) _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000765 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
767 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
768 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000769 void __move_assign(vector& __c, true_type)
770 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771 void __move_assign(vector& __c, false_type);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000772 _LIBCPP_INLINE_VISIBILITY
773 void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
774 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000775#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000776 __c_node* __c = __get_db()->__find_c_and_lock(this);
777 for (__i_node** __p = __c->end_; __p != __c->beg_; )
778 {
779 --__p;
780 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
781 if (__i->base() > __new_last)
782 {
783 (*__p)->__c_ = nullptr;
784 if (--__c->end_ != __p)
785 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
786 }
787 }
788 __get_db()->unlock();
789#endif
790 __base::__destruct_at_end(__new_last);
791 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792};
793
794template <class _Tp, class _Allocator>
795void
796vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
797{
798 for (pointer __p = this->__end_; this->__begin_ < __p;)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000799 __v.push_front(_VSTD::move_if_noexcept(*--__p));
800 _VSTD::swap(this->__begin_, __v.__begin_);
801 _VSTD::swap(this->__end_, __v.__end_);
802 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 __v.__first_ = __v.__begin_;
804 __invalidate_all_iterators();
805}
806
807template <class _Tp, class _Allocator>
808typename vector<_Tp, _Allocator>::pointer
809vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
810{
811 pointer __r = __v.__begin_;
812 for (pointer __i = __p; this->__begin_ < __i;)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000813 __v.push_front(_VSTD::move_if_noexcept(*--__i));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000814 for (pointer __i = __p; __i < this->__end_; ++__i)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000815 __v.push_back(_VSTD::move_if_noexcept(*__i));
816 _VSTD::swap(this->__begin_, __v.__begin_);
817 _VSTD::swap(this->__end_, __v.__end_);
818 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819 __v.__first_ = __v.__begin_;
820 __invalidate_all_iterators();
821 return __r;
822}
823
824// Allocate space for __n objects
825// throws length_error if __n > max_size()
826// throws (probably bad_alloc) if memory run out
827// Precondition: __begin_ == __end_ == __end_cap() == 0
828// Precondition: __n > 0
829// Postcondition: capacity() == __n
830// Postcondition: size() == 0
831template <class _Tp, class _Allocator>
832void
833vector<_Tp, _Allocator>::allocate(size_type __n)
834{
835 if (__n > max_size())
836 this->__throw_length_error();
837 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
838 this->__end_cap() = this->__begin_ + __n;
839}
840
841template <class _Tp, class _Allocator>
842void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000843vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000844{
845 if (this->__begin_ != 0)
846 {
847 clear();
848 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 this->__begin_ = this->__end_ = this->__end_cap() = 0;
850 }
851}
852
853template <class _Tp, class _Allocator>
854typename vector<_Tp, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000855vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000856{
Sean Hunt110b8bf2011-07-29 23:31:58 +0000857 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 +0000858}
859
860// Precondition: __new_size > capacity()
861template <class _Tp, class _Allocator>
862_LIBCPP_INLINE_VISIBILITY inline
863typename vector<_Tp, _Allocator>::size_type
864vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
865{
866 const size_type __ms = max_size();
867 if (__new_size > __ms)
868 this->__throw_length_error();
869 const size_type __cap = capacity();
870 if (__cap >= __ms / 2)
871 return __ms;
Sean Hunt110b8bf2011-07-29 23:31:58 +0000872 return _VSTD::max<size_type>(2*__cap, __new_size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873}
874
875// Default constructs __n objects starting at __end_
876// throws if construction throws
877// Precondition: __n > 0
878// Precondition: size() + __n <= capacity()
879// Postcondition: size() == size() + __n
880template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881void
882vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
883{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000884 allocator_type& __a = this->__alloc();
885 do
886 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000887 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888 ++this->__end_;
889 --__n;
890 } while (__n > 0);
891}
892
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893// Copy constructs __n objects starting at __end_ from __x
894// throws if construction throws
895// Precondition: __n > 0
896// Precondition: size() + __n <= capacity()
897// Postcondition: size() == old size() + __n
898// Postcondition: [i] == __x for all i in [size() - __n, __n)
899template <class _Tp, class _Allocator>
900_LIBCPP_INLINE_VISIBILITY inline
901void
902vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
903{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000904 allocator_type& __a = this->__alloc();
905 do
906 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000907 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908 ++this->__end_;
909 --__n;
910 } while (__n > 0);
911}
912
913template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914template <class _ForwardIterator>
915typename enable_if
916<
917 __is_forward_iterator<_ForwardIterator>::value,
918 void
919>::type
920vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
921{
922 allocator_type& __a = this->__alloc();
923 for (; __first != __last; ++__first)
924 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000925 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000926 ++this->__end_;
927 }
928}
929
930template <class _Tp, class _Allocator>
931void
932vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
933{
934 allocator_type& __a = this->__alloc();
935 for (; __first != __last; ++__first)
936 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000937 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
938 _VSTD::move(*__first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000939 ++this->__end_;
940 }
941}
942
943// Default constructs __n objects starting at __end_
944// throws if construction throws
945// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000946// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947template <class _Tp, class _Allocator>
948void
949vector<_Tp, _Allocator>::__append(size_type __n)
950{
951 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
952 this->__construct_at_end(__n);
953 else
954 {
955 allocator_type& __a = this->__alloc();
956 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
957 __v.__construct_at_end(__n);
958 __swap_out_circular_buffer(__v);
959 }
960}
961
962// Default constructs __n objects starting at __end_
963// throws if construction throws
964// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000965// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000966template <class _Tp, class _Allocator>
967void
968vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
969{
970 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
971 this->__construct_at_end(__n, __x);
972 else
973 {
974 allocator_type& __a = this->__alloc();
975 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
976 __v.__construct_at_end(__n, __x);
977 __swap_out_circular_buffer(__v);
978 }
979}
980
981template <class _Tp, class _Allocator>
982vector<_Tp, _Allocator>::vector(size_type __n)
983{
Howard Hinnant0442b122011-09-16 18:41:29 +0000984#if _LIBCPP_DEBUG_LEVEL >= 2
985 __get_db()->__insert_c(this);
986#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987 if (__n > 0)
988 {
989 allocate(__n);
990 __construct_at_end(__n);
991 }
992}
993
994template <class _Tp, class _Allocator>
995vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
996{
Howard Hinnant0442b122011-09-16 18:41:29 +0000997#if _LIBCPP_DEBUG_LEVEL >= 2
998 __get_db()->__insert_c(this);
999#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001000 if (__n > 0)
1001 {
1002 allocate(__n);
1003 __construct_at_end(__n, __x);
1004 }
1005}
1006
1007template <class _Tp, class _Allocator>
1008vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1009 : __base(__a)
1010{
Howard Hinnant0442b122011-09-16 18:41:29 +00001011#if _LIBCPP_DEBUG_LEVEL >= 2
1012 __get_db()->__insert_c(this);
1013#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014 if (__n > 0)
1015 {
1016 allocate(__n);
1017 __construct_at_end(__n, __x);
1018 }
1019}
1020
1021template <class _Tp, class _Allocator>
1022template <class _InputIterator>
1023vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
1024 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1025 !__is_forward_iterator<_InputIterator>::value>::type*)
1026{
Howard Hinnantabe26282011-09-16 17:29:17 +00001027#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001028 __get_db()->__insert_c(this);
1029#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001030 for (; __first != __last; ++__first)
1031 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001032}
1033
1034template <class _Tp, class _Allocator>
1035template <class _InputIterator>
1036vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1037 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1038 !__is_forward_iterator<_InputIterator>::value>::type*)
1039 : __base(__a)
1040{
Howard Hinnantabe26282011-09-16 17:29:17 +00001041#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001042 __get_db()->__insert_c(this);
1043#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001044 for (; __first != __last; ++__first)
1045 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046}
1047
1048template <class _Tp, class _Allocator>
1049template <class _ForwardIterator>
1050vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
1051 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1052{
Howard Hinnant0442b122011-09-16 18:41:29 +00001053#if _LIBCPP_DEBUG_LEVEL >= 2
1054 __get_db()->__insert_c(this);
1055#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001056 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057 if (__n > 0)
1058 {
1059 allocate(__n);
1060 __construct_at_end(__first, __last);
1061 }
1062}
1063
1064template <class _Tp, class _Allocator>
1065template <class _ForwardIterator>
1066vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1067 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1068 : __base(__a)
1069{
Howard Hinnant0442b122011-09-16 18:41:29 +00001070#if _LIBCPP_DEBUG_LEVEL >= 2
1071 __get_db()->__insert_c(this);
1072#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001073 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001074 if (__n > 0)
1075 {
1076 allocate(__n);
1077 __construct_at_end(__first, __last);
1078 }
1079}
1080
1081template <class _Tp, class _Allocator>
1082vector<_Tp, _Allocator>::vector(const vector& __x)
1083 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1084{
Howard Hinnant0442b122011-09-16 18:41:29 +00001085#if _LIBCPP_DEBUG_LEVEL >= 2
1086 __get_db()->__insert_c(this);
1087#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088 size_type __n = __x.size();
1089 if (__n > 0)
1090 {
1091 allocate(__n);
1092 __construct_at_end(__x.__begin_, __x.__end_);
1093 }
1094}
1095
1096template <class _Tp, class _Allocator>
1097vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1098 : __base(__a)
1099{
Howard Hinnant0442b122011-09-16 18:41:29 +00001100#if _LIBCPP_DEBUG_LEVEL >= 2
1101 __get_db()->__insert_c(this);
1102#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001103 size_type __n = __x.size();
1104 if (__n > 0)
1105 {
1106 allocate(__n);
1107 __construct_at_end(__x.__begin_, __x.__end_);
1108 }
1109}
1110
Howard Hinnant73d21a42010-09-04 23:28:19 +00001111#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001112
1113template <class _Tp, class _Allocator>
1114_LIBCPP_INLINE_VISIBILITY inline
1115vector<_Tp, _Allocator>::vector(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001116 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001117 : __base(_VSTD::move(__x.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118{
Howard Hinnantabe26282011-09-16 17:29:17 +00001119#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001120 __get_db()->__insert_c(this);
Howard Hinnante6125bd2011-09-19 16:34:29 +00001121 __get_db()->swap(this, &__x);
Howard Hinnant7a563db2011-09-14 18:33:51 +00001122#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001123 this->__begin_ = __x.__begin_;
1124 this->__end_ = __x.__end_;
1125 this->__end_cap() = __x.__end_cap();
1126 __x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001127}
1128
1129template <class _Tp, class _Allocator>
1130_LIBCPP_INLINE_VISIBILITY inline
1131vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1132 : __base(__a)
1133{
Howard Hinnant0442b122011-09-16 18:41:29 +00001134#if _LIBCPP_DEBUG_LEVEL >= 2
1135 __get_db()->__insert_c(this);
1136#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001137 if (__a == __x.__alloc())
1138 {
1139 this->__begin_ = __x.__begin_;
1140 this->__end_ = __x.__end_;
1141 this->__end_cap() = __x.__end_cap();
1142 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001143#if _LIBCPP_DEBUG_LEVEL >= 2
1144 __get_db()->swap(this, &__x);
1145#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001146 }
1147 else
1148 {
Howard Hinnant99968442011-11-29 18:15:50 +00001149 typedef move_iterator<iterator> _Ip;
1150 assign(_Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151 }
1152}
1153
Howard Hinnante3e32912011-08-12 21:56:02 +00001154#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1155
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156template <class _Tp, class _Allocator>
1157_LIBCPP_INLINE_VISIBILITY inline
1158vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1159{
Howard Hinnant0442b122011-09-16 18:41:29 +00001160#if _LIBCPP_DEBUG_LEVEL >= 2
1161 __get_db()->__insert_c(this);
1162#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163 if (__il.size() > 0)
1164 {
1165 allocate(__il.size());
1166 __construct_at_end(__il.begin(), __il.end());
1167 }
1168}
1169
1170template <class _Tp, class _Allocator>
1171_LIBCPP_INLINE_VISIBILITY inline
1172vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1173 : __base(__a)
1174{
Howard Hinnant0442b122011-09-16 18:41:29 +00001175#if _LIBCPP_DEBUG_LEVEL >= 2
1176 __get_db()->__insert_c(this);
1177#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001178 if (__il.size() > 0)
1179 {
1180 allocate(__il.size());
1181 __construct_at_end(__il.begin(), __il.end());
1182 }
1183}
1184
Howard Hinnante3e32912011-08-12 21:56:02 +00001185#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1186
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001187template <class _Tp, class _Allocator>
1188_LIBCPP_INLINE_VISIBILITY inline
1189vector<_Tp, _Allocator>&
1190vector<_Tp, _Allocator>::operator=(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001191 _NOEXCEPT_(
1192 __alloc_traits::propagate_on_container_move_assignment::value &&
1193 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001194{
1195 __move_assign(__x, integral_constant<bool,
1196 __alloc_traits::propagate_on_container_move_assignment::value>());
1197 return *this;
1198}
1199
1200template <class _Tp, class _Allocator>
1201void
1202vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1203{
1204 if (__base::__alloc() != __c.__alloc())
1205 {
Howard Hinnant99968442011-11-29 18:15:50 +00001206 typedef move_iterator<iterator> _Ip;
1207 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001208 }
1209 else
1210 __move_assign(__c, true_type());
1211}
1212
1213template <class _Tp, class _Allocator>
1214void
1215vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001216 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001217{
1218 deallocate();
1219 this->__begin_ = __c.__begin_;
1220 this->__end_ = __c.__end_;
1221 this->__end_cap() = __c.__end_cap();
1222 __base::__move_assign_alloc(__c);
1223 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001224#if _LIBCPP_DEBUG_LEVEL >= 2
1225 __get_db()->swap(this, &__c);
1226#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227}
1228
Howard Hinnant73d21a42010-09-04 23:28:19 +00001229#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230
1231template <class _Tp, class _Allocator>
1232_LIBCPP_INLINE_VISIBILITY inline
1233vector<_Tp, _Allocator>&
1234vector<_Tp, _Allocator>::operator=(const vector& __x)
1235{
1236 if (this != &__x)
1237 {
1238 __base::__copy_assign_alloc(__x);
1239 assign(__x.__begin_, __x.__end_);
1240 }
1241 return *this;
1242}
1243
1244template <class _Tp, class _Allocator>
1245template <class _InputIterator>
1246typename enable_if
1247<
1248 __is_input_iterator <_InputIterator>::value &&
1249 !__is_forward_iterator<_InputIterator>::value,
1250 void
1251>::type
1252vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1253{
1254 clear();
1255 for (; __first != __last; ++__first)
1256 push_back(*__first);
1257}
1258
1259template <class _Tp, class _Allocator>
1260template <class _ForwardIterator>
1261typename enable_if
1262<
1263 __is_forward_iterator<_ForwardIterator>::value,
1264 void
1265>::type
1266vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1267{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001268 typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269 if (static_cast<size_type>(__new_size) <= capacity())
1270 {
1271 _ForwardIterator __mid = __last;
1272 bool __growing = false;
1273 if (static_cast<size_type>(__new_size) > size())
1274 {
1275 __growing = true;
1276 __mid = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001277 _VSTD::advance(__mid, size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001278 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001279 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001280 if (__growing)
1281 __construct_at_end(__mid, __last);
1282 else
1283 this->__destruct_at_end(__m);
1284 }
1285 else
1286 {
1287 deallocate();
1288 allocate(__recommend(static_cast<size_type>(__new_size)));
1289 __construct_at_end(__first, __last);
1290 }
1291}
1292
1293template <class _Tp, class _Allocator>
1294void
1295vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1296{
1297 if (__n <= capacity())
1298 {
1299 size_type __s = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001300 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001301 if (__n > __s)
1302 __construct_at_end(__n - __s, __u);
1303 else
Howard Hinnantadff4892010-05-24 17:49:41 +00001304 this->__destruct_at_end(this->__begin_ + __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305 }
1306 else
1307 {
1308 deallocate();
1309 allocate(__recommend(static_cast<size_type>(__n)));
1310 __construct_at_end(__n, __u);
1311 }
1312}
1313
Howard Hinnant324bb032010-08-22 00:02:43 +00001314template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001315_LIBCPP_INLINE_VISIBILITY inline
1316typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001317vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318{
Howard Hinnantabe26282011-09-16 17:29:17 +00001319#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001320 return iterator(this, __p);
1321#else
1322 return iterator(__p);
1323#endif
1324}
1325
Howard Hinnant324bb032010-08-22 00:02:43 +00001326template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001327_LIBCPP_INLINE_VISIBILITY inline
1328typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001329vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001330{
Howard Hinnantabe26282011-09-16 17:29:17 +00001331#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332 return const_iterator(this, __p);
1333#else
1334 return const_iterator(__p);
1335#endif
1336}
1337
Howard Hinnant324bb032010-08-22 00:02:43 +00001338template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001339_LIBCPP_INLINE_VISIBILITY inline
1340typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001341vector<_Tp, _Allocator>::begin() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001342{
1343 return __make_iter(this->__begin_);
1344}
1345
Howard Hinnant324bb032010-08-22 00:02:43 +00001346template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001347_LIBCPP_INLINE_VISIBILITY inline
1348typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001349vector<_Tp, _Allocator>::begin() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001350{
1351 return __make_iter(this->__begin_);
1352}
1353
Howard Hinnant324bb032010-08-22 00:02:43 +00001354template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001355_LIBCPP_INLINE_VISIBILITY inline
1356typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001357vector<_Tp, _Allocator>::end() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001358{
1359 return __make_iter(this->__end_);
1360}
1361
Howard Hinnant324bb032010-08-22 00:02:43 +00001362template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001363_LIBCPP_INLINE_VISIBILITY inline
1364typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001365vector<_Tp, _Allocator>::end() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001366{
1367 return __make_iter(this->__end_);
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>::reference
1373vector<_Tp, _Allocator>::operator[](size_type __n)
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 +00001380_LIBCPP_INLINE_VISIBILITY inline
1381typename vector<_Tp, _Allocator>::const_reference
1382vector<_Tp, _Allocator>::operator[](size_type __n) const
1383{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001384 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001385 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>::reference
1390vector<_Tp, _Allocator>::at(size_type __n)
1391{
1392 if (__n >= size())
1393 this->__throw_out_of_range();
1394 return this->__begin_[__n];
1395}
1396
Howard Hinnant324bb032010-08-22 00:02:43 +00001397template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001398typename vector<_Tp, _Allocator>::const_reference
1399vector<_Tp, _Allocator>::at(size_type __n) const
1400{
1401 if (__n >= size())
1402 this->__throw_out_of_range();
1403 return this->__begin_[__n];
1404}
1405
1406template <class _Tp, class _Allocator>
1407void
1408vector<_Tp, _Allocator>::reserve(size_type __n)
1409{
1410 if (__n > capacity())
1411 {
1412 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001413 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001414 __swap_out_circular_buffer(__v);
1415 }
1416}
1417
1418template <class _Tp, class _Allocator>
1419void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001420vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001421{
1422 if (capacity() > size())
1423 {
1424#ifndef _LIBCPP_NO_EXCEPTIONS
1425 try
1426 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001427#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001428 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001429 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430 __swap_out_circular_buffer(__v);
1431#ifndef _LIBCPP_NO_EXCEPTIONS
1432 }
1433 catch (...)
1434 {
1435 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001436#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437 }
1438}
1439
1440template <class _Tp, class _Allocator>
1441void
1442vector<_Tp, _Allocator>::push_back(const_reference __x)
1443{
1444 if (this->__end_ < this->__end_cap())
1445 {
1446 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001447 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001448 ++this->__end_;
1449 }
1450 else
1451 {
1452 allocator_type& __a = this->__alloc();
1453 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1454 __v.push_back(__x);
1455 __swap_out_circular_buffer(__v);
1456 }
1457}
1458
Howard Hinnant73d21a42010-09-04 23:28:19 +00001459#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001460
1461template <class _Tp, class _Allocator>
1462void
1463vector<_Tp, _Allocator>::push_back(value_type&& __x)
1464{
1465 if (this->__end_ < this->__end_cap())
1466 {
1467 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001468 _VSTD::__to_raw_pointer(this->__end_),
1469 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001470 ++this->__end_;
1471 }
1472 else
1473 {
1474 allocator_type& __a = this->__alloc();
1475 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001476 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477 __swap_out_circular_buffer(__v);
1478 }
1479}
1480
Howard Hinnant73d21a42010-09-04 23:28:19 +00001481#ifndef _LIBCPP_HAS_NO_VARIADICS
1482
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001483template <class _Tp, class _Allocator>
1484template <class... _Args>
1485void
1486vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1487{
1488 if (this->__end_ < this->__end_cap())
1489 {
1490 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001491 _VSTD::__to_raw_pointer(this->__end_),
1492 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493 ++this->__end_;
1494 }
1495 else
1496 {
1497 allocator_type& __a = this->__alloc();
1498 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001499 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500 __swap_out_circular_buffer(__v);
1501 }
1502}
1503
Howard Hinnant73d21a42010-09-04 23:28:19 +00001504#endif // _LIBCPP_HAS_NO_VARIADICS
1505#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506
1507template <class _Tp, class _Allocator>
1508_LIBCPP_INLINE_VISIBILITY inline
1509void
1510vector<_Tp, _Allocator>::pop_back()
1511{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001512 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513 this->__destruct_at_end(this->__end_ - 1);
1514}
1515
1516template <class _Tp, class _Allocator>
1517_LIBCPP_INLINE_VISIBILITY inline
1518typename vector<_Tp, _Allocator>::iterator
1519vector<_Tp, _Allocator>::erase(const_iterator __position)
1520{
Howard Hinnantabe26282011-09-16 17:29:17 +00001521#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001522 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1523 "vector::erase(iterator) called with an iterator not"
1524 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001525#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526 pointer __p = const_cast<pointer>(&*__position);
1527 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001528 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001529 return __r;
1530}
1531
1532template <class _Tp, class _Allocator>
1533typename vector<_Tp, _Allocator>::iterator
1534vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1535{
Howard Hinnantabe26282011-09-16 17:29:17 +00001536#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001537 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1538 "vector::erase(iterator, iterator) called with an iterator not"
1539 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001540#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001541 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001542 pointer __p = this->__begin_ + (__first - begin());
1543 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001544 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545 return __r;
1546}
1547
1548template <class _Tp, class _Allocator>
1549void
1550vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1551{
1552 pointer __old_last = this->__end_;
1553 difference_type __n = __old_last - __to;
1554 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1555 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001556 _VSTD::__to_raw_pointer(this->__end_),
1557 _VSTD::move(*__i));
1558 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001559}
1560
1561template <class _Tp, class _Allocator>
1562typename vector<_Tp, _Allocator>::iterator
1563vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1564{
Howard Hinnantabe26282011-09-16 17:29:17 +00001565#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001566 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1567 "vector::insert(iterator, x) called with an iterator not"
1568 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001569#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001570 pointer __p = this->__begin_ + (__position - begin());
1571 if (this->__end_ < this->__end_cap())
1572 {
1573 if (__p == this->__end_)
1574 {
1575 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001576 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001577 ++this->__end_;
1578 }
1579 else
1580 {
1581 __move_range(__p, this->__end_, __p + 1);
1582 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1583 if (__p <= __xr && __xr < this->__end_)
1584 ++__xr;
1585 *__p = *__xr;
1586 }
1587 }
1588 else
1589 {
1590 allocator_type& __a = this->__alloc();
1591 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1592 __v.push_back(__x);
1593 __p = __swap_out_circular_buffer(__v, __p);
1594 }
1595 return __make_iter(__p);
1596}
1597
Howard Hinnant73d21a42010-09-04 23:28:19 +00001598#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001599
1600template <class _Tp, class _Allocator>
1601typename vector<_Tp, _Allocator>::iterator
1602vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1603{
Howard Hinnantabe26282011-09-16 17:29:17 +00001604#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001605 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1606 "vector::insert(iterator, x) called with an iterator not"
1607 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001608#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609 pointer __p = this->__begin_ + (__position - begin());
1610 if (this->__end_ < this->__end_cap())
1611 {
1612 if (__p == this->__end_)
1613 {
1614 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001615 _VSTD::__to_raw_pointer(this->__end_),
1616 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001617 ++this->__end_;
1618 }
1619 else
1620 {
1621 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001622 *__p = _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001623 }
1624 }
1625 else
1626 {
1627 allocator_type& __a = this->__alloc();
1628 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001629 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001630 __p = __swap_out_circular_buffer(__v, __p);
1631 }
1632 return __make_iter(__p);
1633}
1634
Howard Hinnant73d21a42010-09-04 23:28:19 +00001635#ifndef _LIBCPP_HAS_NO_VARIADICS
1636
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001637template <class _Tp, class _Allocator>
1638template <class... _Args>
1639typename vector<_Tp, _Allocator>::iterator
1640vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1641{
Howard Hinnantabe26282011-09-16 17:29:17 +00001642#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001643 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1644 "vector::emplace(iterator, x) called with an iterator not"
1645 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001646#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647 pointer __p = this->__begin_ + (__position - begin());
1648 if (this->__end_ < this->__end_cap())
1649 {
1650 if (__p == this->__end_)
1651 {
1652 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001653 _VSTD::__to_raw_pointer(this->__end_),
1654 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655 ++this->__end_;
1656 }
1657 else
1658 {
1659 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001660 *__p = value_type(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001661 }
1662 }
1663 else
1664 {
1665 allocator_type& __a = this->__alloc();
1666 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001667 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001668 __p = __swap_out_circular_buffer(__v, __p);
1669 }
1670 return __make_iter(__p);
1671}
1672
Howard Hinnant73d21a42010-09-04 23:28:19 +00001673#endif // _LIBCPP_HAS_NO_VARIADICS
1674#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001675
1676template <class _Tp, class _Allocator>
1677typename vector<_Tp, _Allocator>::iterator
1678vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1679{
Howard Hinnantabe26282011-09-16 17:29:17 +00001680#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001681 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1682 "vector::insert(iterator, n, x) called with an iterator not"
1683 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001684#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001685 pointer __p = this->__begin_ + (__position - begin());
1686 if (__n > 0)
1687 {
1688 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1689 {
1690 size_type __old_n = __n;
1691 pointer __old_last = this->__end_;
1692 if (__n > static_cast<size_type>(this->__end_ - __p))
1693 {
1694 size_type __cx = __n - (this->__end_ - __p);
1695 __construct_at_end(__cx, __x);
1696 __n -= __cx;
1697 }
1698 if (__n > 0)
1699 {
1700 __move_range(__p, __old_last, __p + __old_n);
1701 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1702 if (__p <= __xr && __xr < this->__end_)
1703 __xr += __old_n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001704 _VSTD::fill_n(__p, __n, *__xr);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001705 }
1706 }
1707 else
1708 {
1709 allocator_type& __a = this->__alloc();
1710 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1711 __v.__construct_at_end(__n, __x);
1712 __p = __swap_out_circular_buffer(__v, __p);
1713 }
1714 }
1715 return __make_iter(__p);
1716}
1717
1718template <class _Tp, class _Allocator>
1719template <class _InputIterator>
1720typename enable_if
1721<
1722 __is_input_iterator <_InputIterator>::value &&
1723 !__is_forward_iterator<_InputIterator>::value,
1724 typename vector<_Tp, _Allocator>::iterator
1725>::type
1726vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1727{
Howard Hinnantabe26282011-09-16 17:29:17 +00001728#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001729 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1730 "vector::insert(iterator, range) called with an iterator not"
1731 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001732#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001733 difference_type __off = __position - begin();
1734 pointer __p = this->__begin_ + __off;
1735 allocator_type& __a = this->__alloc();
1736 pointer __old_last = this->__end_;
1737 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1738 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001739 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001740 *__first);
1741 ++this->__end_;
1742 }
1743 __split_buffer<value_type, allocator_type&> __v(__a);
1744 if (__first != __last)
1745 {
1746#ifndef _LIBCPP_NO_EXCEPTIONS
1747 try
1748 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001749#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001750 __v.__construct_at_end(__first, __last);
1751 difference_type __old_size = __old_last - this->__begin_;
1752 difference_type __old_p = __p - this->__begin_;
1753 reserve(__recommend(size() + __v.size()));
1754 __p = this->__begin_ + __old_p;
1755 __old_last = this->__begin_ + __old_size;
1756#ifndef _LIBCPP_NO_EXCEPTIONS
1757 }
1758 catch (...)
1759 {
1760 erase(__make_iter(__old_last), end());
1761 throw;
1762 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001763#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001764 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001765 __p = _VSTD::rotate(__p, __old_last, this->__end_);
Howard Hinnant0442b122011-09-16 18:41:29 +00001766 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1767 make_move_iterator(__v.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001768 return begin() + __off;
1769}
1770
1771template <class _Tp, class _Allocator>
1772template <class _ForwardIterator>
1773typename enable_if
1774<
1775 __is_forward_iterator<_ForwardIterator>::value,
1776 typename vector<_Tp, _Allocator>::iterator
1777>::type
1778vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1779{
Howard Hinnantabe26282011-09-16 17:29:17 +00001780#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001781 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1782 "vector::insert(iterator, range) called with an iterator not"
1783 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001784#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785 pointer __p = this->__begin_ + (__position - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00001786 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001787 if (__n > 0)
1788 {
1789 if (__n <= this->__end_cap() - this->__end_)
1790 {
1791 size_type __old_n = __n;
1792 pointer __old_last = this->__end_;
1793 _ForwardIterator __m = __last;
1794 difference_type __dx = this->__end_ - __p;
1795 if (__n > __dx)
1796 {
1797 __m = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001798 _VSTD::advance(__m, this->__end_ - __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799 __construct_at_end(__m, __last);
1800 __n = __dx;
1801 }
1802 if (__n > 0)
1803 {
1804 __move_range(__p, __old_last, __p + __old_n);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001805 _VSTD::copy(__first, __m, __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806 }
1807 }
1808 else
1809 {
1810 allocator_type& __a = this->__alloc();
1811 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1812 __v.__construct_at_end(__first, __last);
1813 __p = __swap_out_circular_buffer(__v, __p);
1814 }
1815 }
1816 return __make_iter(__p);
1817}
1818
1819template <class _Tp, class _Allocator>
1820void
1821vector<_Tp, _Allocator>::resize(size_type __sz)
1822{
1823 size_type __cs = size();
1824 if (__cs < __sz)
1825 this->__append(__sz - __cs);
1826 else if (__cs > __sz)
1827 this->__destruct_at_end(this->__begin_ + __sz);
1828}
1829
1830template <class _Tp, class _Allocator>
1831void
1832vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1833{
1834 size_type __cs = size();
1835 if (__cs < __sz)
1836 this->__append(__sz - __cs, __x);
1837 else if (__cs > __sz)
1838 this->__destruct_at_end(this->__begin_ + __sz);
1839}
1840
1841template <class _Tp, class _Allocator>
1842void
1843vector<_Tp, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001844 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1845 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001847 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
1848 this->__alloc() == __x.__alloc(),
1849 "vector::swap: Either propagate_on_container_swap must be true"
1850 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19 +00001851 _VSTD::swap(this->__begin_, __x.__begin_);
1852 _VSTD::swap(this->__end_, __x.__end_);
1853 _VSTD::swap(this->__end_cap(), __x.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001854 __base::__swap_alloc(this->__alloc(), __x.__alloc());
Howard Hinnantabe26282011-09-16 17:29:17 +00001855#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001856 __get_db()->swap(this, &__x);
Howard Hinnantabe26282011-09-16 17:29:17 +00001857#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858}
1859
Howard Hinnant324bb032010-08-22 00:02:43 +00001860template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861bool
1862vector<_Tp, _Allocator>::__invariants() const
1863{
1864 if (this->__begin_ == 0)
1865 {
1866 if (this->__end_ != 0 || this->__end_cap() != 0)
1867 return false;
1868 }
1869 else
1870 {
1871 if (this->__begin_ > this->__end_)
1872 return false;
1873 if (this->__begin_ == this->__end_cap())
1874 return false;
1875 if (this->__end_ > this->__end_cap())
1876 return false;
1877 }
1878 return true;
1879}
1880
Howard Hinnantabe26282011-09-16 17:29:17 +00001881#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001882
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001883template <class _Tp, class _Allocator>
Howard Hinnant7a563db2011-09-14 18:33:51 +00001884bool
1885vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
1886{
1887 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
1888}
1889
1890template <class _Tp, class _Allocator>
1891bool
1892vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
1893{
1894 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
1895}
1896
1897template <class _Tp, class _Allocator>
1898bool
1899vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
1900{
1901 const_pointer __p = __i->base() + __n;
1902 return this->__begin_ <= __p && __p <= this->__end_;
1903}
1904
1905template <class _Tp, class _Allocator>
1906bool
1907vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1908{
1909 const_pointer __p = __i->base() + __n;
1910 return this->__begin_ <= __p && __p < this->__end_;
1911}
1912
Howard Hinnantabe26282011-09-16 17:29:17 +00001913#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001914
1915template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001916_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001917void
1918vector<_Tp, _Allocator>::__invalidate_all_iterators()
1919{
Howard Hinnantabe26282011-09-16 17:29:17 +00001920#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001921 __get_db()->__invalidate_all(this);
Howard Hinnantabe26282011-09-16 17:29:17 +00001922#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001923}
1924
1925// vector<bool>
1926
1927template <class _Allocator> class vector<bool, _Allocator>;
1928
1929template <class _Allocator> struct hash<vector<bool, _Allocator> >;
1930
1931template <class _Allocator>
Howard Hinnantf03c3b42011-07-02 20:33:23 +00001932struct __has_storage_type<vector<bool, _Allocator> >
1933{
1934 static const bool value = true;
1935};
1936
1937template <class _Allocator>
Howard Hinnant36cdf022010-09-10 16:42:26 +00001938class _LIBCPP_VISIBLE vector<bool, _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001939 : private __vector_base_common<true>
1940{
1941public:
1942 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +00001943 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001944 typedef _Allocator allocator_type;
1945 typedef allocator_traits<allocator_type> __alloc_traits;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946 typedef typename __alloc_traits::size_type size_type;
1947 typedef typename __alloc_traits::difference_type difference_type;
1948 typedef __bit_iterator<vector, false> pointer;
1949 typedef __bit_iterator<vector, true> const_pointer;
1950#ifdef _LIBCPP_DEBUG
1951 typedef __debug_iter<vector, pointer> iterator;
1952 typedef __debug_iter<vector, const_pointer> const_iterator;
1953
1954 friend class __debug_iter<vector, pointer>;
1955 friend class __debug_iter<vector, const_pointer>;
1956
1957 pair<iterator*, const_iterator*> __iterator_list_;
1958
1959 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1960 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
Howard Hinnant324bb032010-08-22 00:02:43 +00001961#else // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962 typedef pointer iterator;
1963 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001964#endif // _LIBCPP_DEBUG
Howard Hinnant0949eed2011-06-30 21:18:19 +00001965 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1966 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001967
1968private:
1969 typedef size_type __storage_type;
1970 typedef typename __alloc_traits::template
1971#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1972 rebind_alloc<__storage_type>
1973#else
1974 rebind_alloc<__storage_type>::other
1975#endif
1976 __storage_allocator;
1977 typedef allocator_traits<__storage_allocator> __storage_traits;
1978 typedef typename __storage_traits::pointer __storage_pointer;
1979 typedef typename __storage_traits::const_pointer __const_storage_pointer;
1980
1981 __storage_pointer __begin_;
1982 size_type __size_;
1983 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00001984public:
Howard Hinnantf03c3b42011-07-02 20:33:23 +00001985 typedef __bit_reference<vector> reference;
1986 typedef __bit_const_reference<vector> const_reference;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00001987private:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001988 _LIBCPP_INLINE_VISIBILITY
1989 size_type& __cap() _NOEXCEPT
1990 {return __cap_alloc_.first();}
1991 _LIBCPP_INLINE_VISIBILITY
1992 const size_type& __cap() const _NOEXCEPT
1993 {return __cap_alloc_.first();}
1994 _LIBCPP_INLINE_VISIBILITY
1995 __storage_allocator& __alloc() _NOEXCEPT
1996 {return __cap_alloc_.second();}
1997 _LIBCPP_INLINE_VISIBILITY
1998 const __storage_allocator& __alloc() const _NOEXCEPT
1999 {return __cap_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002000
2001 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2002
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002003 _LIBCPP_INLINE_VISIBILITY
2004 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002005 {return __n * __bits_per_word;}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002006 _LIBCPP_INLINE_VISIBILITY
2007 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002008 {return (__n - 1) / __bits_per_word + 1;}
2009
2010public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002011 _LIBCPP_INLINE_VISIBILITY
2012 vector()
2013 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002014 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002015 ~vector();
2016 explicit vector(size_type __n);
2017 vector(size_type __n, const value_type& __v);
2018 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2019 template <class _InputIterator>
2020 vector(_InputIterator __first, _InputIterator __last,
2021 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2022 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2023 template <class _InputIterator>
2024 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2025 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2026 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2027 template <class _ForwardIterator>
2028 vector(_ForwardIterator __first, _ForwardIterator __last,
2029 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2030 template <class _ForwardIterator>
2031 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2032 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2033
2034 vector(const vector& __v);
2035 vector(const vector& __v, const allocator_type& __a);
2036 vector& operator=(const vector& __v);
Howard Hinnante3e32912011-08-12 21:56:02 +00002037#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002038 vector(initializer_list<value_type> __il);
2039 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00002040#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002041
Howard Hinnant73d21a42010-09-04 23:28:19 +00002042#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002043 _LIBCPP_INLINE_VISIBILITY
2044 vector(vector&& __v)
2045 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002046 vector(vector&& __v, const allocator_type& __a);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002047 _LIBCPP_INLINE_VISIBILITY
2048 vector& operator=(vector&& __v)
2049 _NOEXCEPT_(
2050 __alloc_traits::propagate_on_container_move_assignment::value &&
2051 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002052#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00002053#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002055 vector& operator=(initializer_list<value_type> __il)
2056 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00002057#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002058
2059 template <class _InputIterator>
2060 typename enable_if
2061 <
2062 __is_input_iterator<_InputIterator>::value &&
2063 !__is_forward_iterator<_InputIterator>::value,
2064 void
2065 >::type
2066 assign(_InputIterator __first, _InputIterator __last);
2067 template <class _ForwardIterator>
2068 typename enable_if
2069 <
2070 __is_forward_iterator<_ForwardIterator>::value,
2071 void
2072 >::type
2073 assign(_ForwardIterator __first, _ForwardIterator __last);
2074
2075 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:02 +00002076#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002078 void assign(initializer_list<value_type> __il)
2079 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002080#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002081
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002082 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002083 {return allocator_type(this->__alloc());}
2084
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002085 size_type max_size() const _NOEXCEPT;
2086 _LIBCPP_INLINE_VISIBILITY
2087 size_type capacity() const _NOEXCEPT
2088 {return __internal_cap_to_external(__cap());}
2089 _LIBCPP_INLINE_VISIBILITY
2090 size_type size() const _NOEXCEPT
2091 {return __size_;}
2092 _LIBCPP_INLINE_VISIBILITY
2093 bool empty() const _NOEXCEPT
2094 {return __size_ == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002096 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002097
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002098 _LIBCPP_INLINE_VISIBILITY
2099 iterator begin() _NOEXCEPT
2100 {return __make_iter(0);}
2101 _LIBCPP_INLINE_VISIBILITY
2102 const_iterator begin() const _NOEXCEPT
2103 {return __make_iter(0);}
2104 _LIBCPP_INLINE_VISIBILITY
2105 iterator end() _NOEXCEPT
2106 {return __make_iter(__size_);}
2107 _LIBCPP_INLINE_VISIBILITY
2108 const_iterator end() const _NOEXCEPT
2109 {return __make_iter(__size_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002110
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002111 _LIBCPP_INLINE_VISIBILITY
2112 reverse_iterator rbegin() _NOEXCEPT
2113 {return reverse_iterator(end());}
2114 _LIBCPP_INLINE_VISIBILITY
2115 const_reverse_iterator rbegin() const _NOEXCEPT
2116 {return const_reverse_iterator(end());}
2117 _LIBCPP_INLINE_VISIBILITY
2118 reverse_iterator rend() _NOEXCEPT
2119 {return reverse_iterator(begin());}
2120 _LIBCPP_INLINE_VISIBILITY
2121 const_reverse_iterator rend() const _NOEXCEPT
2122 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002123
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002124 _LIBCPP_INLINE_VISIBILITY
2125 const_iterator cbegin() const _NOEXCEPT
2126 {return __make_iter(0);}
2127 _LIBCPP_INLINE_VISIBILITY
2128 const_iterator cend() const _NOEXCEPT
2129 {return __make_iter(__size_);}
2130 _LIBCPP_INLINE_VISIBILITY
2131 const_reverse_iterator crbegin() const _NOEXCEPT
2132 {return rbegin();}
2133 _LIBCPP_INLINE_VISIBILITY
2134 const_reverse_iterator crend() const _NOEXCEPT
2135 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002136
2137 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2138 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2139 reference at(size_type __n);
2140 const_reference at(size_type __n) const;
2141
2142 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2143 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2144 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2145 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2146
2147 void push_back(const value_type& __x);
2148 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2149
2150 iterator insert(const_iterator __position, const value_type& __x);
2151 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2152 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2153 template <class _InputIterator>
2154 typename enable_if
2155 <
2156 __is_input_iterator <_InputIterator>::value &&
2157 !__is_forward_iterator<_InputIterator>::value,
2158 iterator
2159 >::type
2160 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2161 template <class _ForwardIterator>
2162 typename enable_if
2163 <
2164 __is_forward_iterator<_ForwardIterator>::value,
2165 iterator
2166 >::type
2167 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00002168#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002170 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2171 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002172#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002173
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002174 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002175 iterator erase(const_iterator __first, const_iterator __last);
2176
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002177 _LIBCPP_INLINE_VISIBILITY
2178 void clear() _NOEXCEPT {__size_ = 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002179
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002180 void swap(vector&)
2181 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2182 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002183
2184 void resize(size_type __sz, value_type __x = false);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002185 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186
2187 bool __invariants() const;
2188
2189private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002190 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002191 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002192 void deallocate() _NOEXCEPT;
2193 _LIBCPP_INLINE_VISIBILITY
2194 static size_type __align(size_type __new_size) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002195 {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);};
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002196 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2197 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002198 template <class _ForwardIterator>
2199 typename enable_if
2200 <
2201 __is_forward_iterator<_ForwardIterator>::value,
2202 void
2203 >::type
2204 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2205 void __append(size_type __n, const_reference __x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002206 _LIBCPP_INLINE_VISIBILITY
2207 reference __make_ref(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002208 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002209 _LIBCPP_INLINE_VISIBILITY
2210 const_reference __make_ref(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002211 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2212#ifdef _LIBCPP_DEBUG
2213 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos)
2214 {return iterator(this, pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2215 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const
2216 {return const_iterator(this, const_pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2217 _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p)
2218 {return iterator(this, pointer(const_cast<__storage_pointer>(__p.base().__seg_), __p.base().__ctz_));}
Howard Hinnant324bb032010-08-22 00:02:43 +00002219#else // _LIBCPP_DEBUG
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002220 _LIBCPP_INLINE_VISIBILITY
2221 iterator __make_iter(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002222 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002223 _LIBCPP_INLINE_VISIBILITY
2224 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002225 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002226 _LIBCPP_INLINE_VISIBILITY
2227 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002228 {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);}
Howard Hinnant324bb032010-08-22 00:02:43 +00002229#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002230
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002232 void __copy_assign_alloc(const vector& __v)
2233 {__copy_assign_alloc(__v, integral_constant<bool,
2234 __storage_traits::propagate_on_container_copy_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002236 void __copy_assign_alloc(const vector& __c, true_type)
2237 {
2238 if (__alloc() != __c.__alloc())
2239 deallocate();
2240 __alloc() = __c.__alloc();
2241 }
2242
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002243 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002244 void __copy_assign_alloc(const vector& __c, false_type)
2245 {}
2246
2247 void __move_assign(vector& __c, false_type);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002248 void __move_assign(vector& __c, true_type)
2249 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002251 void __move_assign_alloc(vector& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002252 _NOEXCEPT_(
2253 !__storage_traits::propagate_on_container_move_assignment::value ||
2254 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002255 {__move_assign_alloc(__c, integral_constant<bool,
2256 __storage_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00002258 void __move_assign_alloc(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002259 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002260 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002261 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002262 }
2263
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00002265 void __move_assign_alloc(vector& __c, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002266 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002267 {}
2268
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002270 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002271 _NOEXCEPT_(
2272 !__storage_traits::propagate_on_container_swap::value ||
2273 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002274 {__swap_alloc(__x, __y, integral_constant<bool,
2275 __storage_traits::propagate_on_container_swap::value>());}
2276
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002278 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002279 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002280 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002281 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002282 swap(__x, __y);
2283 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002285 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002286 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002287 {}
2288
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002289 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002290
2291 friend class __bit_reference<vector>;
2292 friend class __bit_const_reference<vector>;
2293 friend class __bit_iterator<vector, false>;
2294 friend class __bit_iterator<vector, true>;
2295 friend class __bit_array<vector>;
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002296 friend struct _LIBCPP_VISIBLE hash<vector>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002297};
2298
2299template <class _Allocator>
2300#ifndef _LIBCPP_DEBUG
2301_LIBCPP_INLINE_VISIBILITY inline
2302#endif
2303void
2304vector<bool, _Allocator>::__invalidate_all_iterators()
2305{
2306#ifdef _LIBCPP_DEBUG
2307 iterator::__remove_all(this);
2308 const_iterator::__remove_all(this);
Howard Hinnant324bb032010-08-22 00:02:43 +00002309#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002310}
2311
2312// Allocate space for __n objects
2313// throws length_error if __n > max_size()
2314// throws (probably bad_alloc) if memory run out
2315// Precondition: __begin_ == __end_ == __cap() == 0
2316// Precondition: __n > 0
2317// Postcondition: capacity() == __n
2318// Postcondition: size() == 0
2319template <class _Allocator>
2320void
2321vector<bool, _Allocator>::allocate(size_type __n)
2322{
2323 if (__n > max_size())
2324 this->__throw_length_error();
2325 __n = __external_cap_to_internal(__n);
2326 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2327 this->__size_ = 0;
2328 this->__cap() = __n;
2329}
2330
2331template <class _Allocator>
2332void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002333vector<bool, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002334{
2335 if (this->__begin_ != 0)
2336 {
2337 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2338 __invalidate_all_iterators();
2339 this->__begin_ = 0;
2340 this->__size_ = this->__cap() = 0;
2341 }
2342}
2343
2344template <class _Allocator>
2345typename vector<bool, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002346vector<bool, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002347{
2348 size_type __amax = __storage_traits::max_size(__alloc());
2349 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2350 if (__nmax / __bits_per_word <= __amax)
2351 return __nmax;
2352 return __internal_cap_to_external(__amax);
2353}
2354
2355// Precondition: __new_size > capacity()
2356template <class _Allocator>
2357_LIBCPP_INLINE_VISIBILITY inline
2358typename vector<bool, _Allocator>::size_type
2359vector<bool, _Allocator>::__recommend(size_type __new_size) const
2360{
2361 const size_type __ms = max_size();
2362 if (__new_size > __ms)
2363 this->__throw_length_error();
2364 const size_type __cap = capacity();
2365 if (__cap >= __ms / 2)
2366 return __ms;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002367 return _VSTD::max(2*__cap, __align(__new_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002368}
2369
2370// Default constructs __n objects starting at __end_
2371// Precondition: __n > 0
2372// Precondition: size() + __n <= capacity()
2373// Postcondition: size() == size() + __n
2374template <class _Allocator>
2375_LIBCPP_INLINE_VISIBILITY inline
2376void
2377vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2378{
2379 size_type __old_size = this->__size_;
2380 this->__size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002381 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002382}
2383
2384template <class _Allocator>
2385template <class _ForwardIterator>
2386typename enable_if
2387<
2388 __is_forward_iterator<_ForwardIterator>::value,
2389 void
2390>::type
2391vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2392{
2393 size_type __old_size = this->__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002394 this->__size_ += _VSTD::distance(__first, __last);
2395 _VSTD::copy(__first, __last, __make_iter(__old_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002396}
2397
2398template <class _Allocator>
2399_LIBCPP_INLINE_VISIBILITY inline
2400vector<bool, _Allocator>::vector()
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002401 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002402 : __begin_(0),
2403 __size_(0),
2404 __cap_alloc_(0)
2405{
2406}
2407
2408template <class _Allocator>
2409_LIBCPP_INLINE_VISIBILITY inline
2410vector<bool, _Allocator>::vector(const allocator_type& __a)
2411 : __begin_(0),
2412 __size_(0),
2413 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2414{
2415}
2416
2417template <class _Allocator>
2418vector<bool, _Allocator>::vector(size_type __n)
2419 : __begin_(0),
2420 __size_(0),
2421 __cap_alloc_(0)
2422{
2423 if (__n > 0)
2424 {
2425 allocate(__n);
2426 __construct_at_end(__n, false);
2427 }
2428}
2429
2430template <class _Allocator>
2431vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2432 : __begin_(0),
2433 __size_(0),
2434 __cap_alloc_(0)
2435{
2436 if (__n > 0)
2437 {
2438 allocate(__n);
2439 __construct_at_end(__n, __x);
2440 }
2441}
2442
2443template <class _Allocator>
2444vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2445 : __begin_(0),
2446 __size_(0),
2447 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2448{
2449 if (__n > 0)
2450 {
2451 allocate(__n);
2452 __construct_at_end(__n, __x);
2453 }
2454}
2455
2456template <class _Allocator>
2457template <class _InputIterator>
2458vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2459 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2460 !__is_forward_iterator<_InputIterator>::value>::type*)
2461 : __begin_(0),
2462 __size_(0),
2463 __cap_alloc_(0)
2464{
2465#ifndef _LIBCPP_NO_EXCEPTIONS
2466 try
2467 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002468#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002469 for (; __first != __last; ++__first)
2470 push_back(*__first);
2471#ifndef _LIBCPP_NO_EXCEPTIONS
2472 }
2473 catch (...)
2474 {
2475 if (__begin_ != 0)
2476 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2477 __invalidate_all_iterators();
2478 throw;
2479 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002480#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002481}
2482
2483template <class _Allocator>
2484template <class _InputIterator>
2485vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2486 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2487 !__is_forward_iterator<_InputIterator>::value>::type*)
2488 : __begin_(0),
2489 __size_(0),
2490 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2491{
2492#ifndef _LIBCPP_NO_EXCEPTIONS
2493 try
2494 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002495#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002496 for (; __first != __last; ++__first)
2497 push_back(*__first);
2498#ifndef _LIBCPP_NO_EXCEPTIONS
2499 }
2500 catch (...)
2501 {
2502 if (__begin_ != 0)
2503 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2504 __invalidate_all_iterators();
2505 throw;
2506 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002507#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002508}
2509
2510template <class _Allocator>
2511template <class _ForwardIterator>
2512vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2513 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2514 : __begin_(0),
2515 __size_(0),
2516 __cap_alloc_(0)
2517{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002518 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002519 if (__n > 0)
2520 {
2521 allocate(__n);
2522 __construct_at_end(__first, __last);
2523 }
2524}
2525
2526template <class _Allocator>
2527template <class _ForwardIterator>
2528vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2529 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2530 : __begin_(0),
2531 __size_(0),
2532 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2533{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002534 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002535 if (__n > 0)
2536 {
2537 allocate(__n);
2538 __construct_at_end(__first, __last);
2539 }
2540}
2541
Howard Hinnante3e32912011-08-12 21:56:02 +00002542#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2543
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002544template <class _Allocator>
2545vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2546 : __begin_(0),
2547 __size_(0),
2548 __cap_alloc_(0)
2549{
2550 size_type __n = static_cast<size_type>(__il.size());
2551 if (__n > 0)
2552 {
2553 allocate(__n);
2554 __construct_at_end(__il.begin(), __il.end());
2555 }
2556}
2557
2558template <class _Allocator>
2559vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2560 : __begin_(0),
2561 __size_(0),
2562 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2563{
2564 size_type __n = static_cast<size_type>(__il.size());
2565 if (__n > 0)
2566 {
2567 allocate(__n);
2568 __construct_at_end(__il.begin(), __il.end());
2569 }
2570}
2571
Howard Hinnante3e32912011-08-12 21:56:02 +00002572#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2573
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002574template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002575vector<bool, _Allocator>::~vector()
2576{
2577 if (__begin_ != 0)
2578 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2579#ifdef _LIBCPP_DEBUG
2580 __invalidate_all_iterators();
2581#endif
2582}
2583
2584template <class _Allocator>
2585vector<bool, _Allocator>::vector(const vector& __v)
2586 : __begin_(0),
2587 __size_(0),
2588 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2589{
2590 if (__v.size() > 0)
2591 {
2592 allocate(__v.size());
2593 __construct_at_end(__v.begin(), __v.end());
2594 }
2595}
2596
2597template <class _Allocator>
2598vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2599 : __begin_(0),
2600 __size_(0),
2601 __cap_alloc_(0, __a)
2602{
2603 if (__v.size() > 0)
2604 {
2605 allocate(__v.size());
2606 __construct_at_end(__v.begin(), __v.end());
2607 }
2608}
2609
2610template <class _Allocator>
2611vector<bool, _Allocator>&
2612vector<bool, _Allocator>::operator=(const vector& __v)
2613{
2614 if (this != &__v)
2615 {
2616 __copy_assign_alloc(__v);
2617 if (__v.__size_)
2618 {
2619 if (__v.__size_ > capacity())
2620 {
2621 deallocate();
2622 allocate(__v.__size_);
2623 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002624 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002625 }
2626 __size_ = __v.__size_;
2627 }
2628 return *this;
2629}
2630
Howard Hinnant73d21a42010-09-04 23:28:19 +00002631#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2632
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002633template <class _Allocator>
2634_LIBCPP_INLINE_VISIBILITY inline
2635vector<bool, _Allocator>::vector(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002636 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002637 : __begin_(__v.__begin_),
2638 __size_(__v.__size_),
2639 __cap_alloc_(__v.__cap_alloc_)
2640{
2641 __v.__begin_ = 0;
2642 __v.__size_ = 0;
2643 __v.__cap() = 0;
2644}
2645
2646template <class _Allocator>
2647vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2648 : __begin_(0),
2649 __size_(0),
2650 __cap_alloc_(0, __a)
2651{
2652 if (__a == allocator_type(__v.__alloc()))
2653 {
2654 this->__begin_ = __v.__begin_;
2655 this->__size_ = __v.__size_;
2656 this->__cap() = __v.__cap();
2657 __v.__begin_ = nullptr;
2658 __v.__cap() = __v.__size_ = 0;
2659 }
2660 else if (__v.size() > 0)
2661 {
2662 allocate(__v.size());
2663 __construct_at_end(__v.begin(), __v.end());
2664 }
2665}
2666
2667template <class _Allocator>
2668_LIBCPP_INLINE_VISIBILITY inline
2669vector<bool, _Allocator>&
2670vector<bool, _Allocator>::operator=(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002671 _NOEXCEPT_(
2672 __alloc_traits::propagate_on_container_move_assignment::value &&
2673 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002674{
2675 __move_assign(__v, integral_constant<bool,
2676 __storage_traits::propagate_on_container_move_assignment::value>());
2677}
2678
2679template <class _Allocator>
2680void
2681vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2682{
2683 if (__alloc() != __c.__alloc())
2684 assign(__c.begin(), __c.end());
2685 else
2686 __move_assign(__c, true_type());
2687}
2688
2689template <class _Allocator>
2690void
2691vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002692 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002693{
2694 deallocate();
2695 this->__begin_ = __c.__begin_;
2696 this->__size_ = __c.__size_;
2697 this->__cap() = __c.__cap();
2698 __move_assign_alloc(__c);
2699 __c.__begin_ = nullptr;
2700 __c.__cap() = __c.__size_ = 0;
2701}
Howard Hinnant73d21a42010-09-04 23:28:19 +00002702
2703#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002704
2705template <class _Allocator>
2706void
2707vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2708{
2709 __size_ = 0;
2710 if (__n > 0)
2711 {
2712 size_type __c = capacity();
2713 if (__n <= __c)
2714 __size_ = __n;
2715 else
2716 {
2717 vector __v(__alloc());
2718 __v.reserve(__recommend(__n));
2719 __v.__size_ = __n;
2720 swap(__v);
2721 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002722 _VSTD::fill_n(begin(), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002723 }
2724}
2725
2726template <class _Allocator>
2727template <class _InputIterator>
2728typename enable_if
2729<
2730 __is_input_iterator<_InputIterator>::value &&
2731 !__is_forward_iterator<_InputIterator>::value,
2732 void
2733>::type
2734vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2735{
2736 clear();
2737 for (; __first != __last; ++__first)
2738 push_back(*__first);
2739}
2740
2741template <class _Allocator>
2742template <class _ForwardIterator>
2743typename enable_if
2744<
2745 __is_forward_iterator<_ForwardIterator>::value,
2746 void
2747>::type
2748vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2749{
2750 clear();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002751 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002752 if (__n)
2753 {
2754 if (__n > capacity())
2755 {
2756 deallocate();
2757 allocate(__n);
2758 }
2759 __construct_at_end(__first, __last);
2760 }
2761}
2762
2763template <class _Allocator>
2764void
2765vector<bool, _Allocator>::reserve(size_type __n)
2766{
2767 if (__n > capacity())
2768 {
2769 vector __v(this->__alloc());
2770 __v.allocate(__n);
2771 __v.__construct_at_end(this->begin(), this->end());
2772 swap(__v);
2773 __invalidate_all_iterators();
2774 }
2775}
2776
2777template <class _Allocator>
2778void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002779vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002780{
2781 if (__external_cap_to_internal(size()) > __cap())
2782 {
2783#ifndef _LIBCPP_NO_EXCEPTIONS
2784 try
2785 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002786#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002787 vector(*this, allocator_type(__alloc())).swap(*this);
2788#ifndef _LIBCPP_NO_EXCEPTIONS
2789 }
2790 catch (...)
2791 {
2792 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002793#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002794 }
2795}
2796
2797template <class _Allocator>
2798typename vector<bool, _Allocator>::reference
2799vector<bool, _Allocator>::at(size_type __n)
2800{
2801 if (__n >= size())
2802 this->__throw_out_of_range();
2803 return (*this)[__n];
2804}
2805
2806template <class _Allocator>
2807typename vector<bool, _Allocator>::const_reference
2808vector<bool, _Allocator>::at(size_type __n) const
2809{
2810 if (__n >= size())
2811 this->__throw_out_of_range();
2812 return (*this)[__n];
2813}
2814
2815template <class _Allocator>
2816void
2817vector<bool, _Allocator>::push_back(const value_type& __x)
2818{
2819 if (this->__size_ == this->capacity())
2820 reserve(__recommend(this->__size_ + 1));
2821 ++this->__size_;
2822 back() = __x;
2823}
2824
2825template <class _Allocator>
2826typename vector<bool, _Allocator>::iterator
2827vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2828{
2829 iterator __r;
2830 if (size() < capacity())
2831 {
2832 const_iterator __old_end = end();
2833 ++__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002834 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002835 __r = __const_iterator_cast(__position);
2836 }
2837 else
2838 {
2839 vector __v(__alloc());
2840 __v.reserve(__recommend(__size_ + 1));
2841 __v.__size_ = __size_ + 1;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002842 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2843 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002844 swap(__v);
2845 }
2846 *__r = __x;
2847 return __r;
2848}
2849
2850template <class _Allocator>
2851typename vector<bool, _Allocator>::iterator
2852vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
2853{
2854 iterator __r;
2855 size_type __c = capacity();
2856 if (__n <= __c && size() <= __c - __n)
2857 {
2858 const_iterator __old_end = end();
2859 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002860 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002861 __r = __const_iterator_cast(__position);
2862 }
2863 else
2864 {
2865 vector __v(__alloc());
2866 __v.reserve(__recommend(__size_ + __n));
2867 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002868 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2869 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002870 swap(__v);
2871 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002872 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873 return __r;
2874}
2875
2876template <class _Allocator>
2877template <class _InputIterator>
2878typename enable_if
2879<
2880 __is_input_iterator <_InputIterator>::value &&
2881 !__is_forward_iterator<_InputIterator>::value,
2882 typename vector<bool, _Allocator>::iterator
2883>::type
2884vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
2885{
2886 difference_type __off = __position - begin();
2887 iterator __p = __const_iterator_cast(__position);
2888 iterator __old_end = end();
2889 for (; size() != capacity() && __first != __last; ++__first)
2890 {
2891 ++this->__size_;
2892 back() = *__first;
2893 }
2894 vector __v(__alloc());
2895 if (__first != __last)
2896 {
2897#ifndef _LIBCPP_NO_EXCEPTIONS
2898 try
2899 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002900#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002901 __v.assign(__first, __last);
2902 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
2903 difference_type __old_p = __p - begin();
2904 reserve(__recommend(size() + __v.size()));
2905 __p = begin() + __old_p;
2906 __old_end = begin() + __old_size;
2907#ifndef _LIBCPP_NO_EXCEPTIONS
2908 }
2909 catch (...)
2910 {
2911 erase(__old_end, end());
2912 throw;
2913 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002914#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002915 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002916 __p = _VSTD::rotate(__p, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002917 insert(__p, __v.begin(), __v.end());
2918 return begin() + __off;
2919}
2920
2921template <class _Allocator>
2922template <class _ForwardIterator>
2923typename enable_if
2924<
2925 __is_forward_iterator<_ForwardIterator>::value,
2926 typename vector<bool, _Allocator>::iterator
2927>::type
2928vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
2929{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002930 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002931 iterator __r;
2932 size_type __c = capacity();
2933 if (__n <= __c && size() <= __c - __n)
2934 {
2935 const_iterator __old_end = end();
2936 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002937 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002938 __r = __const_iterator_cast(__position);
2939 }
2940 else
2941 {
2942 vector __v(__alloc());
2943 __v.reserve(__recommend(__size_ + __n));
2944 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002945 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2946 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002947 swap(__v);
2948 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002949 _VSTD::copy(__first, __last, __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002950 return __r;
2951}
2952
2953template <class _Allocator>
2954_LIBCPP_INLINE_VISIBILITY inline
2955typename vector<bool, _Allocator>::iterator
2956vector<bool, _Allocator>::erase(const_iterator __position)
2957{
2958 iterator __r = __const_iterator_cast(__position);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002959 _VSTD::copy(__position + 1, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002960 --__size_;
2961 return __r;
2962}
2963
2964template <class _Allocator>
2965typename vector<bool, _Allocator>::iterator
2966vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
2967{
2968 iterator __r = __const_iterator_cast(__first);
2969 difference_type __d = __last - __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002970 _VSTD::copy(__last, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002971 __size_ -= __d;
2972 return __r;
2973}
2974
2975template <class _Allocator>
2976void
2977vector<bool, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002978 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2979 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002980{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002981 _VSTD::swap(this->__begin_, __x.__begin_);
2982 _VSTD::swap(this->__size_, __x.__size_);
2983 _VSTD::swap(this->__cap(), __x.__cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002984 __swap_alloc(this->__alloc(), __x.__alloc());
2985#ifdef _LIBCPP_DEBUG
2986 iterator::swap(this, &__x);
2987 const_iterator::swap(this, &__x);
Howard Hinnant324bb032010-08-22 00:02:43 +00002988#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002989}
2990
Howard Hinnant324bb032010-08-22 00:02:43 +00002991template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002992void
2993vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
2994{
2995 size_type __cs = size();
2996 if (__cs < __sz)
2997 {
2998 iterator __r;
2999 size_type __c = capacity();
3000 size_type __n = __sz - __cs;
3001 if (__n <= __c && __cs <= __c - __n)
3002 {
3003 __r = end();
3004 __size_ += __n;
3005 }
3006 else
3007 {
3008 vector __v(__alloc());
3009 __v.reserve(__recommend(__size_ + __n));
3010 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003011 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003012 swap(__v);
3013 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003014 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003015 }
3016 else
3017 __size_ = __sz;
3018}
3019
Howard Hinnant324bb032010-08-22 00:02:43 +00003020template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003021void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003022vector<bool, _Allocator>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003023{
3024 // do middle whole words
3025 size_type __n = __size_;
3026 __storage_pointer __p = __begin_;
3027 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3028 *__p = ~*__p;
3029 // do last partial word
3030 if (__n > 0)
3031 {
3032 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3033 __storage_type __b = *__p & __m;
3034 *__p &= ~__m;
3035 *__p |= ~__b & __m;
3036 }
3037}
3038
Howard Hinnant324bb032010-08-22 00:02:43 +00003039template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003040bool
3041vector<bool, _Allocator>::__invariants() const
3042{
3043 if (this->__begin_ == 0)
3044 {
3045 if (this->__size_ != 0 || this->__cap() != 0)
3046 return false;
3047 }
3048 else
3049 {
3050 if (this->__cap() == 0)
3051 return false;
3052 if (this->__size_ > this->capacity())
3053 return false;
3054 }
3055 return true;
3056}
3057
Howard Hinnant324bb032010-08-22 00:02:43 +00003058template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003059size_t
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003060vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003061{
3062 size_t __h = 0;
3063 // do middle whole words
3064 size_type __n = __size_;
3065 __storage_pointer __p = __begin_;
3066 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3067 __h ^= *__p;
3068 // do last partial word
3069 if (__n > 0)
3070 {
3071 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3072 __h ^= *__p & __m;
3073 }
3074 return __h;
3075}
3076
3077template <class _Allocator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003078struct _LIBCPP_VISIBLE hash<vector<bool, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003079 : public unary_function<vector<bool, _Allocator>, size_t>
3080{
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003081 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003082 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003083 {return __vec.__hash_code();}
3084};
3085
3086template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003087_LIBCPP_INLINE_VISIBILITY inline
3088bool
3089operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3090{
3091 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003092 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003093}
3094
3095template <class _Tp, class _Allocator>
3096_LIBCPP_INLINE_VISIBILITY inline
3097bool
3098operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3099{
3100 return !(__x == __y);
3101}
3102
3103template <class _Tp, class _Allocator>
3104_LIBCPP_INLINE_VISIBILITY inline
3105bool
3106operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3107{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003108 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003109}
3110
3111template <class _Tp, class _Allocator>
3112_LIBCPP_INLINE_VISIBILITY inline
3113bool
3114operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3115{
3116 return __y < __x;
3117}
3118
3119template <class _Tp, class _Allocator>
3120_LIBCPP_INLINE_VISIBILITY inline
3121bool
3122operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3123{
3124 return !(__x < __y);
3125}
3126
3127template <class _Tp, class _Allocator>
3128_LIBCPP_INLINE_VISIBILITY inline
3129bool
3130operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3131{
3132 return !(__y < __x);
3133}
3134
3135template <class _Tp, class _Allocator>
3136_LIBCPP_INLINE_VISIBILITY inline
3137void
3138swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003139 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003140{
3141 __x.swap(__y);
3142}
3143
3144_LIBCPP_END_NAMESPACE_STD
3145
3146#endif // _LIBCPP_VECTOR