blob: e4fc024da52cc06f46badf43775ad1585dd4624c [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===------------------------------ vector --------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// 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:168//
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:4320template <class T, class Allocator = allocator<T> >
Howard Hinnantbc8d3f92010-05-11 19:42:1621class vector
Howard Hinnant324bb032010-08-22 00:02:4322{
23public:
24 typedef T value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:1625 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:4037 vector()
38 noexcept(is_nothrow_default_constructible<allocator_type>::value);
39 explicit vector(const allocator_type&);
Howard Hinnantbc8d3f92010-05-11 19:42:1640 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:4045 vector(vector&& x)
46 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1647 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:4051 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:1655 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:4061 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1662
Howard Hinnantd1d27a42011-06-03 19:40:4063 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:1667
Howard Hinnantd1d27a42011-06-03 19:40:4068 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:1672
Howard Hinnantd1d27a42011-06-03 19:40:4073 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:1677
Howard Hinnantd1d27a42011-06-03 19:40:4078 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:1682 void reserve(size_type n);
Howard Hinnantd1d27a42011-06-03 19:40:4083 void shrink_to_fit() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1684
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:4095 value_type* data() noexcept;
96 const value_type* data() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1697
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:40115 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16116
117 void resize(size_type sz);
118 void resize(size_type sz, const value_type& c);
119
Howard Hinnantd1d27a42011-06-03 19:40:40120 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:16123
124 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43125};
Howard Hinnantbc8d3f92010-05-11 19:42:16126
Howard Hinnant324bb032010-08-22 00:02:43127template <class Allocator = allocator<T> >
Howard Hinnantbc8d3f92010-05-11 19:42:16128class vector<bool, Allocator>
Howard Hinnant324bb032010-08-22 00:02:43129{
130public:
131 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16132 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:40145 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:16151 };
152
153 class const_reference
154 {
155 public:
Howard Hinnantd1d27a42011-06-03 19:40:40156 const_reference(const reference&) noexcept;
157 operator bool() const noexcept;
158 const_iterator operator&() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16159 };
160
Howard Hinnantd1d27a42011-06-03 19:40:40161 vector()
162 noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant9cbee432011-09-02 20:42:31163 explicit vector(const allocator_type&);
Howard Hinnantbc8d3f92010-05-11 19:42:16164 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:40168 vector(vector&& x)
169 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16170 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:40174 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:16178 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:40184 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16185
Howard Hinnantd1d27a42011-06-03 19:40:40186 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:16190
Howard Hinnantd1d27a42011-06-03 19:40:40191 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:16195
Howard Hinnantd1d27a42011-06-03 19:40:40196 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:16200
Howard Hinnantd1d27a42011-06-03 19:40:40201 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:16205 void reserve(size_type n);
Howard Hinnantd1d27a42011-06-03 19:40:40206 void shrink_to_fit() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16207
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);
Marshall Clow198a2a52013-08-13 23:54:12219 template <class... Args> void emplace_back(Args&&... args); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16220 void pop_back();
221
Marshall Clow198a2a52013-08-13 23:54:12222 template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16223 iterator insert(const_iterator position, const value_type& x);
224 iterator insert(const_iterator position, size_type n, const value_type& x);
225 template <class InputIterator>
226 iterator insert(const_iterator position, InputIterator first, InputIterator last);
227 iterator insert(const_iterator position, initializer_list<value_type> il);
228
229 iterator erase(const_iterator position);
230 iterator erase(const_iterator first, const_iterator last);
231
Howard Hinnantd1d27a42011-06-03 19:40:40232 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16233
234 void resize(size_type sz);
235 void resize(size_type sz, value_type x);
236
Howard Hinnantd1d27a42011-06-03 19:40:40237 void swap(vector&)
238 noexcept(!allocator_type::propagate_on_container_swap::value ||
239 __is_nothrow_swappable<allocator_type>::value);
240 void flip() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16241
242 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43243};
Howard Hinnantbc8d3f92010-05-11 19:42:16244
245template <class Allocator> struct hash<std::vector<bool, Allocator>>;
246
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);
251template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
252template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
253
Howard Hinnantd1d27a42011-06-03 19:40:40254template <class T, class Allocator>
255void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
256 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16257
258} // std
259
260*/
261
262#include <__config>
263#include <__bit_reference>
264#include <type_traits>
265#include <climits>
266#include <limits>
267#include <initializer_list>
268#include <memory>
269#include <stdexcept>
270#include <algorithm>
271#include <cstring>
272#include <__split_buffer>
273#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16274
Howard Hinnant66c6f972011-11-29 16:45:27275#include <__undef_min_max>
276
Howard Hinnant5e571422013-08-23 20:10:18277#ifdef _LIBCPP_DEBUG
Howard Hinnant8b00e6c2013-08-02 00:26:35278# include <__debug>
279#else
280# define _LIBCPP_ASSERT(x, m) ((void)0)
281#endif
282
Howard Hinnant08e17472011-10-17 20:05:10283#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16284#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10285#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16286
287_LIBCPP_BEGIN_NAMESPACE_STD
288
289template <bool>
290class __vector_base_common
291{
292protected:
293 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
294 void __throw_length_error() const;
295 void __throw_out_of_range() const;
296};
297
298template <bool __b>
299void
300__vector_base_common<__b>::__throw_length_error() const
301{
302#ifndef _LIBCPP_NO_EXCEPTIONS
303 throw length_error("vector");
304#else
305 assert(!"vector length_error");
306#endif
307}
308
309template <bool __b>
310void
311__vector_base_common<__b>::__throw_out_of_range() const
312{
313#ifndef _LIBCPP_NO_EXCEPTIONS
314 throw out_of_range("vector");
315#else
316 assert(!"vector out_of_range");
317#endif
318}
319
Howard Hinnante9df0a52013-08-01 18:17:34320#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45321#pragma warning( push )
322#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34323#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34324_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34325#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45326#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34327#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16328
329template <class _Tp, class _Allocator>
330class __vector_base
331 : protected __vector_base_common<true>
332{
333protected:
Howard Hinnant324bb032010-08-22 00:02:43334 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16335 typedef _Allocator allocator_type;
336 typedef allocator_traits<allocator_type> __alloc_traits;
337 typedef value_type& reference;
338 typedef const value_type& const_reference;
339 typedef typename __alloc_traits::size_type size_type;
340 typedef typename __alloc_traits::difference_type difference_type;
341 typedef typename __alloc_traits::pointer pointer;
342 typedef typename __alloc_traits::const_pointer const_pointer;
343 typedef pointer iterator;
344 typedef const_pointer const_iterator;
345
346 pointer __begin_;
347 pointer __end_;
348 __compressed_pair<pointer, allocator_type> __end_cap_;
349
Howard Hinnantd1d27a42011-06-03 19:40:40350 _LIBCPP_INLINE_VISIBILITY
351 allocator_type& __alloc() _NOEXCEPT
352 {return __end_cap_.second();}
353 _LIBCPP_INLINE_VISIBILITY
354 const allocator_type& __alloc() const _NOEXCEPT
355 {return __end_cap_.second();}
356 _LIBCPP_INLINE_VISIBILITY
357 pointer& __end_cap() _NOEXCEPT
358 {return __end_cap_.first();}
359 _LIBCPP_INLINE_VISIBILITY
360 const pointer& __end_cap() const _NOEXCEPT
361 {return __end_cap_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16362
Howard Hinnantd1d27a42011-06-03 19:40:40363 _LIBCPP_INLINE_VISIBILITY
364 __vector_base()
365 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43366 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16367 ~__vector_base();
368
Howard Hinnantd1d27a42011-06-03 19:40:40369 _LIBCPP_INLINE_VISIBILITY
370 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
371 _LIBCPP_INLINE_VISIBILITY
372 size_type capacity() const _NOEXCEPT
373 {return static_cast<size_type>(__end_cap() - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16374
Howard Hinnantd1d27a42011-06-03 19:40:40375 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2c39cbe2013-06-27 19:35:32376 void __destruct_at_end(pointer __new_last) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16377
Howard Hinnantee6ccd02010-09-23 18:58:28378 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16379 void __copy_assign_alloc(const __vector_base& __c)
380 {__copy_assign_alloc(__c, integral_constant<bool,
381 __alloc_traits::propagate_on_container_copy_assignment::value>());}
382
Howard Hinnantee6ccd02010-09-23 18:58:28383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16384 void __move_assign_alloc(__vector_base& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40385 _NOEXCEPT_(
386 !__alloc_traits::propagate_on_container_move_assignment::value ||
387 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16388 {__move_assign_alloc(__c, integral_constant<bool,
389 __alloc_traits::propagate_on_container_move_assignment::value>());}
390
Howard Hinnantee6ccd02010-09-23 18:58:28391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16392 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40393 _NOEXCEPT_(
394 !__alloc_traits::propagate_on_container_swap::value ||
395 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16396 {__swap_alloc(__x, __y, integral_constant<bool,
397 __alloc_traits::propagate_on_container_swap::value>());}
398private:
Howard Hinnantee6ccd02010-09-23 18:58:28399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16400 void __copy_assign_alloc(const __vector_base& __c, true_type)
401 {
402 if (__alloc() != __c.__alloc())
403 {
404 clear();
405 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
406 __begin_ = __end_ = __end_cap() = nullptr;
407 }
408 __alloc() = __c.__alloc();
409 }
410
Howard Hinnantee6ccd02010-09-23 18:58:28411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04412 void __copy_assign_alloc(const __vector_base&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16413 {}
414
Howard Hinnantee6ccd02010-09-23 18:58:28415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31416 void __move_assign_alloc(__vector_base& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40417 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16418 {
Howard Hinnant0949eed2011-06-30 21:18:19419 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16420 }
421
Howard Hinnantee6ccd02010-09-23 18:58:28422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04423 void __move_assign_alloc(__vector_base&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40424 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16425 {}
426
Howard Hinnantee6ccd02010-09-23 18:58:28427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16428 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40429 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16430 {
Howard Hinnant0949eed2011-06-30 21:18:19431 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16432 swap(__x, __y);
433 }
Howard Hinnantee6ccd02010-09-23 18:58:28434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04435 static void __swap_alloc(allocator_type&, allocator_type&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40436 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16437 {}
438};
439
440template <class _Tp, class _Allocator>
441_LIBCPP_INLINE_VISIBILITY inline
442void
Howard Hinnant2c39cbe2013-06-27 19:35:32443__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16444{
Howard Hinnantb0bfd9b2012-02-15 00:41:34445 while (__new_last != __end_)
Howard Hinnant2c39cbe2013-06-27 19:35:32446 __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16447}
448
449template <class _Tp, class _Allocator>
450_LIBCPP_INLINE_VISIBILITY inline
451__vector_base<_Tp, _Allocator>::__vector_base()
Howard Hinnantd1d27a42011-06-03 19:40:40452 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant2c39cbe2013-06-27 19:35:32453 : __begin_(nullptr),
454 __end_(nullptr),
455 __end_cap_(nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16456{
457}
458
459template <class _Tp, class _Allocator>
460_LIBCPP_INLINE_VISIBILITY inline
461__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32462 : __begin_(nullptr),
463 __end_(nullptr),
464 __end_cap_(nullptr, __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16465{
466}
467
468template <class _Tp, class _Allocator>
469__vector_base<_Tp, _Allocator>::~__vector_base()
470{
Howard Hinnant2c39cbe2013-06-27 19:35:32471 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16472 {
473 clear();
474 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
475 }
476}
477
478template <class _Tp, class _Allocator = allocator<_Tp> >
Howard Hinnant0f678bd2013-08-12 18:38:34479class _LIBCPP_TYPE_VIS_ONLY vector
Howard Hinnantbc8d3f92010-05-11 19:42:16480 : private __vector_base<_Tp, _Allocator>
481{
482private:
483 typedef __vector_base<_Tp, _Allocator> __base;
Howard Hinnant324bb032010-08-22 00:02:43484public:
Howard Hinnantbc8d3f92010-05-11 19:42:16485 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43486 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16487 typedef _Allocator allocator_type;
488 typedef typename __base::__alloc_traits __alloc_traits;
489 typedef typename __base::reference reference;
490 typedef typename __base::const_reference const_reference;
491 typedef typename __base::size_type size_type;
492 typedef typename __base::difference_type difference_type;
493 typedef typename __base::pointer pointer;
494 typedef typename __base::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16495 typedef __wrap_iter<pointer> iterator;
496 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19497 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
498 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16499
Howard Hinnant02d5e182013-03-26 19:04:56500 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
501 "Allocator::value_type must be same type as value_type");
502
Howard Hinnantd1d27a42011-06-03 19:40:40503 _LIBCPP_INLINE_VISIBILITY
504 vector()
505 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant7a563db2011-09-14 18:33:51506 {
Howard Hinnantabe26282011-09-16 17:29:17507#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51508 __get_db()->__insert_c(this);
509#endif
510 }
511 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
512 : __base(__a)
513 {
Howard Hinnantabe26282011-09-16 17:29:17514#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51515 __get_db()->__insert_c(this);
516#endif
517 }
Howard Hinnantbc8d3f92010-05-11 19:42:16518 explicit vector(size_type __n);
519 vector(size_type __n, const_reference __x);
520 vector(size_type __n, const_reference __x, const allocator_type& __a);
521 template <class _InputIterator>
522 vector(_InputIterator __first, _InputIterator __last,
523 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32524 !__is_forward_iterator<_InputIterator>::value &&
525 is_constructible<
526 value_type,
527 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16528 template <class _InputIterator>
529 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
530 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32531 !__is_forward_iterator<_InputIterator>::value &&
532 is_constructible<
533 value_type,
534 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16535 template <class _ForwardIterator>
536 vector(_ForwardIterator __first, _ForwardIterator __last,
Howard Hinnant742fecb2013-03-28 17:44:32537 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
538 is_constructible<
539 value_type,
540 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16541 template <class _ForwardIterator>
542 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
Howard Hinnant742fecb2013-03-28 17:44:32543 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
544 is_constructible<
545 value_type,
546 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02547#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16549 vector(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16551 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02552#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantabe26282011-09-16 17:29:17553#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantee6ccd02010-09-23 18:58:28554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a563db2011-09-14 18:33:51555 ~vector()
556 {
557 __get_db()->__erase_c(this);
558 }
Howard Hinnantbc8d3f92010-05-11 19:42:16559#endif
560
561 vector(const vector& __x);
562 vector(const vector& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16564 vector& operator=(const vector& __x);
Howard Hinnant73d21a42010-09-04 23:28:19565#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40567 vector(vector&& __x)
568 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16570 vector(vector&& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40572 vector& operator=(vector&& __x)
573 _NOEXCEPT_(
574 __alloc_traits::propagate_on_container_move_assignment::value &&
575 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19576#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02577#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16579 vector& operator=(initializer_list<value_type> __il)
580 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02581#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16582
583 template <class _InputIterator>
584 typename enable_if
585 <
586 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32587 !__is_forward_iterator<_InputIterator>::value &&
588 is_constructible<
589 value_type,
590 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16591 void
592 >::type
593 assign(_InputIterator __first, _InputIterator __last);
594 template <class _ForwardIterator>
595 typename enable_if
596 <
Howard Hinnant742fecb2013-03-28 17:44:32597 __is_forward_iterator<_ForwardIterator>::value &&
598 is_constructible<
599 value_type,
600 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16601 void
602 >::type
603 assign(_ForwardIterator __first, _ForwardIterator __last);
604
605 void assign(size_type __n, const_reference __u);
Howard Hinnante3e32912011-08-12 21:56:02606#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16608 void assign(initializer_list<value_type> __il)
609 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02610#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16611
Howard Hinnantd1d27a42011-06-03 19:40:40612 _LIBCPP_INLINE_VISIBILITY
613 allocator_type get_allocator() const _NOEXCEPT
614 {return this->__alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16615
Howard Hinnantd1d27a42011-06-03 19:40:40616 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
617 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
618 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
619 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16620
Howard Hinnantd1d27a42011-06-03 19:40:40621 _LIBCPP_INLINE_VISIBILITY
622 reverse_iterator rbegin() _NOEXCEPT
623 {return reverse_iterator(end());}
624 _LIBCPP_INLINE_VISIBILITY
625 const_reverse_iterator rbegin() const _NOEXCEPT
626 {return const_reverse_iterator(end());}
627 _LIBCPP_INLINE_VISIBILITY
628 reverse_iterator rend() _NOEXCEPT
629 {return reverse_iterator(begin());}
630 _LIBCPP_INLINE_VISIBILITY
631 const_reverse_iterator rend() const _NOEXCEPT
632 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16633
Howard Hinnantd1d27a42011-06-03 19:40:40634 _LIBCPP_INLINE_VISIBILITY
635 const_iterator cbegin() const _NOEXCEPT
636 {return begin();}
637 _LIBCPP_INLINE_VISIBILITY
638 const_iterator cend() const _NOEXCEPT
639 {return end();}
640 _LIBCPP_INLINE_VISIBILITY
641 const_reverse_iterator crbegin() const _NOEXCEPT
642 {return rbegin();}
643 _LIBCPP_INLINE_VISIBILITY
644 const_reverse_iterator crend() const _NOEXCEPT
645 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16646
Howard Hinnantd1d27a42011-06-03 19:40:40647 _LIBCPP_INLINE_VISIBILITY
648 size_type size() const _NOEXCEPT
649 {return static_cast<size_type>(this->__end_ - this->__begin_);}
650 _LIBCPP_INLINE_VISIBILITY
651 size_type capacity() const _NOEXCEPT
652 {return __base::capacity();}
653 _LIBCPP_INLINE_VISIBILITY
654 bool empty() const _NOEXCEPT
655 {return this->__begin_ == this->__end_;}
656 size_type max_size() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16657 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40658 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16659
660 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
661 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
662 reference at(size_type __n);
663 const_reference at(size_type __n) const;
664
Howard Hinnant7a563db2011-09-14 18:33:51665 _LIBCPP_INLINE_VISIBILITY reference front()
666 {
667 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
668 return *this->__begin_;
669 }
670 _LIBCPP_INLINE_VISIBILITY const_reference front() const
671 {
672 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
673 return *this->__begin_;
674 }
675 _LIBCPP_INLINE_VISIBILITY reference back()
676 {
677 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
678 return *(this->__end_ - 1);
679 }
680 _LIBCPP_INLINE_VISIBILITY const_reference back() const
681 {
682 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
683 return *(this->__end_ - 1);
684 }
Howard Hinnantbc8d3f92010-05-11 19:42:16685
Howard Hinnantd1d27a42011-06-03 19:40:40686 _LIBCPP_INLINE_VISIBILITY
687 value_type* data() _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19688 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantd1d27a42011-06-03 19:40:40689 _LIBCPP_INLINE_VISIBILITY
690 const value_type* data() const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19691 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16692
Howard Hinnant2d72b1e2010-12-17 14:46:43693 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19694#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb0bfd9b2012-02-15 00:41:34695 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19696#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16697 template <class... _Args>
698 void emplace_back(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19699#endif // _LIBCPP_HAS_NO_VARIADICS
700#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16701 void pop_back();
702
703 iterator insert(const_iterator __position, const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19704#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16705 iterator insert(const_iterator __position, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19706#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16707 template <class... _Args>
708 iterator emplace(const_iterator __position, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19709#endif // _LIBCPP_HAS_NO_VARIADICS
710#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16711 iterator insert(const_iterator __position, size_type __n, const_reference __x);
712 template <class _InputIterator>
713 typename enable_if
714 <
715 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32716 !__is_forward_iterator<_InputIterator>::value &&
717 is_constructible<
718 value_type,
719 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16720 iterator
721 >::type
722 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
723 template <class _ForwardIterator>
724 typename enable_if
725 <
Howard Hinnant742fecb2013-03-28 17:44:32726 __is_forward_iterator<_ForwardIterator>::value &&
727 is_constructible<
728 value_type,
729 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16730 iterator
731 >::type
732 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02733#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16735 iterator insert(const_iterator __position, initializer_list<value_type> __il)
736 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02737#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16738
Howard Hinnant2d72b1e2010-12-17 14:46:43739 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16740 iterator erase(const_iterator __first, const_iterator __last);
741
Howard Hinnantd1d27a42011-06-03 19:40:40742 _LIBCPP_INLINE_VISIBILITY
743 void clear() _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51744 {
745 __base::clear();
746 __invalidate_all_iterators();
747 }
Howard Hinnantbc8d3f92010-05-11 19:42:16748
749 void resize(size_type __sz);
750 void resize(size_type __sz, const_reference __x);
751
Howard Hinnantd1d27a42011-06-03 19:40:40752 void swap(vector&)
753 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
754 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16755
756 bool __invariants() const;
757
Howard Hinnantabe26282011-09-16 17:29:17758#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51759
760 bool __dereferenceable(const const_iterator* __i) const;
761 bool __decrementable(const const_iterator* __i) const;
762 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
763 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
764
Howard Hinnantabe26282011-09-16 17:29:17765#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51766
Howard Hinnantbc8d3f92010-05-11 19:42:16767private:
Howard Hinnant2d72b1e2010-12-17 14:46:43768 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16769 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40770 void deallocate() _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43771 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
Howard Hinnant04240d92011-01-04 19:53:31772 void __construct_at_end(size_type __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16773 void __construct_at_end(size_type __n, const_reference __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16774 template <class _ForwardIterator>
775 typename enable_if
776 <
777 __is_forward_iterator<_ForwardIterator>::value,
778 void
779 >::type
780 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
781 void __move_construct_at_end(pointer __first, pointer __last);
782 void __append(size_type __n);
783 void __append(size_type __n, const_reference __x);
Howard Hinnant2d72b1e2010-12-17 14:46:43784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40785 iterator __make_iter(pointer __p) _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40787 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16788 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
789 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
790 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
Howard Hinnantd1d27a42011-06-03 19:40:40791 void __move_assign(vector& __c, true_type)
792 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16793 void __move_assign(vector& __c, false_type);
Howard Hinnant7a563db2011-09-14 18:33:51794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2c39cbe2013-06-27 19:35:32795 void __destruct_at_end(pointer __new_last) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51796 {
Howard Hinnantabe26282011-09-16 17:29:17797#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51798 __c_node* __c = __get_db()->__find_c_and_lock(this);
799 for (__i_node** __p = __c->end_; __p != __c->beg_; )
800 {
801 --__p;
802 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
803 if (__i->base() > __new_last)
804 {
805 (*__p)->__c_ = nullptr;
806 if (--__c->end_ != __p)
807 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
808 }
809 }
810 __get_db()->unlock();
811#endif
812 __base::__destruct_at_end(__new_last);
813 }
Howard Hinnantb0bfd9b2012-02-15 00:41:34814 template <class _Up>
815 void
816#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
817 __push_back_slow_path(_Up&& __x);
818#else
819 __push_back_slow_path(_Up& __x);
820#endif
Howard Hinnant0438ea22012-02-26 15:30:12821#if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
822 template <class... _Args>
823 void
824 __emplace_back_slow_path(_Args&&... __args);
825#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16826};
827
828template <class _Tp, class _Allocator>
829void
830vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
831{
Howard Hinnantb0bfd9b2012-02-15 00:41:34832 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
Howard Hinnant0949eed2011-06-30 21:18:19833 _VSTD::swap(this->__begin_, __v.__begin_);
834 _VSTD::swap(this->__end_, __v.__end_);
835 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16836 __v.__first_ = __v.__begin_;
837 __invalidate_all_iterators();
838}
839
840template <class _Tp, class _Allocator>
841typename vector<_Tp, _Allocator>::pointer
842vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
843{
844 pointer __r = __v.__begin_;
Howard Hinnantb0bfd9b2012-02-15 00:41:34845 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
846 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
Howard Hinnant0949eed2011-06-30 21:18:19847 _VSTD::swap(this->__begin_, __v.__begin_);
848 _VSTD::swap(this->__end_, __v.__end_);
849 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16850 __v.__first_ = __v.__begin_;
851 __invalidate_all_iterators();
852 return __r;
853}
854
855// Allocate space for __n objects
856// throws length_error if __n > max_size()
857// throws (probably bad_alloc) if memory run out
858// Precondition: __begin_ == __end_ == __end_cap() == 0
859// Precondition: __n > 0
860// Postcondition: capacity() == __n
861// Postcondition: size() == 0
862template <class _Tp, class _Allocator>
863void
864vector<_Tp, _Allocator>::allocate(size_type __n)
865{
866 if (__n > max_size())
867 this->__throw_length_error();
868 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
869 this->__end_cap() = this->__begin_ + __n;
870}
871
872template <class _Tp, class _Allocator>
873void
Howard Hinnantd1d27a42011-06-03 19:40:40874vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16875{
Howard Hinnant2c39cbe2013-06-27 19:35:32876 if (this->__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16877 {
878 clear();
879 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
Howard Hinnant2c39cbe2013-06-27 19:35:32880 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16881 }
882}
883
884template <class _Tp, class _Allocator>
885typename vector<_Tp, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40886vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16887{
Sean Hunt110b8bf2011-07-29 23:31:58888 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:16889}
890
891// Precondition: __new_size > capacity()
892template <class _Tp, class _Allocator>
893_LIBCPP_INLINE_VISIBILITY inline
894typename vector<_Tp, _Allocator>::size_type
895vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
896{
897 const size_type __ms = max_size();
898 if (__new_size > __ms)
899 this->__throw_length_error();
900 const size_type __cap = capacity();
901 if (__cap >= __ms / 2)
902 return __ms;
Sean Hunt110b8bf2011-07-29 23:31:58903 return _VSTD::max<size_type>(2*__cap, __new_size);
Howard Hinnantbc8d3f92010-05-11 19:42:16904}
905
906// Default constructs __n objects starting at __end_
907// throws if construction throws
908// Precondition: __n > 0
909// Precondition: size() + __n <= capacity()
910// Postcondition: size() == size() + __n
911template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16912void
913vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
914{
Howard Hinnantbc8d3f92010-05-11 19:42:16915 allocator_type& __a = this->__alloc();
916 do
917 {
Howard Hinnant0949eed2011-06-30 21:18:19918 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16919 ++this->__end_;
920 --__n;
921 } while (__n > 0);
922}
923
Howard Hinnantbc8d3f92010-05-11 19:42:16924// Copy constructs __n objects starting at __end_ from __x
925// throws if construction throws
926// Precondition: __n > 0
927// Precondition: size() + __n <= capacity()
928// Postcondition: size() == old size() + __n
929// Postcondition: [i] == __x for all i in [size() - __n, __n)
930template <class _Tp, class _Allocator>
931_LIBCPP_INLINE_VISIBILITY inline
932void
933vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
934{
Howard Hinnantbc8d3f92010-05-11 19:42:16935 allocator_type& __a = this->__alloc();
936 do
937 {
Howard Hinnant0949eed2011-06-30 21:18:19938 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16939 ++this->__end_;
940 --__n;
941 } while (__n > 0);
942}
943
944template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16945template <class _ForwardIterator>
946typename enable_if
947<
948 __is_forward_iterator<_ForwardIterator>::value,
949 void
950>::type
951vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
952{
953 allocator_type& __a = this->__alloc();
954 for (; __first != __last; ++__first)
955 {
Howard Hinnant0949eed2011-06-30 21:18:19956 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16957 ++this->__end_;
958 }
959}
960
961template <class _Tp, class _Allocator>
962void
963vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
964{
965 allocator_type& __a = this->__alloc();
966 for (; __first != __last; ++__first)
967 {
Howard Hinnant0949eed2011-06-30 21:18:19968 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
969 _VSTD::move(*__first));
Howard Hinnantbc8d3f92010-05-11 19:42:16970 ++this->__end_;
971 }
972}
973
974// Default constructs __n objects starting at __end_
975// throws if construction throws
976// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40977// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16978template <class _Tp, class _Allocator>
979void
980vector<_Tp, _Allocator>::__append(size_type __n)
981{
982 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
983 this->__construct_at_end(__n);
984 else
985 {
986 allocator_type& __a = this->__alloc();
987 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
988 __v.__construct_at_end(__n);
989 __swap_out_circular_buffer(__v);
990 }
991}
992
993// Default constructs __n objects starting at __end_
994// throws if construction throws
995// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40996// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16997template <class _Tp, class _Allocator>
998void
999vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1000{
1001 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1002 this->__construct_at_end(__n, __x);
1003 else
1004 {
1005 allocator_type& __a = this->__alloc();
1006 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1007 __v.__construct_at_end(__n, __x);
1008 __swap_out_circular_buffer(__v);
1009 }
1010}
1011
1012template <class _Tp, class _Allocator>
1013vector<_Tp, _Allocator>::vector(size_type __n)
1014{
Howard Hinnant0442b122011-09-16 18:41:291015#if _LIBCPP_DEBUG_LEVEL >= 2
1016 __get_db()->__insert_c(this);
1017#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161018 if (__n > 0)
1019 {
1020 allocate(__n);
1021 __construct_at_end(__n);
1022 }
1023}
1024
1025template <class _Tp, class _Allocator>
1026vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1027{
Howard Hinnant0442b122011-09-16 18:41:291028#if _LIBCPP_DEBUG_LEVEL >= 2
1029 __get_db()->__insert_c(this);
1030#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161031 if (__n > 0)
1032 {
1033 allocate(__n);
1034 __construct_at_end(__n, __x);
1035 }
1036}
1037
1038template <class _Tp, class _Allocator>
1039vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1040 : __base(__a)
1041{
Howard Hinnant0442b122011-09-16 18:41:291042#if _LIBCPP_DEBUG_LEVEL >= 2
1043 __get_db()->__insert_c(this);
1044#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161045 if (__n > 0)
1046 {
1047 allocate(__n);
1048 __construct_at_end(__n, __x);
1049 }
1050}
1051
1052template <class _Tp, class _Allocator>
1053template <class _InputIterator>
1054vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
1055 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:321056 !__is_forward_iterator<_InputIterator>::value &&
1057 is_constructible<
1058 value_type,
1059 typename iterator_traits<_InputIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:161060{
Howard Hinnantabe26282011-09-16 17:29:171061#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511062 __get_db()->__insert_c(this);
1063#endif
Howard Hinnant0442b122011-09-16 18:41:291064 for (; __first != __last; ++__first)
1065 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:161066}
1067
1068template <class _Tp, class _Allocator>
1069template <class _InputIterator>
1070vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1071 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:321072 !__is_forward_iterator<_InputIterator>::value &&
1073 is_constructible<
1074 value_type,
1075 typename iterator_traits<_InputIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:161076 : __base(__a)
1077{
Howard Hinnantabe26282011-09-16 17:29:171078#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511079 __get_db()->__insert_c(this);
1080#endif
Howard Hinnant0442b122011-09-16 18:41:291081 for (; __first != __last; ++__first)
1082 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:161083}
1084
1085template <class _Tp, class _Allocator>
1086template <class _ForwardIterator>
1087vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
Howard Hinnant742fecb2013-03-28 17:44:321088 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1089 is_constructible<
1090 value_type,
1091 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:161092{
Howard Hinnant0442b122011-09-16 18:41:291093#if _LIBCPP_DEBUG_LEVEL >= 2
1094 __get_db()->__insert_c(this);
1095#endif
Howard Hinnant0949eed2011-06-30 21:18:191096 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:161097 if (__n > 0)
1098 {
1099 allocate(__n);
1100 __construct_at_end(__first, __last);
1101 }
1102}
1103
1104template <class _Tp, class _Allocator>
1105template <class _ForwardIterator>
1106vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
Howard Hinnant742fecb2013-03-28 17:44:321107 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1108 is_constructible<
1109 value_type,
1110 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:161111 : __base(__a)
1112{
Howard Hinnant0442b122011-09-16 18:41:291113#if _LIBCPP_DEBUG_LEVEL >= 2
1114 __get_db()->__insert_c(this);
1115#endif
Howard Hinnant0949eed2011-06-30 21:18:191116 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:161117 if (__n > 0)
1118 {
1119 allocate(__n);
1120 __construct_at_end(__first, __last);
1121 }
1122}
1123
1124template <class _Tp, class _Allocator>
1125vector<_Tp, _Allocator>::vector(const vector& __x)
1126 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1127{
Howard Hinnant0442b122011-09-16 18:41:291128#if _LIBCPP_DEBUG_LEVEL >= 2
1129 __get_db()->__insert_c(this);
1130#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161131 size_type __n = __x.size();
1132 if (__n > 0)
1133 {
1134 allocate(__n);
1135 __construct_at_end(__x.__begin_, __x.__end_);
1136 }
1137}
1138
1139template <class _Tp, class _Allocator>
1140vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1141 : __base(__a)
1142{
Howard Hinnant0442b122011-09-16 18:41:291143#if _LIBCPP_DEBUG_LEVEL >= 2
1144 __get_db()->__insert_c(this);
1145#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161146 size_type __n = __x.size();
1147 if (__n > 0)
1148 {
1149 allocate(__n);
1150 __construct_at_end(__x.__begin_, __x.__end_);
1151 }
1152}
1153
Howard Hinnant73d21a42010-09-04 23:28:191154#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161155
1156template <class _Tp, class _Allocator>
1157_LIBCPP_INLINE_VISIBILITY inline
1158vector<_Tp, _Allocator>::vector(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:401159 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:191160 : __base(_VSTD::move(__x.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:161161{
Howard Hinnantabe26282011-09-16 17:29:171162#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511163 __get_db()->__insert_c(this);
Howard Hinnante6125bd2011-09-19 16:34:291164 __get_db()->swap(this, &__x);
Howard Hinnant7a563db2011-09-14 18:33:511165#endif
Howard Hinnant0442b122011-09-16 18:41:291166 this->__begin_ = __x.__begin_;
1167 this->__end_ = __x.__end_;
1168 this->__end_cap() = __x.__end_cap();
Howard Hinnant2c39cbe2013-06-27 19:35:321169 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:161170}
1171
1172template <class _Tp, class _Allocator>
1173_LIBCPP_INLINE_VISIBILITY inline
1174vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1175 : __base(__a)
1176{
Howard Hinnant0442b122011-09-16 18:41:291177#if _LIBCPP_DEBUG_LEVEL >= 2
1178 __get_db()->__insert_c(this);
1179#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161180 if (__a == __x.__alloc())
1181 {
1182 this->__begin_ = __x.__begin_;
1183 this->__end_ = __x.__end_;
1184 this->__end_cap() = __x.__end_cap();
1185 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:291186#if _LIBCPP_DEBUG_LEVEL >= 2
1187 __get_db()->swap(this, &__x);
1188#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161189 }
1190 else
1191 {
Howard Hinnant99968442011-11-29 18:15:501192 typedef move_iterator<iterator> _Ip;
1193 assign(_Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161194 }
1195}
1196
Howard Hinnante3e32912011-08-12 21:56:021197#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1198
Howard Hinnantbc8d3f92010-05-11 19:42:161199template <class _Tp, class _Allocator>
1200_LIBCPP_INLINE_VISIBILITY inline
1201vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1202{
Howard Hinnant0442b122011-09-16 18:41:291203#if _LIBCPP_DEBUG_LEVEL >= 2
1204 __get_db()->__insert_c(this);
1205#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161206 if (__il.size() > 0)
1207 {
1208 allocate(__il.size());
1209 __construct_at_end(__il.begin(), __il.end());
1210 }
1211}
1212
1213template <class _Tp, class _Allocator>
1214_LIBCPP_INLINE_VISIBILITY inline
1215vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1216 : __base(__a)
1217{
Howard Hinnant0442b122011-09-16 18:41:291218#if _LIBCPP_DEBUG_LEVEL >= 2
1219 __get_db()->__insert_c(this);
1220#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161221 if (__il.size() > 0)
1222 {
1223 allocate(__il.size());
1224 __construct_at_end(__il.begin(), __il.end());
1225 }
1226}
1227
Howard Hinnante3e32912011-08-12 21:56:021228#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1229
Howard Hinnantbc8d3f92010-05-11 19:42:161230template <class _Tp, class _Allocator>
1231_LIBCPP_INLINE_VISIBILITY inline
1232vector<_Tp, _Allocator>&
1233vector<_Tp, _Allocator>::operator=(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:401234 _NOEXCEPT_(
1235 __alloc_traits::propagate_on_container_move_assignment::value &&
1236 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161237{
1238 __move_assign(__x, integral_constant<bool,
1239 __alloc_traits::propagate_on_container_move_assignment::value>());
1240 return *this;
1241}
1242
1243template <class _Tp, class _Allocator>
1244void
1245vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1246{
1247 if (__base::__alloc() != __c.__alloc())
1248 {
Howard Hinnant99968442011-11-29 18:15:501249 typedef move_iterator<iterator> _Ip;
1250 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161251 }
1252 else
1253 __move_assign(__c, true_type());
1254}
1255
1256template <class _Tp, class _Allocator>
1257void
1258vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:401259 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161260{
1261 deallocate();
1262 this->__begin_ = __c.__begin_;
1263 this->__end_ = __c.__end_;
1264 this->__end_cap() = __c.__end_cap();
1265 __base::__move_assign_alloc(__c);
1266 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:291267#if _LIBCPP_DEBUG_LEVEL >= 2
1268 __get_db()->swap(this, &__c);
1269#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161270}
1271
Howard Hinnant73d21a42010-09-04 23:28:191272#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161273
1274template <class _Tp, class _Allocator>
1275_LIBCPP_INLINE_VISIBILITY inline
1276vector<_Tp, _Allocator>&
1277vector<_Tp, _Allocator>::operator=(const vector& __x)
1278{
1279 if (this != &__x)
1280 {
1281 __base::__copy_assign_alloc(__x);
1282 assign(__x.__begin_, __x.__end_);
1283 }
1284 return *this;
1285}
1286
1287template <class _Tp, class _Allocator>
1288template <class _InputIterator>
1289typename enable_if
1290<
1291 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:321292 !__is_forward_iterator<_InputIterator>::value &&
1293 is_constructible<
1294 _Tp,
1295 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161296 void
1297>::type
1298vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1299{
1300 clear();
1301 for (; __first != __last; ++__first)
1302 push_back(*__first);
1303}
1304
1305template <class _Tp, class _Allocator>
1306template <class _ForwardIterator>
1307typename enable_if
1308<
Howard Hinnant742fecb2013-03-28 17:44:321309 __is_forward_iterator<_ForwardIterator>::value &&
1310 is_constructible<
1311 _Tp,
1312 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161313 void
1314>::type
1315vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1316{
Howard Hinnant0949eed2011-06-30 21:18:191317 typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:161318 if (static_cast<size_type>(__new_size) <= capacity())
1319 {
1320 _ForwardIterator __mid = __last;
1321 bool __growing = false;
1322 if (static_cast<size_type>(__new_size) > size())
1323 {
1324 __growing = true;
1325 __mid = __first;
Howard Hinnant0949eed2011-06-30 21:18:191326 _VSTD::advance(__mid, size());
Howard Hinnantbc8d3f92010-05-11 19:42:161327 }
Howard Hinnant0949eed2011-06-30 21:18:191328 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:161329 if (__growing)
1330 __construct_at_end(__mid, __last);
1331 else
1332 this->__destruct_at_end(__m);
1333 }
1334 else
1335 {
1336 deallocate();
1337 allocate(__recommend(static_cast<size_type>(__new_size)));
1338 __construct_at_end(__first, __last);
1339 }
1340}
1341
1342template <class _Tp, class _Allocator>
1343void
1344vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1345{
1346 if (__n <= capacity())
1347 {
1348 size_type __s = size();
Howard Hinnant0949eed2011-06-30 21:18:191349 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
Howard Hinnantbc8d3f92010-05-11 19:42:161350 if (__n > __s)
1351 __construct_at_end(__n - __s, __u);
1352 else
Howard Hinnantadff4892010-05-24 17:49:411353 this->__destruct_at_end(this->__begin_ + __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161354 }
1355 else
1356 {
1357 deallocate();
1358 allocate(__recommend(static_cast<size_type>(__n)));
1359 __construct_at_end(__n, __u);
1360 }
1361}
1362
Howard Hinnant324bb032010-08-22 00:02:431363template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161364_LIBCPP_INLINE_VISIBILITY inline
1365typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:401366vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161367{
Howard Hinnantabe26282011-09-16 17:29:171368#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:161369 return iterator(this, __p);
1370#else
1371 return iterator(__p);
1372#endif
1373}
1374
Howard Hinnant324bb032010-08-22 00:02:431375template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161376_LIBCPP_INLINE_VISIBILITY inline
1377typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:401378vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161379{
Howard Hinnantabe26282011-09-16 17:29:171380#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:161381 return const_iterator(this, __p);
1382#else
1383 return const_iterator(__p);
1384#endif
1385}
1386
Howard Hinnant324bb032010-08-22 00:02:431387template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161388_LIBCPP_INLINE_VISIBILITY inline
1389typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:401390vector<_Tp, _Allocator>::begin() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161391{
1392 return __make_iter(this->__begin_);
1393}
1394
Howard Hinnant324bb032010-08-22 00:02:431395template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161396_LIBCPP_INLINE_VISIBILITY inline
1397typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:401398vector<_Tp, _Allocator>::begin() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161399{
1400 return __make_iter(this->__begin_);
1401}
1402
Howard Hinnant324bb032010-08-22 00:02:431403template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161404_LIBCPP_INLINE_VISIBILITY inline
1405typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:401406vector<_Tp, _Allocator>::end() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161407{
1408 return __make_iter(this->__end_);
1409}
1410
Howard Hinnant324bb032010-08-22 00:02:431411template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161412_LIBCPP_INLINE_VISIBILITY inline
1413typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:401414vector<_Tp, _Allocator>::end() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161415{
1416 return __make_iter(this->__end_);
1417}
1418
Howard Hinnant324bb032010-08-22 00:02:431419template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161420_LIBCPP_INLINE_VISIBILITY inline
1421typename vector<_Tp, _Allocator>::reference
1422vector<_Tp, _Allocator>::operator[](size_type __n)
1423{
Howard Hinnant7a563db2011-09-14 18:33:511424 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:161425 return this->__begin_[__n];
1426}
1427
Howard Hinnant324bb032010-08-22 00:02:431428template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161429_LIBCPP_INLINE_VISIBILITY inline
1430typename vector<_Tp, _Allocator>::const_reference
1431vector<_Tp, _Allocator>::operator[](size_type __n) const
1432{
Howard Hinnant7a563db2011-09-14 18:33:511433 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:161434 return this->__begin_[__n];
1435}
1436
Howard Hinnant324bb032010-08-22 00:02:431437template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161438typename vector<_Tp, _Allocator>::reference
1439vector<_Tp, _Allocator>::at(size_type __n)
1440{
1441 if (__n >= size())
1442 this->__throw_out_of_range();
1443 return this->__begin_[__n];
1444}
1445
Howard Hinnant324bb032010-08-22 00:02:431446template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161447typename vector<_Tp, _Allocator>::const_reference
1448vector<_Tp, _Allocator>::at(size_type __n) const
1449{
1450 if (__n >= size())
1451 this->__throw_out_of_range();
1452 return this->__begin_[__n];
1453}
1454
1455template <class _Tp, class _Allocator>
1456void
1457vector<_Tp, _Allocator>::reserve(size_type __n)
1458{
1459 if (__n > capacity())
1460 {
1461 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:401462 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:161463 __swap_out_circular_buffer(__v);
1464 }
1465}
1466
1467template <class _Tp, class _Allocator>
1468void
Howard Hinnantd1d27a42011-06-03 19:40:401469vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161470{
1471 if (capacity() > size())
1472 {
1473#ifndef _LIBCPP_NO_EXCEPTIONS
1474 try
1475 {
Howard Hinnant324bb032010-08-22 00:02:431476#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161477 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:401478 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:161479 __swap_out_circular_buffer(__v);
1480#ifndef _LIBCPP_NO_EXCEPTIONS
1481 }
1482 catch (...)
1483 {
1484 }
Howard Hinnant324bb032010-08-22 00:02:431485#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161486 }
1487}
1488
1489template <class _Tp, class _Allocator>
Howard Hinnantb0bfd9b2012-02-15 00:41:341490template <class _Up>
1491void
1492#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1493vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1494#else
1495vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1496#endif
1497{
1498 allocator_type& __a = this->__alloc();
1499 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1500 // __v.push_back(_VSTD::forward<_Up>(__x));
Howard Hinnantf619e232013-01-11 20:36:591501 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
1502 __v.__end_++;
Howard Hinnantb0bfd9b2012-02-15 00:41:341503 __swap_out_circular_buffer(__v);
1504}
1505
1506template <class _Tp, class _Allocator>
1507_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:161508void
1509vector<_Tp, _Allocator>::push_back(const_reference __x)
1510{
Howard Hinnantb0bfd9b2012-02-15 00:41:341511 if (this->__end_ != this->__end_cap())
Howard Hinnantbc8d3f92010-05-11 19:42:161512 {
1513 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191514 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161515 ++this->__end_;
1516 }
1517 else
Howard Hinnantb0bfd9b2012-02-15 00:41:341518 __push_back_slow_path(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:161519}
1520
Howard Hinnant73d21a42010-09-04 23:28:191521#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161522
1523template <class _Tp, class _Allocator>
Howard Hinnantb0bfd9b2012-02-15 00:41:341524_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:161525void
1526vector<_Tp, _Allocator>::push_back(value_type&& __x)
1527{
1528 if (this->__end_ < this->__end_cap())
1529 {
1530 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191531 _VSTD::__to_raw_pointer(this->__end_),
1532 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:161533 ++this->__end_;
1534 }
1535 else
Howard Hinnantb0bfd9b2012-02-15 00:41:341536 __push_back_slow_path(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:161537}
1538
Howard Hinnant73d21a42010-09-04 23:28:191539#ifndef _LIBCPP_HAS_NO_VARIADICS
1540
Howard Hinnantbc8d3f92010-05-11 19:42:161541template <class _Tp, class _Allocator>
1542template <class... _Args>
1543void
Howard Hinnant0438ea22012-02-26 15:30:121544vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1545{
1546 allocator_type& __a = this->__alloc();
1547 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1548// __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantf619e232013-01-11 20:36:591549 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
1550 __v.__end_++;
Howard Hinnant0438ea22012-02-26 15:30:121551 __swap_out_circular_buffer(__v);
1552}
1553
1554template <class _Tp, class _Allocator>
1555template <class... _Args>
1556_LIBCPP_INLINE_VISIBILITY inline
1557void
Howard Hinnantbc8d3f92010-05-11 19:42:161558vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1559{
1560 if (this->__end_ < this->__end_cap())
1561 {
1562 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191563 _VSTD::__to_raw_pointer(this->__end_),
1564 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161565 ++this->__end_;
1566 }
1567 else
Howard Hinnant0438ea22012-02-26 15:30:121568 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161569}
1570
Howard Hinnant73d21a42010-09-04 23:28:191571#endif // _LIBCPP_HAS_NO_VARIADICS
1572#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161573
1574template <class _Tp, class _Allocator>
1575_LIBCPP_INLINE_VISIBILITY inline
1576void
1577vector<_Tp, _Allocator>::pop_back()
1578{
Howard Hinnant7a563db2011-09-14 18:33:511579 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
Howard Hinnantbc8d3f92010-05-11 19:42:161580 this->__destruct_at_end(this->__end_ - 1);
1581}
1582
1583template <class _Tp, class _Allocator>
1584_LIBCPP_INLINE_VISIBILITY inline
1585typename vector<_Tp, _Allocator>::iterator
1586vector<_Tp, _Allocator>::erase(const_iterator __position)
1587{
Howard Hinnantabe26282011-09-16 17:29:171588#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511589 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1590 "vector::erase(iterator) called with an iterator not"
1591 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171592#endif
Howard Hinnant782da332013-03-25 22:12:261593 _LIBCPP_ASSERT(__position != end(),
1594 "vector::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnant2c39cbe2013-06-27 19:35:321595 difference_type __ps = __position - cbegin();
1596 pointer __p = this->__begin_ + __ps;
Howard Hinnantbc8d3f92010-05-11 19:42:161597 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:191598 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:161599 return __r;
1600}
1601
1602template <class _Tp, class _Allocator>
1603typename vector<_Tp, _Allocator>::iterator
1604vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1605{
Howard Hinnantabe26282011-09-16 17:29:171606#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511607 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1608 "vector::erase(iterator, iterator) called with an iterator not"
1609 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171610#endif
Howard Hinnant7a563db2011-09-14 18:33:511611 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:161612 pointer __p = this->__begin_ + (__first - begin());
1613 iterator __r = __make_iter(__p);
Howard Hinnantb4e67cf2013-04-18 15:02:571614 if (__first != __last)
1615 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:161616 return __r;
1617}
1618
1619template <class _Tp, class _Allocator>
1620void
1621vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1622{
1623 pointer __old_last = this->__end_;
1624 difference_type __n = __old_last - __to;
1625 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1626 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191627 _VSTD::__to_raw_pointer(this->__end_),
1628 _VSTD::move(*__i));
1629 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
Howard Hinnantbc8d3f92010-05-11 19:42:161630}
1631
1632template <class _Tp, class _Allocator>
1633typename vector<_Tp, _Allocator>::iterator
1634vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1635{
Howard Hinnantabe26282011-09-16 17:29:171636#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511637 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1638 "vector::insert(iterator, x) called with an iterator not"
1639 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171640#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161641 pointer __p = this->__begin_ + (__position - begin());
1642 if (this->__end_ < this->__end_cap())
1643 {
1644 if (__p == this->__end_)
1645 {
1646 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191647 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161648 ++this->__end_;
1649 }
1650 else
1651 {
1652 __move_range(__p, this->__end_, __p + 1);
1653 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1654 if (__p <= __xr && __xr < this->__end_)
1655 ++__xr;
1656 *__p = *__xr;
1657 }
1658 }
1659 else
1660 {
1661 allocator_type& __a = this->__alloc();
1662 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1663 __v.push_back(__x);
1664 __p = __swap_out_circular_buffer(__v, __p);
1665 }
1666 return __make_iter(__p);
1667}
1668
Howard Hinnant73d21a42010-09-04 23:28:191669#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161670
1671template <class _Tp, class _Allocator>
1672typename vector<_Tp, _Allocator>::iterator
1673vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1674{
Howard Hinnantabe26282011-09-16 17:29:171675#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511676 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1677 "vector::insert(iterator, x) called with an iterator not"
1678 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171679#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161680 pointer __p = this->__begin_ + (__position - begin());
1681 if (this->__end_ < this->__end_cap())
1682 {
1683 if (__p == this->__end_)
1684 {
1685 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191686 _VSTD::__to_raw_pointer(this->__end_),
1687 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:161688 ++this->__end_;
1689 }
1690 else
1691 {
1692 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:191693 *__p = _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:161694 }
1695 }
1696 else
1697 {
1698 allocator_type& __a = this->__alloc();
1699 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:191700 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:161701 __p = __swap_out_circular_buffer(__v, __p);
1702 }
1703 return __make_iter(__p);
1704}
1705
Howard Hinnant73d21a42010-09-04 23:28:191706#ifndef _LIBCPP_HAS_NO_VARIADICS
1707
Howard Hinnantbc8d3f92010-05-11 19:42:161708template <class _Tp, class _Allocator>
1709template <class... _Args>
1710typename vector<_Tp, _Allocator>::iterator
1711vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1712{
Howard Hinnantabe26282011-09-16 17:29:171713#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511714 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1715 "vector::emplace(iterator, x) called with an iterator not"
1716 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171717#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161718 pointer __p = this->__begin_ + (__position - begin());
1719 if (this->__end_ < this->__end_cap())
1720 {
1721 if (__p == this->__end_)
1722 {
1723 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191724 _VSTD::__to_raw_pointer(this->__end_),
1725 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161726 ++this->__end_;
1727 }
1728 else
1729 {
Howard Hinnanta58402a2012-07-08 23:23:041730 value_type __tmp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161731 __move_range(__p, this->__end_, __p + 1);
Howard Hinnanta58402a2012-07-08 23:23:041732 *__p = _VSTD::move(__tmp);
Howard Hinnantbc8d3f92010-05-11 19:42:161733 }
1734 }
1735 else
1736 {
1737 allocator_type& __a = this->__alloc();
1738 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:191739 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161740 __p = __swap_out_circular_buffer(__v, __p);
1741 }
1742 return __make_iter(__p);
1743}
1744
Howard Hinnant73d21a42010-09-04 23:28:191745#endif // _LIBCPP_HAS_NO_VARIADICS
1746#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161747
1748template <class _Tp, class _Allocator>
1749typename vector<_Tp, _Allocator>::iterator
1750vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1751{
Howard Hinnantabe26282011-09-16 17:29:171752#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511753 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1754 "vector::insert(iterator, n, x) called with an iterator not"
1755 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171756#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161757 pointer __p = this->__begin_ + (__position - begin());
1758 if (__n > 0)
1759 {
1760 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1761 {
1762 size_type __old_n = __n;
1763 pointer __old_last = this->__end_;
1764 if (__n > static_cast<size_type>(this->__end_ - __p))
1765 {
1766 size_type __cx = __n - (this->__end_ - __p);
1767 __construct_at_end(__cx, __x);
1768 __n -= __cx;
1769 }
1770 if (__n > 0)
1771 {
1772 __move_range(__p, __old_last, __p + __old_n);
1773 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1774 if (__p <= __xr && __xr < this->__end_)
1775 __xr += __old_n;
Howard Hinnant0949eed2011-06-30 21:18:191776 _VSTD::fill_n(__p, __n, *__xr);
Howard Hinnantbc8d3f92010-05-11 19:42:161777 }
1778 }
1779 else
1780 {
1781 allocator_type& __a = this->__alloc();
1782 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1783 __v.__construct_at_end(__n, __x);
1784 __p = __swap_out_circular_buffer(__v, __p);
1785 }
1786 }
1787 return __make_iter(__p);
1788}
1789
1790template <class _Tp, class _Allocator>
1791template <class _InputIterator>
1792typename enable_if
1793<
1794 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:321795 !__is_forward_iterator<_InputIterator>::value &&
1796 is_constructible<
1797 _Tp,
1798 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161799 typename vector<_Tp, _Allocator>::iterator
1800>::type
1801vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1802{
Howard Hinnantabe26282011-09-16 17:29:171803#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511804 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1805 "vector::insert(iterator, range) called with an iterator not"
1806 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171807#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161808 difference_type __off = __position - begin();
1809 pointer __p = this->__begin_ + __off;
1810 allocator_type& __a = this->__alloc();
1811 pointer __old_last = this->__end_;
1812 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1813 {
Howard Hinnant0949eed2011-06-30 21:18:191814 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
Howard Hinnantbc8d3f92010-05-11 19:42:161815 *__first);
1816 ++this->__end_;
1817 }
1818 __split_buffer<value_type, allocator_type&> __v(__a);
1819 if (__first != __last)
1820 {
1821#ifndef _LIBCPP_NO_EXCEPTIONS
1822 try
1823 {
Howard Hinnant324bb032010-08-22 00:02:431824#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161825 __v.__construct_at_end(__first, __last);
1826 difference_type __old_size = __old_last - this->__begin_;
1827 difference_type __old_p = __p - this->__begin_;
1828 reserve(__recommend(size() + __v.size()));
1829 __p = this->__begin_ + __old_p;
1830 __old_last = this->__begin_ + __old_size;
1831#ifndef _LIBCPP_NO_EXCEPTIONS
1832 }
1833 catch (...)
1834 {
1835 erase(__make_iter(__old_last), end());
1836 throw;
1837 }
Howard Hinnant324bb032010-08-22 00:02:431838#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161839 }
Howard Hinnant0949eed2011-06-30 21:18:191840 __p = _VSTD::rotate(__p, __old_last, this->__end_);
Howard Hinnant0442b122011-09-16 18:41:291841 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1842 make_move_iterator(__v.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161843 return begin() + __off;
1844}
1845
1846template <class _Tp, class _Allocator>
1847template <class _ForwardIterator>
1848typename enable_if
1849<
Howard Hinnant742fecb2013-03-28 17:44:321850 __is_forward_iterator<_ForwardIterator>::value &&
1851 is_constructible<
1852 _Tp,
1853 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161854 typename vector<_Tp, _Allocator>::iterator
1855>::type
1856vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1857{
Howard Hinnantabe26282011-09-16 17:29:171858#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511859 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1860 "vector::insert(iterator, range) called with an iterator not"
1861 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171862#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161863 pointer __p = this->__begin_ + (__position - begin());
Howard Hinnant0949eed2011-06-30 21:18:191864 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:161865 if (__n > 0)
1866 {
1867 if (__n <= this->__end_cap() - this->__end_)
1868 {
1869 size_type __old_n = __n;
1870 pointer __old_last = this->__end_;
1871 _ForwardIterator __m = __last;
1872 difference_type __dx = this->__end_ - __p;
1873 if (__n > __dx)
1874 {
1875 __m = __first;
Howard Hinnant0949eed2011-06-30 21:18:191876 _VSTD::advance(__m, this->__end_ - __p);
Howard Hinnantbc8d3f92010-05-11 19:42:161877 __construct_at_end(__m, __last);
1878 __n = __dx;
1879 }
1880 if (__n > 0)
1881 {
1882 __move_range(__p, __old_last, __p + __old_n);
Howard Hinnant0949eed2011-06-30 21:18:191883 _VSTD::copy(__first, __m, __p);
Howard Hinnantbc8d3f92010-05-11 19:42:161884 }
1885 }
1886 else
1887 {
1888 allocator_type& __a = this->__alloc();
1889 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1890 __v.__construct_at_end(__first, __last);
1891 __p = __swap_out_circular_buffer(__v, __p);
1892 }
1893 }
1894 return __make_iter(__p);
1895}
1896
1897template <class _Tp, class _Allocator>
1898void
1899vector<_Tp, _Allocator>::resize(size_type __sz)
1900{
1901 size_type __cs = size();
1902 if (__cs < __sz)
1903 this->__append(__sz - __cs);
1904 else if (__cs > __sz)
1905 this->__destruct_at_end(this->__begin_ + __sz);
1906}
1907
1908template <class _Tp, class _Allocator>
1909void
1910vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1911{
1912 size_type __cs = size();
1913 if (__cs < __sz)
1914 this->__append(__sz - __cs, __x);
1915 else if (__cs > __sz)
1916 this->__destruct_at_end(this->__begin_ + __sz);
1917}
1918
1919template <class _Tp, class _Allocator>
1920void
1921vector<_Tp, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:401922 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1923 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161924{
Howard Hinnant7a563db2011-09-14 18:33:511925 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
1926 this->__alloc() == __x.__alloc(),
1927 "vector::swap: Either propagate_on_container_swap must be true"
1928 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:191929 _VSTD::swap(this->__begin_, __x.__begin_);
1930 _VSTD::swap(this->__end_, __x.__end_);
1931 _VSTD::swap(this->__end_cap(), __x.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:161932 __base::__swap_alloc(this->__alloc(), __x.__alloc());
Howard Hinnantabe26282011-09-16 17:29:171933#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511934 __get_db()->swap(this, &__x);
Howard Hinnantabe26282011-09-16 17:29:171935#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:161936}
1937
Howard Hinnant324bb032010-08-22 00:02:431938template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161939bool
1940vector<_Tp, _Allocator>::__invariants() const
1941{
Howard Hinnant2c39cbe2013-06-27 19:35:321942 if (this->__begin_ == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:161943 {
Howard Hinnant2c39cbe2013-06-27 19:35:321944 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:161945 return false;
1946 }
1947 else
1948 {
1949 if (this->__begin_ > this->__end_)
1950 return false;
1951 if (this->__begin_ == this->__end_cap())
1952 return false;
1953 if (this->__end_ > this->__end_cap())
1954 return false;
1955 }
1956 return true;
1957}
1958
Howard Hinnantabe26282011-09-16 17:29:171959#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511960
Howard Hinnantbc8d3f92010-05-11 19:42:161961template <class _Tp, class _Allocator>
Howard Hinnant7a563db2011-09-14 18:33:511962bool
1963vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
1964{
1965 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
1966}
1967
1968template <class _Tp, class _Allocator>
1969bool
1970vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
1971{
1972 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
1973}
1974
1975template <class _Tp, class _Allocator>
1976bool
1977vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
1978{
1979 const_pointer __p = __i->base() + __n;
1980 return this->__begin_ <= __p && __p <= this->__end_;
1981}
1982
1983template <class _Tp, class _Allocator>
1984bool
1985vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1986{
1987 const_pointer __p = __i->base() + __n;
1988 return this->__begin_ <= __p && __p < this->__end_;
1989}
1990
Howard Hinnantabe26282011-09-16 17:29:171991#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511992
1993template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161994_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:161995void
1996vector<_Tp, _Allocator>::__invalidate_all_iterators()
1997{
Howard Hinnantabe26282011-09-16 17:29:171998#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511999 __get_db()->__invalidate_all(this);
Howard Hinnantabe26282011-09-16 17:29:172000#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:162001}
2002
2003// vector<bool>
2004
2005template <class _Allocator> class vector<bool, _Allocator>;
2006
2007template <class _Allocator> struct hash<vector<bool, _Allocator> >;
2008
2009template <class _Allocator>
Howard Hinnantf03c3b42011-07-02 20:33:232010struct __has_storage_type<vector<bool, _Allocator> >
2011{
2012 static const bool value = true;
2013};
2014
2015template <class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:342016class _LIBCPP_TYPE_VIS_ONLY vector<bool, _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162017 : private __vector_base_common<true>
2018{
2019public:
2020 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:432021 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:162022 typedef _Allocator allocator_type;
2023 typedef allocator_traits<allocator_type> __alloc_traits;
Howard Hinnantbc8d3f92010-05-11 19:42:162024 typedef typename __alloc_traits::size_type size_type;
2025 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnantf867f632012-05-07 16:50:382026 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:162027 typedef __bit_iterator<vector, false> pointer;
2028 typedef __bit_iterator<vector, true> const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:162029 typedef pointer iterator;
2030 typedef const_pointer const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:192031 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
2032 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:162033
2034private:
Howard Hinnantbc8d3f92010-05-11 19:42:162035 typedef typename __alloc_traits::template
2036#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
2037 rebind_alloc<__storage_type>
2038#else
2039 rebind_alloc<__storage_type>::other
2040#endif
2041 __storage_allocator;
2042 typedef allocator_traits<__storage_allocator> __storage_traits;
2043 typedef typename __storage_traits::pointer __storage_pointer;
2044 typedef typename __storage_traits::const_pointer __const_storage_pointer;
2045
2046 __storage_pointer __begin_;
2047 size_type __size_;
2048 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
Howard Hinnant2bf1c082011-07-09 15:50:422049public:
Howard Hinnantf03c3b42011-07-02 20:33:232050 typedef __bit_reference<vector> reference;
2051 typedef __bit_const_reference<vector> const_reference;
Howard Hinnant2bf1c082011-07-09 15:50:422052private:
Howard Hinnantd1d27a42011-06-03 19:40:402053 _LIBCPP_INLINE_VISIBILITY
2054 size_type& __cap() _NOEXCEPT
2055 {return __cap_alloc_.first();}
2056 _LIBCPP_INLINE_VISIBILITY
2057 const size_type& __cap() const _NOEXCEPT
2058 {return __cap_alloc_.first();}
2059 _LIBCPP_INLINE_VISIBILITY
2060 __storage_allocator& __alloc() _NOEXCEPT
2061 {return __cap_alloc_.second();}
2062 _LIBCPP_INLINE_VISIBILITY
2063 const __storage_allocator& __alloc() const _NOEXCEPT
2064 {return __cap_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:162065
2066 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2067
Howard Hinnantd1d27a42011-06-03 19:40:402068 _LIBCPP_INLINE_VISIBILITY
2069 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162070 {return __n * __bits_per_word;}
Howard Hinnantd1d27a42011-06-03 19:40:402071 _LIBCPP_INLINE_VISIBILITY
2072 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162073 {return (__n - 1) / __bits_per_word + 1;}
2074
2075public:
Howard Hinnantd1d27a42011-06-03 19:40:402076 _LIBCPP_INLINE_VISIBILITY
2077 vector()
2078 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:432079 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:162080 ~vector();
2081 explicit vector(size_type __n);
2082 vector(size_type __n, const value_type& __v);
2083 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2084 template <class _InputIterator>
2085 vector(_InputIterator __first, _InputIterator __last,
2086 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2087 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2088 template <class _InputIterator>
2089 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2090 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2091 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2092 template <class _ForwardIterator>
2093 vector(_ForwardIterator __first, _ForwardIterator __last,
2094 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2095 template <class _ForwardIterator>
2096 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2097 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2098
2099 vector(const vector& __v);
2100 vector(const vector& __v, const allocator_type& __a);
2101 vector& operator=(const vector& __v);
Howard Hinnante3e32912011-08-12 21:56:022102#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:162103 vector(initializer_list<value_type> __il);
2104 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:022105#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:162106
Howard Hinnant73d21a42010-09-04 23:28:192107#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantd1d27a42011-06-03 19:40:402108 _LIBCPP_INLINE_VISIBILITY
2109 vector(vector&& __v)
2110 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:162111 vector(vector&& __v, const allocator_type& __a);
Howard Hinnantd1d27a42011-06-03 19:40:402112 _LIBCPP_INLINE_VISIBILITY
2113 vector& operator=(vector&& __v)
2114 _NOEXCEPT_(
2115 __alloc_traits::propagate_on_container_move_assignment::value &&
2116 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:192117#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:022118#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:282119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162120 vector& operator=(initializer_list<value_type> __il)
2121 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:022122#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:162123
2124 template <class _InputIterator>
2125 typename enable_if
2126 <
2127 __is_input_iterator<_InputIterator>::value &&
2128 !__is_forward_iterator<_InputIterator>::value,
2129 void
2130 >::type
2131 assign(_InputIterator __first, _InputIterator __last);
2132 template <class _ForwardIterator>
2133 typename enable_if
2134 <
2135 __is_forward_iterator<_ForwardIterator>::value,
2136 void
2137 >::type
2138 assign(_ForwardIterator __first, _ForwardIterator __last);
2139
2140 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:022141#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:282142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162143 void assign(initializer_list<value_type> __il)
2144 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:022145#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:162146
Howard Hinnantd1d27a42011-06-03 19:40:402147 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162148 {return allocator_type(this->__alloc());}
2149
Howard Hinnantd1d27a42011-06-03 19:40:402150 size_type max_size() const _NOEXCEPT;
2151 _LIBCPP_INLINE_VISIBILITY
2152 size_type capacity() const _NOEXCEPT
2153 {return __internal_cap_to_external(__cap());}
2154 _LIBCPP_INLINE_VISIBILITY
2155 size_type size() const _NOEXCEPT
2156 {return __size_;}
2157 _LIBCPP_INLINE_VISIBILITY
2158 bool empty() const _NOEXCEPT
2159 {return __size_ == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:162160 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:402161 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:162162
Howard Hinnantd1d27a42011-06-03 19:40:402163 _LIBCPP_INLINE_VISIBILITY
2164 iterator begin() _NOEXCEPT
2165 {return __make_iter(0);}
2166 _LIBCPP_INLINE_VISIBILITY
2167 const_iterator begin() const _NOEXCEPT
2168 {return __make_iter(0);}
2169 _LIBCPP_INLINE_VISIBILITY
2170 iterator end() _NOEXCEPT
2171 {return __make_iter(__size_);}
2172 _LIBCPP_INLINE_VISIBILITY
2173 const_iterator end() const _NOEXCEPT
2174 {return __make_iter(__size_);}
Howard Hinnantbc8d3f92010-05-11 19:42:162175
Howard Hinnantd1d27a42011-06-03 19:40:402176 _LIBCPP_INLINE_VISIBILITY
2177 reverse_iterator rbegin() _NOEXCEPT
2178 {return reverse_iterator(end());}
2179 _LIBCPP_INLINE_VISIBILITY
2180 const_reverse_iterator rbegin() const _NOEXCEPT
2181 {return const_reverse_iterator(end());}
2182 _LIBCPP_INLINE_VISIBILITY
2183 reverse_iterator rend() _NOEXCEPT
2184 {return reverse_iterator(begin());}
2185 _LIBCPP_INLINE_VISIBILITY
2186 const_reverse_iterator rend() const _NOEXCEPT
2187 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:162188
Howard Hinnantd1d27a42011-06-03 19:40:402189 _LIBCPP_INLINE_VISIBILITY
2190 const_iterator cbegin() const _NOEXCEPT
2191 {return __make_iter(0);}
2192 _LIBCPP_INLINE_VISIBILITY
2193 const_iterator cend() const _NOEXCEPT
2194 {return __make_iter(__size_);}
2195 _LIBCPP_INLINE_VISIBILITY
2196 const_reverse_iterator crbegin() const _NOEXCEPT
2197 {return rbegin();}
2198 _LIBCPP_INLINE_VISIBILITY
2199 const_reverse_iterator crend() const _NOEXCEPT
2200 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:162201
2202 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2203 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2204 reference at(size_type __n);
2205 const_reference at(size_type __n) const;
2206
2207 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2208 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2209 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2210 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2211
2212 void push_back(const value_type& __x);
Marshall Clow198a2a52013-08-13 23:54:122213#if _LIBCPP_STD_VER > 11
2214 template <class... _Args>
2215 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
2216 { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); }
2217#endif
2218
Howard Hinnantbc8d3f92010-05-11 19:42:162219 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2220
Marshall Clow198a2a52013-08-13 23:54:122221#if _LIBCPP_STD_VER > 11
2222 template <class... _Args>
2223 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2224 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2225#endif
2226
Howard Hinnantbc8d3f92010-05-11 19:42:162227 iterator insert(const_iterator __position, const value_type& __x);
2228 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2229 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2230 template <class _InputIterator>
2231 typename enable_if
2232 <
2233 __is_input_iterator <_InputIterator>::value &&
2234 !__is_forward_iterator<_InputIterator>::value,
2235 iterator
2236 >::type
2237 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2238 template <class _ForwardIterator>
2239 typename enable_if
2240 <
2241 __is_forward_iterator<_ForwardIterator>::value,
2242 iterator
2243 >::type
2244 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:022245#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:282246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162247 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2248 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:022249#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:162250
Howard Hinnant2d72b1e2010-12-17 14:46:432251 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:162252 iterator erase(const_iterator __first, const_iterator __last);
2253
Howard Hinnantd1d27a42011-06-03 19:40:402254 _LIBCPP_INLINE_VISIBILITY
2255 void clear() _NOEXCEPT {__size_ = 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:162256
Howard Hinnantd1d27a42011-06-03 19:40:402257 void swap(vector&)
2258 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2259 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:162260
2261 void resize(size_type __sz, value_type __x = false);
Howard Hinnantd1d27a42011-06-03 19:40:402262 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:162263
2264 bool __invariants() const;
2265
2266private:
Howard Hinnant2d72b1e2010-12-17 14:46:432267 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:162268 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:402269 void deallocate() _NOEXCEPT;
2270 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:202271 static size_type __align_it(size_type __new_size) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162272 {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);};
Howard Hinnant2d72b1e2010-12-17 14:46:432273 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2274 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
Howard Hinnantbc8d3f92010-05-11 19:42:162275 template <class _ForwardIterator>
2276 typename enable_if
2277 <
2278 __is_forward_iterator<_ForwardIterator>::value,
2279 void
2280 >::type
2281 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2282 void __append(size_type __n, const_reference __x);
Howard Hinnantd1d27a42011-06-03 19:40:402283 _LIBCPP_INLINE_VISIBILITY
2284 reference __make_ref(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162285 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:402286 _LIBCPP_INLINE_VISIBILITY
2287 const_reference __make_ref(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162288 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:402289 _LIBCPP_INLINE_VISIBILITY
2290 iterator __make_iter(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162291 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:402292 _LIBCPP_INLINE_VISIBILITY
2293 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162294 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:402295 _LIBCPP_INLINE_VISIBILITY
2296 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
Howard Hinnant2c39cbe2013-06-27 19:35:322297 {return begin() + (__p - cbegin());}
Howard Hinnantbc8d3f92010-05-11 19:42:162298
Howard Hinnantee6ccd02010-09-23 18:58:282299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162300 void __copy_assign_alloc(const vector& __v)
2301 {__copy_assign_alloc(__v, integral_constant<bool,
2302 __storage_traits::propagate_on_container_copy_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:282303 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162304 void __copy_assign_alloc(const vector& __c, true_type)
2305 {
2306 if (__alloc() != __c.__alloc())
2307 deallocate();
2308 __alloc() = __c.__alloc();
2309 }
2310
Howard Hinnantee6ccd02010-09-23 18:58:282311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:042312 void __copy_assign_alloc(const vector&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:162313 {}
2314
2315 void __move_assign(vector& __c, false_type);
Howard Hinnantd1d27a42011-06-03 19:40:402316 void __move_assign(vector& __c, true_type)
2317 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantee6ccd02010-09-23 18:58:282318 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162319 void __move_assign_alloc(vector& __c)
Howard Hinnantd1d27a42011-06-03 19:40:402320 _NOEXCEPT_(
2321 !__storage_traits::propagate_on_container_move_assignment::value ||
2322 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:162323 {__move_assign_alloc(__c, integral_constant<bool,
2324 __storage_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:282325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:312326 void __move_assign_alloc(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:402327 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:162328 {
Howard Hinnant0949eed2011-06-30 21:18:192329 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:162330 }
2331
Howard Hinnantee6ccd02010-09-23 18:58:282332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:042333 void __move_assign_alloc(vector&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:402334 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162335 {}
2336
Howard Hinnantee6ccd02010-09-23 18:58:282337 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162338 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
Howard Hinnantd1d27a42011-06-03 19:40:402339 _NOEXCEPT_(
2340 !__storage_traits::propagate_on_container_swap::value ||
2341 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:162342 {__swap_alloc(__x, __y, integral_constant<bool,
2343 __storage_traits::propagate_on_container_swap::value>());}
2344
Howard Hinnantee6ccd02010-09-23 18:58:282345 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162346 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:402347 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:162348 {
Howard Hinnant0949eed2011-06-30 21:18:192349 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:162350 swap(__x, __y);
2351 }
Howard Hinnantee6ccd02010-09-23 18:58:282352 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:042353 static void __swap_alloc(__storage_allocator&, __storage_allocator&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:402354 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162355 {}
2356
Howard Hinnantd1d27a42011-06-03 19:40:402357 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:162358
2359 friend class __bit_reference<vector>;
2360 friend class __bit_const_reference<vector>;
2361 friend class __bit_iterator<vector, false>;
2362 friend class __bit_iterator<vector, true>;
Howard Hinnant4ae952a2012-08-17 17:10:182363 friend struct __bit_array<vector>;
Howard Hinnant0f678bd2013-08-12 18:38:342364 friend struct _LIBCPP_TYPE_VIS_ONLY hash<vector>;
Howard Hinnantbc8d3f92010-05-11 19:42:162365};
2366
2367template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162368_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:162369void
2370vector<bool, _Allocator>::__invalidate_all_iterators()
2371{
Howard Hinnantbc8d3f92010-05-11 19:42:162372}
2373
2374// Allocate space for __n objects
2375// throws length_error if __n > max_size()
2376// throws (probably bad_alloc) if memory run out
2377// Precondition: __begin_ == __end_ == __cap() == 0
2378// Precondition: __n > 0
2379// Postcondition: capacity() == __n
2380// Postcondition: size() == 0
2381template <class _Allocator>
2382void
2383vector<bool, _Allocator>::allocate(size_type __n)
2384{
2385 if (__n > max_size())
2386 this->__throw_length_error();
2387 __n = __external_cap_to_internal(__n);
2388 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2389 this->__size_ = 0;
2390 this->__cap() = __n;
2391}
2392
2393template <class _Allocator>
2394void
Howard Hinnantd1d27a42011-06-03 19:40:402395vector<bool, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162396{
Howard Hinnant2c39cbe2013-06-27 19:35:322397 if (this->__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162398 {
2399 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2400 __invalidate_all_iterators();
Howard Hinnant2c39cbe2013-06-27 19:35:322401 this->__begin_ = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:162402 this->__size_ = this->__cap() = 0;
2403 }
2404}
2405
2406template <class _Allocator>
2407typename vector<bool, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:402408vector<bool, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162409{
2410 size_type __amax = __storage_traits::max_size(__alloc());
2411 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2412 if (__nmax / __bits_per_word <= __amax)
2413 return __nmax;
2414 return __internal_cap_to_external(__amax);
2415}
2416
2417// Precondition: __new_size > capacity()
2418template <class _Allocator>
2419_LIBCPP_INLINE_VISIBILITY inline
2420typename vector<bool, _Allocator>::size_type
2421vector<bool, _Allocator>::__recommend(size_type __new_size) const
2422{
2423 const size_type __ms = max_size();
2424 if (__new_size > __ms)
2425 this->__throw_length_error();
2426 const size_type __cap = capacity();
2427 if (__cap >= __ms / 2)
2428 return __ms;
Howard Hinnant7f764502013-08-14 18:00:202429 return _VSTD::max(2*__cap, __align_it(__new_size));
Howard Hinnantbc8d3f92010-05-11 19:42:162430}
2431
2432// Default constructs __n objects starting at __end_
2433// Precondition: __n > 0
2434// Precondition: size() + __n <= capacity()
2435// Postcondition: size() == size() + __n
2436template <class _Allocator>
2437_LIBCPP_INLINE_VISIBILITY inline
2438void
2439vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2440{
2441 size_type __old_size = this->__size_;
2442 this->__size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:192443 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:162444}
2445
2446template <class _Allocator>
2447template <class _ForwardIterator>
2448typename enable_if
2449<
2450 __is_forward_iterator<_ForwardIterator>::value,
2451 void
2452>::type
2453vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2454{
2455 size_type __old_size = this->__size_;
Howard Hinnant0949eed2011-06-30 21:18:192456 this->__size_ += _VSTD::distance(__first, __last);
2457 _VSTD::copy(__first, __last, __make_iter(__old_size));
Howard Hinnantbc8d3f92010-05-11 19:42:162458}
2459
2460template <class _Allocator>
2461_LIBCPP_INLINE_VISIBILITY inline
2462vector<bool, _Allocator>::vector()
Howard Hinnantd1d27a42011-06-03 19:40:402463 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant2c39cbe2013-06-27 19:35:322464 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162465 __size_(0),
2466 __cap_alloc_(0)
2467{
2468}
2469
2470template <class _Allocator>
2471_LIBCPP_INLINE_VISIBILITY inline
2472vector<bool, _Allocator>::vector(const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:322473 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162474 __size_(0),
2475 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2476{
2477}
2478
2479template <class _Allocator>
2480vector<bool, _Allocator>::vector(size_type __n)
Howard Hinnant2c39cbe2013-06-27 19:35:322481 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162482 __size_(0),
2483 __cap_alloc_(0)
2484{
2485 if (__n > 0)
2486 {
2487 allocate(__n);
2488 __construct_at_end(__n, false);
2489 }
2490}
2491
2492template <class _Allocator>
2493vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
Howard Hinnant2c39cbe2013-06-27 19:35:322494 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162495 __size_(0),
2496 __cap_alloc_(0)
2497{
2498 if (__n > 0)
2499 {
2500 allocate(__n);
2501 __construct_at_end(__n, __x);
2502 }
2503}
2504
2505template <class _Allocator>
2506vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:322507 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162508 __size_(0),
2509 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2510{
2511 if (__n > 0)
2512 {
2513 allocate(__n);
2514 __construct_at_end(__n, __x);
2515 }
2516}
2517
2518template <class _Allocator>
2519template <class _InputIterator>
2520vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2521 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2522 !__is_forward_iterator<_InputIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:322523 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162524 __size_(0),
2525 __cap_alloc_(0)
2526{
2527#ifndef _LIBCPP_NO_EXCEPTIONS
2528 try
2529 {
Howard Hinnant324bb032010-08-22 00:02:432530#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162531 for (; __first != __last; ++__first)
2532 push_back(*__first);
2533#ifndef _LIBCPP_NO_EXCEPTIONS
2534 }
2535 catch (...)
2536 {
Howard Hinnant2c39cbe2013-06-27 19:35:322537 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162538 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2539 __invalidate_all_iterators();
2540 throw;
2541 }
Howard Hinnant324bb032010-08-22 00:02:432542#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162543}
2544
2545template <class _Allocator>
2546template <class _InputIterator>
2547vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2548 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2549 !__is_forward_iterator<_InputIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:322550 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162551 __size_(0),
2552 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2553{
2554#ifndef _LIBCPP_NO_EXCEPTIONS
2555 try
2556 {
Howard Hinnant324bb032010-08-22 00:02:432557#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162558 for (; __first != __last; ++__first)
2559 push_back(*__first);
2560#ifndef _LIBCPP_NO_EXCEPTIONS
2561 }
2562 catch (...)
2563 {
Howard Hinnant2c39cbe2013-06-27 19:35:322564 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162565 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2566 __invalidate_all_iterators();
2567 throw;
2568 }
Howard Hinnant324bb032010-08-22 00:02:432569#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162570}
2571
2572template <class _Allocator>
2573template <class _ForwardIterator>
2574vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2575 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:322576 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162577 __size_(0),
2578 __cap_alloc_(0)
2579{
Howard Hinnant0949eed2011-06-30 21:18:192580 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:162581 if (__n > 0)
2582 {
2583 allocate(__n);
2584 __construct_at_end(__first, __last);
2585 }
2586}
2587
2588template <class _Allocator>
2589template <class _ForwardIterator>
2590vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2591 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:322592 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162593 __size_(0),
2594 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2595{
Howard Hinnant0949eed2011-06-30 21:18:192596 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:162597 if (__n > 0)
2598 {
2599 allocate(__n);
2600 __construct_at_end(__first, __last);
2601 }
2602}
2603
Howard Hinnante3e32912011-08-12 21:56:022604#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2605
Howard Hinnantbc8d3f92010-05-11 19:42:162606template <class _Allocator>
2607vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
Howard Hinnant2c39cbe2013-06-27 19:35:322608 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162609 __size_(0),
2610 __cap_alloc_(0)
2611{
2612 size_type __n = static_cast<size_type>(__il.size());
2613 if (__n > 0)
2614 {
2615 allocate(__n);
2616 __construct_at_end(__il.begin(), __il.end());
2617 }
2618}
2619
2620template <class _Allocator>
2621vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:322622 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162623 __size_(0),
2624 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2625{
2626 size_type __n = static_cast<size_type>(__il.size());
2627 if (__n > 0)
2628 {
2629 allocate(__n);
2630 __construct_at_end(__il.begin(), __il.end());
2631 }
2632}
2633
Howard Hinnante3e32912011-08-12 21:56:022634#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2635
Howard Hinnantbc8d3f92010-05-11 19:42:162636template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162637vector<bool, _Allocator>::~vector()
2638{
Howard Hinnant2c39cbe2013-06-27 19:35:322639 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162640 __storage_traits::deallocate(__alloc(), __begin_, __cap());
Howard Hinnantbc8d3f92010-05-11 19:42:162641 __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:162642}
2643
2644template <class _Allocator>
2645vector<bool, _Allocator>::vector(const vector& __v)
Howard Hinnant2c39cbe2013-06-27 19:35:322646 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162647 __size_(0),
2648 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2649{
2650 if (__v.size() > 0)
2651 {
2652 allocate(__v.size());
2653 __construct_at_end(__v.begin(), __v.end());
2654 }
2655}
2656
2657template <class _Allocator>
2658vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:322659 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162660 __size_(0),
2661 __cap_alloc_(0, __a)
2662{
2663 if (__v.size() > 0)
2664 {
2665 allocate(__v.size());
2666 __construct_at_end(__v.begin(), __v.end());
2667 }
2668}
2669
2670template <class _Allocator>
2671vector<bool, _Allocator>&
2672vector<bool, _Allocator>::operator=(const vector& __v)
2673{
2674 if (this != &__v)
2675 {
2676 __copy_assign_alloc(__v);
2677 if (__v.__size_)
2678 {
2679 if (__v.__size_ > capacity())
2680 {
2681 deallocate();
2682 allocate(__v.__size_);
2683 }
Howard Hinnant0949eed2011-06-30 21:18:192684 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:162685 }
2686 __size_ = __v.__size_;
2687 }
2688 return *this;
2689}
2690
Howard Hinnant73d21a42010-09-04 23:28:192691#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2692
Howard Hinnantbc8d3f92010-05-11 19:42:162693template <class _Allocator>
2694_LIBCPP_INLINE_VISIBILITY inline
2695vector<bool, _Allocator>::vector(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:402696 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:162697 : __begin_(__v.__begin_),
2698 __size_(__v.__size_),
2699 __cap_alloc_(__v.__cap_alloc_)
2700{
Howard Hinnant2c39cbe2013-06-27 19:35:322701 __v.__begin_ = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:162702 __v.__size_ = 0;
2703 __v.__cap() = 0;
2704}
2705
2706template <class _Allocator>
2707vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:322708 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162709 __size_(0),
2710 __cap_alloc_(0, __a)
2711{
2712 if (__a == allocator_type(__v.__alloc()))
2713 {
2714 this->__begin_ = __v.__begin_;
2715 this->__size_ = __v.__size_;
2716 this->__cap() = __v.__cap();
2717 __v.__begin_ = nullptr;
2718 __v.__cap() = __v.__size_ = 0;
2719 }
2720 else if (__v.size() > 0)
2721 {
2722 allocate(__v.size());
2723 __construct_at_end(__v.begin(), __v.end());
2724 }
2725}
2726
2727template <class _Allocator>
2728_LIBCPP_INLINE_VISIBILITY inline
2729vector<bool, _Allocator>&
2730vector<bool, _Allocator>::operator=(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:402731 _NOEXCEPT_(
2732 __alloc_traits::propagate_on_container_move_assignment::value &&
2733 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:162734{
2735 __move_assign(__v, integral_constant<bool,
2736 __storage_traits::propagate_on_container_move_assignment::value>());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:452737 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:162738}
2739
2740template <class _Allocator>
2741void
2742vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2743{
2744 if (__alloc() != __c.__alloc())
2745 assign(__c.begin(), __c.end());
2746 else
2747 __move_assign(__c, true_type());
2748}
2749
2750template <class _Allocator>
2751void
2752vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:402753 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:162754{
2755 deallocate();
2756 this->__begin_ = __c.__begin_;
2757 this->__size_ = __c.__size_;
2758 this->__cap() = __c.__cap();
2759 __move_assign_alloc(__c);
2760 __c.__begin_ = nullptr;
2761 __c.__cap() = __c.__size_ = 0;
2762}
Howard Hinnant73d21a42010-09-04 23:28:192763
2764#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:162765
2766template <class _Allocator>
2767void
2768vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2769{
2770 __size_ = 0;
2771 if (__n > 0)
2772 {
2773 size_type __c = capacity();
2774 if (__n <= __c)
2775 __size_ = __n;
2776 else
2777 {
2778 vector __v(__alloc());
2779 __v.reserve(__recommend(__n));
2780 __v.__size_ = __n;
2781 swap(__v);
2782 }
Howard Hinnant0949eed2011-06-30 21:18:192783 _VSTD::fill_n(begin(), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:162784 }
2785}
2786
2787template <class _Allocator>
2788template <class _InputIterator>
2789typename enable_if
2790<
2791 __is_input_iterator<_InputIterator>::value &&
2792 !__is_forward_iterator<_InputIterator>::value,
2793 void
2794>::type
2795vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2796{
2797 clear();
2798 for (; __first != __last; ++__first)
2799 push_back(*__first);
2800}
2801
2802template <class _Allocator>
2803template <class _ForwardIterator>
2804typename enable_if
2805<
2806 __is_forward_iterator<_ForwardIterator>::value,
2807 void
2808>::type
2809vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2810{
2811 clear();
Howard Hinnant0949eed2011-06-30 21:18:192812 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:162813 if (__n)
2814 {
2815 if (__n > capacity())
2816 {
2817 deallocate();
2818 allocate(__n);
2819 }
2820 __construct_at_end(__first, __last);
2821 }
2822}
2823
2824template <class _Allocator>
2825void
2826vector<bool, _Allocator>::reserve(size_type __n)
2827{
2828 if (__n > capacity())
2829 {
2830 vector __v(this->__alloc());
2831 __v.allocate(__n);
2832 __v.__construct_at_end(this->begin(), this->end());
2833 swap(__v);
2834 __invalidate_all_iterators();
2835 }
2836}
2837
2838template <class _Allocator>
2839void
Howard Hinnantd1d27a42011-06-03 19:40:402840vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162841{
2842 if (__external_cap_to_internal(size()) > __cap())
2843 {
2844#ifndef _LIBCPP_NO_EXCEPTIONS
2845 try
2846 {
Howard Hinnant324bb032010-08-22 00:02:432847#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162848 vector(*this, allocator_type(__alloc())).swap(*this);
2849#ifndef _LIBCPP_NO_EXCEPTIONS
2850 }
2851 catch (...)
2852 {
2853 }
Howard Hinnant324bb032010-08-22 00:02:432854#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162855 }
2856}
2857
2858template <class _Allocator>
2859typename vector<bool, _Allocator>::reference
2860vector<bool, _Allocator>::at(size_type __n)
2861{
2862 if (__n >= size())
2863 this->__throw_out_of_range();
2864 return (*this)[__n];
2865}
2866
2867template <class _Allocator>
2868typename vector<bool, _Allocator>::const_reference
2869vector<bool, _Allocator>::at(size_type __n) const
2870{
2871 if (__n >= size())
2872 this->__throw_out_of_range();
2873 return (*this)[__n];
2874}
2875
2876template <class _Allocator>
2877void
2878vector<bool, _Allocator>::push_back(const value_type& __x)
2879{
2880 if (this->__size_ == this->capacity())
2881 reserve(__recommend(this->__size_ + 1));
2882 ++this->__size_;
2883 back() = __x;
2884}
2885
2886template <class _Allocator>
2887typename vector<bool, _Allocator>::iterator
2888vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2889{
2890 iterator __r;
2891 if (size() < capacity())
2892 {
2893 const_iterator __old_end = end();
2894 ++__size_;
Howard Hinnant0949eed2011-06-30 21:18:192895 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:162896 __r = __const_iterator_cast(__position);
2897 }
2898 else
2899 {
2900 vector __v(__alloc());
2901 __v.reserve(__recommend(__size_ + 1));
2902 __v.__size_ = __size_ + 1;
Howard Hinnant0949eed2011-06-30 21:18:192903 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2904 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:162905 swap(__v);
2906 }
2907 *__r = __x;
2908 return __r;
2909}
2910
2911template <class _Allocator>
2912typename vector<bool, _Allocator>::iterator
2913vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
2914{
2915 iterator __r;
2916 size_type __c = capacity();
2917 if (__n <= __c && size() <= __c - __n)
2918 {
2919 const_iterator __old_end = end();
2920 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:192921 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:162922 __r = __const_iterator_cast(__position);
2923 }
2924 else
2925 {
2926 vector __v(__alloc());
2927 __v.reserve(__recommend(__size_ + __n));
2928 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:192929 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2930 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:162931 swap(__v);
2932 }
Howard Hinnant0949eed2011-06-30 21:18:192933 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:162934 return __r;
2935}
2936
2937template <class _Allocator>
2938template <class _InputIterator>
2939typename enable_if
2940<
2941 __is_input_iterator <_InputIterator>::value &&
2942 !__is_forward_iterator<_InputIterator>::value,
2943 typename vector<bool, _Allocator>::iterator
2944>::type
2945vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
2946{
2947 difference_type __off = __position - begin();
2948 iterator __p = __const_iterator_cast(__position);
2949 iterator __old_end = end();
2950 for (; size() != capacity() && __first != __last; ++__first)
2951 {
2952 ++this->__size_;
2953 back() = *__first;
2954 }
2955 vector __v(__alloc());
2956 if (__first != __last)
2957 {
2958#ifndef _LIBCPP_NO_EXCEPTIONS
2959 try
2960 {
Howard Hinnant324bb032010-08-22 00:02:432961#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162962 __v.assign(__first, __last);
2963 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
2964 difference_type __old_p = __p - begin();
2965 reserve(__recommend(size() + __v.size()));
2966 __p = begin() + __old_p;
2967 __old_end = begin() + __old_size;
2968#ifndef _LIBCPP_NO_EXCEPTIONS
2969 }
2970 catch (...)
2971 {
2972 erase(__old_end, end());
2973 throw;
2974 }
Howard Hinnant324bb032010-08-22 00:02:432975#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162976 }
Howard Hinnant0949eed2011-06-30 21:18:192977 __p = _VSTD::rotate(__p, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:162978 insert(__p, __v.begin(), __v.end());
2979 return begin() + __off;
2980}
2981
2982template <class _Allocator>
2983template <class _ForwardIterator>
2984typename enable_if
2985<
2986 __is_forward_iterator<_ForwardIterator>::value,
2987 typename vector<bool, _Allocator>::iterator
2988>::type
2989vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
2990{
Howard Hinnant0949eed2011-06-30 21:18:192991 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:162992 iterator __r;
2993 size_type __c = capacity();
2994 if (__n <= __c && size() <= __c - __n)
2995 {
2996 const_iterator __old_end = end();
2997 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:192998 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:162999 __r = __const_iterator_cast(__position);
3000 }
3001 else
3002 {
3003 vector __v(__alloc());
3004 __v.reserve(__recommend(__size_ + __n));
3005 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:193006 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3007 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:163008 swap(__v);
3009 }
Howard Hinnant0949eed2011-06-30 21:18:193010 _VSTD::copy(__first, __last, __r);
Howard Hinnantbc8d3f92010-05-11 19:42:163011 return __r;
3012}
3013
3014template <class _Allocator>
3015_LIBCPP_INLINE_VISIBILITY inline
3016typename vector<bool, _Allocator>::iterator
3017vector<bool, _Allocator>::erase(const_iterator __position)
3018{
3019 iterator __r = __const_iterator_cast(__position);
Howard Hinnant0949eed2011-06-30 21:18:193020 _VSTD::copy(__position + 1, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:163021 --__size_;
3022 return __r;
3023}
3024
3025template <class _Allocator>
3026typename vector<bool, _Allocator>::iterator
3027vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3028{
3029 iterator __r = __const_iterator_cast(__first);
3030 difference_type __d = __last - __first;
Howard Hinnant0949eed2011-06-30 21:18:193031 _VSTD::copy(__last, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:163032 __size_ -= __d;
3033 return __r;
3034}
3035
3036template <class _Allocator>
3037void
3038vector<bool, _Allocator>::swap(vector& __x)
Howard Hinnantd1d27a42011-06-03 19:40:403039 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3040 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:163041{
Howard Hinnant0949eed2011-06-30 21:18:193042 _VSTD::swap(this->__begin_, __x.__begin_);
3043 _VSTD::swap(this->__size_, __x.__size_);
3044 _VSTD::swap(this->__cap(), __x.__cap());
Howard Hinnantbc8d3f92010-05-11 19:42:163045 __swap_alloc(this->__alloc(), __x.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:163046}
3047
Howard Hinnant324bb032010-08-22 00:02:433048template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:163049void
3050vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3051{
3052 size_type __cs = size();
3053 if (__cs < __sz)
3054 {
3055 iterator __r;
3056 size_type __c = capacity();
3057 size_type __n = __sz - __cs;
3058 if (__n <= __c && __cs <= __c - __n)
3059 {
3060 __r = end();
3061 __size_ += __n;
3062 }
3063 else
3064 {
3065 vector __v(__alloc());
3066 __v.reserve(__recommend(__size_ + __n));
3067 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:193068 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:163069 swap(__v);
3070 }
Howard Hinnant0949eed2011-06-30 21:18:193071 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:163072 }
3073 else
3074 __size_ = __sz;
3075}
3076
Howard Hinnant324bb032010-08-22 00:02:433077template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:163078void
Howard Hinnantd1d27a42011-06-03 19:40:403079vector<bool, _Allocator>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163080{
3081 // do middle whole words
3082 size_type __n = __size_;
3083 __storage_pointer __p = __begin_;
3084 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3085 *__p = ~*__p;
3086 // do last partial word
3087 if (__n > 0)
3088 {
3089 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3090 __storage_type __b = *__p & __m;
3091 *__p &= ~__m;
3092 *__p |= ~__b & __m;
3093 }
3094}
3095
Howard Hinnant324bb032010-08-22 00:02:433096template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:163097bool
3098vector<bool, _Allocator>::__invariants() const
3099{
Howard Hinnant2c39cbe2013-06-27 19:35:323100 if (this->__begin_ == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:163101 {
3102 if (this->__size_ != 0 || this->__cap() != 0)
3103 return false;
3104 }
3105 else
3106 {
3107 if (this->__cap() == 0)
3108 return false;
3109 if (this->__size_ > this->capacity())
3110 return false;
3111 }
3112 return true;
3113}
3114
Howard Hinnant324bb032010-08-22 00:02:433115template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:163116size_t
Howard Hinnantd1d27a42011-06-03 19:40:403117vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163118{
3119 size_t __h = 0;
3120 // do middle whole words
3121 size_type __n = __size_;
3122 __storage_pointer __p = __begin_;
3123 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3124 __h ^= *__p;
3125 // do last partial word
3126 if (__n > 0)
3127 {
3128 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3129 __h ^= *__p & __m;
3130 }
3131 return __h;
3132}
3133
3134template <class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:343135struct _LIBCPP_TYPE_VIS_ONLY hash<vector<bool, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:163136 : public unary_function<vector<bool, _Allocator>, size_t>
3137{
Howard Hinnantee6ccd02010-09-23 18:58:283138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:403139 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163140 {return __vec.__hash_code();}
3141};
3142
3143template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:163144_LIBCPP_INLINE_VISIBILITY inline
3145bool
3146operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3147{
3148 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
Howard Hinnant0949eed2011-06-30 21:18:193149 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:163150}
3151
3152template <class _Tp, class _Allocator>
3153_LIBCPP_INLINE_VISIBILITY inline
3154bool
3155operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3156{
3157 return !(__x == __y);
3158}
3159
3160template <class _Tp, class _Allocator>
3161_LIBCPP_INLINE_VISIBILITY inline
3162bool
3163operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3164{
Howard Hinnant0949eed2011-06-30 21:18:193165 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:163166}
3167
3168template <class _Tp, class _Allocator>
3169_LIBCPP_INLINE_VISIBILITY inline
3170bool
3171operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3172{
3173 return __y < __x;
3174}
3175
3176template <class _Tp, class _Allocator>
3177_LIBCPP_INLINE_VISIBILITY inline
3178bool
3179operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3180{
3181 return !(__x < __y);
3182}
3183
3184template <class _Tp, class _Allocator>
3185_LIBCPP_INLINE_VISIBILITY inline
3186bool
3187operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3188{
3189 return !(__y < __x);
3190}
3191
3192template <class _Tp, class _Allocator>
3193_LIBCPP_INLINE_VISIBILITY inline
3194void
3195swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
Howard Hinnantd1d27a42011-06-03 19:40:403196 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:163197{
3198 __x.swap(__y);
3199}
3200
3201_LIBCPP_END_NAMESPACE_STD
3202
3203#endif // _LIBCPP_VECTOR