blob: 9b9f2e815edb8ff8d3cfd60ca6fe589272c1c461 [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
37 explicit vector(const allocator_type& = allocator_type());
38 explicit vector(size_type n);
39 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
40 template <class InputIterator>
41 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
42 vector(const vector& x);
43 vector(vector&& x);
44 vector(initializer_list<value_type> il);
45 vector(initializer_list<value_type> il, const allocator_type& a);
46 ~vector();
47 vector& operator=(const vector& x);
48 vector& operator=(vector&& x);
49 vector& operator=(initializer_list<value_type> il);
50 template <class InputIterator>
51 void assign(InputIterator first, InputIterator last);
52 void assign(size_type n, const value_type& u);
53 void assign(initializer_list<value_type> il);
54
55 allocator_type get_allocator() const;
56
57 iterator begin();
58 const_iterator begin() const;
59 iterator end();
60 const_iterator end() const;
61
62 reverse_iterator rbegin();
63 const_reverse_iterator rbegin() const;
64 reverse_iterator rend();
65 const_reverse_iterator rend() const;
66
67 const_iterator cbegin() const;
68 const_iterator cend() const;
69 const_reverse_iterator crbegin() const;
70 const_reverse_iterator crend() const;
71
72 size_type size() const;
73 size_type max_size() const;
74 size_type capacity() const;
75 bool empty() const;
76 void reserve(size_type n);
77 void shrink_to_fit();
78
79 reference operator[](size_type n);
80 const_reference operator[](size_type n) const;
81 reference at(size_type n);
82 const_reference at(size_type n) const;
83
84 reference front();
85 const_reference front() const;
86 reference back();
87 const_reference back() const;
88
89 value_type* data();
90 const value_type* data() const;
91
92 void push_back(const value_type& x);
93 void push_back(value_type&& x);
94 template <class... Args>
95 void emplace_back(Args&&... args);
96 void pop_back();
97
98 template <class... Args> iterator emplace(const_iterator position, Args&&... args);
99 iterator insert(const_iterator position, const value_type& x);
100 iterator insert(const_iterator position, value_type&& x);
101 iterator insert(const_iterator position, size_type n, const value_type& x);
102 template <class InputIterator>
103 iterator insert(const_iterator position, InputIterator first, InputIterator last);
104 iterator insert(const_iterator position, initializer_list<value_type> il);
105
106 iterator erase(const_iterator position);
107 iterator erase(const_iterator first, const_iterator last);
108
109 void clear();
110
111 void resize(size_type sz);
112 void resize(size_type sz, const value_type& c);
113
114 void swap(vector&);
115
116 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43 +0000117};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000118
Howard Hinnant324bb032010-08-22 00:02:43 +0000119template <class Allocator = allocator<T> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120class vector<bool, Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000121{
122public:
123 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000124 typedef Allocator allocator_type;
125 typedef implementation-defined iterator;
126 typedef implementation-defined const_iterator;
127 typedef typename allocator_type::size_type size_type;
128 typedef typename allocator_type::difference_type difference_type;
129 typedef iterator pointer;
130 typedef const_iterator const_pointer;
131 typedef std::reverse_iterator<iterator> reverse_iterator;
132 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
133
134 class reference
135 {
136 public:
137 reference(const reference&);
138 operator bool() const;
139 reference& operator=(const bool x);
140 reference& operator=(const reference& x);
141 iterator operator&() const;
142 void flip();
143 };
144
145 class const_reference
146 {
147 public:
148 const_reference(const reference&);
149 operator bool() const;
150 const_iterator operator&() const;
151 };
152
153 explicit vector(const allocator_type& = allocator_type());
154 explicit vector(size_type n, const value_type& value = value_type(), const allocator_type& = allocator_type());
155 template <class InputIterator>
156 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
157 vector(const vector& x);
158 vector(vector&& x);
159 vector(initializer_list<value_type> il);
160 vector(initializer_list<value_type> il, const allocator_type& a);
161 ~vector();
162 vector& operator=(const vector& x);
163 vector& operator=(vector&& x);
164 vector& operator=(initializer_list<value_type> il);
165 template <class InputIterator>
166 void assign(InputIterator first, InputIterator last);
167 void assign(size_type n, const value_type& u);
168 void assign(initializer_list<value_type> il);
169
170 allocator_type get_allocator() const;
171
172 iterator begin();
173 const_iterator begin() const;
174 iterator end();
175 const_iterator end() const;
176
177 reverse_iterator rbegin();
178 const_reverse_iterator rbegin() const;
179 reverse_iterator rend();
180 const_reverse_iterator rend() const;
181
182 const_iterator cbegin() const;
183 const_iterator cend() const;
184 const_reverse_iterator crbegin() const;
185 const_reverse_iterator crend() const;
186
187 size_type size() const;
188 size_type max_size() const;
189 size_type capacity() const;
190 bool empty() const;
191 void reserve(size_type n);
192 void shrink_to_fit();
193
194 reference operator[](size_type n);
195 const_reference operator[](size_type n) const;
196 reference at(size_type n);
197 const_reference at(size_type n) const;
198
199 reference front();
200 const_reference front() const;
201 reference back();
202 const_reference back() const;
203
204 void push_back(const value_type& x);
205 void pop_back();
206
207 iterator insert(const_iterator position, const value_type& x);
208 iterator insert(const_iterator position, size_type n, const value_type& x);
209 template <class InputIterator>
210 iterator insert(const_iterator position, InputIterator first, InputIterator last);
211 iterator insert(const_iterator position, initializer_list<value_type> il);
212
213 iterator erase(const_iterator position);
214 iterator erase(const_iterator first, const_iterator last);
215
216 void clear();
217
218 void resize(size_type sz);
219 void resize(size_type sz, value_type x);
220
221 void swap(vector&);
222 void flip();
223
224 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43 +0000225};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000226
227template <class Allocator> struct hash<std::vector<bool, Allocator>>;
228
229template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
230template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
231template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
232template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
233template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
234template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
235
236template <class T, class Allocator> void swap(vector<T,Allocator>& x, vector<T,Allocator>& y);
237
238} // std
239
240*/
241
242#include <__config>
243#include <__bit_reference>
244#include <type_traits>
245#include <climits>
246#include <limits>
247#include <initializer_list>
248#include <memory>
249#include <stdexcept>
250#include <algorithm>
251#include <cstring>
252#include <__split_buffer>
253#include <__functional_base>
254#if defined(_LIBCPP_DEBUG) || defined(_LIBCPP_NO_EXCEPTIONS)
255 #include <cassert>
256#endif
257
258#pragma GCC system_header
259
260_LIBCPP_BEGIN_NAMESPACE_STD
261
262template <bool>
263class __vector_base_common
264{
265protected:
266 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
267 void __throw_length_error() const;
268 void __throw_out_of_range() const;
269};
270
271template <bool __b>
272void
273__vector_base_common<__b>::__throw_length_error() const
274{
275#ifndef _LIBCPP_NO_EXCEPTIONS
276 throw length_error("vector");
277#else
278 assert(!"vector length_error");
279#endif
280}
281
282template <bool __b>
283void
284__vector_base_common<__b>::__throw_out_of_range() const
285{
286#ifndef _LIBCPP_NO_EXCEPTIONS
287 throw out_of_range("vector");
288#else
289 assert(!"vector out_of_range");
290#endif
291}
292
293extern template class __vector_base_common<true>;
294
295template <class _Tp, class _Allocator>
296class __vector_base
297 : protected __vector_base_common<true>
298{
299protected:
Howard Hinnant324bb032010-08-22 00:02:43 +0000300 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000301 typedef _Allocator allocator_type;
302 typedef allocator_traits<allocator_type> __alloc_traits;
303 typedef value_type& reference;
304 typedef const value_type& const_reference;
305 typedef typename __alloc_traits::size_type size_type;
306 typedef typename __alloc_traits::difference_type difference_type;
307 typedef typename __alloc_traits::pointer pointer;
308 typedef typename __alloc_traits::const_pointer const_pointer;
309 typedef pointer iterator;
310 typedef const_pointer const_iterator;
311
312 pointer __begin_;
313 pointer __end_;
314 __compressed_pair<pointer, allocator_type> __end_cap_;
315
316 _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __end_cap_.second();}
317 _LIBCPP_INLINE_VISIBILITY const allocator_type& __alloc() const {return __end_cap_.second();}
318 _LIBCPP_INLINE_VISIBILITY pointer& __end_cap() {return __end_cap_.first();}
319 _LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const {return __end_cap_.first();}
320
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000321 _LIBCPP_INLINE_VISIBILITY __vector_base();
322 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000323 ~__vector_base();
324
325 _LIBCPP_INLINE_VISIBILITY void clear() {__destruct_at_end(__begin_);}
326 _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast<size_type>(__end_cap() - __begin_);}
327
328 _LIBCPP_INLINE_VISIBILITY void __destruct_at_end(const_pointer __new_last)
Howard Hinnant1468b662010-11-19 22:17:28 +0000329 {__destruct_at_end(__new_last, is_trivially_destructible<value_type>());}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000330 _LIBCPP_INLINE_VISIBILITY void __destruct_at_end(const_pointer __new_last, false_type);
331 _LIBCPP_INLINE_VISIBILITY void __destruct_at_end(const_pointer __new_last, true_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000332
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000333 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000334 void __copy_assign_alloc(const __vector_base& __c)
335 {__copy_assign_alloc(__c, integral_constant<bool,
336 __alloc_traits::propagate_on_container_copy_assignment::value>());}
337
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000338 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339 void __move_assign_alloc(__vector_base& __c)
340 {__move_assign_alloc(__c, integral_constant<bool,
341 __alloc_traits::propagate_on_container_move_assignment::value>());}
342
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000343 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000344 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
345 {__swap_alloc(__x, __y, integral_constant<bool,
346 __alloc_traits::propagate_on_container_swap::value>());}
347private:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000348 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000349 void __copy_assign_alloc(const __vector_base& __c, true_type)
350 {
351 if (__alloc() != __c.__alloc())
352 {
353 clear();
354 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
355 __begin_ = __end_ = __end_cap() = nullptr;
356 }
357 __alloc() = __c.__alloc();
358 }
359
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361 void __copy_assign_alloc(const __vector_base& __c, false_type)
362 {}
363
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365 void __move_assign_alloc(const __vector_base& __c, true_type)
366 {
367 __alloc() = _STD::move(__c.__alloc());
368 }
369
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000370 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371 void __move_assign_alloc(const __vector_base& __c, false_type)
372 {}
373
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
376 {
377 using _STD::swap;
378 swap(__x, __y);
379 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000380 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381 static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type)
382 {}
383};
384
385template <class _Tp, class _Allocator>
386_LIBCPP_INLINE_VISIBILITY inline
387void
388__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type)
389{
390 while (__new_last < __end_)
391 __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_));
392}
393
394template <class _Tp, class _Allocator>
395_LIBCPP_INLINE_VISIBILITY inline
396void
397__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type)
398{
399 __end_ = const_cast<pointer>(__new_last);
400}
401
402template <class _Tp, class _Allocator>
403_LIBCPP_INLINE_VISIBILITY inline
404__vector_base<_Tp, _Allocator>::__vector_base()
405 : __begin_(0),
406 __end_(0),
407 __end_cap_(0)
408{
409}
410
411template <class _Tp, class _Allocator>
412_LIBCPP_INLINE_VISIBILITY inline
413__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
414 : __begin_(0),
415 __end_(0),
416 __end_cap_(0, __a)
417{
418}
419
420template <class _Tp, class _Allocator>
421__vector_base<_Tp, _Allocator>::~__vector_base()
422{
423 if (__begin_ != 0)
424 {
425 clear();
426 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
427 }
428}
429
430template <class _Tp, class _Allocator = allocator<_Tp> >
Howard Hinnant36cdf022010-09-10 16:42:26 +0000431class _LIBCPP_VISIBLE vector
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432 : private __vector_base<_Tp, _Allocator>
433{
434private:
435 typedef __vector_base<_Tp, _Allocator> __base;
Howard Hinnant324bb032010-08-22 00:02:43 +0000436public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000437 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +0000438 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 typedef _Allocator allocator_type;
440 typedef typename __base::__alloc_traits __alloc_traits;
441 typedef typename __base::reference reference;
442 typedef typename __base::const_reference const_reference;
443 typedef typename __base::size_type size_type;
444 typedef typename __base::difference_type difference_type;
445 typedef typename __base::pointer pointer;
446 typedef typename __base::const_pointer const_pointer;
447#ifdef _LIBCPP_DEBUG
448 typedef __debug_iter<vector, pointer> iterator;
449 typedef __debug_iter<vector, const_pointer> const_iterator;
450
451 friend class __debug_iter<vector, pointer>;
452 friend class __debug_iter<vector, const_pointer>;
453
454 pair<iterator*, const_iterator*> __iterator_list_;
455
456 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
457 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
458#elif defined(_LIBCPP_RAW_ITERATORS)
459 typedef pointer iterator;
460 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000461#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 typedef __wrap_iter<pointer> iterator;
463 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000464#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465 typedef _STD::reverse_iterator<iterator> reverse_iterator;
466 typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
467
468 _LIBCPP_INLINE_VISIBILITY vector() {}
469 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) : __base(__a) {}
470 explicit vector(size_type __n);
471 vector(size_type __n, const_reference __x);
472 vector(size_type __n, const_reference __x, const allocator_type& __a);
473 template <class _InputIterator>
474 vector(_InputIterator __first, _InputIterator __last,
475 typename enable_if<__is_input_iterator <_InputIterator>::value &&
476 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
477 template <class _InputIterator>
478 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
479 typename enable_if<__is_input_iterator <_InputIterator>::value &&
480 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
481 template <class _ForwardIterator>
482 vector(_ForwardIterator __first, _ForwardIterator __last,
483 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
484 template <class _ForwardIterator>
485 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
486 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000488 vector(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 vector(initializer_list<value_type> __il, const allocator_type& __a);
491#ifdef _LIBCPP_DEBUG
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 ~vector() {__invalidate_all_iterators();}
494#endif
495
496 vector(const vector& __x);
497 vector(const vector& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499 vector& operator=(const vector& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000500#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000502 vector(vector&& __x);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504 vector(vector&& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506 vector& operator=(vector&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000507#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509 vector& operator=(initializer_list<value_type> __il)
510 {assign(__il.begin(), __il.end()); return *this;}
511
512 template <class _InputIterator>
513 typename enable_if
514 <
515 __is_input_iterator <_InputIterator>::value &&
516 !__is_forward_iterator<_InputIterator>::value,
517 void
518 >::type
519 assign(_InputIterator __first, _InputIterator __last);
520 template <class _ForwardIterator>
521 typename enable_if
522 <
523 __is_forward_iterator<_ForwardIterator>::value,
524 void
525 >::type
526 assign(_ForwardIterator __first, _ForwardIterator __last);
527
528 void assign(size_type __n, const_reference __u);
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530 void assign(initializer_list<value_type> __il)
531 {assign(__il.begin(), __il.end());}
532
533 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const {return this->__alloc();}
534
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000535 _LIBCPP_INLINE_VISIBILITY iterator begin();
536 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const;
537 _LIBCPP_INLINE_VISIBILITY iterator end();
538 _LIBCPP_INLINE_VISIBILITY const_iterator end() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539
540 _LIBCPP_INLINE_VISIBILITY reverse_iterator rbegin() {return reverse_iterator(end());}
541 _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
542 _LIBCPP_INLINE_VISIBILITY reverse_iterator rend() {return reverse_iterator(begin());}
543 _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rend() const {return const_reverse_iterator(begin());}
544
545 _LIBCPP_INLINE_VISIBILITY const_iterator cbegin() const {return begin();}
546 _LIBCPP_INLINE_VISIBILITY const_iterator cend() const {return end();}
547 _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crbegin() const {return rbegin();}
548 _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const {return rend();}
549
550 _LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast<size_type>(this->__end_ - this->__begin_);}
551 _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return __base::capacity();}
552 _LIBCPP_INLINE_VISIBILITY bool empty() const {return this->__begin_ == this->__end_;}
553 size_type max_size() const;
554 void reserve(size_type __n);
555 void shrink_to_fit();
556
557 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
558 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
559 reference at(size_type __n);
560 const_reference at(size_type __n) const;
561
562 _LIBCPP_INLINE_VISIBILITY reference front() {return *this->__begin_;}
563 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return *this->__begin_;}
564 _LIBCPP_INLINE_VISIBILITY reference back() {return *(this->__end_ - 1);}
565 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return *(this->__end_ - 1);}
566
567 _LIBCPP_INLINE_VISIBILITY value_type* data()
568 {return _STD::__to_raw_pointer(this->__begin_);}
569 _LIBCPP_INLINE_VISIBILITY const value_type* data() const
570 {return _STD::__to_raw_pointer(this->__begin_);}
571
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000572 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000573#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574 void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000575#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000576 template <class... _Args>
577 void emplace_back(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000578#endif // _LIBCPP_HAS_NO_VARIADICS
579#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000580 void pop_back();
581
582 iterator insert(const_iterator __position, const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000583#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584 iterator insert(const_iterator __position, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000585#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586 template <class... _Args>
587 iterator emplace(const_iterator __position, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000588#endif // _LIBCPP_HAS_NO_VARIADICS
589#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590 iterator insert(const_iterator __position, size_type __n, const_reference __x);
591 template <class _InputIterator>
592 typename enable_if
593 <
594 __is_input_iterator <_InputIterator>::value &&
595 !__is_forward_iterator<_InputIterator>::value,
596 iterator
597 >::type
598 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
599 template <class _ForwardIterator>
600 typename enable_if
601 <
602 __is_forward_iterator<_ForwardIterator>::value,
603 iterator
604 >::type
605 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000607 iterator insert(const_iterator __position, initializer_list<value_type> __il)
608 {return insert(__position, __il.begin(), __il.end());}
609
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000610 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000611 iterator erase(const_iterator __first, const_iterator __last);
612
613 _LIBCPP_INLINE_VISIBILITY void clear() {__base::clear();}
614
615 void resize(size_type __sz);
616 void resize(size_type __sz, const_reference __x);
617
618 void swap(vector&);
619
620 bool __invariants() const;
621
622private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000623 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624 void allocate(size_type __n);
625 void deallocate();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000626 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
627 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628 void __construct_at_end(size_type __n, false_type);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000629 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, true_type);
630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631 void __construct_at_end(size_type __n, const_reference __x);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000632 void __construct_at_end(size_type __n, const_reference __x, false_type);
633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634 void __construct_at_end(size_type __n, const_reference __x, true_type);
635 template <class _ForwardIterator>
636 typename enable_if
637 <
638 __is_forward_iterator<_ForwardIterator>::value,
639 void
640 >::type
641 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
642 void __move_construct_at_end(pointer __first, pointer __last);
643 void __append(size_type __n);
644 void __append(size_type __n, const_reference __x);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000646 iterator __make_iter(pointer __p);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000648 const_iterator __make_iter(const_pointer __p) const;
649 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
650 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
651 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
652 void __move_assign(vector& __c, true_type);
653 void __move_assign(vector& __c, false_type);
654};
655
656template <class _Tp, class _Allocator>
657void
658vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
659{
660 for (pointer __p = this->__end_; this->__begin_ < __p;)
661 __v.push_front(_STD::move(*--__p));
662 _STD::swap(this->__begin_, __v.__begin_);
663 _STD::swap(this->__end_, __v.__end_);
664 _STD::swap(this->__end_cap(), __v.__end_cap());
665 __v.__first_ = __v.__begin_;
666 __invalidate_all_iterators();
667}
668
669template <class _Tp, class _Allocator>
670typename vector<_Tp, _Allocator>::pointer
671vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
672{
673 pointer __r = __v.__begin_;
674 for (pointer __i = __p; this->__begin_ < __i;)
675 __v.push_front(_STD::move(*--__i));
676 for (pointer __i = __p; __i < this->__end_; ++__i)
677 __v.push_back(_STD::move(*__i));
678 _STD::swap(this->__begin_, __v.__begin_);
679 _STD::swap(this->__end_, __v.__end_);
680 _STD::swap(this->__end_cap(), __v.__end_cap());
681 __v.__first_ = __v.__begin_;
682 __invalidate_all_iterators();
683 return __r;
684}
685
686// Allocate space for __n objects
687// throws length_error if __n > max_size()
688// throws (probably bad_alloc) if memory run out
689// Precondition: __begin_ == __end_ == __end_cap() == 0
690// Precondition: __n > 0
691// Postcondition: capacity() == __n
692// Postcondition: size() == 0
693template <class _Tp, class _Allocator>
694void
695vector<_Tp, _Allocator>::allocate(size_type __n)
696{
697 if (__n > max_size())
698 this->__throw_length_error();
699 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
700 this->__end_cap() = this->__begin_ + __n;
701}
702
703template <class _Tp, class _Allocator>
704void
705vector<_Tp, _Allocator>::deallocate()
706{
707 if (this->__begin_ != 0)
708 {
709 clear();
710 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
711 __invalidate_all_iterators();
712 this->__begin_ = this->__end_ = this->__end_cap() = 0;
713 }
714}
715
716template <class _Tp, class _Allocator>
717typename vector<_Tp, _Allocator>::size_type
718vector<_Tp, _Allocator>::max_size() const
719{
720 return _STD::min(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2); // end() >= begin(), always
721}
722
723// Precondition: __new_size > capacity()
724template <class _Tp, class _Allocator>
725_LIBCPP_INLINE_VISIBILITY inline
726typename vector<_Tp, _Allocator>::size_type
727vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
728{
729 const size_type __ms = max_size();
730 if (__new_size > __ms)
731 this->__throw_length_error();
732 const size_type __cap = capacity();
733 if (__cap >= __ms / 2)
734 return __ms;
735 return _STD::max(2*__cap, __new_size);
736}
737
738// Default constructs __n objects starting at __end_
739// throws if construction throws
740// Precondition: __n > 0
741// Precondition: size() + __n <= capacity()
742// Postcondition: size() == size() + __n
743template <class _Tp, class _Allocator>
744_LIBCPP_INLINE_VISIBILITY inline
745void
746vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
747{
748 __construct_at_end(__n, __is_zero_default_constructible<value_type>());
749}
750
751template <class _Tp, class _Allocator>
752void
753vector<_Tp, _Allocator>::__construct_at_end(size_type __n, false_type)
754{
755 allocator_type& __a = this->__alloc();
756 do
757 {
758 __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_));
759 ++this->__end_;
760 --__n;
761 } while (__n > 0);
762}
763
764template <class _Tp, class _Allocator>
765_LIBCPP_INLINE_VISIBILITY inline
766void
767vector<_Tp, _Allocator>::__construct_at_end(size_type __n, true_type)
768{
769 _STD::memset(this->__end_, 0, __n*sizeof(value_type));
770 this->__end_ += __n;
771}
772
773// Copy constructs __n objects starting at __end_ from __x
774// throws if construction throws
775// Precondition: __n > 0
776// Precondition: size() + __n <= capacity()
777// Postcondition: size() == old size() + __n
778// Postcondition: [i] == __x for all i in [size() - __n, __n)
779template <class _Tp, class _Allocator>
780_LIBCPP_INLINE_VISIBILITY inline
781void
782vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
783{
Howard Hinnant1468b662010-11-19 22:17:28 +0000784 __construct_at_end(__n, __x, integral_constant<bool, is_trivially_copy_constructible<value_type>::value &&
785 is_trivially_copy_assignable<value_type>::value>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786}
787
788template <class _Tp, class _Allocator>
789void
790vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x, false_type)
791{
792 allocator_type& __a = this->__alloc();
793 do
794 {
795 __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_), __x);
796 ++this->__end_;
797 --__n;
798 } while (__n > 0);
799}
800
801template <class _Tp, class _Allocator>
802_LIBCPP_INLINE_VISIBILITY inline
803void
804vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x, true_type)
805{
806 _STD::fill_n(this->__end_, __n, __x);
807 this->__end_ += __n;
808}
809
810template <class _Tp, class _Allocator>
811template <class _ForwardIterator>
812typename enable_if
813<
814 __is_forward_iterator<_ForwardIterator>::value,
815 void
816>::type
817vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
818{
819 allocator_type& __a = this->__alloc();
820 for (; __first != __last; ++__first)
821 {
822 __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_), *__first);
823 ++this->__end_;
824 }
825}
826
827template <class _Tp, class _Allocator>
828void
829vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
830{
831 allocator_type& __a = this->__alloc();
832 for (; __first != __last; ++__first)
833 {
834 __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_),
835 _STD::move(*__first));
836 ++this->__end_;
837 }
838}
839
840// Default constructs __n objects starting at __end_
841// throws if construction throws
842// Postcondition: size() == size() + __n
843// Exception safety: strong but assumes move ctor doesn't throw (copy ctor can)
844template <class _Tp, class _Allocator>
845void
846vector<_Tp, _Allocator>::__append(size_type __n)
847{
848 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
849 this->__construct_at_end(__n);
850 else
851 {
852 allocator_type& __a = this->__alloc();
853 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
854 __v.__construct_at_end(__n);
855 __swap_out_circular_buffer(__v);
856 }
857}
858
859// Default constructs __n objects starting at __end_
860// throws if construction throws
861// Postcondition: size() == size() + __n
862// Exception safety: strong but assumes move ctor doesn't throw (copy ctor can)
863template <class _Tp, class _Allocator>
864void
865vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
866{
867 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
868 this->__construct_at_end(__n, __x);
869 else
870 {
871 allocator_type& __a = this->__alloc();
872 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
873 __v.__construct_at_end(__n, __x);
874 __swap_out_circular_buffer(__v);
875 }
876}
877
878template <class _Tp, class _Allocator>
879vector<_Tp, _Allocator>::vector(size_type __n)
880{
881 if (__n > 0)
882 {
883 allocate(__n);
884 __construct_at_end(__n);
885 }
886}
887
888template <class _Tp, class _Allocator>
889vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
890{
891 if (__n > 0)
892 {
893 allocate(__n);
894 __construct_at_end(__n, __x);
895 }
896}
897
898template <class _Tp, class _Allocator>
899vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
900 : __base(__a)
901{
902 if (__n > 0)
903 {
904 allocate(__n);
905 __construct_at_end(__n, __x);
906 }
907}
908
909template <class _Tp, class _Allocator>
910template <class _InputIterator>
911vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
912 typename enable_if<__is_input_iterator <_InputIterator>::value &&
913 !__is_forward_iterator<_InputIterator>::value>::type*)
914{
915 for (; __first != __last; ++__first)
916 push_back(*__first);
917}
918
919template <class _Tp, class _Allocator>
920template <class _InputIterator>
921vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
922 typename enable_if<__is_input_iterator <_InputIterator>::value &&
923 !__is_forward_iterator<_InputIterator>::value>::type*)
924 : __base(__a)
925{
926 for (; __first != __last; ++__first)
927 push_back(*__first);
928}
929
930template <class _Tp, class _Allocator>
931template <class _ForwardIterator>
932vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
933 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
934{
935 size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
936 if (__n > 0)
937 {
938 allocate(__n);
939 __construct_at_end(__first, __last);
940 }
941}
942
943template <class _Tp, class _Allocator>
944template <class _ForwardIterator>
945vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
946 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
947 : __base(__a)
948{
949 size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
950 if (__n > 0)
951 {
952 allocate(__n);
953 __construct_at_end(__first, __last);
954 }
955}
956
957template <class _Tp, class _Allocator>
958vector<_Tp, _Allocator>::vector(const vector& __x)
959 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
960{
961 size_type __n = __x.size();
962 if (__n > 0)
963 {
964 allocate(__n);
965 __construct_at_end(__x.__begin_, __x.__end_);
966 }
967}
968
969template <class _Tp, class _Allocator>
970vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
971 : __base(__a)
972{
973 size_type __n = __x.size();
974 if (__n > 0)
975 {
976 allocate(__n);
977 __construct_at_end(__x.__begin_, __x.__end_);
978 }
979}
980
Howard Hinnant73d21a42010-09-04 23:28:19 +0000981#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982
983template <class _Tp, class _Allocator>
984_LIBCPP_INLINE_VISIBILITY inline
985vector<_Tp, _Allocator>::vector(vector&& __x)
986 : __base(_STD::move(__x.__alloc()))
987{
988 this->__begin_ = __x.__begin_;
989 this->__end_ = __x.__end_;
990 this->__end_cap() = __x.__end_cap();
991 __x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
992 __x.__invalidate_all_iterators();
993}
994
995template <class _Tp, class _Allocator>
996_LIBCPP_INLINE_VISIBILITY inline
997vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
998 : __base(__a)
999{
1000 if (__a == __x.__alloc())
1001 {
1002 this->__begin_ = __x.__begin_;
1003 this->__end_ = __x.__end_;
1004 this->__end_cap() = __x.__end_cap();
1005 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1006 __x.__invalidate_all_iterators();
1007 }
1008 else
1009 {
1010 typedef move_iterator<iterator> _I;
1011 assign(_I(__x.begin()), _I(__x.end()));
1012 }
1013}
1014
1015template <class _Tp, class _Allocator>
1016_LIBCPP_INLINE_VISIBILITY inline
1017vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1018{
1019 if (__il.size() > 0)
1020 {
1021 allocate(__il.size());
1022 __construct_at_end(__il.begin(), __il.end());
1023 }
1024}
1025
1026template <class _Tp, class _Allocator>
1027_LIBCPP_INLINE_VISIBILITY inline
1028vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1029 : __base(__a)
1030{
1031 if (__il.size() > 0)
1032 {
1033 allocate(__il.size());
1034 __construct_at_end(__il.begin(), __il.end());
1035 }
1036}
1037
1038template <class _Tp, class _Allocator>
1039_LIBCPP_INLINE_VISIBILITY inline
1040vector<_Tp, _Allocator>&
1041vector<_Tp, _Allocator>::operator=(vector&& __x)
1042{
1043 __move_assign(__x, integral_constant<bool,
1044 __alloc_traits::propagate_on_container_move_assignment::value>());
1045 return *this;
1046}
1047
1048template <class _Tp, class _Allocator>
1049void
1050vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1051{
1052 if (__base::__alloc() != __c.__alloc())
1053 {
1054 typedef move_iterator<iterator> _I;
1055 assign(_I(__c.begin()), _I(__c.end()));
1056 }
1057 else
1058 __move_assign(__c, true_type());
1059}
1060
1061template <class _Tp, class _Allocator>
1062void
1063vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1064{
1065 deallocate();
1066 this->__begin_ = __c.__begin_;
1067 this->__end_ = __c.__end_;
1068 this->__end_cap() = __c.__end_cap();
1069 __base::__move_assign_alloc(__c);
1070 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1071}
1072
Howard Hinnant73d21a42010-09-04 23:28:19 +00001073#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001074
1075template <class _Tp, class _Allocator>
1076_LIBCPP_INLINE_VISIBILITY inline
1077vector<_Tp, _Allocator>&
1078vector<_Tp, _Allocator>::operator=(const vector& __x)
1079{
1080 if (this != &__x)
1081 {
1082 __base::__copy_assign_alloc(__x);
1083 assign(__x.__begin_, __x.__end_);
1084 }
1085 return *this;
1086}
1087
1088template <class _Tp, class _Allocator>
1089template <class _InputIterator>
1090typename enable_if
1091<
1092 __is_input_iterator <_InputIterator>::value &&
1093 !__is_forward_iterator<_InputIterator>::value,
1094 void
1095>::type
1096vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1097{
1098 clear();
1099 for (; __first != __last; ++__first)
1100 push_back(*__first);
1101}
1102
1103template <class _Tp, class _Allocator>
1104template <class _ForwardIterator>
1105typename enable_if
1106<
1107 __is_forward_iterator<_ForwardIterator>::value,
1108 void
1109>::type
1110vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1111{
1112 typename iterator_traits<_ForwardIterator>::difference_type __new_size = _STD::distance(__first, __last);
1113 if (static_cast<size_type>(__new_size) <= capacity())
1114 {
1115 _ForwardIterator __mid = __last;
1116 bool __growing = false;
1117 if (static_cast<size_type>(__new_size) > size())
1118 {
1119 __growing = true;
1120 __mid = __first;
1121 _STD::advance(__mid, size());
1122 }
1123 pointer __m = _STD::copy(__first, __mid, this->__begin_);
1124 if (__growing)
1125 __construct_at_end(__mid, __last);
1126 else
1127 this->__destruct_at_end(__m);
1128 }
1129 else
1130 {
1131 deallocate();
1132 allocate(__recommend(static_cast<size_type>(__new_size)));
1133 __construct_at_end(__first, __last);
1134 }
1135}
1136
1137template <class _Tp, class _Allocator>
1138void
1139vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1140{
1141 if (__n <= capacity())
1142 {
1143 size_type __s = size();
1144 _STD::fill_n(this->__begin_, min(__n, __s), __u);
1145 if (__n > __s)
1146 __construct_at_end(__n - __s, __u);
1147 else
Howard Hinnantadff4892010-05-24 17:49:41 +00001148 this->__destruct_at_end(this->__begin_ + __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149 }
1150 else
1151 {
1152 deallocate();
1153 allocate(__recommend(static_cast<size_type>(__n)));
1154 __construct_at_end(__n, __u);
1155 }
1156}
1157
Howard Hinnant324bb032010-08-22 00:02:43 +00001158template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001159_LIBCPP_INLINE_VISIBILITY inline
1160typename vector<_Tp, _Allocator>::iterator
1161vector<_Tp, _Allocator>::__make_iter(pointer __p)
1162{
1163#ifdef _LIBCPP_DEBUG
1164 return iterator(this, __p);
1165#else
1166 return iterator(__p);
1167#endif
1168}
1169
Howard Hinnant324bb032010-08-22 00:02:43 +00001170template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171_LIBCPP_INLINE_VISIBILITY inline
1172typename vector<_Tp, _Allocator>::const_iterator
1173vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const
1174{
1175#ifdef _LIBCPP_DEBUG
1176 return const_iterator(this, __p);
1177#else
1178 return const_iterator(__p);
1179#endif
1180}
1181
Howard Hinnant324bb032010-08-22 00:02:43 +00001182template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183_LIBCPP_INLINE_VISIBILITY inline
1184typename vector<_Tp, _Allocator>::iterator
1185vector<_Tp, _Allocator>::begin()
1186{
1187 return __make_iter(this->__begin_);
1188}
1189
Howard Hinnant324bb032010-08-22 00:02:43 +00001190template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001191_LIBCPP_INLINE_VISIBILITY inline
1192typename vector<_Tp, _Allocator>::const_iterator
1193vector<_Tp, _Allocator>::begin() const
1194{
1195 return __make_iter(this->__begin_);
1196}
1197
Howard Hinnant324bb032010-08-22 00:02:43 +00001198template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001199_LIBCPP_INLINE_VISIBILITY inline
1200typename vector<_Tp, _Allocator>::iterator
1201vector<_Tp, _Allocator>::end()
1202{
1203 return __make_iter(this->__end_);
1204}
1205
Howard Hinnant324bb032010-08-22 00:02:43 +00001206template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001207_LIBCPP_INLINE_VISIBILITY inline
1208typename vector<_Tp, _Allocator>::const_iterator
1209vector<_Tp, _Allocator>::end() const
1210{
1211 return __make_iter(this->__end_);
1212}
1213
Howard Hinnant324bb032010-08-22 00:02:43 +00001214template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001215_LIBCPP_INLINE_VISIBILITY inline
1216typename vector<_Tp, _Allocator>::reference
1217vector<_Tp, _Allocator>::operator[](size_type __n)
1218{
1219#ifdef _LIBCPP_DEBUG
1220 assert(__n < size());
1221#endif
1222 return this->__begin_[__n];
1223}
1224
Howard Hinnant324bb032010-08-22 00:02:43 +00001225template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001226_LIBCPP_INLINE_VISIBILITY inline
1227typename vector<_Tp, _Allocator>::const_reference
1228vector<_Tp, _Allocator>::operator[](size_type __n) const
1229{
1230#ifdef _LIBCPP_DEBUG
1231 assert(__n < size());
1232#endif
1233 return this->__begin_[__n];
1234}
1235
Howard Hinnant324bb032010-08-22 00:02:43 +00001236template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001237typename vector<_Tp, _Allocator>::reference
1238vector<_Tp, _Allocator>::at(size_type __n)
1239{
1240 if (__n >= size())
1241 this->__throw_out_of_range();
1242 return this->__begin_[__n];
1243}
1244
Howard Hinnant324bb032010-08-22 00:02:43 +00001245template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246typename vector<_Tp, _Allocator>::const_reference
1247vector<_Tp, _Allocator>::at(size_type __n) const
1248{
1249 if (__n >= size())
1250 this->__throw_out_of_range();
1251 return this->__begin_[__n];
1252}
1253
1254template <class _Tp, class _Allocator>
1255void
1256vector<_Tp, _Allocator>::reserve(size_type __n)
1257{
1258 if (__n > capacity())
1259 {
1260 allocator_type& __a = this->__alloc();
1261 __split_buffer<value_type, allocator_type&> __v(__n, 0, __a);
1262 __v.__construct_at_end(move_iterator<pointer>(this->__begin_),
1263 move_iterator<pointer>(this->__end_));
1264 clear();
1265 __swap_out_circular_buffer(__v);
1266 }
1267}
1268
1269template <class _Tp, class _Allocator>
1270void
1271vector<_Tp, _Allocator>::shrink_to_fit()
1272{
1273 if (capacity() > size())
1274 {
1275#ifndef _LIBCPP_NO_EXCEPTIONS
1276 try
1277 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001278#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001279 allocator_type& __a = this->__alloc();
1280 __split_buffer<value_type, allocator_type&> __v(size(), 0, __a);
1281 __v.__construct_at_end(move_iterator<pointer>(this->__begin_),
1282 move_iterator<pointer>(this->__end_));
1283 clear();
1284 __swap_out_circular_buffer(__v);
1285#ifndef _LIBCPP_NO_EXCEPTIONS
1286 }
1287 catch (...)
1288 {
1289 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001290#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001291 }
1292}
1293
1294template <class _Tp, class _Allocator>
1295void
1296vector<_Tp, _Allocator>::push_back(const_reference __x)
1297{
1298 if (this->__end_ < this->__end_cap())
1299 {
1300 __alloc_traits::construct(this->__alloc(),
1301 _STD::__to_raw_pointer(this->__end_), __x);
1302 ++this->__end_;
1303 }
1304 else
1305 {
1306 allocator_type& __a = this->__alloc();
1307 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1308 __v.push_back(__x);
1309 __swap_out_circular_buffer(__v);
1310 }
1311}
1312
Howard Hinnant73d21a42010-09-04 23:28:19 +00001313#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314
1315template <class _Tp, class _Allocator>
1316void
1317vector<_Tp, _Allocator>::push_back(value_type&& __x)
1318{
1319 if (this->__end_ < this->__end_cap())
1320 {
1321 __alloc_traits::construct(this->__alloc(),
1322 _STD::__to_raw_pointer(this->__end_),
1323 _STD::move(__x));
1324 ++this->__end_;
1325 }
1326 else
1327 {
1328 allocator_type& __a = this->__alloc();
1329 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1330 __v.push_back(_STD::move(__x));
1331 __swap_out_circular_buffer(__v);
1332 }
1333}
1334
Howard Hinnant73d21a42010-09-04 23:28:19 +00001335#ifndef _LIBCPP_HAS_NO_VARIADICS
1336
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337template <class _Tp, class _Allocator>
1338template <class... _Args>
1339void
1340vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1341{
1342 if (this->__end_ < this->__end_cap())
1343 {
1344 __alloc_traits::construct(this->__alloc(),
1345 _STD::__to_raw_pointer(this->__end_),
1346 _STD::forward<_Args>(__args)...);
1347 ++this->__end_;
1348 }
1349 else
1350 {
1351 allocator_type& __a = this->__alloc();
1352 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1353 __v.emplace_back(_STD::forward<_Args>(__args)...);
1354 __swap_out_circular_buffer(__v);
1355 }
1356}
1357
Howard Hinnant73d21a42010-09-04 23:28:19 +00001358#endif // _LIBCPP_HAS_NO_VARIADICS
1359#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001360
1361template <class _Tp, class _Allocator>
1362_LIBCPP_INLINE_VISIBILITY inline
1363void
1364vector<_Tp, _Allocator>::pop_back()
1365{
1366 this->__destruct_at_end(this->__end_ - 1);
1367}
1368
1369template <class _Tp, class _Allocator>
1370_LIBCPP_INLINE_VISIBILITY inline
1371typename vector<_Tp, _Allocator>::iterator
1372vector<_Tp, _Allocator>::erase(const_iterator __position)
1373{
1374 pointer __p = const_cast<pointer>(&*__position);
1375 iterator __r = __make_iter(__p);
1376 this->__destruct_at_end(_STD::move(__p + 1, this->__end_, __p));
1377 return __r;
1378}
1379
1380template <class _Tp, class _Allocator>
1381typename vector<_Tp, _Allocator>::iterator
1382vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1383{
1384 pointer __p = this->__begin_ + (__first - begin());
1385 iterator __r = __make_iter(__p);
1386 this->__destruct_at_end(_STD::move(__p + (__last - __first), this->__end_, __p));
1387 return __r;
1388}
1389
1390template <class _Tp, class _Allocator>
1391void
1392vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1393{
1394 pointer __old_last = this->__end_;
1395 difference_type __n = __old_last - __to;
1396 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1397 __alloc_traits::construct(this->__alloc(),
1398 _STD::__to_raw_pointer(this->__end_),
1399 _STD::move(*__i));
1400 _STD::move_backward(__from_s, __from_s + __n, __old_last);
1401}
1402
1403template <class _Tp, class _Allocator>
1404typename vector<_Tp, _Allocator>::iterator
1405vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1406{
1407 pointer __p = this->__begin_ + (__position - begin());
1408 if (this->__end_ < this->__end_cap())
1409 {
1410 if (__p == this->__end_)
1411 {
1412 __alloc_traits::construct(this->__alloc(),
1413 _STD::__to_raw_pointer(this->__end_), __x);
1414 ++this->__end_;
1415 }
1416 else
1417 {
1418 __move_range(__p, this->__end_, __p + 1);
1419 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1420 if (__p <= __xr && __xr < this->__end_)
1421 ++__xr;
1422 *__p = *__xr;
1423 }
1424 }
1425 else
1426 {
1427 allocator_type& __a = this->__alloc();
1428 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1429 __v.push_back(__x);
1430 __p = __swap_out_circular_buffer(__v, __p);
1431 }
1432 return __make_iter(__p);
1433}
1434
Howard Hinnant73d21a42010-09-04 23:28:19 +00001435#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001436
1437template <class _Tp, class _Allocator>
1438typename vector<_Tp, _Allocator>::iterator
1439vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1440{
1441 pointer __p = this->__begin_ + (__position - begin());
1442 if (this->__end_ < this->__end_cap())
1443 {
1444 if (__p == this->__end_)
1445 {
1446 __alloc_traits::construct(this->__alloc(),
1447 _STD::__to_raw_pointer(this->__end_),
1448 _STD::move(__x));
1449 ++this->__end_;
1450 }
1451 else
1452 {
1453 __move_range(__p, this->__end_, __p + 1);
1454 *__p = _STD::move(__x);
1455 }
1456 }
1457 else
1458 {
1459 allocator_type& __a = this->__alloc();
1460 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1461 __v.push_back(_STD::move(__x));
1462 __p = __swap_out_circular_buffer(__v, __p);
1463 }
1464 return __make_iter(__p);
1465}
1466
Howard Hinnant73d21a42010-09-04 23:28:19 +00001467#ifndef _LIBCPP_HAS_NO_VARIADICS
1468
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001469template <class _Tp, class _Allocator>
1470template <class... _Args>
1471typename vector<_Tp, _Allocator>::iterator
1472vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1473{
1474 pointer __p = this->__begin_ + (__position - begin());
1475 if (this->__end_ < this->__end_cap())
1476 {
1477 if (__p == this->__end_)
1478 {
1479 __alloc_traits::construct(this->__alloc(),
1480 _STD::__to_raw_pointer(this->__end_),
1481 _STD::forward<_Args>(__args)...);
1482 ++this->__end_;
1483 }
1484 else
1485 {
1486 __move_range(__p, this->__end_, __p + 1);
1487 *__p = value_type(_STD::forward<_Args>(__args)...);
1488 }
1489 }
1490 else
1491 {
1492 allocator_type& __a = this->__alloc();
1493 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1494 __v.emplace_back(_STD::forward<_Args>(__args)...);
1495 __p = __swap_out_circular_buffer(__v, __p);
1496 }
1497 return __make_iter(__p);
1498}
1499
Howard Hinnant73d21a42010-09-04 23:28:19 +00001500#endif // _LIBCPP_HAS_NO_VARIADICS
1501#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001502
1503template <class _Tp, class _Allocator>
1504typename vector<_Tp, _Allocator>::iterator
1505vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1506{
1507 pointer __p = this->__begin_ + (__position - begin());
1508 if (__n > 0)
1509 {
1510 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1511 {
1512 size_type __old_n = __n;
1513 pointer __old_last = this->__end_;
1514 if (__n > static_cast<size_type>(this->__end_ - __p))
1515 {
1516 size_type __cx = __n - (this->__end_ - __p);
1517 __construct_at_end(__cx, __x);
1518 __n -= __cx;
1519 }
1520 if (__n > 0)
1521 {
1522 __move_range(__p, __old_last, __p + __old_n);
1523 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1524 if (__p <= __xr && __xr < this->__end_)
1525 __xr += __old_n;
1526 _STD::fill_n(__p, __n, *__xr);
1527 }
1528 }
1529 else
1530 {
1531 allocator_type& __a = this->__alloc();
1532 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1533 __v.__construct_at_end(__n, __x);
1534 __p = __swap_out_circular_buffer(__v, __p);
1535 }
1536 }
1537 return __make_iter(__p);
1538}
1539
1540template <class _Tp, class _Allocator>
1541template <class _InputIterator>
1542typename enable_if
1543<
1544 __is_input_iterator <_InputIterator>::value &&
1545 !__is_forward_iterator<_InputIterator>::value,
1546 typename vector<_Tp, _Allocator>::iterator
1547>::type
1548vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1549{
1550 difference_type __off = __position - begin();
1551 pointer __p = this->__begin_ + __off;
1552 allocator_type& __a = this->__alloc();
1553 pointer __old_last = this->__end_;
1554 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1555 {
1556 __alloc_traits::construct(__a, _STD::__to_raw_pointer(this->__end_),
1557 *__first);
1558 ++this->__end_;
1559 }
1560 __split_buffer<value_type, allocator_type&> __v(__a);
1561 if (__first != __last)
1562 {
1563#ifndef _LIBCPP_NO_EXCEPTIONS
1564 try
1565 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001566#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567 __v.__construct_at_end(__first, __last);
1568 difference_type __old_size = __old_last - this->__begin_;
1569 difference_type __old_p = __p - this->__begin_;
1570 reserve(__recommend(size() + __v.size()));
1571 __p = this->__begin_ + __old_p;
1572 __old_last = this->__begin_ + __old_size;
1573#ifndef _LIBCPP_NO_EXCEPTIONS
1574 }
1575 catch (...)
1576 {
1577 erase(__make_iter(__old_last), end());
1578 throw;
1579 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001580#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001581 }
1582 __p = _STD::rotate(__p, __old_last, this->__end_);
1583 insert(__make_iter(__p), move_iterator<iterator>(__v.begin()),
1584 move_iterator<iterator>(__v.end()));
1585 return begin() + __off;
1586}
1587
1588template <class _Tp, class _Allocator>
1589template <class _ForwardIterator>
1590typename enable_if
1591<
1592 __is_forward_iterator<_ForwardIterator>::value,
1593 typename vector<_Tp, _Allocator>::iterator
1594>::type
1595vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1596{
1597 pointer __p = this->__begin_ + (__position - begin());
1598 difference_type __n = _STD::distance(__first, __last);
1599 if (__n > 0)
1600 {
1601 if (__n <= this->__end_cap() - this->__end_)
1602 {
1603 size_type __old_n = __n;
1604 pointer __old_last = this->__end_;
1605 _ForwardIterator __m = __last;
1606 difference_type __dx = this->__end_ - __p;
1607 if (__n > __dx)
1608 {
1609 __m = __first;
1610 _STD::advance(__m, this->__end_ - __p);
1611 __construct_at_end(__m, __last);
1612 __n = __dx;
1613 }
1614 if (__n > 0)
1615 {
1616 __move_range(__p, __old_last, __p + __old_n);
1617 _STD::copy(__first, __m, __p);
1618 }
1619 }
1620 else
1621 {
1622 allocator_type& __a = this->__alloc();
1623 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1624 __v.__construct_at_end(__first, __last);
1625 __p = __swap_out_circular_buffer(__v, __p);
1626 }
1627 }
1628 return __make_iter(__p);
1629}
1630
1631template <class _Tp, class _Allocator>
1632void
1633vector<_Tp, _Allocator>::resize(size_type __sz)
1634{
1635 size_type __cs = size();
1636 if (__cs < __sz)
1637 this->__append(__sz - __cs);
1638 else if (__cs > __sz)
1639 this->__destruct_at_end(this->__begin_ + __sz);
1640}
1641
1642template <class _Tp, class _Allocator>
1643void
1644vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1645{
1646 size_type __cs = size();
1647 if (__cs < __sz)
1648 this->__append(__sz - __cs, __x);
1649 else if (__cs > __sz)
1650 this->__destruct_at_end(this->__begin_ + __sz);
1651}
1652
1653template <class _Tp, class _Allocator>
1654void
1655vector<_Tp, _Allocator>::swap(vector& __x)
1656{
1657 _STD::swap(this->__begin_, __x.__begin_);
1658 _STD::swap(this->__end_, __x.__end_);
1659 _STD::swap(this->__end_cap(), __x.__end_cap());
1660 __base::__swap_alloc(this->__alloc(), __x.__alloc());
1661#ifdef _LIBCPP_DEBUG
1662 iterator::swap(this, &__x);
1663 const_iterator::swap(this, &__x);
Howard Hinnant324bb032010-08-22 00:02:43 +00001664#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001665}
1666
Howard Hinnant324bb032010-08-22 00:02:43 +00001667template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001668bool
1669vector<_Tp, _Allocator>::__invariants() const
1670{
1671 if (this->__begin_ == 0)
1672 {
1673 if (this->__end_ != 0 || this->__end_cap() != 0)
1674 return false;
1675 }
1676 else
1677 {
1678 if (this->__begin_ > this->__end_)
1679 return false;
1680 if (this->__begin_ == this->__end_cap())
1681 return false;
1682 if (this->__end_ > this->__end_cap())
1683 return false;
1684 }
1685 return true;
1686}
1687
1688template <class _Tp, class _Allocator>
1689#ifndef _LIBCPP_DEBUG
1690_LIBCPP_INLINE_VISIBILITY inline
1691#endif
1692void
1693vector<_Tp, _Allocator>::__invalidate_all_iterators()
1694{
1695#ifdef _LIBCPP_DEBUG
1696 iterator::__remove_all(this);
1697 const_iterator::__remove_all(this);
Howard Hinnant324bb032010-08-22 00:02:43 +00001698#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001699}
1700
1701// vector<bool>
1702
1703template <class _Allocator> class vector<bool, _Allocator>;
1704
1705template <class _Allocator> struct hash<vector<bool, _Allocator> >;
1706
1707template <class _Allocator>
Howard Hinnant36cdf022010-09-10 16:42:26 +00001708class _LIBCPP_VISIBLE vector<bool, _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709 : private __vector_base_common<true>
1710{
1711public:
1712 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43 +00001713 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001714 typedef _Allocator allocator_type;
1715 typedef allocator_traits<allocator_type> __alloc_traits;
1716 typedef __bit_reference<vector> reference;
1717 typedef __bit_const_reference<vector> const_reference;
1718 typedef typename __alloc_traits::size_type size_type;
1719 typedef typename __alloc_traits::difference_type difference_type;
1720 typedef __bit_iterator<vector, false> pointer;
1721 typedef __bit_iterator<vector, true> const_pointer;
1722#ifdef _LIBCPP_DEBUG
1723 typedef __debug_iter<vector, pointer> iterator;
1724 typedef __debug_iter<vector, const_pointer> const_iterator;
1725
1726 friend class __debug_iter<vector, pointer>;
1727 friend class __debug_iter<vector, const_pointer>;
1728
1729 pair<iterator*, const_iterator*> __iterator_list_;
1730
1731 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1732 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
Howard Hinnant324bb032010-08-22 00:02:43 +00001733#else // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001734 typedef pointer iterator;
1735 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001736#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001737 typedef _STD::reverse_iterator<iterator> reverse_iterator;
1738 typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
1739
1740private:
1741 typedef size_type __storage_type;
1742 typedef typename __alloc_traits::template
1743#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1744 rebind_alloc<__storage_type>
1745#else
1746 rebind_alloc<__storage_type>::other
1747#endif
1748 __storage_allocator;
1749 typedef allocator_traits<__storage_allocator> __storage_traits;
1750 typedef typename __storage_traits::pointer __storage_pointer;
1751 typedef typename __storage_traits::const_pointer __const_storage_pointer;
1752
1753 __storage_pointer __begin_;
1754 size_type __size_;
1755 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
1756
1757 _LIBCPP_INLINE_VISIBILITY size_type& __cap() {return __cap_alloc_.first();}
1758 _LIBCPP_INLINE_VISIBILITY const size_type& __cap() const {return __cap_alloc_.first();}
1759 _LIBCPP_INLINE_VISIBILITY __storage_allocator& __alloc() {return __cap_alloc_.second();}
1760 _LIBCPP_INLINE_VISIBILITY const __storage_allocator& __alloc() const {return __cap_alloc_.second();}
1761
1762 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
1763
1764 _LIBCPP_INLINE_VISIBILITY static size_type __internal_cap_to_external(size_type __n)
1765 {return __n * __bits_per_word;}
1766 _LIBCPP_INLINE_VISIBILITY static size_type __external_cap_to_internal(size_type __n)
1767 {return (__n - 1) / __bits_per_word + 1;}
1768
1769public:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001770 _LIBCPP_INLINE_VISIBILITY vector();
1771 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001772 ~vector();
1773 explicit vector(size_type __n);
1774 vector(size_type __n, const value_type& __v);
1775 vector(size_type __n, const value_type& __v, const allocator_type& __a);
1776 template <class _InputIterator>
1777 vector(_InputIterator __first, _InputIterator __last,
1778 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1779 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
1780 template <class _InputIterator>
1781 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1782 typename enable_if<__is_input_iterator <_InputIterator>::value &&
1783 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
1784 template <class _ForwardIterator>
1785 vector(_ForwardIterator __first, _ForwardIterator __last,
1786 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
1787 template <class _ForwardIterator>
1788 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1789 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
1790
1791 vector(const vector& __v);
1792 vector(const vector& __v, const allocator_type& __a);
1793 vector& operator=(const vector& __v);
1794 vector(initializer_list<value_type> __il);
1795 vector(initializer_list<value_type> __il, const allocator_type& __a);
1796
Howard Hinnant73d21a42010-09-04 23:28:19 +00001797#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001798 _LIBCPP_INLINE_VISIBILITY vector(vector&& __v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799 vector(vector&& __v, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001800 _LIBCPP_INLINE_VISIBILITY vector& operator=(vector&& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001801#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001803 vector& operator=(initializer_list<value_type> __il)
1804 {assign(__il.begin(), __il.end()); return *this;}
1805
1806 template <class _InputIterator>
1807 typename enable_if
1808 <
1809 __is_input_iterator<_InputIterator>::value &&
1810 !__is_forward_iterator<_InputIterator>::value,
1811 void
1812 >::type
1813 assign(_InputIterator __first, _InputIterator __last);
1814 template <class _ForwardIterator>
1815 typename enable_if
1816 <
1817 __is_forward_iterator<_ForwardIterator>::value,
1818 void
1819 >::type
1820 assign(_ForwardIterator __first, _ForwardIterator __last);
1821
1822 void assign(size_type __n, const value_type& __x);
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001824 void assign(initializer_list<value_type> __il)
1825 {assign(__il.begin(), __il.end());}
1826
1827 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const
1828 {return allocator_type(this->__alloc());}
1829
1830 size_type max_size() const;
1831 _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return __internal_cap_to_external(__cap());}
1832 _LIBCPP_INLINE_VISIBILITY size_type size() const {return __size_;}
1833 _LIBCPP_INLINE_VISIBILITY bool empty() const {return __size_ == 0;}
1834 void reserve(size_type __n);
1835 void shrink_to_fit();
1836
1837 _LIBCPP_INLINE_VISIBILITY iterator begin() {return __make_iter(0);}
1838 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return __make_iter(0);}
1839 _LIBCPP_INLINE_VISIBILITY iterator end() {return __make_iter(__size_);}
1840 _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return __make_iter(__size_);}
1841
1842 _LIBCPP_INLINE_VISIBILITY reverse_iterator rbegin() {return reverse_iterator(end());}
1843 _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
1844 _LIBCPP_INLINE_VISIBILITY reverse_iterator rend() {return reverse_iterator(begin());}
1845 _LIBCPP_INLINE_VISIBILITY const_reverse_iterator rend() const {return const_reverse_iterator(begin());}
1846
1847 _LIBCPP_INLINE_VISIBILITY const_iterator cbegin() const {return __make_iter(0);}
1848 _LIBCPP_INLINE_VISIBILITY const_iterator cend() const {return __make_iter(__size_);}
1849 _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crbegin() const {return rbegin();}
1850 _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const {return rend();}
1851
1852 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
1853 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
1854 reference at(size_type __n);
1855 const_reference at(size_type __n) const;
1856
1857 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
1858 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
1859 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
1860 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
1861
1862 void push_back(const value_type& __x);
1863 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
1864
1865 iterator insert(const_iterator __position, const value_type& __x);
1866 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
1867 iterator insert(const_iterator __position, size_type __n, const_reference __x);
1868 template <class _InputIterator>
1869 typename enable_if
1870 <
1871 __is_input_iterator <_InputIterator>::value &&
1872 !__is_forward_iterator<_InputIterator>::value,
1873 iterator
1874 >::type
1875 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
1876 template <class _ForwardIterator>
1877 typename enable_if
1878 <
1879 __is_forward_iterator<_ForwardIterator>::value,
1880 iterator
1881 >::type
1882 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884 iterator insert(const_iterator __position, initializer_list<value_type> __il)
1885 {return insert(__position, __il.begin(), __il.end());}
1886
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001887 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001888 iterator erase(const_iterator __first, const_iterator __last);
1889
1890 _LIBCPP_INLINE_VISIBILITY void clear() {__size_ = 0;}
1891
1892 void swap(vector&);
1893
1894 void resize(size_type __sz, value_type __x = false);
1895 void flip();
1896
1897 bool __invariants() const;
1898
1899private:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001900 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001901 void allocate(size_type __n);
1902 void deallocate();
1903 _LIBCPP_INLINE_VISIBILITY static size_type __align(size_type __new_size)
1904 {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);};
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001905 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
1906 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001907 template <class _ForwardIterator>
1908 typename enable_if
1909 <
1910 __is_forward_iterator<_ForwardIterator>::value,
1911 void
1912 >::type
1913 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
1914 void __append(size_type __n, const_reference __x);
1915 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_type __pos)
1916 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
1917 _LIBCPP_INLINE_VISIBILITY const_reference __make_ref(size_type __pos) const
1918 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
1919#ifdef _LIBCPP_DEBUG
1920 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos)
1921 {return iterator(this, pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
1922 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const
1923 {return const_iterator(this, const_pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
1924 _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p)
1925 {return iterator(this, pointer(const_cast<__storage_pointer>(__p.base().__seg_), __p.base().__ctz_));}
Howard Hinnant324bb032010-08-22 00:02:43 +00001926#else // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001927 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos)
1928 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
1929 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const
1930 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
1931 _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p)
1932 {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);}
Howard Hinnant324bb032010-08-22 00:02:43 +00001933#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001934
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001936 void __copy_assign_alloc(const vector& __v)
1937 {__copy_assign_alloc(__v, integral_constant<bool,
1938 __storage_traits::propagate_on_container_copy_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940 void __copy_assign_alloc(const vector& __c, true_type)
1941 {
1942 if (__alloc() != __c.__alloc())
1943 deallocate();
1944 __alloc() = __c.__alloc();
1945 }
1946
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001947 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001948 void __copy_assign_alloc(const vector& __c, false_type)
1949 {}
1950
1951 void __move_assign(vector& __c, false_type);
1952 void __move_assign(vector& __c, true_type);
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001954 void __move_assign_alloc(vector& __c)
1955 {__move_assign_alloc(__c, integral_constant<bool,
1956 __storage_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958 void __move_assign_alloc(const vector& __c, true_type)
1959 {
1960 __alloc() = _STD::move(__c.__alloc());
1961 }
1962
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001964 void __move_assign_alloc(const vector& __c, false_type)
1965 {}
1966
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
1969 {__swap_alloc(__x, __y, integral_constant<bool,
1970 __storage_traits::propagate_on_container_swap::value>());}
1971
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001973 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
1974 {
1975 using _STD::swap;
1976 swap(__x, __y);
1977 }
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001979 static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, false_type)
1980 {}
1981
1982 size_t __hash_code() const;
1983
1984 friend class __bit_reference<vector>;
1985 friend class __bit_const_reference<vector>;
1986 friend class __bit_iterator<vector, false>;
1987 friend class __bit_iterator<vector, true>;
1988 friend class __bit_array<vector>;
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001989 friend struct _LIBCPP_VISIBLE hash<vector>;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001990};
1991
1992template <class _Allocator>
1993#ifndef _LIBCPP_DEBUG
1994_LIBCPP_INLINE_VISIBILITY inline
1995#endif
1996void
1997vector<bool, _Allocator>::__invalidate_all_iterators()
1998{
1999#ifdef _LIBCPP_DEBUG
2000 iterator::__remove_all(this);
2001 const_iterator::__remove_all(this);
Howard Hinnant324bb032010-08-22 00:02:43 +00002002#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002003}
2004
2005// Allocate space for __n objects
2006// throws length_error if __n > max_size()
2007// throws (probably bad_alloc) if memory run out
2008// Precondition: __begin_ == __end_ == __cap() == 0
2009// Precondition: __n > 0
2010// Postcondition: capacity() == __n
2011// Postcondition: size() == 0
2012template <class _Allocator>
2013void
2014vector<bool, _Allocator>::allocate(size_type __n)
2015{
2016 if (__n > max_size())
2017 this->__throw_length_error();
2018 __n = __external_cap_to_internal(__n);
2019 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2020 this->__size_ = 0;
2021 this->__cap() = __n;
2022}
2023
2024template <class _Allocator>
2025void
2026vector<bool, _Allocator>::deallocate()
2027{
2028 if (this->__begin_ != 0)
2029 {
2030 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2031 __invalidate_all_iterators();
2032 this->__begin_ = 0;
2033 this->__size_ = this->__cap() = 0;
2034 }
2035}
2036
2037template <class _Allocator>
2038typename vector<bool, _Allocator>::size_type
2039vector<bool, _Allocator>::max_size() const
2040{
2041 size_type __amax = __storage_traits::max_size(__alloc());
2042 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2043 if (__nmax / __bits_per_word <= __amax)
2044 return __nmax;
2045 return __internal_cap_to_external(__amax);
2046}
2047
2048// Precondition: __new_size > capacity()
2049template <class _Allocator>
2050_LIBCPP_INLINE_VISIBILITY inline
2051typename vector<bool, _Allocator>::size_type
2052vector<bool, _Allocator>::__recommend(size_type __new_size) const
2053{
2054 const size_type __ms = max_size();
2055 if (__new_size > __ms)
2056 this->__throw_length_error();
2057 const size_type __cap = capacity();
2058 if (__cap >= __ms / 2)
2059 return __ms;
2060 return _STD::max(2*__cap, __align(__new_size));
2061}
2062
2063// Default constructs __n objects starting at __end_
2064// Precondition: __n > 0
2065// Precondition: size() + __n <= capacity()
2066// Postcondition: size() == size() + __n
2067template <class _Allocator>
2068_LIBCPP_INLINE_VISIBILITY inline
2069void
2070vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2071{
2072 size_type __old_size = this->__size_;
2073 this->__size_ += __n;
2074 _STD::fill_n(__make_iter(__old_size), __n, __x);
2075}
2076
2077template <class _Allocator>
2078template <class _ForwardIterator>
2079typename enable_if
2080<
2081 __is_forward_iterator<_ForwardIterator>::value,
2082 void
2083>::type
2084vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2085{
2086 size_type __old_size = this->__size_;
2087 this->__size_ += _STD::distance(__first, __last);
2088 _STD::copy(__first, __last, __make_iter(__old_size));
2089}
2090
2091template <class _Allocator>
2092_LIBCPP_INLINE_VISIBILITY inline
2093vector<bool, _Allocator>::vector()
2094 : __begin_(0),
2095 __size_(0),
2096 __cap_alloc_(0)
2097{
2098}
2099
2100template <class _Allocator>
2101_LIBCPP_INLINE_VISIBILITY inline
2102vector<bool, _Allocator>::vector(const allocator_type& __a)
2103 : __begin_(0),
2104 __size_(0),
2105 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2106{
2107}
2108
2109template <class _Allocator>
2110vector<bool, _Allocator>::vector(size_type __n)
2111 : __begin_(0),
2112 __size_(0),
2113 __cap_alloc_(0)
2114{
2115 if (__n > 0)
2116 {
2117 allocate(__n);
2118 __construct_at_end(__n, false);
2119 }
2120}
2121
2122template <class _Allocator>
2123vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2124 : __begin_(0),
2125 __size_(0),
2126 __cap_alloc_(0)
2127{
2128 if (__n > 0)
2129 {
2130 allocate(__n);
2131 __construct_at_end(__n, __x);
2132 }
2133}
2134
2135template <class _Allocator>
2136vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2137 : __begin_(0),
2138 __size_(0),
2139 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2140{
2141 if (__n > 0)
2142 {
2143 allocate(__n);
2144 __construct_at_end(__n, __x);
2145 }
2146}
2147
2148template <class _Allocator>
2149template <class _InputIterator>
2150vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2151 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2152 !__is_forward_iterator<_InputIterator>::value>::type*)
2153 : __begin_(0),
2154 __size_(0),
2155 __cap_alloc_(0)
2156{
2157#ifndef _LIBCPP_NO_EXCEPTIONS
2158 try
2159 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002160#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002161 for (; __first != __last; ++__first)
2162 push_back(*__first);
2163#ifndef _LIBCPP_NO_EXCEPTIONS
2164 }
2165 catch (...)
2166 {
2167 if (__begin_ != 0)
2168 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2169 __invalidate_all_iterators();
2170 throw;
2171 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002172#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002173}
2174
2175template <class _Allocator>
2176template <class _InputIterator>
2177vector<bool, _Allocator>::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*)
2180 : __begin_(0),
2181 __size_(0),
2182 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2183{
2184#ifndef _LIBCPP_NO_EXCEPTIONS
2185 try
2186 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002187#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002188 for (; __first != __last; ++__first)
2189 push_back(*__first);
2190#ifndef _LIBCPP_NO_EXCEPTIONS
2191 }
2192 catch (...)
2193 {
2194 if (__begin_ != 0)
2195 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2196 __invalidate_all_iterators();
2197 throw;
2198 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002199#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002200}
2201
2202template <class _Allocator>
2203template <class _ForwardIterator>
2204vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2205 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2206 : __begin_(0),
2207 __size_(0),
2208 __cap_alloc_(0)
2209{
2210 size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
2211 if (__n > 0)
2212 {
2213 allocate(__n);
2214 __construct_at_end(__first, __last);
2215 }
2216}
2217
2218template <class _Allocator>
2219template <class _ForwardIterator>
2220vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2221 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2222 : __begin_(0),
2223 __size_(0),
2224 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2225{
2226 size_type __n = static_cast<size_type>(_STD::distance(__first, __last));
2227 if (__n > 0)
2228 {
2229 allocate(__n);
2230 __construct_at_end(__first, __last);
2231 }
2232}
2233
2234template <class _Allocator>
2235vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2236 : __begin_(0),
2237 __size_(0),
2238 __cap_alloc_(0)
2239{
2240 size_type __n = static_cast<size_type>(__il.size());
2241 if (__n > 0)
2242 {
2243 allocate(__n);
2244 __construct_at_end(__il.begin(), __il.end());
2245 }
2246}
2247
2248template <class _Allocator>
2249vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2250 : __begin_(0),
2251 __size_(0),
2252 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2253{
2254 size_type __n = static_cast<size_type>(__il.size());
2255 if (__n > 0)
2256 {
2257 allocate(__n);
2258 __construct_at_end(__il.begin(), __il.end());
2259 }
2260}
2261
2262template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002263vector<bool, _Allocator>::~vector()
2264{
2265 if (__begin_ != 0)
2266 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2267#ifdef _LIBCPP_DEBUG
2268 __invalidate_all_iterators();
2269#endif
2270}
2271
2272template <class _Allocator>
2273vector<bool, _Allocator>::vector(const vector& __v)
2274 : __begin_(0),
2275 __size_(0),
2276 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2277{
2278 if (__v.size() > 0)
2279 {
2280 allocate(__v.size());
2281 __construct_at_end(__v.begin(), __v.end());
2282 }
2283}
2284
2285template <class _Allocator>
2286vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2287 : __begin_(0),
2288 __size_(0),
2289 __cap_alloc_(0, __a)
2290{
2291 if (__v.size() > 0)
2292 {
2293 allocate(__v.size());
2294 __construct_at_end(__v.begin(), __v.end());
2295 }
2296}
2297
2298template <class _Allocator>
2299vector<bool, _Allocator>&
2300vector<bool, _Allocator>::operator=(const vector& __v)
2301{
2302 if (this != &__v)
2303 {
2304 __copy_assign_alloc(__v);
2305 if (__v.__size_)
2306 {
2307 if (__v.__size_ > capacity())
2308 {
2309 deallocate();
2310 allocate(__v.__size_);
2311 }
2312 _STD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2313 }
2314 __size_ = __v.__size_;
2315 }
2316 return *this;
2317}
2318
Howard Hinnant73d21a42010-09-04 23:28:19 +00002319#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2320
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002321template <class _Allocator>
2322_LIBCPP_INLINE_VISIBILITY inline
2323vector<bool, _Allocator>::vector(vector&& __v)
2324 : __begin_(__v.__begin_),
2325 __size_(__v.__size_),
2326 __cap_alloc_(__v.__cap_alloc_)
2327{
2328 __v.__begin_ = 0;
2329 __v.__size_ = 0;
2330 __v.__cap() = 0;
2331}
2332
2333template <class _Allocator>
2334vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2335 : __begin_(0),
2336 __size_(0),
2337 __cap_alloc_(0, __a)
2338{
2339 if (__a == allocator_type(__v.__alloc()))
2340 {
2341 this->__begin_ = __v.__begin_;
2342 this->__size_ = __v.__size_;
2343 this->__cap() = __v.__cap();
2344 __v.__begin_ = nullptr;
2345 __v.__cap() = __v.__size_ = 0;
2346 }
2347 else if (__v.size() > 0)
2348 {
2349 allocate(__v.size());
2350 __construct_at_end(__v.begin(), __v.end());
2351 }
2352}
2353
2354template <class _Allocator>
2355_LIBCPP_INLINE_VISIBILITY inline
2356vector<bool, _Allocator>&
2357vector<bool, _Allocator>::operator=(vector&& __v)
2358{
2359 __move_assign(__v, integral_constant<bool,
2360 __storage_traits::propagate_on_container_move_assignment::value>());
2361}
2362
2363template <class _Allocator>
2364void
2365vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2366{
2367 if (__alloc() != __c.__alloc())
2368 assign(__c.begin(), __c.end());
2369 else
2370 __move_assign(__c, true_type());
2371}
2372
2373template <class _Allocator>
2374void
2375vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2376{
2377 deallocate();
2378 this->__begin_ = __c.__begin_;
2379 this->__size_ = __c.__size_;
2380 this->__cap() = __c.__cap();
2381 __move_assign_alloc(__c);
2382 __c.__begin_ = nullptr;
2383 __c.__cap() = __c.__size_ = 0;
2384}
Howard Hinnant73d21a42010-09-04 23:28:19 +00002385
2386#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387
2388template <class _Allocator>
2389void
2390vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2391{
2392 __size_ = 0;
2393 if (__n > 0)
2394 {
2395 size_type __c = capacity();
2396 if (__n <= __c)
2397 __size_ = __n;
2398 else
2399 {
2400 vector __v(__alloc());
2401 __v.reserve(__recommend(__n));
2402 __v.__size_ = __n;
2403 swap(__v);
2404 }
2405 _STD::fill_n(begin(), __n, __x);
2406 }
2407}
2408
2409template <class _Allocator>
2410template <class _InputIterator>
2411typename enable_if
2412<
2413 __is_input_iterator<_InputIterator>::value &&
2414 !__is_forward_iterator<_InputIterator>::value,
2415 void
2416>::type
2417vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2418{
2419 clear();
2420 for (; __first != __last; ++__first)
2421 push_back(*__first);
2422}
2423
2424template <class _Allocator>
2425template <class _ForwardIterator>
2426typename enable_if
2427<
2428 __is_forward_iterator<_ForwardIterator>::value,
2429 void
2430>::type
2431vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2432{
2433 clear();
2434 difference_type __n = _STD::distance(__first, __last);
2435 if (__n)
2436 {
2437 if (__n > capacity())
2438 {
2439 deallocate();
2440 allocate(__n);
2441 }
2442 __construct_at_end(__first, __last);
2443 }
2444}
2445
2446template <class _Allocator>
2447void
2448vector<bool, _Allocator>::reserve(size_type __n)
2449{
2450 if (__n > capacity())
2451 {
2452 vector __v(this->__alloc());
2453 __v.allocate(__n);
2454 __v.__construct_at_end(this->begin(), this->end());
2455 swap(__v);
2456 __invalidate_all_iterators();
2457 }
2458}
2459
2460template <class _Allocator>
2461void
2462vector<bool, _Allocator>::shrink_to_fit()
2463{
2464 if (__external_cap_to_internal(size()) > __cap())
2465 {
2466#ifndef _LIBCPP_NO_EXCEPTIONS
2467 try
2468 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002469#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002470 vector(*this, allocator_type(__alloc())).swap(*this);
2471#ifndef _LIBCPP_NO_EXCEPTIONS
2472 }
2473 catch (...)
2474 {
2475 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002476#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002477 }
2478}
2479
2480template <class _Allocator>
2481typename vector<bool, _Allocator>::reference
2482vector<bool, _Allocator>::at(size_type __n)
2483{
2484 if (__n >= size())
2485 this->__throw_out_of_range();
2486 return (*this)[__n];
2487}
2488
2489template <class _Allocator>
2490typename vector<bool, _Allocator>::const_reference
2491vector<bool, _Allocator>::at(size_type __n) const
2492{
2493 if (__n >= size())
2494 this->__throw_out_of_range();
2495 return (*this)[__n];
2496}
2497
2498template <class _Allocator>
2499void
2500vector<bool, _Allocator>::push_back(const value_type& __x)
2501{
2502 if (this->__size_ == this->capacity())
2503 reserve(__recommend(this->__size_ + 1));
2504 ++this->__size_;
2505 back() = __x;
2506}
2507
2508template <class _Allocator>
2509typename vector<bool, _Allocator>::iterator
2510vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2511{
2512 iterator __r;
2513 if (size() < capacity())
2514 {
2515 const_iterator __old_end = end();
2516 ++__size_;
2517 _STD::copy_backward(__position, __old_end, end());
2518 __r = __const_iterator_cast(__position);
2519 }
2520 else
2521 {
2522 vector __v(__alloc());
2523 __v.reserve(__recommend(__size_ + 1));
2524 __v.__size_ = __size_ + 1;
2525 __r = _STD::copy(cbegin(), __position, __v.begin());
2526 _STD::copy_backward(__position, cend(), __v.end());
2527 swap(__v);
2528 }
2529 *__r = __x;
2530 return __r;
2531}
2532
2533template <class _Allocator>
2534typename vector<bool, _Allocator>::iterator
2535vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
2536{
2537 iterator __r;
2538 size_type __c = capacity();
2539 if (__n <= __c && size() <= __c - __n)
2540 {
2541 const_iterator __old_end = end();
2542 __size_ += __n;
2543 _STD::copy_backward(__position, __old_end, end());
2544 __r = __const_iterator_cast(__position);
2545 }
2546 else
2547 {
2548 vector __v(__alloc());
2549 __v.reserve(__recommend(__size_ + __n));
2550 __v.__size_ = __size_ + __n;
2551 __r = _STD::copy(cbegin(), __position, __v.begin());
2552 _STD::copy_backward(__position, cend(), __v.end());
2553 swap(__v);
2554 }
2555 _STD::fill_n(__r, __n, __x);
2556 return __r;
2557}
2558
2559template <class _Allocator>
2560template <class _InputIterator>
2561typename enable_if
2562<
2563 __is_input_iterator <_InputIterator>::value &&
2564 !__is_forward_iterator<_InputIterator>::value,
2565 typename vector<bool, _Allocator>::iterator
2566>::type
2567vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
2568{
2569 difference_type __off = __position - begin();
2570 iterator __p = __const_iterator_cast(__position);
2571 iterator __old_end = end();
2572 for (; size() != capacity() && __first != __last; ++__first)
2573 {
2574 ++this->__size_;
2575 back() = *__first;
2576 }
2577 vector __v(__alloc());
2578 if (__first != __last)
2579 {
2580#ifndef _LIBCPP_NO_EXCEPTIONS
2581 try
2582 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002583#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002584 __v.assign(__first, __last);
2585 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
2586 difference_type __old_p = __p - begin();
2587 reserve(__recommend(size() + __v.size()));
2588 __p = begin() + __old_p;
2589 __old_end = begin() + __old_size;
2590#ifndef _LIBCPP_NO_EXCEPTIONS
2591 }
2592 catch (...)
2593 {
2594 erase(__old_end, end());
2595 throw;
2596 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002597#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002598 }
2599 __p = _STD::rotate(__p, __old_end, end());
2600 insert(__p, __v.begin(), __v.end());
2601 return begin() + __off;
2602}
2603
2604template <class _Allocator>
2605template <class _ForwardIterator>
2606typename enable_if
2607<
2608 __is_forward_iterator<_ForwardIterator>::value,
2609 typename vector<bool, _Allocator>::iterator
2610>::type
2611vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
2612{
2613 difference_type __n = _STD::distance(__first, __last);
2614 iterator __r;
2615 size_type __c = capacity();
2616 if (__n <= __c && size() <= __c - __n)
2617 {
2618 const_iterator __old_end = end();
2619 __size_ += __n;
2620 _STD::copy_backward(__position, __old_end, end());
2621 __r = __const_iterator_cast(__position);
2622 }
2623 else
2624 {
2625 vector __v(__alloc());
2626 __v.reserve(__recommend(__size_ + __n));
2627 __v.__size_ = __size_ + __n;
2628 __r = _STD::copy(cbegin(), __position, __v.begin());
2629 _STD::copy_backward(__position, cend(), __v.end());
2630 swap(__v);
2631 }
2632 _STD::copy(__first, __last, __r);
2633 return __r;
2634}
2635
2636template <class _Allocator>
2637_LIBCPP_INLINE_VISIBILITY inline
2638typename vector<bool, _Allocator>::iterator
2639vector<bool, _Allocator>::erase(const_iterator __position)
2640{
2641 iterator __r = __const_iterator_cast(__position);
2642 _STD::copy(__position + 1, this->cend(), __r);
2643 --__size_;
2644 return __r;
2645}
2646
2647template <class _Allocator>
2648typename vector<bool, _Allocator>::iterator
2649vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
2650{
2651 iterator __r = __const_iterator_cast(__first);
2652 difference_type __d = __last - __first;
2653 _STD::copy(__last, this->cend(), __r);
2654 __size_ -= __d;
2655 return __r;
2656}
2657
2658template <class _Allocator>
2659void
2660vector<bool, _Allocator>::swap(vector& __x)
2661{
2662 _STD::swap(this->__begin_, __x.__begin_);
2663 _STD::swap(this->__size_, __x.__size_);
2664 _STD::swap(this->__cap(), __x.__cap());
2665 __swap_alloc(this->__alloc(), __x.__alloc());
2666#ifdef _LIBCPP_DEBUG
2667 iterator::swap(this, &__x);
2668 const_iterator::swap(this, &__x);
Howard Hinnant324bb032010-08-22 00:02:43 +00002669#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002670}
2671
Howard Hinnant324bb032010-08-22 00:02:43 +00002672template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002673void
2674vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
2675{
2676 size_type __cs = size();
2677 if (__cs < __sz)
2678 {
2679 iterator __r;
2680 size_type __c = capacity();
2681 size_type __n = __sz - __cs;
2682 if (__n <= __c && __cs <= __c - __n)
2683 {
2684 __r = end();
2685 __size_ += __n;
2686 }
2687 else
2688 {
2689 vector __v(__alloc());
2690 __v.reserve(__recommend(__size_ + __n));
2691 __v.__size_ = __size_ + __n;
2692 __r = _STD::copy(cbegin(), cend(), __v.begin());
2693 swap(__v);
2694 }
2695 _STD::fill_n(__r, __n, __x);
2696 }
2697 else
2698 __size_ = __sz;
2699}
2700
Howard Hinnant324bb032010-08-22 00:02:43 +00002701template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002702void
2703vector<bool, _Allocator>::flip()
2704{
2705 // do middle whole words
2706 size_type __n = __size_;
2707 __storage_pointer __p = __begin_;
2708 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
2709 *__p = ~*__p;
2710 // do last partial word
2711 if (__n > 0)
2712 {
2713 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
2714 __storage_type __b = *__p & __m;
2715 *__p &= ~__m;
2716 *__p |= ~__b & __m;
2717 }
2718}
2719
Howard Hinnant324bb032010-08-22 00:02:43 +00002720template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002721bool
2722vector<bool, _Allocator>::__invariants() const
2723{
2724 if (this->__begin_ == 0)
2725 {
2726 if (this->__size_ != 0 || this->__cap() != 0)
2727 return false;
2728 }
2729 else
2730 {
2731 if (this->__cap() == 0)
2732 return false;
2733 if (this->__size_ > this->capacity())
2734 return false;
2735 }
2736 return true;
2737}
2738
Howard Hinnant324bb032010-08-22 00:02:43 +00002739template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002740size_t
2741vector<bool, _Allocator>::__hash_code() const
2742{
2743 size_t __h = 0;
2744 // do middle whole words
2745 size_type __n = __size_;
2746 __storage_pointer __p = __begin_;
2747 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
2748 __h ^= *__p;
2749 // do last partial word
2750 if (__n > 0)
2751 {
2752 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
2753 __h ^= *__p & __m;
2754 }
2755 return __h;
2756}
2757
2758template <class _Allocator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002759struct _LIBCPP_VISIBLE hash<vector<bool, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002760 : public unary_function<vector<bool, _Allocator>, size_t>
2761{
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002763 size_t operator()(const vector<bool, _Allocator>& __vec) const
2764 {return __vec.__hash_code();}
2765};
2766
2767template <class _Tp, class _Allocator>
2768struct __is_zero_default_constructible<vector<_Tp, _Allocator> >
2769 : public integral_constant<bool, __is_zero_default_constructible<_Allocator>::value> {};
2770
2771template <class _Tp, class _Allocator>
2772_LIBCPP_INLINE_VISIBILITY inline
2773bool
2774operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
2775{
2776 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
2777 return __sz == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
2778}
2779
2780template <class _Tp, class _Allocator>
2781_LIBCPP_INLINE_VISIBILITY inline
2782bool
2783operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
2784{
2785 return !(__x == __y);
2786}
2787
2788template <class _Tp, class _Allocator>
2789_LIBCPP_INLINE_VISIBILITY inline
2790bool
2791operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
2792{
2793 return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2794}
2795
2796template <class _Tp, class _Allocator>
2797_LIBCPP_INLINE_VISIBILITY inline
2798bool
2799operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
2800{
2801 return __y < __x;
2802}
2803
2804template <class _Tp, class _Allocator>
2805_LIBCPP_INLINE_VISIBILITY inline
2806bool
2807operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
2808{
2809 return !(__x < __y);
2810}
2811
2812template <class _Tp, class _Allocator>
2813_LIBCPP_INLINE_VISIBILITY inline
2814bool
2815operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
2816{
2817 return !(__y < __x);
2818}
2819
2820template <class _Tp, class _Allocator>
2821_LIBCPP_INLINE_VISIBILITY inline
2822void
2823swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
2824{
2825 __x.swap(__y);
2826}
2827
2828_LIBCPP_END_NAMESPACE_STD
2829
2830#endif // _LIBCPP_VECTOR