blob: 65a087cf80c0cebde156ad2868857dd2e0ec295d [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------------ vector --------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_VECTOR
12#define _LIBCPP_VECTOR
13
14/*
15 vector synopsis
16
17namespace std
18{
19
Howard Hinnant324bb032010-08-22 00:02:43 +000020template <class T, class Allocator = allocator<T> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021class vector
Howard Hinnant324bb032010-08-22 00:02:43 +000022{
23public:
24 typedef T value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000025 typedef Allocator allocator_type;
26 typedef typename allocator_type::reference reference;
27 typedef typename allocator_type::const_reference const_reference;
28 typedef implementation-defined iterator;
29 typedef implementation-defined const_iterator;
30 typedef typename allocator_type::size_type size_type;
31 typedef typename allocator_type::difference_type difference_type;
32 typedef typename allocator_type::pointer pointer;
33 typedef typename allocator_type::const_pointer const_pointer;
34 typedef std::reverse_iterator<iterator> reverse_iterator;
35 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
36
Howard Hinnantd1d27a42011-06-03 19:40:40 +000037 vector()
38 noexcept(is_nothrow_default_constructible<allocator_type>::value);
39 explicit vector(const allocator_type&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000040 explicit vector(size_type n);
Marshall Clowa49a2c92013-09-14 00:47:59 +000041 explicit vector(size_type n, const allocator_type&); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000042 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
43 template <class InputIterator>
44 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
45 vector(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +000046 vector(vector&& x)
47 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000048 vector(initializer_list<value_type> il);
49 vector(initializer_list<value_type> il, const allocator_type& a);
50 ~vector();
51 vector& operator=(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +000052 vector& operator=(vector&& x)
53 noexcept(
54 allocator_type::propagate_on_container_move_assignment::value &&
55 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056 vector& operator=(initializer_list<value_type> il);
57 template <class InputIterator>
58 void assign(InputIterator first, InputIterator last);
59 void assign(size_type n, const value_type& u);
60 void assign(initializer_list<value_type> il);
61
Howard Hinnantd1d27a42011-06-03 19:40:40 +000062 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000063
Howard Hinnantd1d27a42011-06-03 19:40:40 +000064 iterator begin() noexcept;
65 const_iterator begin() const noexcept;
66 iterator end() noexcept;
67 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000068
Howard Hinnantd1d27a42011-06-03 19:40:40 +000069 reverse_iterator rbegin() noexcept;
70 const_reverse_iterator rbegin() const noexcept;
71 reverse_iterator rend() noexcept;
72 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000073
Howard Hinnantd1d27a42011-06-03 19:40:40 +000074 const_iterator cbegin() const noexcept;
75 const_iterator cend() const noexcept;
76 const_reverse_iterator crbegin() const noexcept;
77 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078
Howard Hinnantd1d27a42011-06-03 19:40:40 +000079 size_type size() const noexcept;
80 size_type max_size() const noexcept;
81 size_type capacity() const noexcept;
82 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000083 void reserve(size_type n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +000084 void shrink_to_fit() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000085
86 reference operator[](size_type n);
87 const_reference operator[](size_type n) const;
88 reference at(size_type n);
89 const_reference at(size_type n) const;
90
91 reference front();
92 const_reference front() const;
93 reference back();
94 const_reference back() const;
95
Howard Hinnantd1d27a42011-06-03 19:40:40 +000096 value_type* data() noexcept;
97 const value_type* data() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098
99 void push_back(const value_type& x);
100 void push_back(value_type&& x);
101 template <class... Args>
102 void emplace_back(Args&&... args);
103 void pop_back();
104
105 template <class... Args> iterator emplace(const_iterator position, Args&&... args);
106 iterator insert(const_iterator position, const value_type& x);
107 iterator insert(const_iterator position, value_type&& x);
108 iterator insert(const_iterator position, size_type n, const value_type& x);
109 template <class InputIterator>
110 iterator insert(const_iterator position, InputIterator first, InputIterator last);
111 iterator insert(const_iterator position, initializer_list<value_type> il);
112
113 iterator erase(const_iterator position);
114 iterator erase(const_iterator first, const_iterator last);
115
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000116 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000117
118 void resize(size_type sz);
119 void resize(size_type sz, const value_type& c);
120
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000121 void swap(vector&)
Marshall Clow7d914d12015-07-13 20:04:56 +0000122 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
123 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000124
125 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43 +0000126};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000127
Howard Hinnant324bb032010-08-22 00:02:43 +0000128template <class Allocator = allocator<T> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000129class vector<bool, Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000130{
131public:
132 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000133 typedef Allocator allocator_type;
134 typedef implementation-defined iterator;
135 typedef implementation-defined const_iterator;
136 typedef typename allocator_type::size_type size_type;
137 typedef typename allocator_type::difference_type difference_type;
138 typedef iterator pointer;
139 typedef const_iterator const_pointer;
140 typedef std::reverse_iterator<iterator> reverse_iterator;
141 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
142
143 class reference
144 {
145 public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000146 reference(const reference&) noexcept;
147 operator bool() const noexcept;
148 reference& operator=(const bool x) noexcept;
149 reference& operator=(const reference& x) noexcept;
150 iterator operator&() const noexcept;
151 void flip() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000152 };
153
154 class const_reference
155 {
156 public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000157 const_reference(const reference&) noexcept;
158 operator bool() const noexcept;
159 const_iterator operator&() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000160 };
161
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000162 vector()
163 noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant9cbee432011-09-02 20:42:31 +0000164 explicit vector(const allocator_type&);
Marshall Clowa49a2c92013-09-14 00:47:59 +0000165 explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
166 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000167 template <class InputIterator>
168 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
169 vector(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000170 vector(vector&& x)
171 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000172 vector(initializer_list<value_type> il);
173 vector(initializer_list<value_type> il, const allocator_type& a);
174 ~vector();
175 vector& operator=(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000176 vector& operator=(vector&& x)
177 noexcept(
178 allocator_type::propagate_on_container_move_assignment::value &&
179 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000180 vector& operator=(initializer_list<value_type> il);
181 template <class InputIterator>
182 void assign(InputIterator first, InputIterator last);
183 void assign(size_type n, const value_type& u);
184 void assign(initializer_list<value_type> il);
185
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000186 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000187
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000188 iterator begin() noexcept;
189 const_iterator begin() const noexcept;
190 iterator end() noexcept;
191 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000192
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000193 reverse_iterator rbegin() noexcept;
194 const_reverse_iterator rbegin() const noexcept;
195 reverse_iterator rend() noexcept;
196 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000197
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000198 const_iterator cbegin() const noexcept;
199 const_iterator cend() const noexcept;
200 const_reverse_iterator crbegin() const noexcept;
201 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000202
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000203 size_type size() const noexcept;
204 size_type max_size() const noexcept;
205 size_type capacity() const noexcept;
206 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000207 void reserve(size_type n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000208 void shrink_to_fit() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209
210 reference operator[](size_type n);
211 const_reference operator[](size_type n) const;
212 reference at(size_type n);
213 const_reference at(size_type n) const;
214
215 reference front();
216 const_reference front() const;
217 reference back();
218 const_reference back() const;
219
220 void push_back(const value_type& x);
Marshall Clow198a2a52013-08-13 23:54:12 +0000221 template <class... Args> void emplace_back(Args&&... args); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000222 void pop_back();
223
Marshall Clow198a2a52013-08-13 23:54:12 +0000224 template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225 iterator insert(const_iterator position, const value_type& x);
226 iterator insert(const_iterator position, size_type n, const value_type& x);
227 template <class InputIterator>
228 iterator insert(const_iterator position, InputIterator first, InputIterator last);
229 iterator insert(const_iterator position, initializer_list<value_type> il);
230
231 iterator erase(const_iterator position);
232 iterator erase(const_iterator first, const_iterator last);
233
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000234 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235
236 void resize(size_type sz);
237 void resize(size_type sz, value_type x);
238
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000239 void swap(vector&)
Marshall Clow7d914d12015-07-13 20:04:56 +0000240 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
241 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000242 void flip() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243
244 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43 +0000245};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000246
247template <class Allocator> struct hash<std::vector<bool, Allocator>>;
248
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);
253template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
254template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
255
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000256template <class T, class Allocator>
257void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
258 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000259
260} // std
261
262*/
263
264#include <__config>
265#include <__bit_reference>
266#include <type_traits>
267#include <climits>
268#include <limits>
269#include <initializer_list>
270#include <memory>
271#include <stdexcept>
272#include <algorithm>
273#include <cstring>
274#include <__split_buffer>
275#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
Howard Hinnant66c6f972011-11-29 16:45:27 +0000277#include <__undef_min_max>
278
Eric Fiselierb9536102014-08-10 23:53:08 +0000279#include <__debug>
Howard Hinnant8b00e6c2013-08-02 00:26:35 +0000280
Howard Hinnant08e17472011-10-17 20:05:10 +0000281#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000282#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000283#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000284
285_LIBCPP_BEGIN_NAMESPACE_STD
286
287template <bool>
288class __vector_base_common
289{
290protected:
291 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
292 void __throw_length_error() const;
293 void __throw_out_of_range() const;
294};
295
296template <bool __b>
297void
298__vector_base_common<__b>::__throw_length_error() const
299{
300#ifndef _LIBCPP_NO_EXCEPTIONS
301 throw length_error("vector");
302#else
303 assert(!"vector length_error");
304#endif
305}
306
307template <bool __b>
308void
309__vector_base_common<__b>::__throw_out_of_range() const
310{
311#ifndef _LIBCPP_NO_EXCEPTIONS
312 throw out_of_range("vector");
313#else
314 assert(!"vector out_of_range");
315#endif
316}
317
Howard Hinnante9df0a52013-08-01 18:17:34 +0000318#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000319#pragma warning( push )
320#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000321#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000322_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +0000323#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000324#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000325#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000326
327template <class _Tp, class _Allocator>
328class __vector_base
329 : protected __vector_base_common<true>
330{
331protected:
Howard Hinnant324bb032010-08-22 00:02:43 +0000332 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333 typedef _Allocator allocator_type;
334 typedef allocator_traits<allocator_type> __alloc_traits;
335 typedef value_type& reference;
336 typedef const value_type& const_reference;
337 typedef typename __alloc_traits::size_type size_type;
338 typedef typename __alloc_traits::difference_type difference_type;
339 typedef typename __alloc_traits::pointer pointer;
340 typedef typename __alloc_traits::const_pointer const_pointer;
341 typedef pointer iterator;
342 typedef const_pointer const_iterator;
343
344 pointer __begin_;
345 pointer __end_;
346 __compressed_pair<pointer, allocator_type> __end_cap_;
347
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000348 _LIBCPP_INLINE_VISIBILITY
349 allocator_type& __alloc() _NOEXCEPT
350 {return __end_cap_.second();}
351 _LIBCPP_INLINE_VISIBILITY
352 const allocator_type& __alloc() const _NOEXCEPT
353 {return __end_cap_.second();}
354 _LIBCPP_INLINE_VISIBILITY
355 pointer& __end_cap() _NOEXCEPT
356 {return __end_cap_.first();}
357 _LIBCPP_INLINE_VISIBILITY
358 const pointer& __end_cap() const _NOEXCEPT
359 {return __end_cap_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000360
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000361 _LIBCPP_INLINE_VISIBILITY
362 __vector_base()
363 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000364 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365 ~__vector_base();
366
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000367 _LIBCPP_INLINE_VISIBILITY
368 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
369 _LIBCPP_INLINE_VISIBILITY
370 size_type capacity() const _NOEXCEPT
371 {return static_cast<size_type>(__end_cap() - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000374 void __destruct_at_end(pointer __new_last) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000376 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377 void __copy_assign_alloc(const __vector_base& __c)
378 {__copy_assign_alloc(__c, integral_constant<bool,
379 __alloc_traits::propagate_on_container_copy_assignment::value>());}
380
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382 void __move_assign_alloc(__vector_base& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000383 _NOEXCEPT_(
384 !__alloc_traits::propagate_on_container_move_assignment::value ||
385 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386 {__move_assign_alloc(__c, integral_constant<bool,
387 __alloc_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390 void __copy_assign_alloc(const __vector_base& __c, true_type)
391 {
392 if (__alloc() != __c.__alloc())
393 {
394 clear();
395 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
396 __begin_ = __end_ = __end_cap() = nullptr;
397 }
398 __alloc() = __c.__alloc();
399 }
400
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +0000402 void __copy_assign_alloc(const __vector_base&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000403 {}
404
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000406 void __move_assign_alloc(__vector_base& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000407 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000409 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410 }
411
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +0000413 void __move_assign_alloc(__vector_base&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000414 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415 {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416};
417
418template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000419inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420void
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000421__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422{
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000423 while (__new_last != __end_)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000424 __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000425}
426
427template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000428inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429__vector_base<_Tp, _Allocator>::__vector_base()
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000430 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000431 : __begin_(nullptr),
432 __end_(nullptr),
433 __end_cap_(nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434{
435}
436
437template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000438inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000440 : __begin_(nullptr),
441 __end_(nullptr),
442 __end_cap_(nullptr, __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443{
444}
445
446template <class _Tp, class _Allocator>
447__vector_base<_Tp, _Allocator>::~__vector_base()
448{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000449 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000450 {
451 clear();
452 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
453 }
454}
455
456template <class _Tp, class _Allocator = allocator<_Tp> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000457class _LIBCPP_TYPE_VIS_ONLY vector
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000458 : private __vector_base<_Tp, _Allocator>
459{
460private:
461 typedef __vector_base<_Tp, _Allocator> __base;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000462 typedef allocator<_Tp> __default_allocator_type;
Howard Hinnant324bb032010-08-22 00:02:43 +0000463public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +0000465 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466 typedef _Allocator allocator_type;
467 typedef typename __base::__alloc_traits __alloc_traits;
468 typedef typename __base::reference reference;
469 typedef typename __base::const_reference const_reference;
470 typedef typename __base::size_type size_type;
471 typedef typename __base::difference_type difference_type;
472 typedef typename __base::pointer pointer;
473 typedef typename __base::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474 typedef __wrap_iter<pointer> iterator;
475 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000476 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
477 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478
Howard Hinnant02d5e182013-03-26 19:04:56 +0000479 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
480 "Allocator::value_type must be same type as value_type");
481
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000482 _LIBCPP_INLINE_VISIBILITY
Marshall Clowc912c0c2015-06-04 02:05:41 +0000483 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant7a563db2011-09-14 18:33:51 +0000484 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000485#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000486 __get_db()->__insert_c(this);
487#endif
488 }
489 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
Marshall Clow127db912015-06-04 00:10:20 +0000490#if _LIBCPP_STD_VER <= 14
491 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
492#else
493 _NOEXCEPT
494#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +0000495 : __base(__a)
496 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000497#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000498 __get_db()->__insert_c(this);
499#endif
500 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501 explicit vector(size_type __n);
Marshall Clowa49a2c92013-09-14 00:47:59 +0000502#if _LIBCPP_STD_VER > 11
503 explicit vector(size_type __n, const allocator_type& __a);
504#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000505 vector(size_type __n, const_reference __x);
506 vector(size_type __n, const_reference __x, const allocator_type& __a);
507 template <class _InputIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +0000508 vector(_InputIterator __first,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000510 !__is_forward_iterator<_InputIterator>::value &&
511 is_constructible<
512 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +0000513 typename iterator_traits<_InputIterator>::reference>::value,
514 _InputIterator>::type __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515 template <class _InputIterator>
516 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
517 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000518 !__is_forward_iterator<_InputIterator>::value &&
519 is_constructible<
520 value_type,
521 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000522 template <class _ForwardIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +0000523 vector(_ForwardIterator __first,
Howard Hinnant742fecb2013-03-28 17:44:32 +0000524 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
525 is_constructible<
526 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +0000527 typename iterator_traits<_ForwardIterator>::reference>::value,
528 _ForwardIterator>::type __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 template <class _ForwardIterator>
530 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
Howard Hinnant742fecb2013-03-28 17:44:32 +0000531 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
532 is_constructible<
533 value_type,
534 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02 +0000535#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537 vector(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000540#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantabe26282011-09-16 17:29:17 +0000541#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a563db2011-09-14 18:33:51 +0000543 ~vector()
544 {
545 __get_db()->__erase_c(this);
546 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547#endif
548
549 vector(const vector& __x);
550 vector(const vector& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552 vector& operator=(const vector& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000553#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000555 vector(vector&& __x)
556 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558 vector(vector&& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000560 vector& operator=(vector&& __x)
561 _NOEXCEPT_(
562 __alloc_traits::propagate_on_container_move_assignment::value &&
563 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000564#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000565#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567 vector& operator=(initializer_list<value_type> __il)
568 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000569#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570
571 template <class _InputIterator>
572 typename enable_if
573 <
574 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000575 !__is_forward_iterator<_InputIterator>::value &&
576 is_constructible<
577 value_type,
578 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579 void
580 >::type
581 assign(_InputIterator __first, _InputIterator __last);
582 template <class _ForwardIterator>
583 typename enable_if
584 <
Howard Hinnant742fecb2013-03-28 17:44:32 +0000585 __is_forward_iterator<_ForwardIterator>::value &&
586 is_constructible<
587 value_type,
588 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000589 void
590 >::type
591 assign(_ForwardIterator __first, _ForwardIterator __last);
592
593 void assign(size_type __n, const_reference __u);
Howard Hinnante3e32912011-08-12 21:56:02 +0000594#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000596 void assign(initializer_list<value_type> __il)
597 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000598#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000600 _LIBCPP_INLINE_VISIBILITY
601 allocator_type get_allocator() const _NOEXCEPT
602 {return this->__alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000603
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000604 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
605 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
606 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
607 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000609 _LIBCPP_INLINE_VISIBILITY
610 reverse_iterator rbegin() _NOEXCEPT
611 {return reverse_iterator(end());}
612 _LIBCPP_INLINE_VISIBILITY
613 const_reverse_iterator rbegin() const _NOEXCEPT
614 {return const_reverse_iterator(end());}
615 _LIBCPP_INLINE_VISIBILITY
616 reverse_iterator rend() _NOEXCEPT
617 {return reverse_iterator(begin());}
618 _LIBCPP_INLINE_VISIBILITY
619 const_reverse_iterator rend() const _NOEXCEPT
620 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000622 _LIBCPP_INLINE_VISIBILITY
623 const_iterator cbegin() const _NOEXCEPT
624 {return begin();}
625 _LIBCPP_INLINE_VISIBILITY
626 const_iterator cend() const _NOEXCEPT
627 {return end();}
628 _LIBCPP_INLINE_VISIBILITY
629 const_reverse_iterator crbegin() const _NOEXCEPT
630 {return rbegin();}
631 _LIBCPP_INLINE_VISIBILITY
632 const_reverse_iterator crend() const _NOEXCEPT
633 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000635 _LIBCPP_INLINE_VISIBILITY
636 size_type size() const _NOEXCEPT
637 {return static_cast<size_type>(this->__end_ - this->__begin_);}
638 _LIBCPP_INLINE_VISIBILITY
639 size_type capacity() const _NOEXCEPT
640 {return __base::capacity();}
641 _LIBCPP_INLINE_VISIBILITY
642 bool empty() const _NOEXCEPT
643 {return this->__begin_ == this->__end_;}
644 size_type max_size() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000646 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647
648 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
649 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
650 reference at(size_type __n);
651 const_reference at(size_type __n) const;
652
Howard Hinnant7a563db2011-09-14 18:33:51 +0000653 _LIBCPP_INLINE_VISIBILITY reference front()
654 {
655 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
656 return *this->__begin_;
657 }
658 _LIBCPP_INLINE_VISIBILITY const_reference front() const
659 {
660 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
661 return *this->__begin_;
662 }
663 _LIBCPP_INLINE_VISIBILITY reference back()
664 {
665 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
666 return *(this->__end_ - 1);
667 }
668 _LIBCPP_INLINE_VISIBILITY const_reference back() const
669 {
670 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
671 return *(this->__end_ - 1);
672 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000674 _LIBCPP_INLINE_VISIBILITY
675 value_type* data() _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000676 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000677 _LIBCPP_INLINE_VISIBILITY
678 const value_type* data() const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000679 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000681 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000682#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000683 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000684#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000685 template <class... _Args>
686 void emplace_back(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000687#endif // _LIBCPP_HAS_NO_VARIADICS
688#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689 void pop_back();
690
691 iterator insert(const_iterator __position, const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000692#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693 iterator insert(const_iterator __position, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000694#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695 template <class... _Args>
696 iterator emplace(const_iterator __position, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000697#endif // _LIBCPP_HAS_NO_VARIADICS
698#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699 iterator insert(const_iterator __position, size_type __n, const_reference __x);
700 template <class _InputIterator>
701 typename enable_if
702 <
703 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +0000704 !__is_forward_iterator<_InputIterator>::value &&
705 is_constructible<
706 value_type,
707 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 iterator
709 >::type
710 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
711 template <class _ForwardIterator>
712 typename enable_if
713 <
Howard Hinnant742fecb2013-03-28 17:44:32 +0000714 __is_forward_iterator<_ForwardIterator>::value &&
715 is_constructible<
716 value_type,
717 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 iterator
719 >::type
720 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000721#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723 iterator insert(const_iterator __position, initializer_list<value_type> __il)
724 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000725#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000727 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728 iterator erase(const_iterator __first, const_iterator __last);
729
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000730 _LIBCPP_INLINE_VISIBILITY
731 void clear() _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +0000732 {
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000733 size_type __old_size = size();
Howard Hinnant7a563db2011-09-14 18:33:51 +0000734 __base::clear();
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000735 __annotate_shrink(__old_size);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000736 __invalidate_all_iterators();
737 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738
739 void resize(size_type __sz);
740 void resize(size_type __sz, const_reference __x);
741
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000742 void swap(vector&)
Marshall Clow7d914d12015-07-13 20:04:56 +0000743#if _LIBCPP_STD_VER >= 14
744 _NOEXCEPT;
745#else
746 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
747 __is_nothrow_swappable<allocator_type>::value);
748#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000749
750 bool __invariants() const;
751
Howard Hinnantabe26282011-09-16 17:29:17 +0000752#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000753
754 bool __dereferenceable(const const_iterator* __i) const;
755 bool __decrementable(const const_iterator* __i) const;
756 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
757 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
758
Howard Hinnantabe26282011-09-16 17:29:17 +0000759#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000760
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000762 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000763 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000764 void deallocate() _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000765 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
Howard Hinnant04240d92011-01-04 19:53:31 +0000766 void __construct_at_end(size_type __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000767 void __construct_at_end(size_type __n, const_reference __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000768 template <class _ForwardIterator>
769 typename enable_if
770 <
771 __is_forward_iterator<_ForwardIterator>::value,
772 void
773 >::type
Eric Fiselier088ed9f2015-03-31 16:54:19 +0000774 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775 void __append(size_type __n);
776 void __append(size_type __n, const_reference __x);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000778 iterator __make_iter(pointer __p) _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000780 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000781 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
782 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
783 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000784 void __move_assign(vector& __c, true_type)
785 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786 void __move_assign(vector& __c, false_type);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000788 void __destruct_at_end(pointer __new_last) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51 +0000789 {
Howard Hinnantabe26282011-09-16 17:29:17 +0000790#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +0000791 __c_node* __c = __get_db()->__find_c_and_lock(this);
792 for (__i_node** __p = __c->end_; __p != __c->beg_; )
793 {
794 --__p;
795 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
796 if (__i->base() > __new_last)
797 {
798 (*__p)->__c_ = nullptr;
799 if (--__c->end_ != __p)
800 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
801 }
802 }
803 __get_db()->unlock();
804#endif
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000805 size_type __old_size = size();
Howard Hinnant7a563db2011-09-14 18:33:51 +0000806 __base::__destruct_at_end(__new_last);
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000807 __annotate_shrink(__old_size);
Howard Hinnant7a563db2011-09-14 18:33:51 +0000808 }
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000809 template <class _Up>
810 void
811#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
812 __push_back_slow_path(_Up&& __x);
813#else
814 __push_back_slow_path(_Up& __x);
815#endif
Howard Hinnant0438ea22012-02-26 15:30:12 +0000816#if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
817 template <class... _Args>
818 void
819 __emplace_back_slow_path(_Args&&... __args);
820#endif
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000821 // The following functions are no-ops outside of AddressSanitizer mode.
822 // We call annotatations only for the default Allocator because other allocators
823 // may not meet the AddressSanitizer alignment constraints.
824 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
825 void __annotate_contiguous_container
Kostya Serebryany497f9122014-09-02 23:43:38 +0000826 (const void *__beg, const void *__end, const void *__old_mid, const void *__new_mid) const
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000827 {
828#ifndef _LIBCPP_HAS_NO_ASAN
829 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
830 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
831#endif
832 }
833
Kostya Serebryany497f9122014-09-02 23:43:38 +0000834 void __annotate_new(size_type __current_size) const
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000835 {
836 __annotate_contiguous_container(data(), data() + capacity(),
837 data() + capacity(), data() + __current_size);
838 }
Kostya Serebryany497f9122014-09-02 23:43:38 +0000839 void __annotate_delete() const
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000840 {
841 __annotate_contiguous_container(data(), data() + capacity(),
842 data() + size(), data() + capacity());
843 }
Kostya Serebryany497f9122014-09-02 23:43:38 +0000844 void __annotate_increase(size_type __n) const
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000845 {
846 __annotate_contiguous_container(data(), data() + capacity(),
847 data() + size(), data() + size() + __n);
848 }
Kostya Serebryany497f9122014-09-02 23:43:38 +0000849 void __annotate_shrink(size_type __old_size) const
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000850 {
851 __annotate_contiguous_container(data(), data() + capacity(),
852 data() + __old_size, data() + size());
853 }
Marshall Clow26f472d2014-09-03 21:37:43 +0000854#ifndef _LIBCPP_HAS_NO_ASAN
Kostya Serebryany497f9122014-09-02 23:43:38 +0000855 // The annotation for size increase should happen before the actual increase,
856 // but if an exception is thrown after that the annotation has to be undone.
857 struct __RAII_IncreaseAnnotator {
858 __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1)
Eric Fiselier9f4f2212015-03-10 00:25:20 +0000859 : __commit(false), __v(__v), __old_size(__v.size() + __n) {
Kostya Serebryany497f9122014-09-02 23:43:38 +0000860 __v.__annotate_increase(__n);
861 }
862 void __done() { __commit = true; }
863 ~__RAII_IncreaseAnnotator() {
864 if (__commit) return;
Eric Fiselier9f4f2212015-03-10 00:25:20 +0000865 __v.__annotate_shrink(__old_size);
Kostya Serebryany497f9122014-09-02 23:43:38 +0000866 }
867 bool __commit;
Kostya Serebryany497f9122014-09-02 23:43:38 +0000868 const vector &__v;
Eric Fiselier9f4f2212015-03-10 00:25:20 +0000869 size_type __old_size;
Kostya Serebryany497f9122014-09-02 23:43:38 +0000870 };
Marshall Clow26f472d2014-09-03 21:37:43 +0000871#else
872 struct __RAII_IncreaseAnnotator {
873 inline __RAII_IncreaseAnnotator(const vector &, size_type __n = 1) {}
874 inline void __done() {}
875 };
876#endif
877
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878};
879
880template <class _Tp, class _Allocator>
881void
882vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
883{
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000884 __annotate_delete();
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000885 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000886 _VSTD::swap(this->__begin_, __v.__begin_);
887 _VSTD::swap(this->__end_, __v.__end_);
888 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889 __v.__first_ = __v.__begin_;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000890 __annotate_new(size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891 __invalidate_all_iterators();
892}
893
894template <class _Tp, class _Allocator>
895typename vector<_Tp, _Allocator>::pointer
896vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
897{
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000898 __annotate_delete();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 pointer __r = __v.__begin_;
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000900 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
901 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000902 _VSTD::swap(this->__begin_, __v.__begin_);
903 _VSTD::swap(this->__end_, __v.__end_);
904 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905 __v.__first_ = __v.__begin_;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000906 __annotate_new(size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000907 __invalidate_all_iterators();
908 return __r;
909}
910
911// Allocate space for __n objects
912// throws length_error if __n > max_size()
913// throws (probably bad_alloc) if memory run out
914// Precondition: __begin_ == __end_ == __end_cap() == 0
915// Precondition: __n > 0
916// Postcondition: capacity() == __n
917// Postcondition: size() == 0
918template <class _Tp, class _Allocator>
919void
920vector<_Tp, _Allocator>::allocate(size_type __n)
921{
922 if (__n > max_size())
923 this->__throw_length_error();
924 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
925 this->__end_cap() = this->__begin_ + __n;
Marshall Clow1f50f2d2014-05-08 14:14:06 +0000926 __annotate_new(0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927}
928
929template <class _Tp, class _Allocator>
930void
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000931vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000933 if (this->__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934 {
935 clear();
936 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
Howard Hinnant2c39cbe2013-06-27 19:35:32 +0000937 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938 }
939}
940
941template <class _Tp, class _Allocator>
942typename vector<_Tp, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +0000943vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000944{
Sean Hunt110b8bf2011-07-29 23:31:58 +0000945 return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2); // end() >= begin(), always
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946}
947
948// Precondition: __new_size > capacity()
949template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000950inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951typename vector<_Tp, _Allocator>::size_type
952vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
953{
954 const size_type __ms = max_size();
955 if (__new_size > __ms)
956 this->__throw_length_error();
957 const size_type __cap = capacity();
958 if (__cap >= __ms / 2)
959 return __ms;
Sean Hunt110b8bf2011-07-29 23:31:58 +0000960 return _VSTD::max<size_type>(2*__cap, __new_size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000961}
962
963// Default constructs __n objects starting at __end_
964// throws if construction throws
965// Precondition: __n > 0
966// Precondition: size() + __n <= capacity()
967// Postcondition: size() == size() + __n
968template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000969void
970vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
971{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972 allocator_type& __a = this->__alloc();
973 do
974 {
Kostya Serebryany497f9122014-09-02 23:43:38 +0000975 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000976 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000977 ++this->__end_;
978 --__n;
Kostya Serebryany497f9122014-09-02 23:43:38 +0000979 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000980 } while (__n > 0);
981}
982
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983// Copy constructs __n objects starting at __end_ from __x
984// throws if construction throws
985// Precondition: __n > 0
986// Precondition: size() + __n <= capacity()
987// Postcondition: size() == old size() + __n
988// Postcondition: [i] == __x for all i in [size() - __n, __n)
989template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +0000990inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991void
992vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
993{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000994 allocator_type& __a = this->__alloc();
995 do
996 {
Kostya Serebryany497f9122014-09-02 23:43:38 +0000997 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000998 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999 ++this->__end_;
1000 --__n;
Kostya Serebryany497f9122014-09-02 23:43:38 +00001001 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001002 } while (__n > 0);
1003}
1004
1005template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001006template <class _ForwardIterator>
1007typename enable_if
1008<
1009 __is_forward_iterator<_ForwardIterator>::value,
1010 void
1011>::type
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001012vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001013{
1014 allocator_type& __a = this->__alloc();
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001015 __RAII_IncreaseAnnotator __annotator(*this, __n);
1016 __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_);
1017 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001018}
1019
1020// Default constructs __n objects starting at __end_
1021// throws if construction throws
1022// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001023// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001024template <class _Tp, class _Allocator>
1025void
1026vector<_Tp, _Allocator>::__append(size_type __n)
1027{
1028 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1029 this->__construct_at_end(__n);
1030 else
1031 {
1032 allocator_type& __a = this->__alloc();
1033 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1034 __v.__construct_at_end(__n);
1035 __swap_out_circular_buffer(__v);
1036 }
1037}
1038
1039// Default constructs __n objects starting at __end_
1040// throws if construction throws
1041// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001042// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001043template <class _Tp, class _Allocator>
1044void
1045vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1046{
1047 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1048 this->__construct_at_end(__n, __x);
1049 else
1050 {
1051 allocator_type& __a = this->__alloc();
1052 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1053 __v.__construct_at_end(__n, __x);
1054 __swap_out_circular_buffer(__v);
1055 }
1056}
1057
1058template <class _Tp, class _Allocator>
1059vector<_Tp, _Allocator>::vector(size_type __n)
1060{
Howard Hinnant0442b122011-09-16 18:41:29 +00001061#if _LIBCPP_DEBUG_LEVEL >= 2
1062 __get_db()->__insert_c(this);
1063#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064 if (__n > 0)
1065 {
1066 allocate(__n);
1067 __construct_at_end(__n);
1068 }
1069}
1070
Marshall Clowa49a2c92013-09-14 00:47:59 +00001071#if _LIBCPP_STD_VER > 11
1072template <class _Tp, class _Allocator>
1073vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1074 : __base(__a)
1075{
1076#if _LIBCPP_DEBUG_LEVEL >= 2
1077 __get_db()->__insert_c(this);
1078#endif
1079 if (__n > 0)
1080 {
1081 allocate(__n);
1082 __construct_at_end(__n);
1083 }
1084}
1085#endif
1086
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001087template <class _Tp, class _Allocator>
1088vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1089{
Howard Hinnant0442b122011-09-16 18:41:29 +00001090#if _LIBCPP_DEBUG_LEVEL >= 2
1091 __get_db()->__insert_c(this);
1092#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001093 if (__n > 0)
1094 {
1095 allocate(__n);
1096 __construct_at_end(__n, __x);
1097 }
1098}
1099
1100template <class _Tp, class _Allocator>
1101vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1102 : __base(__a)
1103{
Howard Hinnant0442b122011-09-16 18:41:29 +00001104#if _LIBCPP_DEBUG_LEVEL >= 2
1105 __get_db()->__insert_c(this);
1106#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001107 if (__n > 0)
1108 {
1109 allocate(__n);
1110 __construct_at_end(__n, __x);
1111 }
1112}
1113
1114template <class _Tp, class _Allocator>
1115template <class _InputIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +00001116vector<_Tp, _Allocator>::vector(_InputIterator __first,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001118 !__is_forward_iterator<_InputIterator>::value &&
1119 is_constructible<
1120 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +00001121 typename iterator_traits<_InputIterator>::reference>::value,
1122 _InputIterator>::type __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123{
Howard Hinnantabe26282011-09-16 17:29:17 +00001124#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001125 __get_db()->__insert_c(this);
1126#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001127 for (; __first != __last; ++__first)
1128 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001129}
1130
1131template <class _Tp, class _Allocator>
1132template <class _InputIterator>
1133vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1134 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001135 !__is_forward_iterator<_InputIterator>::value &&
1136 is_constructible<
1137 value_type,
1138 typename iterator_traits<_InputIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001139 : __base(__a)
1140{
Howard Hinnantabe26282011-09-16 17:29:17 +00001141#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001142 __get_db()->__insert_c(this);
1143#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001144 for (; __first != __last; ++__first)
1145 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001146}
1147
1148template <class _Tp, class _Allocator>
1149template <class _ForwardIterator>
Howard Hinnantde589f22013-09-21 21:13:54 +00001150vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
Howard Hinnant742fecb2013-03-28 17:44:32 +00001151 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1152 is_constructible<
1153 value_type,
Howard Hinnantde589f22013-09-21 21:13:54 +00001154 typename iterator_traits<_ForwardIterator>::reference>::value,
1155 _ForwardIterator>::type __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156{
Howard Hinnant0442b122011-09-16 18:41:29 +00001157#if _LIBCPP_DEBUG_LEVEL >= 2
1158 __get_db()->__insert_c(this);
1159#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001160 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001161 if (__n > 0)
1162 {
1163 allocate(__n);
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001164 __construct_at_end(__first, __last, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001165 }
1166}
1167
1168template <class _Tp, class _Allocator>
1169template <class _ForwardIterator>
1170vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
Howard Hinnant742fecb2013-03-28 17:44:32 +00001171 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1172 is_constructible<
1173 value_type,
1174 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001175 : __base(__a)
1176{
Howard Hinnant0442b122011-09-16 18:41:29 +00001177#if _LIBCPP_DEBUG_LEVEL >= 2
1178 __get_db()->__insert_c(this);
1179#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001180 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001181 if (__n > 0)
1182 {
1183 allocate(__n);
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001184 __construct_at_end(__first, __last, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001185 }
1186}
1187
1188template <class _Tp, class _Allocator>
1189vector<_Tp, _Allocator>::vector(const vector& __x)
1190 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1191{
Howard Hinnant0442b122011-09-16 18:41:29 +00001192#if _LIBCPP_DEBUG_LEVEL >= 2
1193 __get_db()->__insert_c(this);
1194#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001195 size_type __n = __x.size();
1196 if (__n > 0)
1197 {
1198 allocate(__n);
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001199 __construct_at_end(__x.__begin_, __x.__end_, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001200 }
1201}
1202
1203template <class _Tp, class _Allocator>
1204vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1205 : __base(__a)
1206{
Howard Hinnant0442b122011-09-16 18:41:29 +00001207#if _LIBCPP_DEBUG_LEVEL >= 2
1208 __get_db()->__insert_c(this);
1209#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001210 size_type __n = __x.size();
1211 if (__n > 0)
1212 {
1213 allocate(__n);
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001214 __construct_at_end(__x.__begin_, __x.__end_, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001215 }
1216}
1217
Howard Hinnant73d21a42010-09-04 23:28:19 +00001218#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001219
1220template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001221inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222vector<_Tp, _Allocator>::vector(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001223 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001224 : __base(_VSTD::move(__x.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001225{
Howard Hinnantabe26282011-09-16 17:29:17 +00001226#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001227 __get_db()->__insert_c(this);
Howard Hinnante6125bd2011-09-19 16:34:29 +00001228 __get_db()->swap(this, &__x);
Howard Hinnant7a563db2011-09-14 18:33:51 +00001229#endif
Howard Hinnant0442b122011-09-16 18:41:29 +00001230 this->__begin_ = __x.__begin_;
1231 this->__end_ = __x.__end_;
1232 this->__end_cap() = __x.__end_cap();
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001233 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001234}
1235
1236template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001237inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001238vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1239 : __base(__a)
1240{
Howard Hinnant0442b122011-09-16 18:41:29 +00001241#if _LIBCPP_DEBUG_LEVEL >= 2
1242 __get_db()->__insert_c(this);
1243#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001244 if (__a == __x.__alloc())
1245 {
1246 this->__begin_ = __x.__begin_;
1247 this->__end_ = __x.__end_;
1248 this->__end_cap() = __x.__end_cap();
1249 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001250#if _LIBCPP_DEBUG_LEVEL >= 2
1251 __get_db()->swap(this, &__x);
1252#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001253 }
1254 else
1255 {
Howard Hinnant99968442011-11-29 18:15:50 +00001256 typedef move_iterator<iterator> _Ip;
1257 assign(_Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258 }
1259}
1260
Howard Hinnante3e32912011-08-12 21:56:02 +00001261#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1262
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001264inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001265vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1266{
Howard Hinnant0442b122011-09-16 18:41:29 +00001267#if _LIBCPP_DEBUG_LEVEL >= 2
1268 __get_db()->__insert_c(this);
1269#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001270 if (__il.size() > 0)
1271 {
1272 allocate(__il.size());
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001273 __construct_at_end(__il.begin(), __il.end(), __il.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274 }
1275}
1276
1277template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001278inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001279vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1280 : __base(__a)
1281{
Howard Hinnant0442b122011-09-16 18:41:29 +00001282#if _LIBCPP_DEBUG_LEVEL >= 2
1283 __get_db()->__insert_c(this);
1284#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001285 if (__il.size() > 0)
1286 {
1287 allocate(__il.size());
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001288 __construct_at_end(__il.begin(), __il.end(), __il.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001289 }
1290}
1291
Howard Hinnante3e32912011-08-12 21:56:02 +00001292#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1293
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001294template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001295inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001296vector<_Tp, _Allocator>&
1297vector<_Tp, _Allocator>::operator=(vector&& __x)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001298 _NOEXCEPT_(
1299 __alloc_traits::propagate_on_container_move_assignment::value &&
1300 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001301{
1302 __move_assign(__x, integral_constant<bool,
1303 __alloc_traits::propagate_on_container_move_assignment::value>());
1304 return *this;
1305}
1306
1307template <class _Tp, class _Allocator>
1308void
1309vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1310{
1311 if (__base::__alloc() != __c.__alloc())
1312 {
Howard Hinnant99968442011-11-29 18:15:50 +00001313 typedef move_iterator<iterator> _Ip;
1314 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001315 }
1316 else
1317 __move_assign(__c, true_type());
1318}
1319
1320template <class _Tp, class _Allocator>
1321void
1322vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001323 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324{
1325 deallocate();
Marshall Clow3c2eac62014-07-21 15:11:13 +00001326 __base::__move_assign_alloc(__c); // this can throw
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001327 this->__begin_ = __c.__begin_;
1328 this->__end_ = __c.__end_;
1329 this->__end_cap() = __c.__end_cap();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001330 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:29 +00001331#if _LIBCPP_DEBUG_LEVEL >= 2
1332 __get_db()->swap(this, &__c);
1333#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334}
1335
Howard Hinnant73d21a42010-09-04 23:28:19 +00001336#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337
1338template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001339inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340vector<_Tp, _Allocator>&
1341vector<_Tp, _Allocator>::operator=(const vector& __x)
1342{
1343 if (this != &__x)
1344 {
1345 __base::__copy_assign_alloc(__x);
1346 assign(__x.__begin_, __x.__end_);
1347 }
1348 return *this;
1349}
1350
1351template <class _Tp, class _Allocator>
1352template <class _InputIterator>
1353typename enable_if
1354<
1355 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001356 !__is_forward_iterator<_InputIterator>::value &&
1357 is_constructible<
1358 _Tp,
1359 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001360 void
1361>::type
1362vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1363{
1364 clear();
1365 for (; __first != __last; ++__first)
1366 push_back(*__first);
1367}
1368
1369template <class _Tp, class _Allocator>
1370template <class _ForwardIterator>
1371typename enable_if
1372<
Howard Hinnant742fecb2013-03-28 17:44:32 +00001373 __is_forward_iterator<_ForwardIterator>::value &&
1374 is_constructible<
1375 _Tp,
1376 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001377 void
1378>::type
1379vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1380{
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001381 size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
1382 if (__new_size <= capacity())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001383 {
1384 _ForwardIterator __mid = __last;
1385 bool __growing = false;
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001386 if (__new_size > size())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387 {
1388 __growing = true;
1389 __mid = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001390 _VSTD::advance(__mid, size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001392 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393 if (__growing)
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001394 __construct_at_end(__mid, __last, __new_size - size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001395 else
1396 this->__destruct_at_end(__m);
1397 }
1398 else
1399 {
1400 deallocate();
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001401 allocate(__recommend(__new_size));
1402 __construct_at_end(__first, __last, __new_size);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403 }
1404}
1405
1406template <class _Tp, class _Allocator>
1407void
1408vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1409{
1410 if (__n <= capacity())
1411 {
1412 size_type __s = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001413 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001414 if (__n > __s)
1415 __construct_at_end(__n - __s, __u);
1416 else
Howard Hinnantadff4892010-05-24 17:49:41 +00001417 this->__destruct_at_end(this->__begin_ + __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418 }
1419 else
1420 {
1421 deallocate();
1422 allocate(__recommend(static_cast<size_type>(__n)));
1423 __construct_at_end(__n, __u);
1424 }
1425}
1426
Howard Hinnant324bb032010-08-22 00:02:43 +00001427template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001428inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001429typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001430vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001431{
Howard Hinnantabe26282011-09-16 17:29:17 +00001432#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001433 return iterator(this, __p);
1434#else
1435 return iterator(__p);
1436#endif
1437}
1438
Howard Hinnant324bb032010-08-22 00:02:43 +00001439template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001440inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001441typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001442vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001443{
Howard Hinnantabe26282011-09-16 17:29:17 +00001444#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001445 return const_iterator(this, __p);
1446#else
1447 return const_iterator(__p);
1448#endif
1449}
1450
Howard Hinnant324bb032010-08-22 00:02:43 +00001451template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001452inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001454vector<_Tp, _Allocator>::begin() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001455{
1456 return __make_iter(this->__begin_);
1457}
1458
Howard Hinnant324bb032010-08-22 00:02:43 +00001459template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001460inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001461typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001462vector<_Tp, _Allocator>::begin() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001463{
1464 return __make_iter(this->__begin_);
1465}
1466
Howard Hinnant324bb032010-08-22 00:02:43 +00001467template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001468inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001469typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001470vector<_Tp, _Allocator>::end() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471{
1472 return __make_iter(this->__end_);
1473}
1474
Howard Hinnant324bb032010-08-22 00:02:43 +00001475template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001476inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001478vector<_Tp, _Allocator>::end() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001479{
1480 return __make_iter(this->__end_);
1481}
1482
Howard Hinnant324bb032010-08-22 00:02:43 +00001483template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001484inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001485typename vector<_Tp, _Allocator>::reference
1486vector<_Tp, _Allocator>::operator[](size_type __n)
1487{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001488 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001489 return this->__begin_[__n];
1490}
1491
Howard Hinnant324bb032010-08-22 00:02:43 +00001492template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001493inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001494typename vector<_Tp, _Allocator>::const_reference
1495vector<_Tp, _Allocator>::operator[](size_type __n) const
1496{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001497 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001498 return this->__begin_[__n];
1499}
1500
Howard Hinnant324bb032010-08-22 00:02:43 +00001501template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001502typename vector<_Tp, _Allocator>::reference
1503vector<_Tp, _Allocator>::at(size_type __n)
1504{
1505 if (__n >= size())
1506 this->__throw_out_of_range();
1507 return this->__begin_[__n];
1508}
1509
Howard Hinnant324bb032010-08-22 00:02:43 +00001510template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511typename vector<_Tp, _Allocator>::const_reference
1512vector<_Tp, _Allocator>::at(size_type __n) const
1513{
1514 if (__n >= size())
1515 this->__throw_out_of_range();
1516 return this->__begin_[__n];
1517}
1518
1519template <class _Tp, class _Allocator>
1520void
1521vector<_Tp, _Allocator>::reserve(size_type __n)
1522{
1523 if (__n > capacity())
1524 {
1525 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001526 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001527 __swap_out_circular_buffer(__v);
1528 }
1529}
1530
1531template <class _Tp, class _Allocator>
1532void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001533vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534{
1535 if (capacity() > size())
1536 {
1537#ifndef _LIBCPP_NO_EXCEPTIONS
1538 try
1539 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001540#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001541 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:40 +00001542 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543 __swap_out_circular_buffer(__v);
1544#ifndef _LIBCPP_NO_EXCEPTIONS
1545 }
1546 catch (...)
1547 {
1548 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001549#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550 }
1551}
1552
1553template <class _Tp, class _Allocator>
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001554template <class _Up>
1555void
1556#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1557vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1558#else
1559vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1560#endif
1561{
1562 allocator_type& __a = this->__alloc();
1563 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1564 // __v.push_back(_VSTD::forward<_Up>(__x));
Howard Hinnantf619e232013-01-11 20:36:59 +00001565 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
1566 __v.__end_++;
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001567 __swap_out_circular_buffer(__v);
1568}
1569
1570template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001571inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001572void
1573vector<_Tp, _Allocator>::push_back(const_reference __x)
1574{
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001575 if (this->__end_ != this->__end_cap())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001576 {
Kostya Serebryany497f9122014-09-02 23:43:38 +00001577 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001579 _VSTD::__to_raw_pointer(this->__end_), __x);
Kostya Serebryany497f9122014-09-02 23:43:38 +00001580 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001581 ++this->__end_;
1582 }
1583 else
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001584 __push_back_slow_path(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001585}
1586
Howard Hinnant73d21a42010-09-04 23:28:19 +00001587#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001588
1589template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001590inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001591void
1592vector<_Tp, _Allocator>::push_back(value_type&& __x)
1593{
1594 if (this->__end_ < this->__end_cap())
1595 {
Kostya Serebryany497f9122014-09-02 23:43:38 +00001596 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001597 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001598 _VSTD::__to_raw_pointer(this->__end_),
1599 _VSTD::move(__x));
Kostya Serebryany497f9122014-09-02 23:43:38 +00001600 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601 ++this->__end_;
1602 }
1603 else
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001604 __push_back_slow_path(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001605}
1606
Howard Hinnant73d21a42010-09-04 23:28:19 +00001607#ifndef _LIBCPP_HAS_NO_VARIADICS
1608
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609template <class _Tp, class _Allocator>
1610template <class... _Args>
1611void
Howard Hinnant0438ea22012-02-26 15:30:12 +00001612vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1613{
1614 allocator_type& __a = this->__alloc();
1615 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1616// __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantf619e232013-01-11 20:36:59 +00001617 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
1618 __v.__end_++;
Howard Hinnant0438ea22012-02-26 15:30:12 +00001619 __swap_out_circular_buffer(__v);
1620}
1621
1622template <class _Tp, class _Allocator>
1623template <class... _Args>
Howard Hinnant1e564242013-10-04 22:09:00 +00001624inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0438ea22012-02-26 15:30:12 +00001625void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001626vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1627{
1628 if (this->__end_ < this->__end_cap())
1629 {
Kostya Serebryany497f9122014-09-02 23:43:38 +00001630 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001631 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001632 _VSTD::__to_raw_pointer(this->__end_),
1633 _VSTD::forward<_Args>(__args)...);
Kostya Serebryany497f9122014-09-02 23:43:38 +00001634 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001635 ++this->__end_;
1636 }
1637 else
Howard Hinnant0438ea22012-02-26 15:30:12 +00001638 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001639}
1640
Howard Hinnant73d21a42010-09-04 23:28:19 +00001641#endif // _LIBCPP_HAS_NO_VARIADICS
1642#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001643
1644template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001645inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646void
1647vector<_Tp, _Allocator>::pop_back()
1648{
Howard Hinnant7a563db2011-09-14 18:33:51 +00001649 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650 this->__destruct_at_end(this->__end_ - 1);
1651}
1652
1653template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001654inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655typename vector<_Tp, _Allocator>::iterator
1656vector<_Tp, _Allocator>::erase(const_iterator __position)
1657{
Howard Hinnantabe26282011-09-16 17:29:17 +00001658#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001659 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1660 "vector::erase(iterator) called with an iterator not"
1661 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001662#endif
Howard Hinnant782da332013-03-25 22:12:26 +00001663 _LIBCPP_ASSERT(__position != end(),
1664 "vector::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00001665 difference_type __ps = __position - cbegin();
1666 pointer __p = this->__begin_ + __ps;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001667 iterator __r = __make_iter(__p);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001668 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001669 return __r;
1670}
1671
1672template <class _Tp, class _Allocator>
1673typename vector<_Tp, _Allocator>::iterator
1674vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1675{
Howard Hinnantabe26282011-09-16 17:29:17 +00001676#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001677 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1678 "vector::erase(iterator, iterator) called with an iterator not"
1679 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001680#endif
Howard Hinnant7a563db2011-09-14 18:33:51 +00001681 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001682 pointer __p = this->__begin_ + (__first - begin());
1683 iterator __r = __make_iter(__p);
Howard Hinnantb4e67cf2013-04-18 15:02:57 +00001684 if (__first != __last)
1685 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001686 return __r;
1687}
1688
1689template <class _Tp, class _Allocator>
1690void
1691vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1692{
1693 pointer __old_last = this->__end_;
1694 difference_type __n = __old_last - __to;
1695 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1696 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001697 _VSTD::__to_raw_pointer(this->__end_),
1698 _VSTD::move(*__i));
1699 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700}
1701
1702template <class _Tp, class _Allocator>
1703typename vector<_Tp, _Allocator>::iterator
1704vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1705{
Howard Hinnantabe26282011-09-16 17:29:17 +00001706#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001707 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1708 "vector::insert(iterator, x) called with an iterator not"
1709 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001710#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001711 pointer __p = this->__begin_ + (__position - begin());
1712 if (this->__end_ < this->__end_cap())
1713 {
Kostya Serebryany497f9122014-09-02 23:43:38 +00001714 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001715 if (__p == this->__end_)
1716 {
1717 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001718 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001719 ++this->__end_;
1720 }
1721 else
1722 {
1723 __move_range(__p, this->__end_, __p + 1);
1724 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1725 if (__p <= __xr && __xr < this->__end_)
1726 ++__xr;
1727 *__p = *__xr;
1728 }
Kostya Serebryany497f9122014-09-02 23:43:38 +00001729 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001730 }
1731 else
1732 {
1733 allocator_type& __a = this->__alloc();
1734 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1735 __v.push_back(__x);
1736 __p = __swap_out_circular_buffer(__v, __p);
1737 }
1738 return __make_iter(__p);
1739}
1740
Howard Hinnant73d21a42010-09-04 23:28:19 +00001741#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742
1743template <class _Tp, class _Allocator>
1744typename vector<_Tp, _Allocator>::iterator
1745vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1746{
Howard Hinnantabe26282011-09-16 17:29:17 +00001747#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001748 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1749 "vector::insert(iterator, x) called with an iterator not"
1750 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001751#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752 pointer __p = this->__begin_ + (__position - begin());
1753 if (this->__end_ < this->__end_cap())
1754 {
Kostya Serebryany497f9122014-09-02 23:43:38 +00001755 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001756 if (__p == this->__end_)
1757 {
1758 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001759 _VSTD::__to_raw_pointer(this->__end_),
1760 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001761 ++this->__end_;
1762 }
1763 else
1764 {
1765 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001766 *__p = _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001767 }
Kostya Serebryany497f9122014-09-02 23:43:38 +00001768 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769 }
1770 else
1771 {
1772 allocator_type& __a = this->__alloc();
1773 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001774 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001775 __p = __swap_out_circular_buffer(__v, __p);
1776 }
1777 return __make_iter(__p);
1778}
1779
Howard Hinnant73d21a42010-09-04 23:28:19 +00001780#ifndef _LIBCPP_HAS_NO_VARIADICS
1781
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782template <class _Tp, class _Allocator>
1783template <class... _Args>
1784typename vector<_Tp, _Allocator>::iterator
1785vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1786{
Howard Hinnantabe26282011-09-16 17:29:17 +00001787#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001788 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1789 "vector::emplace(iterator, x) called with an iterator not"
1790 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001791#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001792 pointer __p = this->__begin_ + (__position - begin());
1793 if (this->__end_ < this->__end_cap())
1794 {
Kostya Serebryany497f9122014-09-02 23:43:38 +00001795 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001796 if (__p == this->__end_)
1797 {
1798 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001799 _VSTD::__to_raw_pointer(this->__end_),
1800 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001801 ++this->__end_;
1802 }
1803 else
1804 {
Howard Hinnanta58402a2012-07-08 23:23:04 +00001805 value_type __tmp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806 __move_range(__p, this->__end_, __p + 1);
Howard Hinnanta58402a2012-07-08 23:23:04 +00001807 *__p = _VSTD::move(__tmp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808 }
Kostya Serebryany497f9122014-09-02 23:43:38 +00001809 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001810 }
1811 else
1812 {
1813 allocator_type& __a = this->__alloc();
1814 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001815 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001816 __p = __swap_out_circular_buffer(__v, __p);
1817 }
1818 return __make_iter(__p);
1819}
1820
Howard Hinnant73d21a42010-09-04 23:28:19 +00001821#endif // _LIBCPP_HAS_NO_VARIADICS
1822#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823
1824template <class _Tp, class _Allocator>
1825typename vector<_Tp, _Allocator>::iterator
1826vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1827{
Howard Hinnantabe26282011-09-16 17:29:17 +00001828#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001829 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1830 "vector::insert(iterator, n, x) called with an iterator not"
1831 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001832#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833 pointer __p = this->__begin_ + (__position - begin());
1834 if (__n > 0)
1835 {
1836 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1837 {
1838 size_type __old_n = __n;
1839 pointer __old_last = this->__end_;
1840 if (__n > static_cast<size_type>(this->__end_ - __p))
1841 {
1842 size_type __cx = __n - (this->__end_ - __p);
1843 __construct_at_end(__cx, __x);
1844 __n -= __cx;
1845 }
1846 if (__n > 0)
1847 {
Eric Fiselierd7590952014-11-14 18:28:36 +00001848 __RAII_IncreaseAnnotator __annotator(*this, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001849 __move_range(__p, __old_last, __p + __old_n);
Kostya Serebryany497f9122014-09-02 23:43:38 +00001850 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001851 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1852 if (__p <= __xr && __xr < this->__end_)
1853 __xr += __old_n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001854 _VSTD::fill_n(__p, __n, *__xr);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001855 }
1856 }
1857 else
1858 {
1859 allocator_type& __a = this->__alloc();
1860 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1861 __v.__construct_at_end(__n, __x);
1862 __p = __swap_out_circular_buffer(__v, __p);
1863 }
1864 }
1865 return __make_iter(__p);
1866}
1867
1868template <class _Tp, class _Allocator>
1869template <class _InputIterator>
1870typename enable_if
1871<
1872 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32 +00001873 !__is_forward_iterator<_InputIterator>::value &&
1874 is_constructible<
1875 _Tp,
1876 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001877 typename vector<_Tp, _Allocator>::iterator
1878>::type
1879vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1880{
Howard Hinnantabe26282011-09-16 17:29:17 +00001881#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001882 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1883 "vector::insert(iterator, range) called with an iterator not"
1884 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001885#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001886 difference_type __off = __position - begin();
1887 pointer __p = this->__begin_ + __off;
1888 allocator_type& __a = this->__alloc();
1889 pointer __old_last = this->__end_;
1890 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1891 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001892 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001893 *__first);
1894 ++this->__end_;
1895 }
1896 __split_buffer<value_type, allocator_type&> __v(__a);
1897 if (__first != __last)
1898 {
1899#ifndef _LIBCPP_NO_EXCEPTIONS
1900 try
1901 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001902#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001903 __v.__construct_at_end(__first, __last);
1904 difference_type __old_size = __old_last - this->__begin_;
1905 difference_type __old_p = __p - this->__begin_;
1906 reserve(__recommend(size() + __v.size()));
1907 __p = this->__begin_ + __old_p;
1908 __old_last = this->__begin_ + __old_size;
1909#ifndef _LIBCPP_NO_EXCEPTIONS
1910 }
1911 catch (...)
1912 {
1913 erase(__make_iter(__old_last), end());
1914 throw;
1915 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001916#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001917 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00001918 __p = _VSTD::rotate(__p, __old_last, this->__end_);
Howard Hinnant0442b122011-09-16 18:41:29 +00001919 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1920 make_move_iterator(__v.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001921 return begin() + __off;
1922}
1923
1924template <class _Tp, class _Allocator>
1925template <class _ForwardIterator>
1926typename enable_if
1927<
Howard Hinnant742fecb2013-03-28 17:44:32 +00001928 __is_forward_iterator<_ForwardIterator>::value &&
1929 is_constructible<
1930 _Tp,
1931 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001932 typename vector<_Tp, _Allocator>::iterator
1933>::type
1934vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1935{
Howard Hinnantabe26282011-09-16 17:29:17 +00001936#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00001937 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1938 "vector::insert(iterator, range) called with an iterator not"
1939 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:17 +00001940#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001941 pointer __p = this->__begin_ + (__position - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00001942 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943 if (__n > 0)
1944 {
1945 if (__n <= this->__end_cap() - this->__end_)
1946 {
1947 size_type __old_n = __n;
1948 pointer __old_last = this->__end_;
1949 _ForwardIterator __m = __last;
1950 difference_type __dx = this->__end_ - __p;
1951 if (__n > __dx)
1952 {
1953 __m = __first;
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001954 difference_type __diff = this->__end_ - __p;
1955 _VSTD::advance(__m, __diff);
1956 __construct_at_end(__m, __last, __n - __diff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001957 __n = __dx;
1958 }
1959 if (__n > 0)
1960 {
Kostya Serebryany497f9122014-09-02 23:43:38 +00001961 __RAII_IncreaseAnnotator __annotator(*this, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962 __move_range(__p, __old_last, __p + __old_n);
Kostya Serebryany497f9122014-09-02 23:43:38 +00001963 __annotator.__done();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001964 _VSTD::copy(__first, __m, __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001965 }
1966 }
1967 else
1968 {
1969 allocator_type& __a = this->__alloc();
1970 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1971 __v.__construct_at_end(__first, __last);
1972 __p = __swap_out_circular_buffer(__v, __p);
1973 }
1974 }
1975 return __make_iter(__p);
1976}
1977
1978template <class _Tp, class _Allocator>
1979void
1980vector<_Tp, _Allocator>::resize(size_type __sz)
1981{
1982 size_type __cs = size();
1983 if (__cs < __sz)
1984 this->__append(__sz - __cs);
1985 else if (__cs > __sz)
1986 this->__destruct_at_end(this->__begin_ + __sz);
1987}
1988
1989template <class _Tp, class _Allocator>
1990void
1991vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1992{
1993 size_type __cs = size();
1994 if (__cs < __sz)
1995 this->__append(__sz - __cs, __x);
1996 else if (__cs > __sz)
1997 this->__destruct_at_end(this->__begin_ + __sz);
1998}
1999
2000template <class _Tp, class _Allocator>
2001void
2002vector<_Tp, _Allocator>::swap(vector& __x)
Marshall Clow7d914d12015-07-13 20:04:56 +00002003#if _LIBCPP_STD_VER >= 14
2004 _NOEXCEPT
2005#else
2006 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2007 __is_nothrow_swappable<allocator_type>::value)
2008#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002009{
Howard Hinnant7a563db2011-09-14 18:33:51 +00002010 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
2011 this->__alloc() == __x.__alloc(),
2012 "vector::swap: Either propagate_on_container_swap must be true"
2013 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19 +00002014 _VSTD::swap(this->__begin_, __x.__begin_);
2015 _VSTD::swap(this->__end_, __x.__end_);
2016 _VSTD::swap(this->__end_cap(), __x.__end_cap());
Marshall Clow7d914d12015-07-13 20:04:56 +00002017 __swap_allocator(this->__alloc(), __x.__alloc(),
2018 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
Howard Hinnantabe26282011-09-16 17:29:17 +00002019#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002020 __get_db()->swap(this, &__x);
Howard Hinnantabe26282011-09-16 17:29:17 +00002021#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002022}
2023
Howard Hinnant324bb032010-08-22 00:02:43 +00002024template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002025bool
2026vector<_Tp, _Allocator>::__invariants() const
2027{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002028 if (this->__begin_ == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002029 {
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002030 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002031 return false;
2032 }
2033 else
2034 {
2035 if (this->__begin_ > this->__end_)
2036 return false;
2037 if (this->__begin_ == this->__end_cap())
2038 return false;
2039 if (this->__end_ > this->__end_cap())
2040 return false;
2041 }
2042 return true;
2043}
2044
Howard Hinnantabe26282011-09-16 17:29:17 +00002045#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002046
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002047template <class _Tp, class _Allocator>
Howard Hinnant7a563db2011-09-14 18:33:51 +00002048bool
2049vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
2050{
2051 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
2052}
2053
2054template <class _Tp, class _Allocator>
2055bool
2056vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
2057{
2058 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
2059}
2060
2061template <class _Tp, class _Allocator>
2062bool
2063vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2064{
2065 const_pointer __p = __i->base() + __n;
2066 return this->__begin_ <= __p && __p <= this->__end_;
2067}
2068
2069template <class _Tp, class _Allocator>
2070bool
2071vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2072{
2073 const_pointer __p = __i->base() + __n;
2074 return this->__begin_ <= __p && __p < this->__end_;
2075}
2076
Howard Hinnantabe26282011-09-16 17:29:17 +00002077#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002078
2079template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002080inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002081void
2082vector<_Tp, _Allocator>::__invalidate_all_iterators()
2083{
Howard Hinnantabe26282011-09-16 17:29:17 +00002084#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51 +00002085 __get_db()->__invalidate_all(this);
Howard Hinnantabe26282011-09-16 17:29:17 +00002086#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002087}
2088
2089// vector<bool>
2090
2091template <class _Allocator> class vector<bool, _Allocator>;
2092
2093template <class _Allocator> struct hash<vector<bool, _Allocator> >;
2094
2095template <class _Allocator>
Howard Hinnantf03c3b42011-07-02 20:33:23 +00002096struct __has_storage_type<vector<bool, _Allocator> >
2097{
2098 static const bool value = true;
2099};
2100
2101template <class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002102class _LIBCPP_TYPE_VIS_ONLY vector<bool, _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002103 : private __vector_base_common<true>
2104{
2105public:
2106 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +00002107 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002108 typedef _Allocator allocator_type;
2109 typedef allocator_traits<allocator_type> __alloc_traits;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002110 typedef typename __alloc_traits::size_type size_type;
2111 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnantf867f632012-05-07 16:50:38 +00002112 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113 typedef __bit_iterator<vector, false> pointer;
2114 typedef __bit_iterator<vector, true> const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115 typedef pointer iterator;
2116 typedef const_pointer const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002117 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
2118 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002119
2120private:
Marshall Clow66302c62015-04-07 05:21:38 +00002121 typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002122 typedef allocator_traits<__storage_allocator> __storage_traits;
2123 typedef typename __storage_traits::pointer __storage_pointer;
2124 typedef typename __storage_traits::const_pointer __const_storage_pointer;
2125
2126 __storage_pointer __begin_;
2127 size_type __size_;
2128 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00002129public:
Howard Hinnantf03c3b42011-07-02 20:33:23 +00002130 typedef __bit_reference<vector> reference;
2131 typedef __bit_const_reference<vector> const_reference;
Howard Hinnant2bf1c082011-07-09 15:50:42 +00002132private:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002133 _LIBCPP_INLINE_VISIBILITY
2134 size_type& __cap() _NOEXCEPT
2135 {return __cap_alloc_.first();}
2136 _LIBCPP_INLINE_VISIBILITY
2137 const size_type& __cap() const _NOEXCEPT
2138 {return __cap_alloc_.first();}
2139 _LIBCPP_INLINE_VISIBILITY
2140 __storage_allocator& __alloc() _NOEXCEPT
2141 {return __cap_alloc_.second();}
2142 _LIBCPP_INLINE_VISIBILITY
2143 const __storage_allocator& __alloc() const _NOEXCEPT
2144 {return __cap_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002145
2146 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2147
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002148 _LIBCPP_INLINE_VISIBILITY
2149 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002150 {return __n * __bits_per_word;}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002151 _LIBCPP_INLINE_VISIBILITY
2152 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002153 {return (__n - 1) / __bits_per_word + 1;}
2154
2155public:
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002156 _LIBCPP_INLINE_VISIBILITY
Marshall Clowc912c0c2015-06-04 02:05:41 +00002157 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow127db912015-06-04 00:10:20 +00002158
2159 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
2160#if _LIBCPP_STD_VER <= 14
2161 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
2162#else
2163 _NOEXCEPT;
2164#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002165 ~vector();
2166 explicit vector(size_type __n);
Marshall Clowa49a2c92013-09-14 00:47:59 +00002167#if _LIBCPP_STD_VER > 11
2168 explicit vector(size_type __n, const allocator_type& __a);
2169#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002170 vector(size_type __n, const value_type& __v);
2171 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2172 template <class _InputIterator>
2173 vector(_InputIterator __first, _InputIterator __last,
2174 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2175 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2176 template <class _InputIterator>
2177 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2178 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2179 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2180 template <class _ForwardIterator>
2181 vector(_ForwardIterator __first, _ForwardIterator __last,
2182 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2183 template <class _ForwardIterator>
2184 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2185 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2186
2187 vector(const vector& __v);
2188 vector(const vector& __v, const allocator_type& __a);
2189 vector& operator=(const vector& __v);
Howard Hinnante3e32912011-08-12 21:56:02 +00002190#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002191 vector(initializer_list<value_type> __il);
2192 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00002193#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002194
Howard Hinnant73d21a42010-09-04 23:28:19 +00002195#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002196 _LIBCPP_INLINE_VISIBILITY
2197 vector(vector&& __v)
2198 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002199 vector(vector&& __v, const allocator_type& __a);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002200 _LIBCPP_INLINE_VISIBILITY
2201 vector& operator=(vector&& __v)
2202 _NOEXCEPT_(
2203 __alloc_traits::propagate_on_container_move_assignment::value &&
2204 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002205#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00002206#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002208 vector& operator=(initializer_list<value_type> __il)
2209 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00002210#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002211
2212 template <class _InputIterator>
2213 typename enable_if
2214 <
2215 __is_input_iterator<_InputIterator>::value &&
2216 !__is_forward_iterator<_InputIterator>::value,
2217 void
2218 >::type
2219 assign(_InputIterator __first, _InputIterator __last);
2220 template <class _ForwardIterator>
2221 typename enable_if
2222 <
2223 __is_forward_iterator<_ForwardIterator>::value,
2224 void
2225 >::type
2226 assign(_ForwardIterator __first, _ForwardIterator __last);
2227
2228 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:02 +00002229#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002231 void assign(initializer_list<value_type> __il)
2232 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002233#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002234
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002235 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002236 {return allocator_type(this->__alloc());}
2237
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002238 size_type max_size() const _NOEXCEPT;
2239 _LIBCPP_INLINE_VISIBILITY
2240 size_type capacity() const _NOEXCEPT
2241 {return __internal_cap_to_external(__cap());}
2242 _LIBCPP_INLINE_VISIBILITY
2243 size_type size() const _NOEXCEPT
2244 {return __size_;}
2245 _LIBCPP_INLINE_VISIBILITY
2246 bool empty() const _NOEXCEPT
2247 {return __size_ == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002248 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002249 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002250
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002251 _LIBCPP_INLINE_VISIBILITY
2252 iterator begin() _NOEXCEPT
2253 {return __make_iter(0);}
2254 _LIBCPP_INLINE_VISIBILITY
2255 const_iterator begin() const _NOEXCEPT
2256 {return __make_iter(0);}
2257 _LIBCPP_INLINE_VISIBILITY
2258 iterator end() _NOEXCEPT
2259 {return __make_iter(__size_);}
2260 _LIBCPP_INLINE_VISIBILITY
2261 const_iterator end() const _NOEXCEPT
2262 {return __make_iter(__size_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002263
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002264 _LIBCPP_INLINE_VISIBILITY
2265 reverse_iterator rbegin() _NOEXCEPT
2266 {return reverse_iterator(end());}
2267 _LIBCPP_INLINE_VISIBILITY
2268 const_reverse_iterator rbegin() const _NOEXCEPT
2269 {return const_reverse_iterator(end());}
2270 _LIBCPP_INLINE_VISIBILITY
2271 reverse_iterator rend() _NOEXCEPT
2272 {return reverse_iterator(begin());}
2273 _LIBCPP_INLINE_VISIBILITY
2274 const_reverse_iterator rend() const _NOEXCEPT
2275 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002276
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002277 _LIBCPP_INLINE_VISIBILITY
2278 const_iterator cbegin() const _NOEXCEPT
2279 {return __make_iter(0);}
2280 _LIBCPP_INLINE_VISIBILITY
2281 const_iterator cend() const _NOEXCEPT
2282 {return __make_iter(__size_);}
2283 _LIBCPP_INLINE_VISIBILITY
2284 const_reverse_iterator crbegin() const _NOEXCEPT
2285 {return rbegin();}
2286 _LIBCPP_INLINE_VISIBILITY
2287 const_reverse_iterator crend() const _NOEXCEPT
2288 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002289
2290 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2291 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2292 reference at(size_type __n);
2293 const_reference at(size_type __n) const;
2294
2295 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2296 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2297 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2298 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2299
2300 void push_back(const value_type& __x);
Marshall Clow198a2a52013-08-13 23:54:12 +00002301#if _LIBCPP_STD_VER > 11
2302 template <class... _Args>
2303 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
2304 { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); }
2305#endif
2306
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002307 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2308
Marshall Clow198a2a52013-08-13 23:54:12 +00002309#if _LIBCPP_STD_VER > 11
2310 template <class... _Args>
2311 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2312 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2313#endif
2314
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002315 iterator insert(const_iterator __position, const value_type& __x);
2316 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2317 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2318 template <class _InputIterator>
2319 typename enable_if
2320 <
2321 __is_input_iterator <_InputIterator>::value &&
2322 !__is_forward_iterator<_InputIterator>::value,
2323 iterator
2324 >::type
2325 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2326 template <class _ForwardIterator>
2327 typename enable_if
2328 <
2329 __is_forward_iterator<_ForwardIterator>::value,
2330 iterator
2331 >::type
2332 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00002333#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2336 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002337#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002338
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002339 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002340 iterator erase(const_iterator __first, const_iterator __last);
2341
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002342 _LIBCPP_INLINE_VISIBILITY
2343 void clear() _NOEXCEPT {__size_ = 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002344
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002345 void swap(vector&)
Marshall Clow7d914d12015-07-13 20:04:56 +00002346#if _LIBCPP_STD_VER >= 14
2347 _NOEXCEPT;
2348#else
2349 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2350 __is_nothrow_swappable<allocator_type>::value);
2351#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002352
2353 void resize(size_type __sz, value_type __x = false);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002354 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002355
2356 bool __invariants() const;
2357
2358private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002359 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002360 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002361 void deallocate() _NOEXCEPT;
2362 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00002363 static size_type __align_it(size_type __new_size) _NOEXCEPT
Marshall Clow0d1965d2014-07-28 15:02:42 +00002364 {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);};
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00002365 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2366 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002367 template <class _ForwardIterator>
2368 typename enable_if
2369 <
2370 __is_forward_iterator<_ForwardIterator>::value,
2371 void
2372 >::type
2373 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2374 void __append(size_type __n, const_reference __x);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002375 _LIBCPP_INLINE_VISIBILITY
2376 reference __make_ref(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002377 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002378 _LIBCPP_INLINE_VISIBILITY
2379 const_reference __make_ref(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002380 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002381 _LIBCPP_INLINE_VISIBILITY
2382 iterator __make_iter(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002383 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002384 _LIBCPP_INLINE_VISIBILITY
2385 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002386 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002387 _LIBCPP_INLINE_VISIBILITY
2388 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002389 {return begin() + (__p - cbegin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002390
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002392 void __copy_assign_alloc(const vector& __v)
2393 {__copy_assign_alloc(__v, integral_constant<bool,
2394 __storage_traits::propagate_on_container_copy_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002396 void __copy_assign_alloc(const vector& __c, true_type)
2397 {
2398 if (__alloc() != __c.__alloc())
2399 deallocate();
2400 __alloc() = __c.__alloc();
2401 }
2402
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00002404 void __copy_assign_alloc(const vector&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002405 {}
2406
2407 void __move_assign(vector& __c, false_type);
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002408 void __move_assign(vector& __c, true_type)
2409 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002411 void __move_assign_alloc(vector& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002412 _NOEXCEPT_(
2413 !__storage_traits::propagate_on_container_move_assignment::value ||
2414 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002415 {__move_assign_alloc(__c, integral_constant<bool,
2416 __storage_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00002418 void __move_assign_alloc(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002419 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002420 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002421 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002422 }
2423
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00002425 void __move_assign_alloc(vector&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002426 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002427 {}
2428
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002429 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002430
2431 friend class __bit_reference<vector>;
2432 friend class __bit_const_reference<vector>;
2433 friend class __bit_iterator<vector, false>;
2434 friend class __bit_iterator<vector, true>;
Howard Hinnant4ae952a2012-08-17 17:10:18 +00002435 friend struct __bit_array<vector>;
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002436 friend struct _LIBCPP_TYPE_VIS_ONLY hash<vector>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002437};
2438
2439template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002440inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002441void
2442vector<bool, _Allocator>::__invalidate_all_iterators()
2443{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002444}
2445
2446// Allocate space for __n objects
2447// throws length_error if __n > max_size()
2448// throws (probably bad_alloc) if memory run out
2449// Precondition: __begin_ == __end_ == __cap() == 0
2450// Precondition: __n > 0
2451// Postcondition: capacity() == __n
2452// Postcondition: size() == 0
2453template <class _Allocator>
2454void
2455vector<bool, _Allocator>::allocate(size_type __n)
2456{
2457 if (__n > max_size())
2458 this->__throw_length_error();
2459 __n = __external_cap_to_internal(__n);
2460 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2461 this->__size_ = 0;
2462 this->__cap() = __n;
2463}
2464
2465template <class _Allocator>
2466void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002467vector<bool, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002468{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002469 if (this->__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002470 {
2471 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2472 __invalidate_all_iterators();
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002473 this->__begin_ = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002474 this->__size_ = this->__cap() = 0;
2475 }
2476}
2477
2478template <class _Allocator>
2479typename vector<bool, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002480vector<bool, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002481{
2482 size_type __amax = __storage_traits::max_size(__alloc());
2483 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2484 if (__nmax / __bits_per_word <= __amax)
2485 return __nmax;
2486 return __internal_cap_to_external(__amax);
2487}
2488
2489// Precondition: __new_size > capacity()
2490template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002491inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002492typename vector<bool, _Allocator>::size_type
2493vector<bool, _Allocator>::__recommend(size_type __new_size) const
2494{
2495 const size_type __ms = max_size();
2496 if (__new_size > __ms)
2497 this->__throw_length_error();
2498 const size_type __cap = capacity();
2499 if (__cap >= __ms / 2)
2500 return __ms;
Howard Hinnant7f764502013-08-14 18:00:20 +00002501 return _VSTD::max(2*__cap, __align_it(__new_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002502}
2503
2504// Default constructs __n objects starting at __end_
2505// Precondition: __n > 0
2506// Precondition: size() + __n <= capacity()
2507// Postcondition: size() == size() + __n
2508template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002509inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002510void
2511vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2512{
2513 size_type __old_size = this->__size_;
2514 this->__size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002515 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002516}
2517
2518template <class _Allocator>
2519template <class _ForwardIterator>
2520typename enable_if
2521<
2522 __is_forward_iterator<_ForwardIterator>::value,
2523 void
2524>::type
2525vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2526{
2527 size_type __old_size = this->__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002528 this->__size_ += _VSTD::distance(__first, __last);
2529 _VSTD::copy(__first, __last, __make_iter(__old_size));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002530}
2531
2532template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002533inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002534vector<bool, _Allocator>::vector()
Marshall Clowc912c0c2015-06-04 02:05:41 +00002535 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002536 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002537 __size_(0),
2538 __cap_alloc_(0)
2539{
2540}
2541
2542template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002543inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002544vector<bool, _Allocator>::vector(const allocator_type& __a)
Marshall Clow127db912015-06-04 00:10:20 +00002545#if _LIBCPP_STD_VER <= 14
2546 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
2547#else
2548 _NOEXCEPT
2549#endif
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002550 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002551 __size_(0),
2552 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2553{
2554}
2555
2556template <class _Allocator>
2557vector<bool, _Allocator>::vector(size_type __n)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002558 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002559 __size_(0),
2560 __cap_alloc_(0)
2561{
2562 if (__n > 0)
2563 {
2564 allocate(__n);
2565 __construct_at_end(__n, false);
2566 }
2567}
2568
Marshall Clowa49a2c92013-09-14 00:47:59 +00002569#if _LIBCPP_STD_VER > 11
2570template <class _Allocator>
2571vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2572 : __begin_(nullptr),
2573 __size_(0),
2574 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2575{
2576 if (__n > 0)
2577 {
2578 allocate(__n);
2579 __construct_at_end(__n, false);
2580 }
2581}
2582#endif
2583
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002584template <class _Allocator>
2585vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002586 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002587 __size_(0),
2588 __cap_alloc_(0)
2589{
2590 if (__n > 0)
2591 {
2592 allocate(__n);
2593 __construct_at_end(__n, __x);
2594 }
2595}
2596
2597template <class _Allocator>
2598vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002599 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002600 __size_(0),
2601 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2602{
2603 if (__n > 0)
2604 {
2605 allocate(__n);
2606 __construct_at_end(__n, __x);
2607 }
2608}
2609
2610template <class _Allocator>
2611template <class _InputIterator>
2612vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2613 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2614 !__is_forward_iterator<_InputIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002615 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002616 __size_(0),
2617 __cap_alloc_(0)
2618{
2619#ifndef _LIBCPP_NO_EXCEPTIONS
2620 try
2621 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002622#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002623 for (; __first != __last; ++__first)
2624 push_back(*__first);
2625#ifndef _LIBCPP_NO_EXCEPTIONS
2626 }
2627 catch (...)
2628 {
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002629 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002630 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2631 __invalidate_all_iterators();
2632 throw;
2633 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002634#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002635}
2636
2637template <class _Allocator>
2638template <class _InputIterator>
2639vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2640 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2641 !__is_forward_iterator<_InputIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002642 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002643 __size_(0),
2644 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2645{
2646#ifndef _LIBCPP_NO_EXCEPTIONS
2647 try
2648 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002649#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002650 for (; __first != __last; ++__first)
2651 push_back(*__first);
2652#ifndef _LIBCPP_NO_EXCEPTIONS
2653 }
2654 catch (...)
2655 {
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002656 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002657 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2658 __invalidate_all_iterators();
2659 throw;
2660 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002661#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002662}
2663
2664template <class _Allocator>
2665template <class _ForwardIterator>
2666vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2667 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002668 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002669 __size_(0),
2670 __cap_alloc_(0)
2671{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002672 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002673 if (__n > 0)
2674 {
2675 allocate(__n);
2676 __construct_at_end(__first, __last);
2677 }
2678}
2679
2680template <class _Allocator>
2681template <class _ForwardIterator>
2682vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2683 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002684 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002685 __size_(0),
2686 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2687{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002688 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002689 if (__n > 0)
2690 {
2691 allocate(__n);
2692 __construct_at_end(__first, __last);
2693 }
2694}
2695
Howard Hinnante3e32912011-08-12 21:56:02 +00002696#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2697
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002698template <class _Allocator>
2699vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002700 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002701 __size_(0),
2702 __cap_alloc_(0)
2703{
2704 size_type __n = static_cast<size_type>(__il.size());
2705 if (__n > 0)
2706 {
2707 allocate(__n);
2708 __construct_at_end(__il.begin(), __il.end());
2709 }
2710}
2711
2712template <class _Allocator>
2713vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002714 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002715 __size_(0),
2716 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2717{
2718 size_type __n = static_cast<size_type>(__il.size());
2719 if (__n > 0)
2720 {
2721 allocate(__n);
2722 __construct_at_end(__il.begin(), __il.end());
2723 }
2724}
2725
Howard Hinnante3e32912011-08-12 21:56:02 +00002726#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2727
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002728template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002729vector<bool, _Allocator>::~vector()
2730{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002731 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002732 __storage_traits::deallocate(__alloc(), __begin_, __cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002733 __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002734}
2735
2736template <class _Allocator>
2737vector<bool, _Allocator>::vector(const vector& __v)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002738 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002739 __size_(0),
2740 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2741{
2742 if (__v.size() > 0)
2743 {
2744 allocate(__v.size());
2745 __construct_at_end(__v.begin(), __v.end());
2746 }
2747}
2748
2749template <class _Allocator>
2750vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002751 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002752 __size_(0),
2753 __cap_alloc_(0, __a)
2754{
2755 if (__v.size() > 0)
2756 {
2757 allocate(__v.size());
2758 __construct_at_end(__v.begin(), __v.end());
2759 }
2760}
2761
2762template <class _Allocator>
2763vector<bool, _Allocator>&
2764vector<bool, _Allocator>::operator=(const vector& __v)
2765{
2766 if (this != &__v)
2767 {
2768 __copy_assign_alloc(__v);
2769 if (__v.__size_)
2770 {
2771 if (__v.__size_ > capacity())
2772 {
2773 deallocate();
2774 allocate(__v.__size_);
2775 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002776 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002777 }
2778 __size_ = __v.__size_;
2779 }
2780 return *this;
2781}
2782
Howard Hinnant73d21a42010-09-04 23:28:19 +00002783#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2784
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002785template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002786inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002787vector<bool, _Allocator>::vector(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002788 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002789 : __begin_(__v.__begin_),
2790 __size_(__v.__size_),
2791 __cap_alloc_(__v.__cap_alloc_)
2792{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002793 __v.__begin_ = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002794 __v.__size_ = 0;
2795 __v.__cap() = 0;
2796}
2797
2798template <class _Allocator>
2799vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00002800 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002801 __size_(0),
2802 __cap_alloc_(0, __a)
2803{
2804 if (__a == allocator_type(__v.__alloc()))
2805 {
2806 this->__begin_ = __v.__begin_;
2807 this->__size_ = __v.__size_;
2808 this->__cap() = __v.__cap();
2809 __v.__begin_ = nullptr;
2810 __v.__cap() = __v.__size_ = 0;
2811 }
2812 else if (__v.size() > 0)
2813 {
2814 allocate(__v.size());
2815 __construct_at_end(__v.begin(), __v.end());
2816 }
2817}
2818
2819template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002820inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002821vector<bool, _Allocator>&
2822vector<bool, _Allocator>::operator=(vector&& __v)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002823 _NOEXCEPT_(
2824 __alloc_traits::propagate_on_container_move_assignment::value &&
2825 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002826{
2827 __move_assign(__v, integral_constant<bool,
2828 __storage_traits::propagate_on_container_move_assignment::value>());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002829 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002830}
2831
2832template <class _Allocator>
2833void
2834vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2835{
2836 if (__alloc() != __c.__alloc())
2837 assign(__c.begin(), __c.end());
2838 else
2839 __move_assign(__c, true_type());
2840}
2841
2842template <class _Allocator>
2843void
2844vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002845 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002846{
2847 deallocate();
Marshall Clowdb5e54d2014-07-21 15:15:15 +00002848 __move_assign_alloc(__c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002849 this->__begin_ = __c.__begin_;
2850 this->__size_ = __c.__size_;
2851 this->__cap() = __c.__cap();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002852 __c.__begin_ = nullptr;
2853 __c.__cap() = __c.__size_ = 0;
2854}
Howard Hinnant73d21a42010-09-04 23:28:19 +00002855
2856#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002857
2858template <class _Allocator>
2859void
2860vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2861{
2862 __size_ = 0;
2863 if (__n > 0)
2864 {
2865 size_type __c = capacity();
2866 if (__n <= __c)
2867 __size_ = __n;
2868 else
2869 {
2870 vector __v(__alloc());
2871 __v.reserve(__recommend(__n));
2872 __v.__size_ = __n;
2873 swap(__v);
2874 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002875 _VSTD::fill_n(begin(), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002876 }
2877}
2878
2879template <class _Allocator>
2880template <class _InputIterator>
2881typename enable_if
2882<
2883 __is_input_iterator<_InputIterator>::value &&
2884 !__is_forward_iterator<_InputIterator>::value,
2885 void
2886>::type
2887vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2888{
2889 clear();
2890 for (; __first != __last; ++__first)
2891 push_back(*__first);
2892}
2893
2894template <class _Allocator>
2895template <class _ForwardIterator>
2896typename enable_if
2897<
2898 __is_forward_iterator<_ForwardIterator>::value,
2899 void
2900>::type
2901vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2902{
2903 clear();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002904 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002905 if (__n)
2906 {
2907 if (__n > capacity())
2908 {
2909 deallocate();
2910 allocate(__n);
2911 }
2912 __construct_at_end(__first, __last);
2913 }
2914}
2915
2916template <class _Allocator>
2917void
2918vector<bool, _Allocator>::reserve(size_type __n)
2919{
2920 if (__n > capacity())
2921 {
2922 vector __v(this->__alloc());
2923 __v.allocate(__n);
2924 __v.__construct_at_end(this->begin(), this->end());
2925 swap(__v);
2926 __invalidate_all_iterators();
2927 }
2928}
2929
2930template <class _Allocator>
2931void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00002932vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002933{
2934 if (__external_cap_to_internal(size()) > __cap())
2935 {
2936#ifndef _LIBCPP_NO_EXCEPTIONS
2937 try
2938 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002939#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002940 vector(*this, allocator_type(__alloc())).swap(*this);
2941#ifndef _LIBCPP_NO_EXCEPTIONS
2942 }
2943 catch (...)
2944 {
2945 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002946#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002947 }
2948}
2949
2950template <class _Allocator>
2951typename vector<bool, _Allocator>::reference
2952vector<bool, _Allocator>::at(size_type __n)
2953{
2954 if (__n >= size())
2955 this->__throw_out_of_range();
2956 return (*this)[__n];
2957}
2958
2959template <class _Allocator>
2960typename vector<bool, _Allocator>::const_reference
2961vector<bool, _Allocator>::at(size_type __n) const
2962{
2963 if (__n >= size())
2964 this->__throw_out_of_range();
2965 return (*this)[__n];
2966}
2967
2968template <class _Allocator>
2969void
2970vector<bool, _Allocator>::push_back(const value_type& __x)
2971{
2972 if (this->__size_ == this->capacity())
2973 reserve(__recommend(this->__size_ + 1));
2974 ++this->__size_;
2975 back() = __x;
2976}
2977
2978template <class _Allocator>
2979typename vector<bool, _Allocator>::iterator
2980vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2981{
2982 iterator __r;
2983 if (size() < capacity())
2984 {
2985 const_iterator __old_end = end();
2986 ++__size_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002987 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002988 __r = __const_iterator_cast(__position);
2989 }
2990 else
2991 {
2992 vector __v(__alloc());
2993 __v.reserve(__recommend(__size_ + 1));
2994 __v.__size_ = __size_ + 1;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002995 __r = _VSTD::copy(cbegin(), __position, __v.begin());
2996 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002997 swap(__v);
2998 }
2999 *__r = __x;
3000 return __r;
3001}
3002
3003template <class _Allocator>
3004typename vector<bool, _Allocator>::iterator
3005vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
3006{
3007 iterator __r;
3008 size_type __c = capacity();
3009 if (__n <= __c && size() <= __c - __n)
3010 {
3011 const_iterator __old_end = end();
3012 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003013 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003014 __r = __const_iterator_cast(__position);
3015 }
3016 else
3017 {
3018 vector __v(__alloc());
3019 __v.reserve(__recommend(__size_ + __n));
3020 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003021 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3022 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003023 swap(__v);
3024 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003025 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003026 return __r;
3027}
3028
3029template <class _Allocator>
3030template <class _InputIterator>
3031typename enable_if
3032<
3033 __is_input_iterator <_InputIterator>::value &&
3034 !__is_forward_iterator<_InputIterator>::value,
3035 typename vector<bool, _Allocator>::iterator
3036>::type
3037vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
3038{
3039 difference_type __off = __position - begin();
3040 iterator __p = __const_iterator_cast(__position);
3041 iterator __old_end = end();
3042 for (; size() != capacity() && __first != __last; ++__first)
3043 {
3044 ++this->__size_;
3045 back() = *__first;
3046 }
3047 vector __v(__alloc());
3048 if (__first != __last)
3049 {
3050#ifndef _LIBCPP_NO_EXCEPTIONS
3051 try
3052 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003053#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003054 __v.assign(__first, __last);
3055 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
3056 difference_type __old_p = __p - begin();
3057 reserve(__recommend(size() + __v.size()));
3058 __p = begin() + __old_p;
3059 __old_end = begin() + __old_size;
3060#ifndef _LIBCPP_NO_EXCEPTIONS
3061 }
3062 catch (...)
3063 {
3064 erase(__old_end, end());
3065 throw;
3066 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003067#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003068 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003069 __p = _VSTD::rotate(__p, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003070 insert(__p, __v.begin(), __v.end());
3071 return begin() + __off;
3072}
3073
3074template <class _Allocator>
3075template <class _ForwardIterator>
3076typename enable_if
3077<
3078 __is_forward_iterator<_ForwardIterator>::value,
3079 typename vector<bool, _Allocator>::iterator
3080>::type
3081vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
3082{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003083 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003084 iterator __r;
3085 size_type __c = capacity();
3086 if (__n <= __c && size() <= __c - __n)
3087 {
3088 const_iterator __old_end = end();
3089 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003090 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003091 __r = __const_iterator_cast(__position);
3092 }
3093 else
3094 {
3095 vector __v(__alloc());
3096 __v.reserve(__recommend(__size_ + __n));
3097 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003098 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3099 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003100 swap(__v);
3101 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003102 _VSTD::copy(__first, __last, __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003103 return __r;
3104}
3105
3106template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003107inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003108typename vector<bool, _Allocator>::iterator
3109vector<bool, _Allocator>::erase(const_iterator __position)
3110{
3111 iterator __r = __const_iterator_cast(__position);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003112 _VSTD::copy(__position + 1, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003113 --__size_;
3114 return __r;
3115}
3116
3117template <class _Allocator>
3118typename vector<bool, _Allocator>::iterator
3119vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3120{
3121 iterator __r = __const_iterator_cast(__first);
3122 difference_type __d = __last - __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003123 _VSTD::copy(__last, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003124 __size_ -= __d;
3125 return __r;
3126}
3127
3128template <class _Allocator>
3129void
3130vector<bool, _Allocator>::swap(vector& __x)
Marshall Clow7d914d12015-07-13 20:04:56 +00003131#if _LIBCPP_STD_VER >= 14
3132 _NOEXCEPT
3133#else
3134 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3135 __is_nothrow_swappable<allocator_type>::value)
3136#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003137{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003138 _VSTD::swap(this->__begin_, __x.__begin_);
3139 _VSTD::swap(this->__size_, __x.__size_);
3140 _VSTD::swap(this->__cap(), __x.__cap());
Marshall Clow7d914d12015-07-13 20:04:56 +00003141 __swap_allocator(this->__alloc(), __x.__alloc(),
3142 integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003143}
3144
Howard Hinnant324bb032010-08-22 00:02:43 +00003145template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003146void
3147vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3148{
3149 size_type __cs = size();
3150 if (__cs < __sz)
3151 {
3152 iterator __r;
3153 size_type __c = capacity();
3154 size_type __n = __sz - __cs;
3155 if (__n <= __c && __cs <= __c - __n)
3156 {
3157 __r = end();
3158 __size_ += __n;
3159 }
3160 else
3161 {
3162 vector __v(__alloc());
3163 __v.reserve(__recommend(__size_ + __n));
3164 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:19 +00003165 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003166 swap(__v);
3167 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003168 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003169 }
3170 else
3171 __size_ = __sz;
3172}
3173
Howard Hinnant324bb032010-08-22 00:02:43 +00003174template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003175void
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003176vector<bool, _Allocator>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003177{
3178 // do middle whole words
3179 size_type __n = __size_;
3180 __storage_pointer __p = __begin_;
3181 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3182 *__p = ~*__p;
3183 // do last partial word
3184 if (__n > 0)
3185 {
3186 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3187 __storage_type __b = *__p & __m;
3188 *__p &= ~__m;
3189 *__p |= ~__b & __m;
3190 }
3191}
3192
Howard Hinnant324bb032010-08-22 00:02:43 +00003193template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003194bool
3195vector<bool, _Allocator>::__invariants() const
3196{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +00003197 if (this->__begin_ == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003198 {
3199 if (this->__size_ != 0 || this->__cap() != 0)
3200 return false;
3201 }
3202 else
3203 {
3204 if (this->__cap() == 0)
3205 return false;
3206 if (this->__size_ > this->capacity())
3207 return false;
3208 }
3209 return true;
3210}
3211
Howard Hinnant324bb032010-08-22 00:02:43 +00003212template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003213size_t
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003214vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003215{
3216 size_t __h = 0;
3217 // do middle whole words
3218 size_type __n = __size_;
3219 __storage_pointer __p = __begin_;
3220 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3221 __h ^= *__p;
3222 // do last partial word
3223 if (__n > 0)
3224 {
3225 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3226 __h ^= *__p & __m;
3227 }
3228 return __h;
3229}
3230
3231template <class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003232struct _LIBCPP_TYPE_VIS_ONLY hash<vector<bool, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003233 : public unary_function<vector<bool, _Allocator>, size_t>
3234{
Howard Hinnantee6ccd02010-09-23 18:58:28 +00003235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003236 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003237 {return __vec.__hash_code();}
3238};
3239
3240template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003241inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003242bool
3243operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3244{
3245 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003246 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003247}
3248
3249template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003250inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003251bool
3252operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3253{
3254 return !(__x == __y);
3255}
3256
3257template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003258inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003259bool
3260operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3261{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003262 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003263}
3264
3265template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003266inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003267bool
3268operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3269{
3270 return __y < __x;
3271}
3272
3273template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003274inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003275bool
3276operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3277{
3278 return !(__x < __y);
3279}
3280
3281template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003282inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003283bool
3284operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3285{
3286 return !(__y < __x);
3287}
3288
3289template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003290inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003291void
3292swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
Howard Hinnantd1d27a42011-06-03 19:40:40 +00003293 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003294{
3295 __x.swap(__y);
3296}
3297
3298_LIBCPP_END_NAMESPACE_STD
3299
3300#endif // _LIBCPP_VECTOR