blob: 282713e70fbec47e4c21dec248d3b39e67690239 [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 Hinnantb0bfd9b2012-02-15 00:41:34 +0000369 {__destruct_at_end(__new_last, false_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 Hinnantec3773c2011-12-01 20:21:04 +0000409 void __copy_assign_alloc(const __vector_base&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410 {}
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 Hinnantec3773c2011-12-01 20:21:04 +0000420 void __move_assign_alloc(__vector_base&, 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 Hinnantec3773c2011-12-01 20:21:04 +0000432 static void __swap_alloc(allocator_type&, allocator_type&, 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{
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000442 while (__new_last != __end_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443 __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 Hinnantb0bfd9b2012-02-15 00:41:34 +0000679 _LIBCPP_INLINE_VISIBILITY 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 Hinnantb0bfd9b2012-02-15 00:41:34 +0000792 template <class _Up>
793 void
794#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
795 __push_back_slow_path(_Up&& __x);
796#else
797 __push_back_slow_path(_Up& __x);
798#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799};
800
801template <class _Tp, class _Allocator>
802void
803vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
804{
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000805 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000806 _VSTD::swap(this->__begin_, __v.__begin_);
807 _VSTD::swap(this->__end_, __v.__end_);
808 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000809 __v.__first_ = __v.__begin_;
810 __invalidate_all_iterators();
811}
812
813template <class _Tp, class _Allocator>
814typename vector<_Tp, _Allocator>::pointer
815vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
816{
817 pointer __r = __v.__begin_;
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000818 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
819 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000820 _VSTD::swap(this->__begin_, __v.__begin_);
821 _VSTD::swap(this->__end_, __v.__end_);
822 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000823 __v.__first_ = __v.__begin_;
824 __invalidate_all_iterators();
825 return __r;
826}
827
828// Allocate space for __n objects
829// throws length_error if __n > max_size()
830// throws (probably bad_alloc) if memory run out
831// Precondition: __begin_ == __end_ == __end_cap() == 0
832// Precondition: __n > 0
833// Postcondition: capacity() == __n
834// Postcondition: size() == 0
835template <class _Tp, class _Allocator>
836void
837vector<_Tp, _Allocator>::allocate(size_type __n)
838{
839 if (__n > max_size())
840 this->__throw_length_error();
841 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
842 this->__end_cap() = this->__begin_ + __n;
843}
844
845template <class _Tp, class _Allocator>
846void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000847vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848{
849 if (this->__begin_ != 0)
850 {
851 clear();
852 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853 this->__begin_ = this->__end_ = this->__end_cap() = 0;
854 }
855}
856
857template <class _Tp, class _Allocator>
858typename vector<_Tp, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000859vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860{
Sean Hunt110b8bf2011-07-29 23:31:58 +0000861 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 +0000862}
863
864// Precondition: __new_size > capacity()
865template <class _Tp, class _Allocator>
866_LIBCPP_INLINE_VISIBILITY inline
867typename vector<_Tp, _Allocator>::size_type
868vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
869{
870 const size_type __ms = max_size();
871 if (__new_size > __ms)
872 this->__throw_length_error();
873 const size_type __cap = capacity();
874 if (__cap >= __ms / 2)
875 return __ms;
Sean Hunt110b8bf2011-07-29 23:31:58 +0000876 return _VSTD::max<size_type>(2*__cap, __new_size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877}
878
879// Default constructs __n objects starting at __end_
880// throws if construction throws
881// Precondition: __n > 0
882// Precondition: size() + __n <= capacity()
883// Postcondition: size() == size() + __n
884template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000885void
886vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
887{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888 allocator_type& __a = this->__alloc();
889 do
890 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000891 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892 ++this->__end_;
893 --__n;
894 } while (__n > 0);
895}
896
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897// Copy constructs __n objects starting at __end_ from __x
898// throws if construction throws
899// Precondition: __n > 0
900// Precondition: size() + __n <= capacity()
901// Postcondition: size() == old size() + __n
902// Postcondition: [i] == __x for all i in [size() - __n, __n)
903template <class _Tp, class _Allocator>
904_LIBCPP_INLINE_VISIBILITY inline
905void
906vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
907{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908 allocator_type& __a = this->__alloc();
909 do
910 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000911 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000912 ++this->__end_;
913 --__n;
914 } while (__n > 0);
915}
916
917template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918template <class _ForwardIterator>
919typename enable_if
920<
921 __is_forward_iterator<_ForwardIterator>::value,
922 void
923>::type
924vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
925{
926 allocator_type& __a = this->__alloc();
927 for (; __first != __last; ++__first)
928 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000929 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000930 ++this->__end_;
931 }
932}
933
934template <class _Tp, class _Allocator>
935void
936vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
937{
938 allocator_type& __a = this->__alloc();
939 for (; __first != __last; ++__first)
940 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000941 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
942 _VSTD::move(*__first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943 ++this->__end_;
944 }
945}
946
947// Default constructs __n objects starting at __end_
948// throws if construction throws
949// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000950// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951template <class _Tp, class _Allocator>
952void
953vector<_Tp, _Allocator>::__append(size_type __n)
954{
955 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
956 this->__construct_at_end(__n);
957 else
958 {
959 allocator_type& __a = this->__alloc();
960 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
961 __v.__construct_at_end(__n);
962 __swap_out_circular_buffer(__v);
963 }
964}
965
966// Default constructs __n objects starting at __end_
967// throws if construction throws
968// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000969// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000970template <class _Tp, class _Allocator>
971void
972vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
973{
974 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
975 this->__construct_at_end(__n, __x);
976 else
977 {
978 allocator_type& __a = this->__alloc();
979 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
980 __v.__construct_at_end(__n, __x);
981 __swap_out_circular_buffer(__v);
982 }
983}
984
985template <class _Tp, class _Allocator>
986vector<_Tp, _Allocator>::vector(size_type __n)
987{
Howard Hinnant0442b122011-09-16 18:41:29 +0000988#if _LIBCPP_DEBUG_LEVEL >= 2
989 __get_db()->__insert_c(this);
990#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991 if (__n > 0)
992 {
993 allocate(__n);
994 __construct_at_end(__n);
995 }
996}
997
998template <class _Tp, class _Allocator>
999vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1000{
Howard Hinnant0442b122011-09-16 18:41:29 +00001001#if _LIBCPP_DEBUG_LEVEL >= 2
1002 __get_db()->__insert_c(this);
1003#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001004 if (__n > 0)
1005 {
1006 allocate(__n);
1007 __construct_at_end(__n, __x);
1008 }
1009}
1010
1011template <class _Tp, class _Allocator>
1012vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1013 : __base(__a)
1014{
Howard Hinnant0442b122011-09-16 18:41:29 +00001015#if _LIBCPP_DEBUG_LEVEL >= 2
1016 __get_db()->__insert_c(this);
1017#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001018 if (__n > 0)
1019 {
1020 allocate(__n);
1021 __construct_at_end(__n, __x);
1022 }
1023}
1024
1025template <class _Tp, class _Allocator>
1026template <class _InputIterator>
1027vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
1028 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1029 !__is_forward_iterator<_InputIterator>::value>::type*)
1030{
Howard Hinnantabe26282011-09-16 17:29:17 +00001031#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001032 __get_db()->__insert_c(this);
1033#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001034 for (; __first != __last; ++__first)
1035 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036}
1037
1038template <class _Tp, class _Allocator>
1039template <class _InputIterator>
1040vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1041 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1042 !__is_forward_iterator<_InputIterator>::value>::type*)
1043 : __base(__a)
1044{
Howard Hinnantabe26282011-09-16 17:29:17 +00001045#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001046 __get_db()->__insert_c(this);
1047#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001048 for (; __first != __last; ++__first)
1049 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001050}
1051
1052template <class _Tp, class _Allocator>
1053template <class _ForwardIterator>
1054vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
1055 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1056{
Howard Hinnant0442b122011-09-16 18:41:29 +00001057#if _LIBCPP_DEBUG_LEVEL >= 2
1058 __get_db()->__insert_c(this);
1059#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001060 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001061 if (__n > 0)
1062 {
1063 allocate(__n);
1064 __construct_at_end(__first, __last);
1065 }
1066}
1067
1068template <class _Tp, class _Allocator>
1069template <class _ForwardIterator>
1070vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1071 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1072 : __base(__a)
1073{
Howard Hinnant0442b122011-09-16 18:41:29 +00001074#if _LIBCPP_DEBUG_LEVEL >= 2
1075 __get_db()->__insert_c(this);
1076#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001077 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078 if (__n > 0)
1079 {
1080 allocate(__n);
1081 __construct_at_end(__first, __last);
1082 }
1083}
1084
1085template <class _Tp, class _Allocator>
1086vector<_Tp, _Allocator>::vector(const vector& __x)
1087 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1088{
Howard Hinnant0442b122011-09-16 18:41:29 +00001089#if _LIBCPP_DEBUG_LEVEL >= 2
1090 __get_db()->__insert_c(this);
1091#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001092 size_type __n = __x.size();
1093 if (__n > 0)
1094 {
1095 allocate(__n);
1096 __construct_at_end(__x.__begin_, __x.__end_);
1097 }
1098}
1099
1100template <class _Tp, class _Allocator>
1101vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1102 : __base(__a)
1103{
Howard Hinnant0442b122011-09-16 18:41:29 +00001104#if _LIBCPP_DEBUG_LEVEL >= 2
1105 __get_db()->__insert_c(this);
1106#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001107 size_type __n = __x.size();
1108 if (__n > 0)
1109 {
1110 allocate(__n);
1111 __construct_at_end(__x.__begin_, __x.__end_);
1112 }
1113}
1114
Howard Hinnant73d21a42010-09-04 23:28:19 +00001115#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001116
1117template <class _Tp, class _Allocator>
1118_LIBCPP_INLINE_VISIBILITY inline
1119vector<_Tp, _Allocator>::vector(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001120 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001121 : __base(_VSTD::move(__x.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001122{
Howard Hinnantabe26282011-09-16 17:29:17 +00001123#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001124 __get_db()->__insert_c(this);
Howard Hinnante6125bd2011-09-19 16:34:29 +00001125 __get_db()->swap(this, &__x);
Howard Hinnant7a563db2011-09-14 18:33:51 +00001126#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001127 this->__begin_ = __x.__begin_;
1128 this->__end_ = __x.__end_;
1129 this->__end_cap() = __x.__end_cap();
1130 __x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131}
1132
1133template <class _Tp, class _Allocator>
1134_LIBCPP_INLINE_VISIBILITY inline
1135vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1136 : __base(__a)
1137{
Howard Hinnant0442b122011-09-16 18:41:29 +00001138#if _LIBCPP_DEBUG_LEVEL >= 2
1139 __get_db()->__insert_c(this);
1140#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001141 if (__a == __x.__alloc())
1142 {
1143 this->__begin_ = __x.__begin_;
1144 this->__end_ = __x.__end_;
1145 this->__end_cap() = __x.__end_cap();
1146 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001147#if _LIBCPP_DEBUG_LEVEL >= 2
1148 __get_db()->swap(this, &__x);
1149#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001150 }
1151 else
1152 {
Howard Hinnant99968442011-11-29 18:15:50 +00001153 typedef move_iterator<iterator> _Ip;
1154 assign(_Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155 }
1156}
1157
Howard Hinnante3e32912011-08-12 21:56:02 +00001158#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1159
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160template <class _Tp, class _Allocator>
1161_LIBCPP_INLINE_VISIBILITY inline
1162vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1163{
Howard Hinnant0442b122011-09-16 18:41:29 +00001164#if _LIBCPP_DEBUG_LEVEL >= 2
1165 __get_db()->__insert_c(this);
1166#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167 if (__il.size() > 0)
1168 {
1169 allocate(__il.size());
1170 __construct_at_end(__il.begin(), __il.end());
1171 }
1172}
1173
1174template <class _Tp, class _Allocator>
1175_LIBCPP_INLINE_VISIBILITY inline
1176vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1177 : __base(__a)
1178{
Howard Hinnant0442b122011-09-16 18:41:29 +00001179#if _LIBCPP_DEBUG_LEVEL >= 2
1180 __get_db()->__insert_c(this);
1181#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001182 if (__il.size() > 0)
1183 {
1184 allocate(__il.size());
1185 __construct_at_end(__il.begin(), __il.end());
1186 }
1187}
1188
Howard Hinnante3e32912011-08-12 21:56:02 +00001189#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1190
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001191template <class _Tp, class _Allocator>
1192_LIBCPP_INLINE_VISIBILITY inline
1193vector<_Tp, _Allocator>&
1194vector<_Tp, _Allocator>::operator=(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001195 _NOEXCEPT_(
1196 __alloc_traits::propagate_on_container_move_assignment::value &&
1197 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198{
1199 __move_assign(__x, integral_constant<bool,
1200 __alloc_traits::propagate_on_container_move_assignment::value>());
1201 return *this;
1202}
1203
1204template <class _Tp, class _Allocator>
1205void
1206vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1207{
1208 if (__base::__alloc() != __c.__alloc())
1209 {
Howard Hinnant99968442011-11-29 18:15:50 +00001210 typedef move_iterator<iterator> _Ip;
1211 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001212 }
1213 else
1214 __move_assign(__c, true_type());
1215}
1216
1217template <class _Tp, class _Allocator>
1218void
1219vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001220 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001221{
1222 deallocate();
1223 this->__begin_ = __c.__begin_;
1224 this->__end_ = __c.__end_;
1225 this->__end_cap() = __c.__end_cap();
1226 __base::__move_assign_alloc(__c);
1227 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001228#if _LIBCPP_DEBUG_LEVEL >= 2
1229 __get_db()->swap(this, &__c);
1230#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001231}
1232
Howard Hinnant73d21a42010-09-04 23:28:19 +00001233#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001234
1235template <class _Tp, class _Allocator>
1236_LIBCPP_INLINE_VISIBILITY inline
1237vector<_Tp, _Allocator>&
1238vector<_Tp, _Allocator>::operator=(const vector& __x)
1239{
1240 if (this != &__x)
1241 {
1242 __base::__copy_assign_alloc(__x);
1243 assign(__x.__begin_, __x.__end_);
1244 }
1245 return *this;
1246}
1247
1248template <class _Tp, class _Allocator>
1249template <class _InputIterator>
1250typename enable_if
1251<
1252 __is_input_iterator <_InputIterator>::value &&
1253 !__is_forward_iterator<_InputIterator>::value,
1254 void
1255>::type
1256vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1257{
1258 clear();
1259 for (; __first != __last; ++__first)
1260 push_back(*__first);
1261}
1262
1263template <class _Tp, class _Allocator>
1264template <class _ForwardIterator>
1265typename enable_if
1266<
1267 __is_forward_iterator<_ForwardIterator>::value,
1268 void
1269>::type
1270vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1271{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001272 typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273 if (static_cast<size_type>(__new_size) <= capacity())
1274 {
1275 _ForwardIterator __mid = __last;
1276 bool __growing = false;
1277 if (static_cast<size_type>(__new_size) > size())
1278 {
1279 __growing = true;
1280 __mid = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001281 _VSTD::advance(__mid, size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001282 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001283 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001284 if (__growing)
1285 __construct_at_end(__mid, __last);
1286 else
1287 this->__destruct_at_end(__m);
1288 }
1289 else
1290 {
1291 deallocate();
1292 allocate(__recommend(static_cast<size_type>(__new_size)));
1293 __construct_at_end(__first, __last);
1294 }
1295}
1296
1297template <class _Tp, class _Allocator>
1298void
1299vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1300{
1301 if (__n <= capacity())
1302 {
1303 size_type __s = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001304 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305 if (__n > __s)
1306 __construct_at_end(__n - __s, __u);
1307 else
Howard Hinnantadff4892010-05-24 17:49:41 +00001308 this->__destruct_at_end(this->__begin_ + __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309 }
1310 else
1311 {
1312 deallocate();
1313 allocate(__recommend(static_cast<size_type>(__n)));
1314 __construct_at_end(__n, __u);
1315 }
1316}
1317
Howard Hinnant324bb032010-08-22 00:02:43 +00001318template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001319_LIBCPP_INLINE_VISIBILITY inline
1320typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001321vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001322{
Howard Hinnantabe26282011-09-16 17:29:17 +00001323#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324 return iterator(this, __p);
1325#else
1326 return iterator(__p);
1327#endif
1328}
1329
Howard Hinnant324bb032010-08-22 00:02:43 +00001330template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331_LIBCPP_INLINE_VISIBILITY inline
1332typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001333vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334{
Howard Hinnantabe26282011-09-16 17:29:17 +00001335#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336 return const_iterator(this, __p);
1337#else
1338 return const_iterator(__p);
1339#endif
1340}
1341
Howard Hinnant324bb032010-08-22 00:02:43 +00001342template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343_LIBCPP_INLINE_VISIBILITY inline
1344typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001345vector<_Tp, _Allocator>::begin() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001346{
1347 return __make_iter(this->__begin_);
1348}
1349
Howard Hinnant324bb032010-08-22 00:02:43 +00001350template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001351_LIBCPP_INLINE_VISIBILITY inline
1352typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001353vector<_Tp, _Allocator>::begin() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001354{
1355 return __make_iter(this->__begin_);
1356}
1357
Howard Hinnant324bb032010-08-22 00:02:43 +00001358template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001359_LIBCPP_INLINE_VISIBILITY inline
1360typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001361vector<_Tp, _Allocator>::end() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001362{
1363 return __make_iter(this->__end_);
1364}
1365
Howard Hinnant324bb032010-08-22 00:02:43 +00001366template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367_LIBCPP_INLINE_VISIBILITY inline
1368typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001369vector<_Tp, _Allocator>::end() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370{
1371 return __make_iter(this->__end_);
1372}
1373
Howard Hinnant324bb032010-08-22 00:02:43 +00001374template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001375_LIBCPP_INLINE_VISIBILITY inline
1376typename vector<_Tp, _Allocator>::reference
1377vector<_Tp, _Allocator>::operator[](size_type __n)
1378{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001379 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380 return this->__begin_[__n];
1381}
1382
Howard Hinnant324bb032010-08-22 00:02:43 +00001383template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001384_LIBCPP_INLINE_VISIBILITY inline
1385typename vector<_Tp, _Allocator>::const_reference
1386vector<_Tp, _Allocator>::operator[](size_type __n) const
1387{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001388 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001389 return this->__begin_[__n];
1390}
1391
Howard Hinnant324bb032010-08-22 00:02:43 +00001392template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393typename vector<_Tp, _Allocator>::reference
1394vector<_Tp, _Allocator>::at(size_type __n)
1395{
1396 if (__n >= size())
1397 this->__throw_out_of_range();
1398 return this->__begin_[__n];
1399}
1400
Howard Hinnant324bb032010-08-22 00:02:43 +00001401template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001402typename vector<_Tp, _Allocator>::const_reference
1403vector<_Tp, _Allocator>::at(size_type __n) const
1404{
1405 if (__n >= size())
1406 this->__throw_out_of_range();
1407 return this->__begin_[__n];
1408}
1409
1410template <class _Tp, class _Allocator>
1411void
1412vector<_Tp, _Allocator>::reserve(size_type __n)
1413{
1414 if (__n > capacity())
1415 {
1416 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001417 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418 __swap_out_circular_buffer(__v);
1419 }
1420}
1421
1422template <class _Tp, class _Allocator>
1423void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001424vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001425{
1426 if (capacity() > size())
1427 {
1428#ifndef _LIBCPP_NO_EXCEPTIONS
1429 try
1430 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001431#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001432 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001433 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434 __swap_out_circular_buffer(__v);
1435#ifndef _LIBCPP_NO_EXCEPTIONS
1436 }
1437 catch (...)
1438 {
1439 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001440#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001441 }
1442}
1443
1444template <class _Tp, class _Allocator>
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001445template <class _Up>
1446void
1447#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1448vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1449#else
1450vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1451#endif
1452{
1453 allocator_type& __a = this->__alloc();
1454 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1455 // __v.push_back(_VSTD::forward<_Up>(__x));
1456 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_++), _VSTD::forward<_Up>(__x));
1457 __swap_out_circular_buffer(__v);
1458}
1459
1460template <class _Tp, class _Allocator>
1461_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001462void
1463vector<_Tp, _Allocator>::push_back(const_reference __x)
1464{
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001465 if (this->__end_ != this->__end_cap())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001466 {
1467 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001468 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001469 ++this->__end_;
1470 }
1471 else
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001472 __push_back_slow_path(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001473}
1474
Howard Hinnant73d21a42010-09-04 23:28:19 +00001475#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001476
1477template <class _Tp, class _Allocator>
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001478_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001479void
1480vector<_Tp, _Allocator>::push_back(value_type&& __x)
1481{
1482 if (this->__end_ < this->__end_cap())
1483 {
1484 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001485 _VSTD::__to_raw_pointer(this->__end_),
1486 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487 ++this->__end_;
1488 }
1489 else
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001490 __push_back_slow_path(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001491}
1492
Howard Hinnant73d21a42010-09-04 23:28:19 +00001493#ifndef _LIBCPP_HAS_NO_VARIADICS
1494
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001495template <class _Tp, class _Allocator>
1496template <class... _Args>
1497void
1498vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1499{
1500 if (this->__end_ < this->__end_cap())
1501 {
1502 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001503 _VSTD::__to_raw_pointer(this->__end_),
1504 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001505 ++this->__end_;
1506 }
1507 else
1508 {
1509 allocator_type& __a = this->__alloc();
1510 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001511 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001512 __swap_out_circular_buffer(__v);
1513 }
1514}
1515
Howard Hinnant73d21a42010-09-04 23:28:19 +00001516#endif // _LIBCPP_HAS_NO_VARIADICS
1517#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518
1519template <class _Tp, class _Allocator>
1520_LIBCPP_INLINE_VISIBILITY inline
1521void
1522vector<_Tp, _Allocator>::pop_back()
1523{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001524 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525 this->__destruct_at_end(this->__end_ - 1);
1526}
1527
1528template <class _Tp, class _Allocator>
1529_LIBCPP_INLINE_VISIBILITY inline
1530typename vector<_Tp, _Allocator>::iterator
1531vector<_Tp, _Allocator>::erase(const_iterator __position)
1532{
Howard Hinnantabe26282011-09-16 17:29:17 +00001533#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001534 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1535 "vector::erase(iterator) called with an iterator not"
1536 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001537#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001538 pointer __p = const_cast<pointer>(&*__position);
1539 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001540 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001541 return __r;
1542}
1543
1544template <class _Tp, class _Allocator>
1545typename vector<_Tp, _Allocator>::iterator
1546vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1547{
Howard Hinnantabe26282011-09-16 17:29:17 +00001548#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001549 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1550 "vector::erase(iterator, iterator) called with an iterator not"
1551 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001552#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001553 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554 pointer __p = this->__begin_ + (__first - begin());
1555 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001556 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557 return __r;
1558}
1559
1560template <class _Tp, class _Allocator>
1561void
1562vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1563{
1564 pointer __old_last = this->__end_;
1565 difference_type __n = __old_last - __to;
1566 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1567 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001568 _VSTD::__to_raw_pointer(this->__end_),
1569 _VSTD::move(*__i));
1570 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571}
1572
1573template <class _Tp, class _Allocator>
1574typename vector<_Tp, _Allocator>::iterator
1575vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1576{
Howard Hinnantabe26282011-09-16 17:29:17 +00001577#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001578 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1579 "vector::insert(iterator, x) called with an iterator not"
1580 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001581#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001582 pointer __p = this->__begin_ + (__position - begin());
1583 if (this->__end_ < this->__end_cap())
1584 {
1585 if (__p == this->__end_)
1586 {
1587 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001588 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001589 ++this->__end_;
1590 }
1591 else
1592 {
1593 __move_range(__p, this->__end_, __p + 1);
1594 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1595 if (__p <= __xr && __xr < this->__end_)
1596 ++__xr;
1597 *__p = *__xr;
1598 }
1599 }
1600 else
1601 {
1602 allocator_type& __a = this->__alloc();
1603 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1604 __v.push_back(__x);
1605 __p = __swap_out_circular_buffer(__v, __p);
1606 }
1607 return __make_iter(__p);
1608}
1609
Howard Hinnant73d21a42010-09-04 23:28:19 +00001610#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001611
1612template <class _Tp, class _Allocator>
1613typename vector<_Tp, _Allocator>::iterator
1614vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1615{
Howard Hinnantabe26282011-09-16 17:29:17 +00001616#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001617 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1618 "vector::insert(iterator, x) called with an iterator not"
1619 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001620#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621 pointer __p = this->__begin_ + (__position - begin());
1622 if (this->__end_ < this->__end_cap())
1623 {
1624 if (__p == this->__end_)
1625 {
1626 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001627 _VSTD::__to_raw_pointer(this->__end_),
1628 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629 ++this->__end_;
1630 }
1631 else
1632 {
1633 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001634 *__p = _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001635 }
1636 }
1637 else
1638 {
1639 allocator_type& __a = this->__alloc();
1640 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001641 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001642 __p = __swap_out_circular_buffer(__v, __p);
1643 }
1644 return __make_iter(__p);
1645}
1646
Howard Hinnant73d21a42010-09-04 23:28:19 +00001647#ifndef _LIBCPP_HAS_NO_VARIADICS
1648
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649template <class _Tp, class _Allocator>
1650template <class... _Args>
1651typename vector<_Tp, _Allocator>::iterator
1652vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1653{
Howard Hinnantabe26282011-09-16 17:29:17 +00001654#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001655 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1656 "vector::emplace(iterator, x) called with an iterator not"
1657 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001658#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659 pointer __p = this->__begin_ + (__position - begin());
1660 if (this->__end_ < this->__end_cap())
1661 {
1662 if (__p == this->__end_)
1663 {
1664 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001665 _VSTD::__to_raw_pointer(this->__end_),
1666 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001667 ++this->__end_;
1668 }
1669 else
1670 {
1671 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001672 *__p = value_type(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673 }
1674 }
1675 else
1676 {
1677 allocator_type& __a = this->__alloc();
1678 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001679 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001680 __p = __swap_out_circular_buffer(__v, __p);
1681 }
1682 return __make_iter(__p);
1683}
1684
Howard Hinnant73d21a42010-09-04 23:28:19 +00001685#endif // _LIBCPP_HAS_NO_VARIADICS
1686#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001687
1688template <class _Tp, class _Allocator>
1689typename vector<_Tp, _Allocator>::iterator
1690vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1691{
Howard Hinnantabe26282011-09-16 17:29:17 +00001692#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001693 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1694 "vector::insert(iterator, n, x) called with an iterator not"
1695 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001696#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001697 pointer __p = this->__begin_ + (__position - begin());
1698 if (__n > 0)
1699 {
1700 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1701 {
1702 size_type __old_n = __n;
1703 pointer __old_last = this->__end_;
1704 if (__n > static_cast<size_type>(this->__end_ - __p))
1705 {
1706 size_type __cx = __n - (this->__end_ - __p);
1707 __construct_at_end(__cx, __x);
1708 __n -= __cx;
1709 }
1710 if (__n > 0)
1711 {
1712 __move_range(__p, __old_last, __p + __old_n);
1713 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1714 if (__p <= __xr && __xr < this->__end_)
1715 __xr += __old_n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001716 _VSTD::fill_n(__p, __n, *__xr);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001717 }
1718 }
1719 else
1720 {
1721 allocator_type& __a = this->__alloc();
1722 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1723 __v.__construct_at_end(__n, __x);
1724 __p = __swap_out_circular_buffer(__v, __p);
1725 }
1726 }
1727 return __make_iter(__p);
1728}
1729
1730template <class _Tp, class _Allocator>
1731template <class _InputIterator>
1732typename enable_if
1733<
1734 __is_input_iterator <_InputIterator>::value &&
1735 !__is_forward_iterator<_InputIterator>::value,
1736 typename vector<_Tp, _Allocator>::iterator
1737>::type
1738vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1739{
Howard Hinnantabe26282011-09-16 17:29:17 +00001740#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001741 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1742 "vector::insert(iterator, range) called with an iterator not"
1743 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001744#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001745 difference_type __off = __position - begin();
1746 pointer __p = this->__begin_ + __off;
1747 allocator_type& __a = this->__alloc();
1748 pointer __old_last = this->__end_;
1749 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1750 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001751 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752 *__first);
1753 ++this->__end_;
1754 }
1755 __split_buffer<value_type, allocator_type&> __v(__a);
1756 if (__first != __last)
1757 {
1758#ifndef _LIBCPP_NO_EXCEPTIONS
1759 try
1760 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001761#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001762 __v.__construct_at_end(__first, __last);
1763 difference_type __old_size = __old_last - this->__begin_;
1764 difference_type __old_p = __p - this->__begin_;
1765 reserve(__recommend(size() + __v.size()));
1766 __p = this->__begin_ + __old_p;
1767 __old_last = this->__begin_ + __old_size;
1768#ifndef _LIBCPP_NO_EXCEPTIONS
1769 }
1770 catch (...)
1771 {
1772 erase(__make_iter(__old_last), end());
1773 throw;
1774 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001775#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001776 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001777 __p = _VSTD::rotate(__p, __old_last, this->__end_);
Howard Hinnant0442b122011-09-16 18:41:29 +00001778 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1779 make_move_iterator(__v.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001780 return begin() + __off;
1781}
1782
1783template <class _Tp, class _Allocator>
1784template <class _ForwardIterator>
1785typename enable_if
1786<
1787 __is_forward_iterator<_ForwardIterator>::value,
1788 typename vector<_Tp, _Allocator>::iterator
1789>::type
1790vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1791{
Howard Hinnantabe26282011-09-16 17:29:17 +00001792#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001793 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1794 "vector::insert(iterator, range) called with an iterator not"
1795 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001796#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797 pointer __p = this->__begin_ + (__position - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00001798 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799 if (__n > 0)
1800 {
1801 if (__n <= this->__end_cap() - this->__end_)
1802 {
1803 size_type __old_n = __n;
1804 pointer __old_last = this->__end_;
1805 _ForwardIterator __m = __last;
1806 difference_type __dx = this->__end_ - __p;
1807 if (__n > __dx)
1808 {
1809 __m = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001810 _VSTD::advance(__m, this->__end_ - __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001811 __construct_at_end(__m, __last);
1812 __n = __dx;
1813 }
1814 if (__n > 0)
1815 {
1816 __move_range(__p, __old_last, __p + __old_n);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001817 _VSTD::copy(__first, __m, __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818 }
1819 }
1820 else
1821 {
1822 allocator_type& __a = this->__alloc();
1823 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1824 __v.__construct_at_end(__first, __last);
1825 __p = __swap_out_circular_buffer(__v, __p);
1826 }
1827 }
1828 return __make_iter(__p);
1829}
1830
1831template <class _Tp, class _Allocator>
1832void
1833vector<_Tp, _Allocator>::resize(size_type __sz)
1834{
1835 size_type __cs = size();
1836 if (__cs < __sz)
1837 this->__append(__sz - __cs);
1838 else if (__cs > __sz)
1839 this->__destruct_at_end(this->__begin_ + __sz);
1840}
1841
1842template <class _Tp, class _Allocator>
1843void
1844vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1845{
1846 size_type __cs = size();
1847 if (__cs < __sz)
1848 this->__append(__sz - __cs, __x);
1849 else if (__cs > __sz)
1850 this->__destruct_at_end(this->__begin_ + __sz);
1851}
1852
1853template <class _Tp, class _Allocator>
1854void
1855vector<_Tp, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001856 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1857 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001859 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
1860 this->__alloc() == __x.__alloc(),
1861 "vector::swap: Either propagate_on_container_swap must be true"
1862 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19 +00001863 _VSTD::swap(this->__begin_, __x.__begin_);
1864 _VSTD::swap(this->__end_, __x.__end_);
1865 _VSTD::swap(this->__end_cap(), __x.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001866 __base::__swap_alloc(this->__alloc(), __x.__alloc());
Howard Hinnantabe26282011-09-16 17:29:17 +00001867#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001868 __get_db()->swap(this, &__x);
Howard Hinnantabe26282011-09-16 17:29:17 +00001869#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001870}
1871
Howard Hinnant324bb032010-08-22 00:02:43 +00001872template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873bool
1874vector<_Tp, _Allocator>::__invariants() const
1875{
1876 if (this->__begin_ == 0)
1877 {
1878 if (this->__end_ != 0 || this->__end_cap() != 0)
1879 return false;
1880 }
1881 else
1882 {
1883 if (this->__begin_ > this->__end_)
1884 return false;
1885 if (this->__begin_ == this->__end_cap())
1886 return false;
1887 if (this->__end_ > this->__end_cap())
1888 return false;
1889 }
1890 return true;
1891}
1892
Howard Hinnantabe26282011-09-16 17:29:17 +00001893#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001894
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001895template <class _Tp, class _Allocator>
Howard Hinnant7a563db2011-09-14 18:33:51 +00001896bool
1897vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
1898{
1899 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
1900}
1901
1902template <class _Tp, class _Allocator>
1903bool
1904vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
1905{
1906 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
1907}
1908
1909template <class _Tp, class _Allocator>
1910bool
1911vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
1912{
1913 const_pointer __p = __i->base() + __n;
1914 return this->__begin_ <= __p && __p <= this->__end_;
1915}
1916
1917template <class _Tp, class _Allocator>
1918bool
1919vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1920{
1921 const_pointer __p = __i->base() + __n;
1922 return this->__begin_ <= __p && __p < this->__end_;
1923}
1924
Howard Hinnantabe26282011-09-16 17:29:17 +00001925#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001926
1927template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001929void
1930vector<_Tp, _Allocator>::__invalidate_all_iterators()
1931{
Howard Hinnantabe26282011-09-16 17:29:17 +00001932#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001933 __get_db()->__invalidate_all(this);
Howard Hinnantabe26282011-09-16 17:29:17 +00001934#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935}
1936
1937// vector<bool>
1938
1939template <class _Allocator> class vector<bool, _Allocator>;
1940
1941template <class _Allocator> struct hash<vector<bool, _Allocator> >;
1942
1943template <class _Allocator>
Howard Hinnantf03c3b42011-07-02 20:33:23 +00001944struct __has_storage_type<vector<bool, _Allocator> >
1945{
1946 static const bool value = true;
1947};
1948
1949template <class _Allocator>
Howard Hinnant36cdf022010-09-10 16:42:26 +00001950class _LIBCPP_VISIBLE vector<bool, _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951 : private __vector_base_common<true>
1952{
1953public:
1954 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +00001955 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001956 typedef _Allocator allocator_type;
1957 typedef allocator_traits<allocator_type> __alloc_traits;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958 typedef typename __alloc_traits::size_type size_type;
1959 typedef typename __alloc_traits::difference_type difference_type;
1960 typedef __bit_iterator<vector, false> pointer;
1961 typedef __bit_iterator<vector, true> const_pointer;
1962#ifdef _LIBCPP_DEBUG
1963 typedef __debug_iter<vector, pointer> iterator;
1964 typedef __debug_iter<vector, const_pointer> const_iterator;
1965
1966 friend class __debug_iter<vector, pointer>;
1967 friend class __debug_iter<vector, const_pointer>;
1968
1969 pair<iterator*, const_iterator*> __iterator_list_;
1970
1971 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1972 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
Howard Hinnant324bb032010-08-22 00:02:43 +00001973#else // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001974 typedef pointer iterator;
1975 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001976#endif // _LIBCPP_DEBUG
Howard Hinnant0949eed2011-06-30 21:18:19 +00001977 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1978 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001979
1980private:
1981 typedef size_type __storage_type;
1982 typedef typename __alloc_traits::template
1983#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1984 rebind_alloc<__storage_type>
1985#else
1986 rebind_alloc<__storage_type>::other
1987#endif
1988 __storage_allocator;
1989 typedef allocator_traits<__storage_allocator> __storage_traits;
1990 typedef typename __storage_traits::pointer __storage_pointer;
1991 typedef typename __storage_traits::const_pointer __const_storage_pointer;
1992
1993 __storage_pointer __begin_;
1994 size_type __size_;
1995 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00001996public:
Howard Hinnantf03c3b42011-07-02 20:33:23 +00001997 typedef __bit_reference<vector> reference;
1998 typedef __bit_const_reference<vector> const_reference;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00001999private:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002000 _LIBCPP_INLINE_VISIBILITY
2001 size_type& __cap() _NOEXCEPT
2002 {return __cap_alloc_.first();}
2003 _LIBCPP_INLINE_VISIBILITY
2004 const size_type& __cap() const _NOEXCEPT
2005 {return __cap_alloc_.first();}
2006 _LIBCPP_INLINE_VISIBILITY
2007 __storage_allocator& __alloc() _NOEXCEPT
2008 {return __cap_alloc_.second();}
2009 _LIBCPP_INLINE_VISIBILITY
2010 const __storage_allocator& __alloc() const _NOEXCEPT
2011 {return __cap_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002012
2013 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2014
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002015 _LIBCPP_INLINE_VISIBILITY
2016 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002017 {return __n * __bits_per_word;}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002018 _LIBCPP_INLINE_VISIBILITY
2019 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002020 {return (__n - 1) / __bits_per_word + 1;}
2021
2022public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002023 _LIBCPP_INLINE_VISIBILITY
2024 vector()
2025 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002026 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002027 ~vector();
2028 explicit vector(size_type __n);
2029 vector(size_type __n, const value_type& __v);
2030 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2031 template <class _InputIterator>
2032 vector(_InputIterator __first, _InputIterator __last,
2033 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2034 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2035 template <class _InputIterator>
2036 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2037 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2038 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2039 template <class _ForwardIterator>
2040 vector(_ForwardIterator __first, _ForwardIterator __last,
2041 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2042 template <class _ForwardIterator>
2043 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2044 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2045
2046 vector(const vector& __v);
2047 vector(const vector& __v, const allocator_type& __a);
2048 vector& operator=(const vector& __v);
Howard Hinnante3e32912011-08-12 21:56:02 +00002049#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002050 vector(initializer_list<value_type> __il);
2051 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00002052#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002053
Howard Hinnant73d21a42010-09-04 23:28:19 +00002054#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002055 _LIBCPP_INLINE_VISIBILITY
2056 vector(vector&& __v)
2057 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002058 vector(vector&& __v, const allocator_type& __a);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002059 _LIBCPP_INLINE_VISIBILITY
2060 vector& operator=(vector&& __v)
2061 _NOEXCEPT_(
2062 __alloc_traits::propagate_on_container_move_assignment::value &&
2063 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002064#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00002065#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002066 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002067 vector& operator=(initializer_list<value_type> __il)
2068 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00002069#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002070
2071 template <class _InputIterator>
2072 typename enable_if
2073 <
2074 __is_input_iterator<_InputIterator>::value &&
2075 !__is_forward_iterator<_InputIterator>::value,
2076 void
2077 >::type
2078 assign(_InputIterator __first, _InputIterator __last);
2079 template <class _ForwardIterator>
2080 typename enable_if
2081 <
2082 __is_forward_iterator<_ForwardIterator>::value,
2083 void
2084 >::type
2085 assign(_ForwardIterator __first, _ForwardIterator __last);
2086
2087 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:02 +00002088#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090 void assign(initializer_list<value_type> __il)
2091 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002092#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002093
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002094 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095 {return allocator_type(this->__alloc());}
2096
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002097 size_type max_size() const _NOEXCEPT;
2098 _LIBCPP_INLINE_VISIBILITY
2099 size_type capacity() const _NOEXCEPT
2100 {return __internal_cap_to_external(__cap());}
2101 _LIBCPP_INLINE_VISIBILITY
2102 size_type size() const _NOEXCEPT
2103 {return __size_;}
2104 _LIBCPP_INLINE_VISIBILITY
2105 bool empty() const _NOEXCEPT
2106 {return __size_ == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002107 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002108 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002109
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002110 _LIBCPP_INLINE_VISIBILITY
2111 iterator begin() _NOEXCEPT
2112 {return __make_iter(0);}
2113 _LIBCPP_INLINE_VISIBILITY
2114 const_iterator begin() const _NOEXCEPT
2115 {return __make_iter(0);}
2116 _LIBCPP_INLINE_VISIBILITY
2117 iterator end() _NOEXCEPT
2118 {return __make_iter(__size_);}
2119 _LIBCPP_INLINE_VISIBILITY
2120 const_iterator end() const _NOEXCEPT
2121 {return __make_iter(__size_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002122
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002123 _LIBCPP_INLINE_VISIBILITY
2124 reverse_iterator rbegin() _NOEXCEPT
2125 {return reverse_iterator(end());}
2126 _LIBCPP_INLINE_VISIBILITY
2127 const_reverse_iterator rbegin() const _NOEXCEPT
2128 {return const_reverse_iterator(end());}
2129 _LIBCPP_INLINE_VISIBILITY
2130 reverse_iterator rend() _NOEXCEPT
2131 {return reverse_iterator(begin());}
2132 _LIBCPP_INLINE_VISIBILITY
2133 const_reverse_iterator rend() const _NOEXCEPT
2134 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002135
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002136 _LIBCPP_INLINE_VISIBILITY
2137 const_iterator cbegin() const _NOEXCEPT
2138 {return __make_iter(0);}
2139 _LIBCPP_INLINE_VISIBILITY
2140 const_iterator cend() const _NOEXCEPT
2141 {return __make_iter(__size_);}
2142 _LIBCPP_INLINE_VISIBILITY
2143 const_reverse_iterator crbegin() const _NOEXCEPT
2144 {return rbegin();}
2145 _LIBCPP_INLINE_VISIBILITY
2146 const_reverse_iterator crend() const _NOEXCEPT
2147 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002148
2149 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2150 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2151 reference at(size_type __n);
2152 const_reference at(size_type __n) const;
2153
2154 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2155 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2156 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2157 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2158
2159 void push_back(const value_type& __x);
2160 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2161
2162 iterator insert(const_iterator __position, const value_type& __x);
2163 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2164 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2165 template <class _InputIterator>
2166 typename enable_if
2167 <
2168 __is_input_iterator <_InputIterator>::value &&
2169 !__is_forward_iterator<_InputIterator>::value,
2170 iterator
2171 >::type
2172 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2173 template <class _ForwardIterator>
2174 typename enable_if
2175 <
2176 __is_forward_iterator<_ForwardIterator>::value,
2177 iterator
2178 >::type
2179 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00002180#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002181 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2183 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002184#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002185
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002186 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002187 iterator erase(const_iterator __first, const_iterator __last);
2188
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002189 _LIBCPP_INLINE_VISIBILITY
2190 void clear() _NOEXCEPT {__size_ = 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002191
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002192 void swap(vector&)
2193 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2194 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002195
2196 void resize(size_type __sz, value_type __x = false);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002197 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002198
2199 bool __invariants() const;
2200
2201private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002202 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002203 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002204 void deallocate() _NOEXCEPT;
2205 _LIBCPP_INLINE_VISIBILITY
2206 static size_type __align(size_type __new_size) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002207 {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);};
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002208 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2209 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002210 template <class _ForwardIterator>
2211 typename enable_if
2212 <
2213 __is_forward_iterator<_ForwardIterator>::value,
2214 void
2215 >::type
2216 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2217 void __append(size_type __n, const_reference __x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002218 _LIBCPP_INLINE_VISIBILITY
2219 reference __make_ref(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002220 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002221 _LIBCPP_INLINE_VISIBILITY
2222 const_reference __make_ref(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002223 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2224#ifdef _LIBCPP_DEBUG
2225 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos)
2226 {return iterator(this, pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2227 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const
2228 {return const_iterator(this, const_pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2229 _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p)
2230 {return iterator(this, pointer(const_cast<__storage_pointer>(__p.base().__seg_), __p.base().__ctz_));}
Howard Hinnant324bb032010-08-22 00:02:43 +00002231#else // _LIBCPP_DEBUG
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002232 _LIBCPP_INLINE_VISIBILITY
2233 iterator __make_iter(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002234 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002235 _LIBCPP_INLINE_VISIBILITY
2236 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002237 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002238 _LIBCPP_INLINE_VISIBILITY
2239 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002240 {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);}
Howard Hinnant324bb032010-08-22 00:02:43 +00002241#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002242
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& __v)
2245 {__copy_assign_alloc(__v, integral_constant<bool,
2246 __storage_traits::propagate_on_container_copy_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002248 void __copy_assign_alloc(const vector& __c, true_type)
2249 {
2250 if (__alloc() != __c.__alloc())
2251 deallocate();
2252 __alloc() = __c.__alloc();
2253 }
2254
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00002256 void __copy_assign_alloc(const vector&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002257 {}
2258
2259 void __move_assign(vector& __c, false_type);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002260 void __move_assign(vector& __c, true_type)
2261 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002263 void __move_assign_alloc(vector& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002264 _NOEXCEPT_(
2265 !__storage_traits::propagate_on_container_move_assignment::value ||
2266 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002267 {__move_assign_alloc(__c, integral_constant<bool,
2268 __storage_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00002270 void __move_assign_alloc(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002271 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002272 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002273 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002274 }
2275
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00002277 void __move_assign_alloc(vector&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002278 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002279 {}
2280
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002281 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002282 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002283 _NOEXCEPT_(
2284 !__storage_traits::propagate_on_container_swap::value ||
2285 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002286 {__swap_alloc(__x, __y, integral_constant<bool,
2287 __storage_traits::propagate_on_container_swap::value>());}
2288
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002290 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002291 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002292 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002293 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002294 swap(__x, __y);
2295 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00002297 static void __swap_alloc(__storage_allocator&, __storage_allocator&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002298 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002299 {}
2300
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002301 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002302
2303 friend class __bit_reference<vector>;
2304 friend class __bit_const_reference<vector>;
2305 friend class __bit_iterator<vector, false>;
2306 friend class __bit_iterator<vector, true>;
2307 friend class __bit_array<vector>;
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002308 friend struct _LIBCPP_VISIBLE hash<vector>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002309};
2310
2311template <class _Allocator>
2312#ifndef _LIBCPP_DEBUG
2313_LIBCPP_INLINE_VISIBILITY inline
2314#endif
2315void
2316vector<bool, _Allocator>::__invalidate_all_iterators()
2317{
2318#ifdef _LIBCPP_DEBUG
2319 iterator::__remove_all(this);
2320 const_iterator::__remove_all(this);
Howard Hinnant324bb032010-08-22 00:02:43 +00002321#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002322}
2323
2324// Allocate space for __n objects
2325// throws length_error if __n > max_size()
2326// throws (probably bad_alloc) if memory run out
2327// Precondition: __begin_ == __end_ == __cap() == 0
2328// Precondition: __n > 0
2329// Postcondition: capacity() == __n
2330// Postcondition: size() == 0
2331template <class _Allocator>
2332void
2333vector<bool, _Allocator>::allocate(size_type __n)
2334{
2335 if (__n > max_size())
2336 this->__throw_length_error();
2337 __n = __external_cap_to_internal(__n);
2338 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2339 this->__size_ = 0;
2340 this->__cap() = __n;
2341}
2342
2343template <class _Allocator>
2344void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002345vector<bool, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002346{
2347 if (this->__begin_ != 0)
2348 {
2349 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2350 __invalidate_all_iterators();
2351 this->__begin_ = 0;
2352 this->__size_ = this->__cap() = 0;
2353 }
2354}
2355
2356template <class _Allocator>
2357typename vector<bool, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002358vector<bool, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002359{
2360 size_type __amax = __storage_traits::max_size(__alloc());
2361 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2362 if (__nmax / __bits_per_word <= __amax)
2363 return __nmax;
2364 return __internal_cap_to_external(__amax);
2365}
2366
2367// Precondition: __new_size > capacity()
2368template <class _Allocator>
2369_LIBCPP_INLINE_VISIBILITY inline
2370typename vector<bool, _Allocator>::size_type
2371vector<bool, _Allocator>::__recommend(size_type __new_size) const
2372{
2373 const size_type __ms = max_size();
2374 if (__new_size > __ms)
2375 this->__throw_length_error();
2376 const size_type __cap = capacity();
2377 if (__cap >= __ms / 2)
2378 return __ms;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002379 return _VSTD::max(2*__cap, __align(__new_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002380}
2381
2382// Default constructs __n objects starting at __end_
2383// Precondition: __n > 0
2384// Precondition: size() + __n <= capacity()
2385// Postcondition: size() == size() + __n
2386template <class _Allocator>
2387_LIBCPP_INLINE_VISIBILITY inline
2388void
2389vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2390{
2391 size_type __old_size = this->__size_;
2392 this->__size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002393 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002394}
2395
2396template <class _Allocator>
2397template <class _ForwardIterator>
2398typename enable_if
2399<
2400 __is_forward_iterator<_ForwardIterator>::value,
2401 void
2402>::type
2403vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2404{
2405 size_type __old_size = this->__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002406 this->__size_ += _VSTD::distance(__first, __last);
2407 _VSTD::copy(__first, __last, __make_iter(__old_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002408}
2409
2410template <class _Allocator>
2411_LIBCPP_INLINE_VISIBILITY inline
2412vector<bool, _Allocator>::vector()
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002413 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002414 : __begin_(0),
2415 __size_(0),
2416 __cap_alloc_(0)
2417{
2418}
2419
2420template <class _Allocator>
2421_LIBCPP_INLINE_VISIBILITY inline
2422vector<bool, _Allocator>::vector(const allocator_type& __a)
2423 : __begin_(0),
2424 __size_(0),
2425 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2426{
2427}
2428
2429template <class _Allocator>
2430vector<bool, _Allocator>::vector(size_type __n)
2431 : __begin_(0),
2432 __size_(0),
2433 __cap_alloc_(0)
2434{
2435 if (__n > 0)
2436 {
2437 allocate(__n);
2438 __construct_at_end(__n, false);
2439 }
2440}
2441
2442template <class _Allocator>
2443vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2444 : __begin_(0),
2445 __size_(0),
2446 __cap_alloc_(0)
2447{
2448 if (__n > 0)
2449 {
2450 allocate(__n);
2451 __construct_at_end(__n, __x);
2452 }
2453}
2454
2455template <class _Allocator>
2456vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2457 : __begin_(0),
2458 __size_(0),
2459 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2460{
2461 if (__n > 0)
2462 {
2463 allocate(__n);
2464 __construct_at_end(__n, __x);
2465 }
2466}
2467
2468template <class _Allocator>
2469template <class _InputIterator>
2470vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2471 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2472 !__is_forward_iterator<_InputIterator>::value>::type*)
2473 : __begin_(0),
2474 __size_(0),
2475 __cap_alloc_(0)
2476{
2477#ifndef _LIBCPP_NO_EXCEPTIONS
2478 try
2479 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002480#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002481 for (; __first != __last; ++__first)
2482 push_back(*__first);
2483#ifndef _LIBCPP_NO_EXCEPTIONS
2484 }
2485 catch (...)
2486 {
2487 if (__begin_ != 0)
2488 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2489 __invalidate_all_iterators();
2490 throw;
2491 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002492#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002493}
2494
2495template <class _Allocator>
2496template <class _InputIterator>
2497vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2498 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2499 !__is_forward_iterator<_InputIterator>::value>::type*)
2500 : __begin_(0),
2501 __size_(0),
2502 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2503{
2504#ifndef _LIBCPP_NO_EXCEPTIONS
2505 try
2506 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002507#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002508 for (; __first != __last; ++__first)
2509 push_back(*__first);
2510#ifndef _LIBCPP_NO_EXCEPTIONS
2511 }
2512 catch (...)
2513 {
2514 if (__begin_ != 0)
2515 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2516 __invalidate_all_iterators();
2517 throw;
2518 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002519#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002520}
2521
2522template <class _Allocator>
2523template <class _ForwardIterator>
2524vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2525 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2526 : __begin_(0),
2527 __size_(0),
2528 __cap_alloc_(0)
2529{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002530 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002531 if (__n > 0)
2532 {
2533 allocate(__n);
2534 __construct_at_end(__first, __last);
2535 }
2536}
2537
2538template <class _Allocator>
2539template <class _ForwardIterator>
2540vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2541 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2542 : __begin_(0),
2543 __size_(0),
2544 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2545{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002546 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002547 if (__n > 0)
2548 {
2549 allocate(__n);
2550 __construct_at_end(__first, __last);
2551 }
2552}
2553
Howard Hinnante3e32912011-08-12 21:56:02 +00002554#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2555
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002556template <class _Allocator>
2557vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2558 : __begin_(0),
2559 __size_(0),
2560 __cap_alloc_(0)
2561{
2562 size_type __n = static_cast<size_type>(__il.size());
2563 if (__n > 0)
2564 {
2565 allocate(__n);
2566 __construct_at_end(__il.begin(), __il.end());
2567 }
2568}
2569
2570template <class _Allocator>
2571vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2572 : __begin_(0),
2573 __size_(0),
2574 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2575{
2576 size_type __n = static_cast<size_type>(__il.size());
2577 if (__n > 0)
2578 {
2579 allocate(__n);
2580 __construct_at_end(__il.begin(), __il.end());
2581 }
2582}
2583
Howard Hinnante3e32912011-08-12 21:56:02 +00002584#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2585
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002586template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002587vector<bool, _Allocator>::~vector()
2588{
2589 if (__begin_ != 0)
2590 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2591#ifdef _LIBCPP_DEBUG
2592 __invalidate_all_iterators();
2593#endif
2594}
2595
2596template <class _Allocator>
2597vector<bool, _Allocator>::vector(const vector& __v)
2598 : __begin_(0),
2599 __size_(0),
2600 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2601{
2602 if (__v.size() > 0)
2603 {
2604 allocate(__v.size());
2605 __construct_at_end(__v.begin(), __v.end());
2606 }
2607}
2608
2609template <class _Allocator>
2610vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2611 : __begin_(0),
2612 __size_(0),
2613 __cap_alloc_(0, __a)
2614{
2615 if (__v.size() > 0)
2616 {
2617 allocate(__v.size());
2618 __construct_at_end(__v.begin(), __v.end());
2619 }
2620}
2621
2622template <class _Allocator>
2623vector<bool, _Allocator>&
2624vector<bool, _Allocator>::operator=(const vector& __v)
2625{
2626 if (this != &__v)
2627 {
2628 __copy_assign_alloc(__v);
2629 if (__v.__size_)
2630 {
2631 if (__v.__size_ > capacity())
2632 {
2633 deallocate();
2634 allocate(__v.__size_);
2635 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002636 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002637 }
2638 __size_ = __v.__size_;
2639 }
2640 return *this;
2641}
2642
Howard Hinnant73d21a42010-09-04 23:28:19 +00002643#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2644
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002645template <class _Allocator>
2646_LIBCPP_INLINE_VISIBILITY inline
2647vector<bool, _Allocator>::vector(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002648 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002649 : __begin_(__v.__begin_),
2650 __size_(__v.__size_),
2651 __cap_alloc_(__v.__cap_alloc_)
2652{
2653 __v.__begin_ = 0;
2654 __v.__size_ = 0;
2655 __v.__cap() = 0;
2656}
2657
2658template <class _Allocator>
2659vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2660 : __begin_(0),
2661 __size_(0),
2662 __cap_alloc_(0, __a)
2663{
2664 if (__a == allocator_type(__v.__alloc()))
2665 {
2666 this->__begin_ = __v.__begin_;
2667 this->__size_ = __v.__size_;
2668 this->__cap() = __v.__cap();
2669 __v.__begin_ = nullptr;
2670 __v.__cap() = __v.__size_ = 0;
2671 }
2672 else if (__v.size() > 0)
2673 {
2674 allocate(__v.size());
2675 __construct_at_end(__v.begin(), __v.end());
2676 }
2677}
2678
2679template <class _Allocator>
2680_LIBCPP_INLINE_VISIBILITY inline
2681vector<bool, _Allocator>&
2682vector<bool, _Allocator>::operator=(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002683 _NOEXCEPT_(
2684 __alloc_traits::propagate_on_container_move_assignment::value &&
2685 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002686{
2687 __move_assign(__v, integral_constant<bool,
2688 __storage_traits::propagate_on_container_move_assignment::value>());
2689}
2690
2691template <class _Allocator>
2692void
2693vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2694{
2695 if (__alloc() != __c.__alloc())
2696 assign(__c.begin(), __c.end());
2697 else
2698 __move_assign(__c, true_type());
2699}
2700
2701template <class _Allocator>
2702void
2703vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002704 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002705{
2706 deallocate();
2707 this->__begin_ = __c.__begin_;
2708 this->__size_ = __c.__size_;
2709 this->__cap() = __c.__cap();
2710 __move_assign_alloc(__c);
2711 __c.__begin_ = nullptr;
2712 __c.__cap() = __c.__size_ = 0;
2713}
Howard Hinnant73d21a42010-09-04 23:28:19 +00002714
2715#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002716
2717template <class _Allocator>
2718void
2719vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2720{
2721 __size_ = 0;
2722 if (__n > 0)
2723 {
2724 size_type __c = capacity();
2725 if (__n <= __c)
2726 __size_ = __n;
2727 else
2728 {
2729 vector __v(__alloc());
2730 __v.reserve(__recommend(__n));
2731 __v.__size_ = __n;
2732 swap(__v);
2733 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002734 _VSTD::fill_n(begin(), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002735 }
2736}
2737
2738template <class _Allocator>
2739template <class _InputIterator>
2740typename enable_if
2741<
2742 __is_input_iterator<_InputIterator>::value &&
2743 !__is_forward_iterator<_InputIterator>::value,
2744 void
2745>::type
2746vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2747{
2748 clear();
2749 for (; __first != __last; ++__first)
2750 push_back(*__first);
2751}
2752
2753template <class _Allocator>
2754template <class _ForwardIterator>
2755typename enable_if
2756<
2757 __is_forward_iterator<_ForwardIterator>::value,
2758 void
2759>::type
2760vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2761{
2762 clear();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002763 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002764 if (__n)
2765 {
2766 if (__n > capacity())
2767 {
2768 deallocate();
2769 allocate(__n);
2770 }
2771 __construct_at_end(__first, __last);
2772 }
2773}
2774
2775template <class _Allocator>
2776void
2777vector<bool, _Allocator>::reserve(size_type __n)
2778{
2779 if (__n > capacity())
2780 {
2781 vector __v(this->__alloc());
2782 __v.allocate(__n);
2783 __v.__construct_at_end(this->begin(), this->end());
2784 swap(__v);
2785 __invalidate_all_iterators();
2786 }
2787}
2788
2789template <class _Allocator>
2790void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002791vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002792{
2793 if (__external_cap_to_internal(size()) > __cap())
2794 {
2795#ifndef _LIBCPP_NO_EXCEPTIONS
2796 try
2797 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002798#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002799 vector(*this, allocator_type(__alloc())).swap(*this);
2800#ifndef _LIBCPP_NO_EXCEPTIONS
2801 }
2802 catch (...)
2803 {
2804 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002805#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002806 }
2807}
2808
2809template <class _Allocator>
2810typename vector<bool, _Allocator>::reference
2811vector<bool, _Allocator>::at(size_type __n)
2812{
2813 if (__n >= size())
2814 this->__throw_out_of_range();
2815 return (*this)[__n];
2816}
2817
2818template <class _Allocator>
2819typename vector<bool, _Allocator>::const_reference
2820vector<bool, _Allocator>::at(size_type __n) const
2821{
2822 if (__n >= size())
2823 this->__throw_out_of_range();
2824 return (*this)[__n];
2825}
2826
2827template <class _Allocator>
2828void
2829vector<bool, _Allocator>::push_back(const value_type& __x)
2830{
2831 if (this->__size_ == this->capacity())
2832 reserve(__recommend(this->__size_ + 1));
2833 ++this->__size_;
2834 back() = __x;
2835}
2836
2837template <class _Allocator>
2838typename vector<bool, _Allocator>::iterator
2839vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2840{
2841 iterator __r;
2842 if (size() < capacity())
2843 {
2844 const_iterator __old_end = end();
2845 ++__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002846 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002847 __r = __const_iterator_cast(__position);
2848 }
2849 else
2850 {
2851 vector __v(__alloc());
2852 __v.reserve(__recommend(__size_ + 1));
2853 __v.__size_ = __size_ + 1;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002854 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2855 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002856 swap(__v);
2857 }
2858 *__r = __x;
2859 return __r;
2860}
2861
2862template <class _Allocator>
2863typename vector<bool, _Allocator>::iterator
2864vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
2865{
2866 iterator __r;
2867 size_type __c = capacity();
2868 if (__n <= __c && size() <= __c - __n)
2869 {
2870 const_iterator __old_end = end();
2871 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002872 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873 __r = __const_iterator_cast(__position);
2874 }
2875 else
2876 {
2877 vector __v(__alloc());
2878 __v.reserve(__recommend(__size_ + __n));
2879 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002880 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2881 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002882 swap(__v);
2883 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002884 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002885 return __r;
2886}
2887
2888template <class _Allocator>
2889template <class _InputIterator>
2890typename enable_if
2891<
2892 __is_input_iterator <_InputIterator>::value &&
2893 !__is_forward_iterator<_InputIterator>::value,
2894 typename vector<bool, _Allocator>::iterator
2895>::type
2896vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
2897{
2898 difference_type __off = __position - begin();
2899 iterator __p = __const_iterator_cast(__position);
2900 iterator __old_end = end();
2901 for (; size() != capacity() && __first != __last; ++__first)
2902 {
2903 ++this->__size_;
2904 back() = *__first;
2905 }
2906 vector __v(__alloc());
2907 if (__first != __last)
2908 {
2909#ifndef _LIBCPP_NO_EXCEPTIONS
2910 try
2911 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002912#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002913 __v.assign(__first, __last);
2914 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
2915 difference_type __old_p = __p - begin();
2916 reserve(__recommend(size() + __v.size()));
2917 __p = begin() + __old_p;
2918 __old_end = begin() + __old_size;
2919#ifndef _LIBCPP_NO_EXCEPTIONS
2920 }
2921 catch (...)
2922 {
2923 erase(__old_end, end());
2924 throw;
2925 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002926#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002927 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002928 __p = _VSTD::rotate(__p, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002929 insert(__p, __v.begin(), __v.end());
2930 return begin() + __off;
2931}
2932
2933template <class _Allocator>
2934template <class _ForwardIterator>
2935typename enable_if
2936<
2937 __is_forward_iterator<_ForwardIterator>::value,
2938 typename vector<bool, _Allocator>::iterator
2939>::type
2940vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
2941{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002942 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002943 iterator __r;
2944 size_type __c = capacity();
2945 if (__n <= __c && size() <= __c - __n)
2946 {
2947 const_iterator __old_end = end();
2948 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002949 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002950 __r = __const_iterator_cast(__position);
2951 }
2952 else
2953 {
2954 vector __v(__alloc());
2955 __v.reserve(__recommend(__size_ + __n));
2956 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002957 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2958 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002959 swap(__v);
2960 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002961 _VSTD::copy(__first, __last, __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002962 return __r;
2963}
2964
2965template <class _Allocator>
2966_LIBCPP_INLINE_VISIBILITY inline
2967typename vector<bool, _Allocator>::iterator
2968vector<bool, _Allocator>::erase(const_iterator __position)
2969{
2970 iterator __r = __const_iterator_cast(__position);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002971 _VSTD::copy(__position + 1, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002972 --__size_;
2973 return __r;
2974}
2975
2976template <class _Allocator>
2977typename vector<bool, _Allocator>::iterator
2978vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
2979{
2980 iterator __r = __const_iterator_cast(__first);
2981 difference_type __d = __last - __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002982 _VSTD::copy(__last, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002983 __size_ -= __d;
2984 return __r;
2985}
2986
2987template <class _Allocator>
2988void
2989vector<bool, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002990 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2991 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002992{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002993 _VSTD::swap(this->__begin_, __x.__begin_);
2994 _VSTD::swap(this->__size_, __x.__size_);
2995 _VSTD::swap(this->__cap(), __x.__cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002996 __swap_alloc(this->__alloc(), __x.__alloc());
2997#ifdef _LIBCPP_DEBUG
2998 iterator::swap(this, &__x);
2999 const_iterator::swap(this, &__x);
Howard Hinnant324bb032010-08-22 00:02:43 +00003000#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003001}
3002
Howard Hinnant324bb032010-08-22 00:02:43 +00003003template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003004void
3005vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3006{
3007 size_type __cs = size();
3008 if (__cs < __sz)
3009 {
3010 iterator __r;
3011 size_type __c = capacity();
3012 size_type __n = __sz - __cs;
3013 if (__n <= __c && __cs <= __c - __n)
3014 {
3015 __r = end();
3016 __size_ += __n;
3017 }
3018 else
3019 {
3020 vector __v(__alloc());
3021 __v.reserve(__recommend(__size_ + __n));
3022 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003023 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003024 swap(__v);
3025 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003026 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003027 }
3028 else
3029 __size_ = __sz;
3030}
3031
Howard Hinnant324bb032010-08-22 00:02:43 +00003032template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003033void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003034vector<bool, _Allocator>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003035{
3036 // do middle whole words
3037 size_type __n = __size_;
3038 __storage_pointer __p = __begin_;
3039 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3040 *__p = ~*__p;
3041 // do last partial word
3042 if (__n > 0)
3043 {
3044 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3045 __storage_type __b = *__p & __m;
3046 *__p &= ~__m;
3047 *__p |= ~__b & __m;
3048 }
3049}
3050
Howard Hinnant324bb032010-08-22 00:02:43 +00003051template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003052bool
3053vector<bool, _Allocator>::__invariants() const
3054{
3055 if (this->__begin_ == 0)
3056 {
3057 if (this->__size_ != 0 || this->__cap() != 0)
3058 return false;
3059 }
3060 else
3061 {
3062 if (this->__cap() == 0)
3063 return false;
3064 if (this->__size_ > this->capacity())
3065 return false;
3066 }
3067 return true;
3068}
3069
Howard Hinnant324bb032010-08-22 00:02:43 +00003070template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003071size_t
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003072vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003073{
3074 size_t __h = 0;
3075 // do middle whole words
3076 size_type __n = __size_;
3077 __storage_pointer __p = __begin_;
3078 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3079 __h ^= *__p;
3080 // do last partial word
3081 if (__n > 0)
3082 {
3083 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3084 __h ^= *__p & __m;
3085 }
3086 return __h;
3087}
3088
3089template <class _Allocator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003090struct _LIBCPP_VISIBLE hash<vector<bool, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003091 : public unary_function<vector<bool, _Allocator>, size_t>
3092{
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003094 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003095 {return __vec.__hash_code();}
3096};
3097
3098template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003099_LIBCPP_INLINE_VISIBILITY inline
3100bool
3101operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3102{
3103 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003104 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003105}
3106
3107template <class _Tp, class _Allocator>
3108_LIBCPP_INLINE_VISIBILITY inline
3109bool
3110operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3111{
3112 return !(__x == __y);
3113}
3114
3115template <class _Tp, class _Allocator>
3116_LIBCPP_INLINE_VISIBILITY inline
3117bool
3118operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3119{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003120 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003121}
3122
3123template <class _Tp, class _Allocator>
3124_LIBCPP_INLINE_VISIBILITY inline
3125bool
3126operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3127{
3128 return __y < __x;
3129}
3130
3131template <class _Tp, class _Allocator>
3132_LIBCPP_INLINE_VISIBILITY inline
3133bool
3134operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3135{
3136 return !(__x < __y);
3137}
3138
3139template <class _Tp, class _Allocator>
3140_LIBCPP_INLINE_VISIBILITY inline
3141bool
3142operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3143{
3144 return !(__y < __x);
3145}
3146
3147template <class _Tp, class _Allocator>
3148_LIBCPP_INLINE_VISIBILITY inline
3149void
3150swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003151 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003152{
3153 __x.swap(__y);
3154}
3155
3156_LIBCPP_END_NAMESPACE_STD
3157
3158#endif // _LIBCPP_VECTOR