blob: 5602d4a3fdc5a91db448ae21e5bd4dedaacd8899 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:161// -*- C++ -*-
2//===---------------------------- deque -----------------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:165//
Howard Hinnant412dbeb2010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_DEQUE
12#define _LIBCPP_DEQUE
13
14/*
15 deque synopsis
16
17namespace std
18{
19
20template <class T, class Allocator = allocator<T> >
21class deque
22{
23public:
24 // types:
25 typedef T value_type;
26 typedef Allocator allocator_type;
27
28 typedef typename allocator_type::reference reference;
29 typedef typename allocator_type::const_reference const_reference;
30 typedef implementation-defined iterator;
31 typedef implementation-defined const_iterator;
32 typedef typename allocator_type::size_type size_type;
33 typedef typename allocator_type::difference_type difference_type;
34
35 typedef typename allocator_type::pointer pointer;
36 typedef typename allocator_type::const_pointer const_pointer;
37 typedef std::reverse_iterator<iterator> reverse_iterator;
38 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
39
40 // construct/copy/destroy:
Howard Hinnant80129112011-06-03 15:16:4941 deque() noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:1642 explicit deque(const allocator_type& a);
43 explicit deque(size_type n);
Marshall Clowf1b6d1b2013-09-09 18:19:4544 explicit deque(size_type n, const allocator_type& a); // C++14
Howard Hinnant3e519522010-05-11 19:42:1645 deque(size_type n, const value_type& v);
46 deque(size_type n, const value_type& v, const allocator_type& a);
47 template <class InputIterator>
48 deque(InputIterator f, InputIterator l);
49 template <class InputIterator>
50 deque(InputIterator f, InputIterator l, const allocator_type& a);
51 deque(const deque& c);
Howard Hinnantb58f59c2011-06-02 21:38:5752 deque(deque&& c)
53 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:1654 deque(initializer_list<value_type> il, const Allocator& a = allocator_type());
55 deque(const deque& c, const allocator_type& a);
56 deque(deque&& c, const allocator_type& a);
57 ~deque();
58
59 deque& operator=(const deque& c);
Howard Hinnantb58f59c2011-06-02 21:38:5760 deque& operator=(deque&& c)
61 noexcept(
62 allocator_type::propagate_on_container_move_assignment::value &&
63 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:1664 deque& operator=(initializer_list<value_type> il);
65
66 template <class InputIterator>
67 void assign(InputIterator f, InputIterator l);
68 void assign(size_type n, const value_type& v);
69 void assign(initializer_list<value_type> il);
70
Howard Hinnanta87e8362011-06-02 16:10:2271 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1672
73 // iterators:
74
Howard Hinnanta87e8362011-06-02 16:10:2275 iterator begin() noexcept;
76 const_iterator begin() const noexcept;
77 iterator end() noexcept;
78 const_iterator end() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1679
Howard Hinnanta87e8362011-06-02 16:10:2280 reverse_iterator rbegin() noexcept;
81 const_reverse_iterator rbegin() const noexcept;
82 reverse_iterator rend() noexcept;
83 const_reverse_iterator rend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1684
Howard Hinnanta87e8362011-06-02 16:10:2285 const_iterator cbegin() const noexcept;
86 const_iterator cend() const noexcept;
87 const_reverse_iterator crbegin() const noexcept;
88 const_reverse_iterator crend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1689
90 // capacity:
Howard Hinnanta87e8362011-06-02 16:10:2291 size_type size() const noexcept;
92 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1693 void resize(size_type n);
94 void resize(size_type n, const value_type& v);
95 void shrink_to_fit();
Howard Hinnanta87e8362011-06-02 16:10:2296 bool empty() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1697
98 // element access:
99 reference operator[](size_type i);
100 const_reference operator[](size_type i) const;
101 reference at(size_type i);
102 const_reference at(size_type i) const;
103 reference front();
104 const_reference front() const;
105 reference back();
106 const_reference back() const;
107
108 // modifiers:
109 void push_front(const value_type& v);
110 void push_front(value_type&& v);
111 void push_back(const value_type& v);
112 void push_back(value_type&& v);
113 template <class... Args> void emplace_front(Args&&... args);
114 template <class... Args> void emplace_back(Args&&... args);
115 template <class... Args> iterator emplace(const_iterator p, Args&&... args);
116 iterator insert(const_iterator p, const value_type& v);
117 iterator insert(const_iterator p, value_type&& v);
118 iterator insert(const_iterator p, size_type n, const value_type& v);
119 template <class InputIterator>
120 iterator insert (const_iterator p, InputIterator f, InputIterator l);
121 iterator insert(const_iterator p, initializer_list<value_type> il);
122 void pop_front();
123 void pop_back();
124 iterator erase(const_iterator p);
125 iterator erase(const_iterator f, const_iterator l);
Howard Hinnantb58f59c2011-06-02 21:38:57126 void swap(deque& c)
127 noexcept(!allocator_type::propagate_on_container_swap::value ||
128 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnanta87e8362011-06-02 16:10:22129 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16130};
131
132template <class T, class Allocator>
133 bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
134template <class T, class Allocator>
135 bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
136template <class T, class Allocator>
137 bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
138template <class T, class Allocator>
139 bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
140template <class T, class Allocator>
141 bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
142template <class T, class Allocator>
143 bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
144
145// specialized algorithms:
146template <class T, class Allocator>
Howard Hinnant45900102011-06-03 17:30:28147 void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
148 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16149
150} // std
151
152*/
153
Howard Hinnant073458b2011-10-17 20:05:10154#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16155#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10156#endif
Howard Hinnant3e519522010-05-11 19:42:16157
158#include <__config>
159#include <__split_buffer>
160#include <type_traits>
161#include <initializer_list>
162#include <iterator>
163#include <algorithm>
164#include <stdexcept>
165
Howard Hinnantab4f4382011-11-29 16:45:27166#include <__undef_min_max>
167
Howard Hinnant3e519522010-05-11 19:42:16168_LIBCPP_BEGIN_NAMESPACE_STD
169
170template <class _Tp, class _Allocator> class __deque_base;
171
172template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
173 class _DiffType, _DiffType _BlockSize>
Howard Hinnantf0544c22013-08-12 18:38:34174class _LIBCPP_TYPE_VIS_ONLY __deque_iterator;
Howard Hinnant3e519522010-05-11 19:42:16175
176template <class _RAIter,
177 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
178__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
179copy(_RAIter __f,
180 _RAIter __l,
181 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
182 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
183
184template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
185 class _OutputIterator>
186_OutputIterator
187copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
188 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
189 _OutputIterator __r);
190
191template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
192 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
193__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
194copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
195 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
196 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
197
198template <class _RAIter,
199 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
200__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
201copy_backward(_RAIter __f,
202 _RAIter __l,
203 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
204 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
205
206template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
207 class _OutputIterator>
208_OutputIterator
209copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
210 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
211 _OutputIterator __r);
212
213template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
214 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
215__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
216copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
217 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
218 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
219
220template <class _RAIter,
221 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
222__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
223move(_RAIter __f,
224 _RAIter __l,
225 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
226 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
227
228template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
229 class _OutputIterator>
230_OutputIterator
231move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
232 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
233 _OutputIterator __r);
234
235template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
236 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
237__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
238move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
239 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
240 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
241
242template <class _RAIter,
243 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
244__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
245move_backward(_RAIter __f,
246 _RAIter __l,
247 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
248 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
249
250template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
251 class _OutputIterator>
252_OutputIterator
253move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
254 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
255 _OutputIterator __r);
256
257template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
258 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
259__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
260move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
261 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
262 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
263
264template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
265 class _DiffType, _DiffType _BlockSize>
Howard Hinnantf0544c22013-08-12 18:38:34266class _LIBCPP_TYPE_VIS_ONLY __deque_iterator
Howard Hinnant3e519522010-05-11 19:42:16267{
268 typedef _MapPointer __map_iterator;
269public:
270 typedef _Pointer pointer;
271 typedef _DiffType difference_type;
272private:
273 __map_iterator __m_iter_;
274 pointer __ptr_;
275
276 static const difference_type __block_size = _BlockSize;
277public:
278 typedef _ValueType value_type;
279 typedef random_access_iterator_tag iterator_category;
280 typedef _Reference reference;
281
Marshall Clow8fe0a372013-08-06 16:14:36282 _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT
283#if _LIBCPP_STD_VER > 11
284 : __m_iter_(nullptr), __ptr_(nullptr)
285#endif
286 {}
Howard Hinnant3e519522010-05-11 19:42:16287
Howard Hinnantc003db12011-11-29 18:15:50288 template <class _Pp, class _Rp, class _MP>
Howard Hinnant3e519522010-05-11 19:42:16289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:50290 __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, __block_size>& __it,
291 typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16292 : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {}
293
294 _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;}
295 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;}
296
297 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++()
298 {
299 if (++__ptr_ - *__m_iter_ == __block_size)
300 {
301 ++__m_iter_;
302 __ptr_ = *__m_iter_;
303 }
304 return *this;
305 }
306
307 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int)
308 {
309 __deque_iterator __tmp = *this;
310 ++(*this);
311 return __tmp;
312 }
313
314 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--()
315 {
316 if (__ptr_ == *__m_iter_)
317 {
318 --__m_iter_;
319 __ptr_ = *__m_iter_ + __block_size;
320 }
321 --__ptr_;
322 return *this;
323 }
324
325 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int)
326 {
327 __deque_iterator __tmp = *this;
328 --(*this);
329 return __tmp;
330 }
331
332 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n)
333 {
334 if (__n != 0)
335 {
336 __n += __ptr_ - *__m_iter_;
337 if (__n > 0)
338 {
339 __m_iter_ += __n / __block_size;
340 __ptr_ = *__m_iter_ + __n % __block_size;
341 }
342 else // (__n < 0)
343 {
344 difference_type __z = __block_size - 1 - __n;
345 __m_iter_ -= __z / __block_size;
346 __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size);
347 }
348 }
349 return *this;
350 }
Howard Hinnantb3371f62010-08-22 00:02:43351
Howard Hinnant3e519522010-05-11 19:42:16352 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n)
353 {
354 return *this += -__n;
355 }
Howard Hinnantb3371f62010-08-22 00:02:43356
Howard Hinnant3e519522010-05-11 19:42:16357 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const
358 {
359 __deque_iterator __t(*this);
360 __t += __n;
361 return __t;
362 }
Howard Hinnantb3371f62010-08-22 00:02:43363
Howard Hinnant3e519522010-05-11 19:42:16364 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const
365 {
366 __deque_iterator __t(*this);
367 __t -= __n;
368 return __t;
369 }
370
371 _LIBCPP_INLINE_VISIBILITY
372 friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it)
373 {return __it + __n;}
374
375 _LIBCPP_INLINE_VISIBILITY
376 friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y)
377 {
378 if (__x != __y)
379 return (__x.__m_iter_ - __y.__m_iter_) * __block_size
380 + (__x.__ptr_ - *__x.__m_iter_)
381 - (__y.__ptr_ - *__y.__m_iter_);
382 return 0;
383 }
384
385 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
386 {return *(*this + __n);}
387
388 _LIBCPP_INLINE_VISIBILITY friend
389 bool operator==(const __deque_iterator& __x, const __deque_iterator& __y)
390 {return __x.__ptr_ == __y.__ptr_;}
391
392 _LIBCPP_INLINE_VISIBILITY friend
393 bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y)
394 {return !(__x == __y);}
395
396 _LIBCPP_INLINE_VISIBILITY friend
397 bool operator<(const __deque_iterator& __x, const __deque_iterator& __y)
398 {return __x.__m_iter_ < __y.__m_iter_ ||
399 (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);}
400
401 _LIBCPP_INLINE_VISIBILITY friend
402 bool operator>(const __deque_iterator& __x, const __deque_iterator& __y)
403 {return __y < __x;}
404
405 _LIBCPP_INLINE_VISIBILITY friend
406 bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y)
407 {return !(__y < __x);}
408
409 _LIBCPP_INLINE_VISIBILITY friend
410 bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y)
411 {return !(__x < __y);}
412
413private:
Howard Hinnanta87e8362011-06-02 16:10:22414 _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16415 : __m_iter_(__m), __ptr_(__p) {}
416
Howard Hinnantc003db12011-11-29 18:15:50417 template <class _Tp, class _Ap> friend class __deque_base;
Howard Hinnantf0544c22013-08-12 18:38:34418 template <class _Tp, class _Ap> friend class _LIBCPP_TYPE_VIS_ONLY deque;
Howard Hinnantc003db12011-11-29 18:15:50419 template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp>
Howard Hinnantf0544c22013-08-12 18:38:34420 friend class _LIBCPP_TYPE_VIS_ONLY __deque_iterator;
Howard Hinnant3e519522010-05-11 19:42:16421
422 template <class _RAIter,
423 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
424 friend
425 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
426 copy(_RAIter __f,
427 _RAIter __l,
428 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
429 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
430
431 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
432 class _OutputIterator>
433 friend
434 _OutputIterator
435 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
436 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
437 _OutputIterator __r);
438
439 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
440 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
441 friend
442 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
443 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
444 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
445 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
446
447 template <class _RAIter,
448 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
449 friend
450 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
451 copy_backward(_RAIter __f,
452 _RAIter __l,
453 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
454 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
455
456 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
457 class _OutputIterator>
458 friend
459 _OutputIterator
460 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
461 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
462 _OutputIterator __r);
463
464 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
465 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
466 friend
467 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
468 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
469 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
470 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
471
472 template <class _RAIter,
473 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
474 friend
475 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
476 move(_RAIter __f,
477 _RAIter __l,
478 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
479 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
480
481 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
482 class _OutputIterator>
483 friend
484 _OutputIterator
485 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
486 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
487 _OutputIterator __r);
488
489 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
490 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
491 friend
492 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
493 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
494 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
495 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
496
497 template <class _RAIter,
498 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
499 friend
500 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
501 move_backward(_RAIter __f,
502 _RAIter __l,
503 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
504 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
505
506 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
507 class _OutputIterator>
508 friend
509 _OutputIterator
510 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
511 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
512 _OutputIterator __r);
513
514 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
515 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
516 friend
517 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
518 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
519 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
520 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
521};
522
523// copy
524
525template <class _RAIter,
526 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
527__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
528copy(_RAIter __f,
529 _RAIter __l,
530 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
531 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
532{
533 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
534 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
535 while (__f != __l)
536 {
537 pointer __rb = __r.__ptr_;
538 pointer __re = *__r.__m_iter_ + _B2;
539 difference_type __bs = __re - __rb;
540 difference_type __n = __l - __f;
541 _RAIter __m = __l;
542 if (__n > __bs)
543 {
544 __n = __bs;
545 __m = __f + __n;
546 }
Howard Hinnantce48a112011-06-30 21:18:19547 _VSTD::copy(__f, __m, __rb);
Howard Hinnant3e519522010-05-11 19:42:16548 __f = __m;
549 __r += __n;
550 }
551 return __r;
552}
553
554template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
555 class _OutputIterator>
556_OutputIterator
557copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
558 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
559 _OutputIterator __r)
560{
561 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
562 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
563 difference_type __n = __l - __f;
564 while (__n > 0)
565 {
566 pointer __fb = __f.__ptr_;
567 pointer __fe = *__f.__m_iter_ + _B1;
568 difference_type __bs = __fe - __fb;
569 if (__bs > __n)
570 {
571 __bs = __n;
572 __fe = __fb + __bs;
573 }
Howard Hinnantce48a112011-06-30 21:18:19574 __r = _VSTD::copy(__fb, __fe, __r);
Howard Hinnant3e519522010-05-11 19:42:16575 __n -= __bs;
576 __f += __bs;
577 }
578 return __r;
579}
580
581template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
582 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
583__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
584copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
585 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
586 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
587{
588 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
589 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
590 difference_type __n = __l - __f;
591 while (__n > 0)
592 {
593 pointer __fb = __f.__ptr_;
594 pointer __fe = *__f.__m_iter_ + _B1;
595 difference_type __bs = __fe - __fb;
596 if (__bs > __n)
597 {
598 __bs = __n;
599 __fe = __fb + __bs;
600 }
Howard Hinnantce48a112011-06-30 21:18:19601 __r = _VSTD::copy(__fb, __fe, __r);
Howard Hinnant3e519522010-05-11 19:42:16602 __n -= __bs;
603 __f += __bs;
604 }
605 return __r;
606}
607
608// copy_backward
609
610template <class _RAIter,
611 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
612__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
613copy_backward(_RAIter __f,
614 _RAIter __l,
615 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
616 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
617{
618 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
619 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
620 while (__f != __l)
621 {
Howard Hinnantce48a112011-06-30 21:18:19622 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r);
Howard Hinnant3e519522010-05-11 19:42:16623 pointer __rb = *__rp.__m_iter_;
624 pointer __re = __rp.__ptr_ + 1;
625 difference_type __bs = __re - __rb;
626 difference_type __n = __l - __f;
627 _RAIter __m = __f;
628 if (__n > __bs)
629 {
630 __n = __bs;
631 __m = __l - __n;
632 }
Howard Hinnantce48a112011-06-30 21:18:19633 _VSTD::copy_backward(__m, __l, __re);
Howard Hinnant3e519522010-05-11 19:42:16634 __l = __m;
635 __r -= __n;
636 }
637 return __r;
638}
639
640template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
641 class _OutputIterator>
642_OutputIterator
643copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
644 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
645 _OutputIterator __r)
646{
647 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
648 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
649 difference_type __n = __l - __f;
650 while (__n > 0)
651 {
652 --__l;
653 pointer __lb = *__l.__m_iter_;
654 pointer __le = __l.__ptr_ + 1;
655 difference_type __bs = __le - __lb;
656 if (__bs > __n)
657 {
658 __bs = __n;
659 __lb = __le - __bs;
660 }
Howard Hinnantce48a112011-06-30 21:18:19661 __r = _VSTD::copy_backward(__lb, __le, __r);
Howard Hinnant3e519522010-05-11 19:42:16662 __n -= __bs;
663 __l -= __bs - 1;
664 }
665 return __r;
666}
667
668template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
669 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
670__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
671copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
672 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
673 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
674{
675 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
676 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
677 difference_type __n = __l - __f;
678 while (__n > 0)
679 {
680 --__l;
681 pointer __lb = *__l.__m_iter_;
682 pointer __le = __l.__ptr_ + 1;
683 difference_type __bs = __le - __lb;
684 if (__bs > __n)
685 {
686 __bs = __n;
687 __lb = __le - __bs;
688 }
Howard Hinnantce48a112011-06-30 21:18:19689 __r = _VSTD::copy_backward(__lb, __le, __r);
Howard Hinnant3e519522010-05-11 19:42:16690 __n -= __bs;
691 __l -= __bs - 1;
692 }
693 return __r;
694}
695
696// move
697
698template <class _RAIter,
699 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
700__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
701move(_RAIter __f,
702 _RAIter __l,
703 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
704 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
705{
706 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
707 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
708 while (__f != __l)
709 {
710 pointer __rb = __r.__ptr_;
711 pointer __re = *__r.__m_iter_ + _B2;
712 difference_type __bs = __re - __rb;
713 difference_type __n = __l - __f;
714 _RAIter __m = __l;
715 if (__n > __bs)
716 {
717 __n = __bs;
718 __m = __f + __n;
719 }
Howard Hinnantce48a112011-06-30 21:18:19720 _VSTD::move(__f, __m, __rb);
Howard Hinnant3e519522010-05-11 19:42:16721 __f = __m;
722 __r += __n;
723 }
724 return __r;
725}
726
727template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
728 class _OutputIterator>
729_OutputIterator
730move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
731 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
732 _OutputIterator __r)
733{
734 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
735 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
736 difference_type __n = __l - __f;
737 while (__n > 0)
738 {
739 pointer __fb = __f.__ptr_;
740 pointer __fe = *__f.__m_iter_ + _B1;
741 difference_type __bs = __fe - __fb;
742 if (__bs > __n)
743 {
744 __bs = __n;
745 __fe = __fb + __bs;
746 }
Howard Hinnantce48a112011-06-30 21:18:19747 __r = _VSTD::move(__fb, __fe, __r);
Howard Hinnant3e519522010-05-11 19:42:16748 __n -= __bs;
749 __f += __bs;
750 }
751 return __r;
752}
753
754template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
755 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
756__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
757move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
758 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
759 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
760{
761 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
762 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
763 difference_type __n = __l - __f;
764 while (__n > 0)
765 {
766 pointer __fb = __f.__ptr_;
767 pointer __fe = *__f.__m_iter_ + _B1;
768 difference_type __bs = __fe - __fb;
769 if (__bs > __n)
770 {
771 __bs = __n;
772 __fe = __fb + __bs;
773 }
Howard Hinnantce48a112011-06-30 21:18:19774 __r = _VSTD::move(__fb, __fe, __r);
Howard Hinnant3e519522010-05-11 19:42:16775 __n -= __bs;
776 __f += __bs;
777 }
778 return __r;
779}
780
781// move_backward
782
783template <class _RAIter,
784 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
785__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
786move_backward(_RAIter __f,
787 _RAIter __l,
788 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
789 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
790{
791 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
792 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
793 while (__f != __l)
794 {
Howard Hinnantce48a112011-06-30 21:18:19795 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r);
Howard Hinnant3e519522010-05-11 19:42:16796 pointer __rb = *__rp.__m_iter_;
797 pointer __re = __rp.__ptr_ + 1;
798 difference_type __bs = __re - __rb;
799 difference_type __n = __l - __f;
800 _RAIter __m = __f;
801 if (__n > __bs)
802 {
803 __n = __bs;
804 __m = __l - __n;
805 }
Howard Hinnantce48a112011-06-30 21:18:19806 _VSTD::move_backward(__m, __l, __re);
Howard Hinnant3e519522010-05-11 19:42:16807 __l = __m;
808 __r -= __n;
809 }
810 return __r;
811}
812
813template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
814 class _OutputIterator>
815_OutputIterator
816move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
817 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
818 _OutputIterator __r)
819{
820 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
821 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
822 difference_type __n = __l - __f;
823 while (__n > 0)
824 {
825 --__l;
826 pointer __lb = *__l.__m_iter_;
827 pointer __le = __l.__ptr_ + 1;
828 difference_type __bs = __le - __lb;
829 if (__bs > __n)
830 {
831 __bs = __n;
832 __lb = __le - __bs;
833 }
Howard Hinnantce48a112011-06-30 21:18:19834 __r = _VSTD::move_backward(__lb, __le, __r);
Howard Hinnant3e519522010-05-11 19:42:16835 __n -= __bs;
836 __l -= __bs - 1;
837 }
838 return __r;
839}
840
841template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
842 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
843__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
844move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
845 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
846 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
847{
848 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
849 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
850 difference_type __n = __l - __f;
851 while (__n > 0)
852 {
853 --__l;
854 pointer __lb = *__l.__m_iter_;
855 pointer __le = __l.__ptr_ + 1;
856 difference_type __bs = __le - __lb;
857 if (__bs > __n)
858 {
859 __bs = __n;
860 __lb = __le - __bs;
861 }
Howard Hinnantce48a112011-06-30 21:18:19862 __r = _VSTD::move_backward(__lb, __le, __r);
Howard Hinnant3e519522010-05-11 19:42:16863 __n -= __bs;
864 __l -= __bs - 1;
865 }
866 return __r;
867}
868
869template <bool>
870class __deque_base_common
871{
872protected:
873 void __throw_length_error() const;
874 void __throw_out_of_range() const;
875};
876
877template <bool __b>
878void
879__deque_base_common<__b>::__throw_length_error() const
880{
881#ifndef _LIBCPP_NO_EXCEPTIONS
882 throw length_error("deque");
883#endif
884}
885
886template <bool __b>
887void
888__deque_base_common<__b>::__throw_out_of_range() const
889{
890#ifndef _LIBCPP_NO_EXCEPTIONS
891 throw out_of_range("deque");
892#endif
893}
894
895template <class _Tp, class _Allocator>
896class __deque_base
897 : protected __deque_base_common<true>
898{
899 __deque_base(const __deque_base& __c);
900 __deque_base& operator=(const __deque_base& __c);
901protected:
902 typedef _Tp value_type;
903 typedef _Allocator allocator_type;
904 typedef allocator_traits<allocator_type> __alloc_traits;
905 typedef value_type& reference;
906 typedef const value_type& const_reference;
907 typedef typename __alloc_traits::size_type size_type;
908 typedef typename __alloc_traits::difference_type difference_type;
909 typedef typename __alloc_traits::pointer pointer;
910 typedef typename __alloc_traits::const_pointer const_pointer;
911
912 static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16;
913
914 typedef typename __alloc_traits::template
915#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
916 rebind_alloc<pointer>
917#else
918 rebind_alloc<pointer>::other
919#endif
920 __pointer_allocator;
921 typedef allocator_traits<__pointer_allocator> __map_traits;
922 typedef typename __map_traits::pointer __map_pointer;
Howard Hinnant14e200d2013-06-23 21:17:24923 typedef typename __alloc_traits::template
924#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
925 rebind_alloc<const_pointer>
926#else
927 rebind_alloc<const_pointer>::other
928#endif
929 __const_pointer_allocator;
930 typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer;
Howard Hinnant3e519522010-05-11 19:42:16931 typedef __split_buffer<pointer, __pointer_allocator> __map;
932
933 typedef __deque_iterator<value_type, pointer, reference, __map_pointer,
934 difference_type, __block_size> iterator;
935 typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer,
936 difference_type, __block_size> const_iterator;
937
938 __map __map_;
939 size_type __start_;
940 __compressed_pair<size_type, allocator_type> __size_;
941
Howard Hinnanta87e8362011-06-02 16:10:22942 iterator begin() _NOEXCEPT;
943 const_iterator begin() const _NOEXCEPT;
944 iterator end() _NOEXCEPT;
945 const_iterator end() const _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16946
947 _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();}
Howard Hinnanta87e8362011-06-02 16:10:22948 _LIBCPP_INLINE_VISIBILITY
949 const size_type& size() const _NOEXCEPT {return __size_.first();}
Howard Hinnant3e519522010-05-11 19:42:16950 _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();}
Howard Hinnanta87e8362011-06-02 16:10:22951 _LIBCPP_INLINE_VISIBILITY
952 const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();}
Howard Hinnant3e519522010-05-11 19:42:16953
Howard Hinnant80129112011-06-03 15:16:49954 __deque_base()
955 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16956 explicit __deque_base(const allocator_type& __a);
Howard Hinnant9eebe112011-06-02 20:00:14957public:
Howard Hinnant3e519522010-05-11 19:42:16958 ~__deque_base();
959
Howard Hinnant7609c9b2010-09-04 23:28:19960#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16961
Howard Hinnant9eebe112011-06-02 20:00:14962 __deque_base(__deque_base&& __c)
963 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16964 __deque_base(__deque_base&& __c, const allocator_type& __a);
965
Howard Hinnant7609c9b2010-09-04 23:28:19966#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9eebe112011-06-02 20:00:14967 void swap(__deque_base& __c)
Howard Hinnant91a47502011-06-03 16:20:53968 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Howard Hinnant9eebe112011-06-02 20:00:14969 __is_nothrow_swappable<allocator_type>::value);
970protected:
Howard Hinnanta87e8362011-06-02 16:10:22971 void clear() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16972
973 bool __invariants() const;
974
Howard Hinnantfb100022010-09-21 21:28:23975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16976 void __move_assign(__deque_base& __c)
Howard Hinnantb58f59c2011-06-02 21:38:57977 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
978 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16979 {
Howard Hinnantce48a112011-06-30 21:18:19980 __map_ = _VSTD::move(__c.__map_);
Howard Hinnant3e519522010-05-11 19:42:16981 __start_ = __c.__start_;
982 size() = __c.size();
983 __move_assign_alloc(__c);
984 __c.__start_ = __c.size() = 0;
985 }
986
Howard Hinnantfb100022010-09-21 21:28:23987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16988 void __move_assign_alloc(__deque_base& __c)
Howard Hinnant9eebe112011-06-02 20:00:14989 _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value ||
990 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16991 {__move_assign_alloc(__c, integral_constant<bool,
992 __alloc_traits::propagate_on_container_move_assignment::value>());}
993
994private:
Howard Hinnantfb100022010-09-21 21:28:23995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86681392011-09-02 20:42:31996 void __move_assign_alloc(__deque_base& __c, true_type)
Howard Hinnant9eebe112011-06-02 20:00:14997 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16998 {
Howard Hinnantce48a112011-06-30 21:18:19999 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnant3e519522010-05-11 19:42:161000 }
1001
Howard Hinnantfb100022010-09-21 21:28:231002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc2063662011-12-01 20:21:041003 void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161004 {}
1005
Howard Hinnantfb100022010-09-21 21:28:231006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161007 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
Howard Hinnant9eebe112011-06-02 20:00:141008 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1009 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:161010 {__swap_alloc(__x, __y, integral_constant<bool,
1011 __alloc_traits::propagate_on_container_swap::value>());}
1012
Howard Hinnantfb100022010-09-21 21:28:231013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161014 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
Howard Hinnant9eebe112011-06-02 20:00:141015 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:161016 {
Howard Hinnantce48a112011-06-30 21:18:191017 using _VSTD::swap;
Howard Hinnant3e519522010-05-11 19:42:161018 swap(__x, __y);
1019 }
Howard Hinnantfb100022010-09-21 21:28:231020
1021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc2063662011-12-01 20:21:041022 static void __swap_alloc(allocator_type&, allocator_type&, false_type)
Howard Hinnant9eebe112011-06-02 20:00:141023 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161024 {}
1025};
1026
1027template <class _Tp, class _Allocator>
1028bool
1029__deque_base<_Tp, _Allocator>::__invariants() const
1030{
1031 if (!__map_.__invariants())
1032 return false;
1033 if (__map_.size() >= size_type(-1) / __block_size)
1034 return false;
1035 for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end();
1036 __i != __e; ++__i)
1037 if (*__i == nullptr)
1038 return false;
1039 if (__map_.size() != 0)
1040 {
1041 if (size() >= __map_.size() * __block_size)
1042 return false;
1043 if (__start_ >= __map_.size() * __block_size - size())
1044 return false;
1045 }
1046 else
1047 {
1048 if (size() != 0)
1049 return false;
1050 if (__start_ != 0)
1051 return false;
1052 }
1053 return true;
1054}
1055
1056template <class _Tp, class _Allocator>
1057typename __deque_base<_Tp, _Allocator>::iterator
Howard Hinnanta87e8362011-06-02 16:10:221058__deque_base<_Tp, _Allocator>::begin() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161059{
1060 __map_pointer __mp = __map_.begin() + __start_ / __block_size;
1061 return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
1062}
1063
1064template <class _Tp, class _Allocator>
1065typename __deque_base<_Tp, _Allocator>::const_iterator
Howard Hinnanta87e8362011-06-02 16:10:221066__deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161067{
Howard Hinnant14e200d2013-06-23 21:17:241068 __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size);
Howard Hinnant3e519522010-05-11 19:42:161069 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
1070}
1071
1072template <class _Tp, class _Allocator>
1073typename __deque_base<_Tp, _Allocator>::iterator
Howard Hinnanta87e8362011-06-02 16:10:221074__deque_base<_Tp, _Allocator>::end() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161075{
1076 size_type __p = size() + __start_;
1077 __map_pointer __mp = __map_.begin() + __p / __block_size;
1078 return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
1079}
1080
1081template <class _Tp, class _Allocator>
1082typename __deque_base<_Tp, _Allocator>::const_iterator
Howard Hinnanta87e8362011-06-02 16:10:221083__deque_base<_Tp, _Allocator>::end() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161084{
1085 size_type __p = size() + __start_;
Howard Hinnant14e200d2013-06-23 21:17:241086 __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size);
Howard Hinnant3e519522010-05-11 19:42:161087 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
1088}
1089
1090template <class _Tp, class _Allocator>
1091inline _LIBCPP_INLINE_VISIBILITY
1092__deque_base<_Tp, _Allocator>::__deque_base()
Howard Hinnant80129112011-06-03 15:16:491093 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:161094 : __start_(0), __size_(0) {}
1095
1096template <class _Tp, class _Allocator>
1097inline _LIBCPP_INLINE_VISIBILITY
1098__deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a)
1099 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {}
1100
1101template <class _Tp, class _Allocator>
1102__deque_base<_Tp, _Allocator>::~__deque_base()
1103{
1104 clear();
1105 typename __map::iterator __i = __map_.begin();
1106 typename __map::iterator __e = __map_.end();
1107 for (; __i != __e; ++__i)
1108 __alloc_traits::deallocate(__alloc(), *__i, __block_size);
1109}
1110
Howard Hinnant7609c9b2010-09-04 23:28:191111#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161112
1113template <class _Tp, class _Allocator>
1114__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c)
Howard Hinnant9eebe112011-06-02 20:00:141115 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnantce48a112011-06-30 21:18:191116 : __map_(_VSTD::move(__c.__map_)),
1117 __start_(_VSTD::move(__c.__start_)),
1118 __size_(_VSTD::move(__c.__size_))
Howard Hinnant3e519522010-05-11 19:42:161119{
1120 __c.__start_ = 0;
1121 __c.size() = 0;
1122}
1123
1124template <class _Tp, class _Allocator>
1125__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:191126 : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)),
1127 __start_(_VSTD::move(__c.__start_)),
1128 __size_(_VSTD::move(__c.size()), __a)
Howard Hinnant3e519522010-05-11 19:42:161129{
1130 if (__a == __c.__alloc())
1131 {
1132 __c.__start_ = 0;
1133 __c.size() = 0;
1134 }
1135 else
1136 {
1137 __map_.clear();
1138 __start_ = 0;
1139 size() = 0;
1140 }
1141}
1142
Howard Hinnant7609c9b2010-09-04 23:28:191143#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161144
1145template <class _Tp, class _Allocator>
1146void
1147__deque_base<_Tp, _Allocator>::swap(__deque_base& __c)
Howard Hinnant9eebe112011-06-02 20:00:141148 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
1149 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:161150{
1151 __map_.swap(__c.__map_);
Howard Hinnantce48a112011-06-30 21:18:191152 _VSTD::swap(__start_, __c.__start_);
1153 _VSTD::swap(size(), __c.size());
Howard Hinnant3e519522010-05-11 19:42:161154 __swap_alloc(__alloc(), __c.__alloc());
1155}
1156
1157template <class _Tp, class _Allocator>
1158void
Howard Hinnanta87e8362011-06-02 16:10:221159__deque_base<_Tp, _Allocator>::clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161160{
1161 allocator_type& __a = __alloc();
1162 for (iterator __i = begin(), __e = end(); __i != __e; ++__i)
Howard Hinnantce48a112011-06-30 21:18:191163 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
Howard Hinnant3e519522010-05-11 19:42:161164 size() = 0;
1165 while (__map_.size() > 2)
1166 {
1167 __alloc_traits::deallocate(__a, __map_.front(), __block_size);
1168 __map_.pop_front();
1169 }
1170 switch (__map_.size())
1171 {
1172 case 1:
1173 __start_ = __block_size / 2;
1174 break;
1175 case 2:
1176 __start_ = __block_size;
1177 break;
1178 }
1179}
1180
1181template <class _Tp, class _Allocator = allocator<_Tp> >
Howard Hinnantf0544c22013-08-12 18:38:341182class _LIBCPP_TYPE_VIS_ONLY deque
Howard Hinnant3e519522010-05-11 19:42:161183 : private __deque_base<_Tp, _Allocator>
1184{
1185public:
1186 // types:
Howard Hinnantb3371f62010-08-22 00:02:431187
Howard Hinnant3e519522010-05-11 19:42:161188 typedef _Tp value_type;
1189 typedef _Allocator allocator_type;
1190
1191 typedef __deque_base<value_type, allocator_type> __base;
1192
1193 typedef typename __base::__alloc_traits __alloc_traits;
1194 typedef typename __base::reference reference;
1195 typedef typename __base::const_reference const_reference;
1196 typedef typename __base::iterator iterator;
1197 typedef typename __base::const_iterator const_iterator;
1198 typedef typename __base::size_type size_type;
1199 typedef typename __base::difference_type difference_type;
1200
1201 typedef typename __base::pointer pointer;
1202 typedef typename __base::const_pointer const_pointer;
Howard Hinnantce48a112011-06-30 21:18:191203 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1204 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnant3e519522010-05-11 19:42:161205
1206 // construct/copy/destroy:
Howard Hinnant80129112011-06-03 15:16:491207 _LIBCPP_INLINE_VISIBILITY
1208 deque()
1209 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1210 {}
Marshall Clow78a87e82014-03-05 19:06:201211 _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {}
Howard Hinnant3e519522010-05-11 19:42:161212 explicit deque(size_type __n);
Marshall Clow630c5e52013-09-07 16:16:191213#if _LIBCPP_STD_VER > 11
1214 explicit deque(size_type __n, const _Allocator& __a);
1215#endif
Howard Hinnant3e519522010-05-11 19:42:161216 deque(size_type __n, const value_type& __v);
1217 deque(size_type __n, const value_type& __v, const allocator_type& __a);
1218 template <class _InputIter>
1219 deque(_InputIter __f, _InputIter __l,
1220 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
1221 template <class _InputIter>
1222 deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
1223 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
1224 deque(const deque& __c);
1225 deque(const deque& __c, const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:021226#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:161227 deque(initializer_list<value_type> __il);
1228 deque(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:021229#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:161230
1231 deque& operator=(const deque& __c);
Howard Hinnant54976f22011-08-12 21:56:021232#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantfb100022010-09-21 21:28:231233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161234 deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;}
Howard Hinnant54976f22011-08-12 21:56:021235#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:161236
Howard Hinnant7609c9b2010-09-04 23:28:191237#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9eebe112011-06-02 20:00:141238 deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value);
Howard Hinnant3e519522010-05-11 19:42:161239 deque(deque&& __c, const allocator_type& __a);
Howard Hinnant9eebe112011-06-02 20:00:141240 deque& operator=(deque&& __c)
Howard Hinnantb58f59c2011-06-02 21:38:571241 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1242 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant7609c9b2010-09-04 23:28:191243#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161244
1245 template <class _InputIter>
1246 void assign(_InputIter __f, _InputIter __l,
1247 typename enable_if<__is_input_iterator<_InputIter>::value &&
1248 !__is_random_access_iterator<_InputIter>::value>::type* = 0);
1249 template <class _RAIter>
1250 void assign(_RAIter __f, _RAIter __l,
1251 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
1252 void assign(size_type __n, const value_type& __v);
Howard Hinnant54976f22011-08-12 21:56:021253#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantfb100022010-09-21 21:28:231254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161255 void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:021256#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:161257
Howard Hinnanta87e8362011-06-02 16:10:221258 allocator_type get_allocator() const _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:161259
1260 // iterators:
1261
Howard Hinnantfb100022010-09-21 21:28:231262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221263 iterator begin() _NOEXCEPT {return __base::begin();}
Howard Hinnantfb100022010-09-21 21:28:231264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221265 const_iterator begin() const _NOEXCEPT {return __base::begin();}
Howard Hinnantfb100022010-09-21 21:28:231266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221267 iterator end() _NOEXCEPT {return __base::end();}
Howard Hinnantfb100022010-09-21 21:28:231268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221269 const_iterator end() const _NOEXCEPT {return __base::end();}
Howard Hinnant3e519522010-05-11 19:42:161270
Howard Hinnantfb100022010-09-21 21:28:231271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221272 reverse_iterator rbegin() _NOEXCEPT
1273 {return reverse_iterator(__base::end());}
Howard Hinnantfb100022010-09-21 21:28:231274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221275 const_reverse_iterator rbegin() const _NOEXCEPT
1276 {return const_reverse_iterator(__base::end());}
Howard Hinnantfb100022010-09-21 21:28:231277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221278 reverse_iterator rend() _NOEXCEPT
1279 {return reverse_iterator(__base::begin());}
Howard Hinnantfb100022010-09-21 21:28:231280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221281 const_reverse_iterator rend() const _NOEXCEPT
1282 {return const_reverse_iterator(__base::begin());}
Howard Hinnant3e519522010-05-11 19:42:161283
Howard Hinnantfb100022010-09-21 21:28:231284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221285 const_iterator cbegin() const _NOEXCEPT
1286 {return __base::begin();}
Howard Hinnantfb100022010-09-21 21:28:231287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221288 const_iterator cend() const _NOEXCEPT
1289 {return __base::end();}
Howard Hinnantfb100022010-09-21 21:28:231290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221291 const_reverse_iterator crbegin() const _NOEXCEPT
1292 {return const_reverse_iterator(__base::end());}
Howard Hinnantfb100022010-09-21 21:28:231293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221294 const_reverse_iterator crend() const _NOEXCEPT
1295 {return const_reverse_iterator(__base::begin());}
Howard Hinnant3e519522010-05-11 19:42:161296
1297 // capacity:
Howard Hinnantfb100022010-09-21 21:28:231298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta87e8362011-06-02 16:10:221299 size_type size() const _NOEXCEPT {return __base::size();}
1300 _LIBCPP_INLINE_VISIBILITY
1301 size_type max_size() const _NOEXCEPT
1302 {return __alloc_traits::max_size(__base::__alloc());}
Howard Hinnant3e519522010-05-11 19:42:161303 void resize(size_type __n);
1304 void resize(size_type __n, const value_type& __v);
Howard Hinnantb58f59c2011-06-02 21:38:571305 void shrink_to_fit() _NOEXCEPT;
Howard Hinnanta87e8362011-06-02 16:10:221306 _LIBCPP_INLINE_VISIBILITY
1307 bool empty() const _NOEXCEPT {return __base::size() == 0;}
Howard Hinnant3e519522010-05-11 19:42:161308
1309 // element access:
1310 reference operator[](size_type __i);
1311 const_reference operator[](size_type __i) const;
1312 reference at(size_type __i);
1313 const_reference at(size_type __i) const;
1314 reference front();
1315 const_reference front() const;
1316 reference back();
1317 const_reference back() const;
1318
1319 // 23.2.2.3 modifiers:
1320 void push_front(const value_type& __v);
1321 void push_back(const value_type& __v);
Howard Hinnant7609c9b2010-09-04 23:28:191322#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1323#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:161324 template <class... _Args> void emplace_front(_Args&&... __args);
1325 template <class... _Args> void emplace_back(_Args&&... __args);
1326 template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:191327#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:161328 void push_front(value_type&& __v);
1329 void push_back(value_type&& __v);
1330 iterator insert(const_iterator __p, value_type&& __v);
Howard Hinnant7609c9b2010-09-04 23:28:191331#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161332 iterator insert(const_iterator __p, const value_type& __v);
1333 iterator insert(const_iterator __p, size_type __n, const value_type& __v);
1334 template <class _InputIter>
1335 iterator insert (const_iterator __p, _InputIter __f, _InputIter __l,
1336 typename enable_if<__is_input_iterator<_InputIter>::value
1337 &&!__is_bidirectional_iterator<_InputIter>::value>::type* = 0);
1338 template <class _BiIter>
1339 iterator insert (const_iterator __p, _BiIter __f, _BiIter __l,
1340 typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0);
Howard Hinnant54976f22011-08-12 21:56:021341#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantfb100022010-09-21 21:28:231342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161343 iterator insert(const_iterator __p, initializer_list<value_type> __il)
1344 {return insert(__p, __il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:021345#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:161346 void pop_front();
1347 void pop_back();
1348 iterator erase(const_iterator __p);
1349 iterator erase(const_iterator __f, const_iterator __l);
1350
Howard Hinnant9eebe112011-06-02 20:00:141351 void swap(deque& __c)
1352 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1353 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnanta87e8362011-06-02 16:10:221354 void clear() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:161355
Howard Hinnantfb100022010-09-21 21:28:231356 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161357 bool __invariants() const {return __base::__invariants();}
1358private:
Howard Hinnant14e200d2013-06-23 21:17:241359 typedef typename __base::__map_const_pointer __map_const_pointer;
1360
Howard Hinnantfb100022010-09-21 21:28:231361 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161362 static size_type __recommend_blocks(size_type __n)
1363 {
1364 return __n / __base::__block_size + (__n % __base::__block_size != 0);
1365 }
Howard Hinnantfb100022010-09-21 21:28:231366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161367 size_type __capacity() const
1368 {
1369 return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1;
1370 }
Howard Hinnantfb100022010-09-21 21:28:231371 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161372 size_type __front_spare() const
1373 {
1374 return __base::__start_;
1375 }
Howard Hinnantfb100022010-09-21 21:28:231376 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161377 size_type __back_spare() const
1378 {
1379 return __capacity() - (__base::__start_ + __base::size());
1380 }
1381
1382 template <class _InpIter>
1383 void __append(_InpIter __f, _InpIter __l,
1384 typename enable_if<__is_input_iterator<_InpIter>::value &&
1385 !__is_forward_iterator<_InpIter>::value>::type* = 0);
1386 template <class _ForIter>
1387 void __append(_ForIter __f, _ForIter __l,
1388 typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0);
1389 void __append(size_type __n);
1390 void __append(size_type __n, const value_type& __v);
1391 void __erase_to_end(const_iterator __f);
1392 void __add_front_capacity();
1393 void __add_front_capacity(size_type __n);
1394 void __add_back_capacity();
1395 void __add_back_capacity(size_type __n);
1396 iterator __move_and_check(iterator __f, iterator __l, iterator __r,
1397 const_pointer& __vt);
1398 iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r,
1399 const_pointer& __vt);
1400 void __move_construct_and_check(iterator __f, iterator __l,
1401 iterator __r, const_pointer& __vt);
1402 void __move_construct_backward_and_check(iterator __f, iterator __l,
1403 iterator __r, const_pointer& __vt);
1404
Howard Hinnantfb100022010-09-21 21:28:231405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161406 void __copy_assign_alloc(const deque& __c)
1407 {__copy_assign_alloc(__c, integral_constant<bool,
1408 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1409
Howard Hinnantfb100022010-09-21 21:28:231410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161411 void __copy_assign_alloc(const deque& __c, true_type)
1412 {
1413 if (__base::__alloc() != __c.__alloc())
1414 {
1415 clear();
1416 shrink_to_fit();
1417 }
1418 __base::__alloc() = __c.__alloc();
1419 __base::__map_.__alloc() = __c.__map_.__alloc();
1420 }
1421
Howard Hinnantfb100022010-09-21 21:28:231422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc2063662011-12-01 20:21:041423 void __copy_assign_alloc(const deque&, false_type)
Howard Hinnant3e519522010-05-11 19:42:161424 {}
1425
Howard Hinnantb58f59c2011-06-02 21:38:571426 void __move_assign(deque& __c, true_type)
1427 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:161428 void __move_assign(deque& __c, false_type);
1429};
1430
1431template <class _Tp, class _Allocator>
1432deque<_Tp, _Allocator>::deque(size_type __n)
1433{
1434 if (__n > 0)
1435 __append(__n);
1436}
1437
Marshall Clow630c5e52013-09-07 16:16:191438#if _LIBCPP_STD_VER > 11
1439template <class _Tp, class _Allocator>
1440deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a)
1441 : __base(__a)
1442{
1443 if (__n > 0)
1444 __append(__n);
1445}
1446#endif
1447
Howard Hinnant3e519522010-05-11 19:42:161448template <class _Tp, class _Allocator>
1449deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v)
1450{
1451 if (__n > 0)
1452 __append(__n, __v);
1453}
1454
1455template <class _Tp, class _Allocator>
1456deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a)
1457 : __base(__a)
1458{
1459 if (__n > 0)
1460 __append(__n, __v);
1461}
1462
1463template <class _Tp, class _Allocator>
1464template <class _InputIter>
1465deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l,
1466 typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
1467{
1468 __append(__f, __l);
1469}
1470
1471template <class _Tp, class _Allocator>
1472template <class _InputIter>
1473deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
1474 typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
1475 : __base(__a)
1476{
1477 __append(__f, __l);
1478}
1479
1480template <class _Tp, class _Allocator>
1481deque<_Tp, _Allocator>::deque(const deque& __c)
1482 : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc()))
1483{
1484 __append(__c.begin(), __c.end());
1485}
1486
1487template <class _Tp, class _Allocator>
1488deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a)
1489 : __base(__a)
1490{
1491 __append(__c.begin(), __c.end());
1492}
1493
Howard Hinnant54976f22011-08-12 21:56:021494#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1495
Howard Hinnant3e519522010-05-11 19:42:161496template <class _Tp, class _Allocator>
1497deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il)
1498{
1499 __append(__il.begin(), __il.end());
1500}
1501
1502template <class _Tp, class _Allocator>
1503deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a)
1504 : __base(__a)
1505{
1506 __append(__il.begin(), __il.end());
1507}
1508
Howard Hinnant54976f22011-08-12 21:56:021509#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1510
Howard Hinnant3e519522010-05-11 19:42:161511template <class _Tp, class _Allocator>
1512deque<_Tp, _Allocator>&
1513deque<_Tp, _Allocator>::operator=(const deque& __c)
1514{
1515 if (this != &__c)
1516 {
1517 __copy_assign_alloc(__c);
1518 assign(__c.begin(), __c.end());
1519 }
1520 return *this;
1521}
1522
Howard Hinnant7609c9b2010-09-04 23:28:191523#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161524
1525template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231526inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161527deque<_Tp, _Allocator>::deque(deque&& __c)
Howard Hinnant9eebe112011-06-02 20:00:141528 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantce48a112011-06-30 21:18:191529 : __base(_VSTD::move(__c))
Howard Hinnant3e519522010-05-11 19:42:161530{
1531}
1532
1533template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231534inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161535deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:191536 : __base(_VSTD::move(__c), __a)
Howard Hinnant3e519522010-05-11 19:42:161537{
1538 if (__a != __c.__alloc())
1539 {
Howard Hinnantc003db12011-11-29 18:15:501540 typedef move_iterator<iterator> _Ip;
1541 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnant3e519522010-05-11 19:42:161542 }
1543}
1544
1545template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231546inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161547deque<_Tp, _Allocator>&
1548deque<_Tp, _Allocator>::operator=(deque&& __c)
Howard Hinnantb58f59c2011-06-02 21:38:571549 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1550 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:161551{
1552 __move_assign(__c, integral_constant<bool,
1553 __alloc_traits::propagate_on_container_move_assignment::value>());
1554 return *this;
1555}
1556
1557template <class _Tp, class _Allocator>
1558void
1559deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type)
1560{
1561 if (__base::__alloc() != __c.__alloc())
1562 {
Howard Hinnantc003db12011-11-29 18:15:501563 typedef move_iterator<iterator> _Ip;
1564 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnant3e519522010-05-11 19:42:161565 }
1566 else
1567 __move_assign(__c, true_type());
1568}
1569
1570template <class _Tp, class _Allocator>
1571void
1572deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type)
Howard Hinnantb58f59c2011-06-02 21:38:571573 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:161574{
1575 clear();
1576 shrink_to_fit();
1577 __base::__move_assign(__c);
1578}
1579
Howard Hinnant7609c9b2010-09-04 23:28:191580#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161581
1582template <class _Tp, class _Allocator>
1583template <class _InputIter>
1584void
1585deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l,
1586 typename enable_if<__is_input_iterator<_InputIter>::value &&
1587 !__is_random_access_iterator<_InputIter>::value>::type*)
1588{
1589 iterator __i = __base::begin();
1590 iterator __e = __base::end();
Eric Fiselier910285b2014-10-27 19:28:201591 for (; __f != __l && __i != __e; ++__f, (void) ++__i)
Howard Hinnant3e519522010-05-11 19:42:161592 *__i = *__f;
1593 if (__f != __l)
1594 __append(__f, __l);
1595 else
1596 __erase_to_end(__i);
1597}
1598
1599template <class _Tp, class _Allocator>
1600template <class _RAIter>
1601void
1602deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l,
1603 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
1604{
1605 if (static_cast<size_type>(__l - __f) > __base::size())
1606 {
1607 _RAIter __m = __f + __base::size();
Howard Hinnantce48a112011-06-30 21:18:191608 _VSTD::copy(__f, __m, __base::begin());
Howard Hinnant3e519522010-05-11 19:42:161609 __append(__m, __l);
1610 }
1611 else
Howard Hinnantce48a112011-06-30 21:18:191612 __erase_to_end(_VSTD::copy(__f, __l, __base::begin()));
Howard Hinnant3e519522010-05-11 19:42:161613}
1614
1615template <class _Tp, class _Allocator>
1616void
1617deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v)
1618{
1619 if (__n > __base::size())
1620 {
Howard Hinnantce48a112011-06-30 21:18:191621 _VSTD::fill_n(__base::begin(), __base::size(), __v);
Howard Hinnant3e519522010-05-11 19:42:161622 __n -= __base::size();
1623 __append(__n, __v);
1624 }
1625 else
Howard Hinnantce48a112011-06-30 21:18:191626 __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v));
Howard Hinnant3e519522010-05-11 19:42:161627}
1628
1629template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161631_Allocator
Howard Hinnanta87e8362011-06-02 16:10:221632deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161633{
1634 return __base::__alloc();
1635}
1636
1637template <class _Tp, class _Allocator>
1638void
1639deque<_Tp, _Allocator>::resize(size_type __n)
1640{
1641 if (__n > __base::size())
1642 __append(__n - __base::size());
1643 else if (__n < __base::size())
1644 __erase_to_end(__base::begin() + __n);
1645}
1646
1647template <class _Tp, class _Allocator>
1648void
1649deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v)
1650{
1651 if (__n > __base::size())
1652 __append(__n - __base::size(), __v);
1653 else if (__n < __base::size())
1654 __erase_to_end(__base::begin() + __n);
1655}
1656
1657template <class _Tp, class _Allocator>
1658void
Howard Hinnantb58f59c2011-06-02 21:38:571659deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161660{
1661 allocator_type& __a = __base::__alloc();
1662 if (empty())
1663 {
1664 while (__base::__map_.size() > 0)
1665 {
1666 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
1667 __base::__map_.pop_back();
1668 }
1669 __base::__start_ = 0;
1670 }
1671 else
1672 {
1673 if (__front_spare() >= __base::__block_size)
1674 {
1675 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
1676 __base::__map_.pop_front();
1677 __base::__start_ -= __base::__block_size;
1678 }
1679 if (__back_spare() >= __base::__block_size)
1680 {
1681 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
1682 __base::__map_.pop_back();
1683 }
1684 }
1685 __base::__map_.shrink_to_fit();
1686}
1687
1688template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231689inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161690typename deque<_Tp, _Allocator>::reference
1691deque<_Tp, _Allocator>::operator[](size_type __i)
1692{
1693 size_type __p = __base::__start_ + __i;
1694 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1695}
1696
1697template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231698inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161699typename deque<_Tp, _Allocator>::const_reference
1700deque<_Tp, _Allocator>::operator[](size_type __i) const
1701{
1702 size_type __p = __base::__start_ + __i;
1703 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1704}
1705
1706template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231707inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161708typename deque<_Tp, _Allocator>::reference
1709deque<_Tp, _Allocator>::at(size_type __i)
1710{
1711 if (__i >= __base::size())
1712 __base::__throw_out_of_range();
1713 size_type __p = __base::__start_ + __i;
1714 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1715}
1716
1717template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231718inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161719typename deque<_Tp, _Allocator>::const_reference
1720deque<_Tp, _Allocator>::at(size_type __i) const
1721{
1722 if (__i >= __base::size())
1723 __base::__throw_out_of_range();
1724 size_type __p = __base::__start_ + __i;
1725 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1726}
1727
1728template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231729inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161730typename deque<_Tp, _Allocator>::reference
1731deque<_Tp, _Allocator>::front()
1732{
1733 return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
1734 + __base::__start_ % __base::__block_size);
1735}
1736
1737template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231738inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161739typename deque<_Tp, _Allocator>::const_reference
1740deque<_Tp, _Allocator>::front() const
1741{
1742 return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
1743 + __base::__start_ % __base::__block_size);
1744}
1745
1746template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231747inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161748typename deque<_Tp, _Allocator>::reference
1749deque<_Tp, _Allocator>::back()
1750{
1751 size_type __p = __base::size() + __base::__start_ - 1;
1752 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1753}
1754
1755template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:231756inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161757typename deque<_Tp, _Allocator>::const_reference
1758deque<_Tp, _Allocator>::back() const
1759{
1760 size_type __p = __base::size() + __base::__start_ - 1;
1761 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1762}
1763
1764template <class _Tp, class _Allocator>
1765void
1766deque<_Tp, _Allocator>::push_back(const value_type& __v)
1767{
1768 allocator_type& __a = __base::__alloc();
1769 if (__back_spare() == 0)
1770 __add_back_capacity();
1771 // __back_spare() >= 1
Howard Hinnantce48a112011-06-30 21:18:191772 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v);
Howard Hinnant3e519522010-05-11 19:42:161773 ++__base::size();
1774}
1775
Howard Hinnant7609c9b2010-09-04 23:28:191776#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161777
1778template <class _Tp, class _Allocator>
1779void
1780deque<_Tp, _Allocator>::push_back(value_type&& __v)
1781{
1782 allocator_type& __a = __base::__alloc();
1783 if (__back_spare() == 0)
1784 __add_back_capacity();
1785 // __back_spare() >= 1
Howard Hinnantce48a112011-06-30 21:18:191786 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:161787 ++__base::size();
1788}
1789
Howard Hinnant7609c9b2010-09-04 23:28:191790#ifndef _LIBCPP_HAS_NO_VARIADICS
1791
Howard Hinnant3e519522010-05-11 19:42:161792template <class _Tp, class _Allocator>
1793template <class... _Args>
1794void
1795deque<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1796{
1797 allocator_type& __a = __base::__alloc();
1798 if (__back_spare() == 0)
1799 __add_back_capacity();
1800 // __back_spare() >= 1
Howard Hinnantce48a112011-06-30 21:18:191801 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:161802 ++__base::size();
1803}
1804
Howard Hinnant7609c9b2010-09-04 23:28:191805#endif // _LIBCPP_HAS_NO_VARIADICS
1806#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161807
1808template <class _Tp, class _Allocator>
1809void
1810deque<_Tp, _Allocator>::push_front(const value_type& __v)
1811{
1812 allocator_type& __a = __base::__alloc();
1813 if (__front_spare() == 0)
1814 __add_front_capacity();
1815 // __front_spare() >= 1
Howard Hinnantce48a112011-06-30 21:18:191816 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v);
Howard Hinnant3e519522010-05-11 19:42:161817 --__base::__start_;
1818 ++__base::size();
1819}
1820
Howard Hinnant7609c9b2010-09-04 23:28:191821#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161822
1823template <class _Tp, class _Allocator>
1824void
1825deque<_Tp, _Allocator>::push_front(value_type&& __v)
1826{
1827 allocator_type& __a = __base::__alloc();
1828 if (__front_spare() == 0)
1829 __add_front_capacity();
1830 // __front_spare() >= 1
Howard Hinnantce48a112011-06-30 21:18:191831 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:161832 --__base::__start_;
1833 ++__base::size();
1834}
1835
Howard Hinnant7609c9b2010-09-04 23:28:191836#ifndef _LIBCPP_HAS_NO_VARIADICS
1837
Howard Hinnant3e519522010-05-11 19:42:161838template <class _Tp, class _Allocator>
1839template <class... _Args>
1840void
1841deque<_Tp, _Allocator>::emplace_front(_Args&&... __args)
1842{
1843 allocator_type& __a = __base::__alloc();
1844 if (__front_spare() == 0)
1845 __add_front_capacity();
1846 // __front_spare() >= 1
Howard Hinnantce48a112011-06-30 21:18:191847 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:161848 --__base::__start_;
1849 ++__base::size();
1850}
1851
Howard Hinnant7609c9b2010-09-04 23:28:191852#endif // _LIBCPP_HAS_NO_VARIADICS
1853#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161854
1855template <class _Tp, class _Allocator>
1856typename deque<_Tp, _Allocator>::iterator
1857deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v)
1858{
1859 size_type __pos = __p - __base::begin();
1860 size_type __to_end = __base::size() - __pos;
1861 allocator_type& __a = __base::__alloc();
1862 if (__pos < __to_end)
1863 { // insert by shifting things backward
1864 if (__front_spare() == 0)
1865 __add_front_capacity();
1866 // __front_spare() >= 1
1867 if (__pos == 0)
1868 {
Howard Hinnantce48a112011-06-30 21:18:191869 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v);
Howard Hinnant3e519522010-05-11 19:42:161870 --__base::__start_;
1871 ++__base::size();
1872 }
1873 else
1874 {
1875 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
1876 iterator __b = __base::begin();
Howard Hinnantce48a112011-06-30 21:18:191877 iterator __bm1 = _VSTD::prev(__b);
Howard Hinnant3e519522010-05-11 19:42:161878 if (__vt == pointer_traits<const_pointer>::pointer_to(*__b))
1879 __vt = pointer_traits<const_pointer>::pointer_to(*__bm1);
Howard Hinnantce48a112011-06-30 21:18:191880 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
Howard Hinnant3e519522010-05-11 19:42:161881 --__base::__start_;
1882 ++__base::size();
1883 if (__pos > 1)
Howard Hinnantce48a112011-06-30 21:18:191884 __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt);
Howard Hinnant3e519522010-05-11 19:42:161885 *__b = *__vt;
1886 }
1887 }
1888 else
1889 { // insert by shifting things forward
1890 if (__back_spare() == 0)
1891 __add_back_capacity();
1892 // __back_capacity >= 1
1893 size_type __de = __base::size() - __pos;
1894 if (__de == 0)
1895 {
Howard Hinnantce48a112011-06-30 21:18:191896 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v);
Howard Hinnant3e519522010-05-11 19:42:161897 ++__base::size();
1898 }
1899 else
1900 {
1901 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
1902 iterator __e = __base::end();
Howard Hinnantce48a112011-06-30 21:18:191903 iterator __em1 = _VSTD::prev(__e);
Howard Hinnant3e519522010-05-11 19:42:161904 if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1))
1905 __vt = pointer_traits<const_pointer>::pointer_to(*__e);
Howard Hinnantce48a112011-06-30 21:18:191906 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
Howard Hinnant3e519522010-05-11 19:42:161907 ++__base::size();
1908 if (__de > 1)
1909 __e = __move_backward_and_check(__e - __de, __em1, __e, __vt);
1910 *--__e = *__vt;
1911 }
1912 }
1913 return __base::begin() + __pos;
1914}
1915
Howard Hinnant7609c9b2010-09-04 23:28:191916#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161917
1918template <class _Tp, class _Allocator>
1919typename deque<_Tp, _Allocator>::iterator
1920deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v)
1921{
1922 size_type __pos = __p - __base::begin();
1923 size_type __to_end = __base::size() - __pos;
1924 allocator_type& __a = __base::__alloc();
1925 if (__pos < __to_end)
1926 { // insert by shifting things backward
1927 if (__front_spare() == 0)
1928 __add_front_capacity();
1929 // __front_spare() >= 1
1930 if (__pos == 0)
1931 {
Howard Hinnantce48a112011-06-30 21:18:191932 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:161933 --__base::__start_;
1934 ++__base::size();
1935 }
1936 else
1937 {
1938 iterator __b = __base::begin();
Howard Hinnantce48a112011-06-30 21:18:191939 iterator __bm1 = _VSTD::prev(__b);
1940 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
Howard Hinnant3e519522010-05-11 19:42:161941 --__base::__start_;
1942 ++__base::size();
1943 if (__pos > 1)
Howard Hinnantce48a112011-06-30 21:18:191944 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
1945 *__b = _VSTD::move(__v);
Howard Hinnant3e519522010-05-11 19:42:161946 }
1947 }
1948 else
1949 { // insert by shifting things forward
1950 if (__back_spare() == 0)
1951 __add_back_capacity();
1952 // __back_capacity >= 1
1953 size_type __de = __base::size() - __pos;
1954 if (__de == 0)
1955 {
Howard Hinnantce48a112011-06-30 21:18:191956 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:161957 ++__base::size();
1958 }
1959 else
1960 {
1961 iterator __e = __base::end();
Howard Hinnantce48a112011-06-30 21:18:191962 iterator __em1 = _VSTD::prev(__e);
1963 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
Howard Hinnant3e519522010-05-11 19:42:161964 ++__base::size();
1965 if (__de > 1)
Howard Hinnantce48a112011-06-30 21:18:191966 __e = _VSTD::move_backward(__e - __de, __em1, __e);
1967 *--__e = _VSTD::move(__v);
Howard Hinnant3e519522010-05-11 19:42:161968 }
1969 }
1970 return __base::begin() + __pos;
1971}
1972
Howard Hinnant7609c9b2010-09-04 23:28:191973#ifndef _LIBCPP_HAS_NO_VARIADICS
1974
Howard Hinnant3e519522010-05-11 19:42:161975template <class _Tp, class _Allocator>
1976template <class... _Args>
1977typename deque<_Tp, _Allocator>::iterator
1978deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args)
1979{
1980 size_type __pos = __p - __base::begin();
1981 size_type __to_end = __base::size() - __pos;
1982 allocator_type& __a = __base::__alloc();
1983 if (__pos < __to_end)
1984 { // insert by shifting things backward
1985 if (__front_spare() == 0)
1986 __add_front_capacity();
1987 // __front_spare() >= 1
1988 if (__pos == 0)
1989 {
Howard Hinnantce48a112011-06-30 21:18:191990 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:161991 --__base::__start_;
1992 ++__base::size();
1993 }
1994 else
1995 {
Howard Hinnant598f702b2012-07-08 23:23:041996 value_type __tmp(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:161997 iterator __b = __base::begin();
Howard Hinnantce48a112011-06-30 21:18:191998 iterator __bm1 = _VSTD::prev(__b);
1999 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
Howard Hinnant3e519522010-05-11 19:42:162000 --__base::__start_;
2001 ++__base::size();
2002 if (__pos > 1)
Howard Hinnantce48a112011-06-30 21:18:192003 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
Howard Hinnant598f702b2012-07-08 23:23:042004 *__b = _VSTD::move(__tmp);
Howard Hinnant3e519522010-05-11 19:42:162005 }
2006 }
2007 else
2008 { // insert by shifting things forward
2009 if (__back_spare() == 0)
2010 __add_back_capacity();
2011 // __back_capacity >= 1
2012 size_type __de = __base::size() - __pos;
2013 if (__de == 0)
2014 {
Howard Hinnantce48a112011-06-30 21:18:192015 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:162016 ++__base::size();
2017 }
2018 else
2019 {
Howard Hinnant598f702b2012-07-08 23:23:042020 value_type __tmp(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:162021 iterator __e = __base::end();
Howard Hinnantce48a112011-06-30 21:18:192022 iterator __em1 = _VSTD::prev(__e);
2023 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
Howard Hinnant3e519522010-05-11 19:42:162024 ++__base::size();
2025 if (__de > 1)
Howard Hinnantce48a112011-06-30 21:18:192026 __e = _VSTD::move_backward(__e - __de, __em1, __e);
Howard Hinnant598f702b2012-07-08 23:23:042027 *--__e = _VSTD::move(__tmp);
Howard Hinnant3e519522010-05-11 19:42:162028 }
2029 }
2030 return __base::begin() + __pos;
2031}
2032
Howard Hinnant7609c9b2010-09-04 23:28:192033#endif // _LIBCPP_HAS_NO_VARIADICS
2034#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162035
2036template <class _Tp, class _Allocator>
2037typename deque<_Tp, _Allocator>::iterator
2038deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v)
2039{
2040 size_type __pos = __p - __base::begin();
2041 size_type __to_end = __base::size() - __pos;
2042 allocator_type& __a = __base::__alloc();
2043 if (__pos < __to_end)
2044 { // insert by shifting things backward
2045 if (__n > __front_spare())
2046 __add_front_capacity(__n - __front_spare());
2047 // __n <= __front_spare()
2048 size_type __old_n = __n;
2049 iterator __old_begin = __base::begin();
2050 iterator __i = __old_begin;
2051 if (__n > __pos)
2052 {
2053 for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size())
Howard Hinnantce48a112011-06-30 21:18:192054 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v);
Howard Hinnant3e519522010-05-11 19:42:162055 __n = __pos;
2056 }
2057 if (__n > 0)
2058 {
2059 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
2060 iterator __obn = __old_begin + __n;
2061 __move_construct_backward_and_check(__old_begin, __obn, __i, __vt);
2062 if (__n < __pos)
2063 __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt);
Howard Hinnantce48a112011-06-30 21:18:192064 _VSTD::fill_n(__old_begin, __n, *__vt);
Howard Hinnant3e519522010-05-11 19:42:162065 }
2066 }
2067 else
2068 { // insert by shifting things forward
2069 size_type __back_capacity = __back_spare();
2070 if (__n > __back_capacity)
2071 __add_back_capacity(__n - __back_capacity);
2072 // __n <= __back_capacity
2073 size_type __old_n = __n;
2074 iterator __old_end = __base::end();
2075 iterator __i = __old_end;
2076 size_type __de = __base::size() - __pos;
2077 if (__n > __de)
2078 {
2079 for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size())
Howard Hinnantce48a112011-06-30 21:18:192080 __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v);
Howard Hinnant3e519522010-05-11 19:42:162081 __n = __de;
2082 }
2083 if (__n > 0)
2084 {
2085 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
2086 iterator __oen = __old_end - __n;
2087 __move_construct_and_check(__oen, __old_end, __i, __vt);
2088 if (__n < __de)
2089 __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt);
Howard Hinnantce48a112011-06-30 21:18:192090 _VSTD::fill_n(__old_end - __n, __n, *__vt);
Howard Hinnant3e519522010-05-11 19:42:162091 }
2092 }
2093 return __base::begin() + __pos;
2094}
2095
2096template <class _Tp, class _Allocator>
2097template <class _InputIter>
2098typename deque<_Tp, _Allocator>::iterator
2099deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l,
2100 typename enable_if<__is_input_iterator<_InputIter>::value
2101 &&!__is_bidirectional_iterator<_InputIter>::value>::type*)
2102{
2103 __split_buffer<value_type, allocator_type&> __buf(__base::__alloc());
2104 __buf.__construct_at_end(__f, __l);
2105 typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi;
2106 return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end()));
2107}
2108
2109template <class _Tp, class _Allocator>
2110template <class _BiIter>
2111typename deque<_Tp, _Allocator>::iterator
2112deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l,
2113 typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*)
2114{
Howard Hinnantce48a112011-06-30 21:18:192115 size_type __n = _VSTD::distance(__f, __l);
Howard Hinnant3e519522010-05-11 19:42:162116 size_type __pos = __p - __base::begin();
2117 size_type __to_end = __base::size() - __pos;
2118 allocator_type& __a = __base::__alloc();
2119 if (__pos < __to_end)
2120 { // insert by shifting things backward
2121 if (__n > __front_spare())
2122 __add_front_capacity(__n - __front_spare());
2123 // __n <= __front_spare()
2124 size_type __old_n = __n;
2125 iterator __old_begin = __base::begin();
2126 iterator __i = __old_begin;
2127 _BiIter __m = __f;
2128 if (__n > __pos)
2129 {
Howard Hinnantce48a112011-06-30 21:18:192130 __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos);
Howard Hinnant3e519522010-05-11 19:42:162131 for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size())
Howard Hinnantce48a112011-06-30 21:18:192132 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j);
Howard Hinnant3e519522010-05-11 19:42:162133 __n = __pos;
2134 }
2135 if (__n > 0)
2136 {
2137 iterator __obn = __old_begin + __n;
2138 for (iterator __j = __obn; __j != __old_begin;)
2139 {
Howard Hinnantce48a112011-06-30 21:18:192140 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j));
Howard Hinnant3e519522010-05-11 19:42:162141 --__base::__start_;
2142 ++__base::size();
2143 }
2144 if (__n < __pos)
Howard Hinnantce48a112011-06-30 21:18:192145 __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin);
2146 _VSTD::copy(__m, __l, __old_begin);
Howard Hinnant3e519522010-05-11 19:42:162147 }
2148 }
2149 else
2150 { // insert by shifting things forward
2151 size_type __back_capacity = __back_spare();
2152 if (__n > __back_capacity)
2153 __add_back_capacity(__n - __back_capacity);
2154 // __n <= __back_capacity
2155 size_type __old_n = __n;
2156 iterator __old_end = __base::end();
2157 iterator __i = __old_end;
2158 _BiIter __m = __l;
2159 size_type __de = __base::size() - __pos;
2160 if (__n > __de)
2161 {
Howard Hinnantce48a112011-06-30 21:18:192162 __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de);
Eric Fiselier910285b2014-10-27 19:28:202163 for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size())
Howard Hinnantce48a112011-06-30 21:18:192164 __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j);
Howard Hinnant3e519522010-05-11 19:42:162165 __n = __de;
2166 }
2167 if (__n > 0)
2168 {
2169 iterator __oen = __old_end - __n;
2170 for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size())
Howard Hinnantce48a112011-06-30 21:18:192171 __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j));
Howard Hinnant3e519522010-05-11 19:42:162172 if (__n < __de)
Howard Hinnantce48a112011-06-30 21:18:192173 __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end);
2174 _VSTD::copy_backward(__f, __m, __old_end);
Howard Hinnant3e519522010-05-11 19:42:162175 }
2176 }
2177 return __base::begin() + __pos;
2178}
2179
2180template <class _Tp, class _Allocator>
2181template <class _InpIter>
2182void
2183deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l,
2184 typename enable_if<__is_input_iterator<_InpIter>::value &&
2185 !__is_forward_iterator<_InpIter>::value>::type*)
2186{
2187 for (; __f != __l; ++__f)
2188 push_back(*__f);
2189}
2190
2191template <class _Tp, class _Allocator>
2192template <class _ForIter>
2193void
2194deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l,
2195 typename enable_if<__is_forward_iterator<_ForIter>::value>::type*)
2196{
Howard Hinnantce48a112011-06-30 21:18:192197 size_type __n = _VSTD::distance(__f, __l);
Howard Hinnant3e519522010-05-11 19:42:162198 allocator_type& __a = __base::__alloc();
2199 size_type __back_capacity = __back_spare();
2200 if (__n > __back_capacity)
2201 __add_back_capacity(__n - __back_capacity);
2202 // __n <= __back_capacity
Eric Fiselier910285b2014-10-27 19:28:202203 for (iterator __i = __base::end(); __f != __l; ++__i, (void) ++__f, ++__base::size())
Howard Hinnantce48a112011-06-30 21:18:192204 __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__f);
Howard Hinnant3e519522010-05-11 19:42:162205}
2206
2207template <class _Tp, class _Allocator>
2208void
2209deque<_Tp, _Allocator>::__append(size_type __n)
2210{
2211 allocator_type& __a = __base::__alloc();
2212 size_type __back_capacity = __back_spare();
2213 if (__n > __back_capacity)
2214 __add_back_capacity(__n - __back_capacity);
2215 // __n <= __back_capacity
2216 for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size())
Howard Hinnantce48a112011-06-30 21:18:192217 __alloc_traits::construct(__a, _VSTD::addressof(*__i));
Howard Hinnant3e519522010-05-11 19:42:162218}
2219
2220template <class _Tp, class _Allocator>
2221void
2222deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v)
2223{
2224 allocator_type& __a = __base::__alloc();
2225 size_type __back_capacity = __back_spare();
2226 if (__n > __back_capacity)
2227 __add_back_capacity(__n - __back_capacity);
2228 // __n <= __back_capacity
2229 for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size())
Howard Hinnantce48a112011-06-30 21:18:192230 __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v);
Howard Hinnant3e519522010-05-11 19:42:162231}
2232
2233// Create front capacity for one block of elements.
2234// Strong guarantee. Either do it or don't touch anything.
2235template <class _Tp, class _Allocator>
2236void
2237deque<_Tp, _Allocator>::__add_front_capacity()
2238{
2239 allocator_type& __a = __base::__alloc();
2240 if (__back_spare() >= __base::__block_size)
2241 {
2242 __base::__start_ += __base::__block_size;
2243 pointer __pt = __base::__map_.back();
2244 __base::__map_.pop_back();
2245 __base::__map_.push_front(__pt);
2246 }
2247 // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer
2248 else if (__base::__map_.size() < __base::__map_.capacity())
2249 { // we can put the new buffer into the map, but don't shift things around
2250 // until all buffers are allocated. If we throw, we don't need to fix
2251 // anything up (any added buffers are undetectible)
2252 if (__base::__map_.__front_spare() > 0)
2253 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2254 else
2255 {
2256 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2257 // Done allocating, reorder capacity
2258 pointer __pt = __base::__map_.back();
2259 __base::__map_.pop_back();
2260 __base::__map_.push_front(__pt);
2261 }
2262 __base::__start_ = __base::__map_.size() == 1 ?
2263 __base::__block_size / 2 :
2264 __base::__start_ + __base::__block_size;
2265 }
2266 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
2267 else
2268 {
2269 __split_buffer<pointer, typename __base::__pointer_allocator&>
2270 __buf(max<size_type>(2 * __base::__map_.capacity(), 1),
2271 0, __base::__map_.__alloc());
2272#ifndef _LIBCPP_NO_EXCEPTIONS
2273 try
2274 {
Howard Hinnantb3371f62010-08-22 00:02:432275#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:162276 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2277#ifndef _LIBCPP_NO_EXCEPTIONS
2278 }
2279 catch (...)
2280 {
2281 __alloc_traits::deallocate(__a, __buf.front(), __base::__block_size);
2282 throw;
2283 }
Howard Hinnantb3371f62010-08-22 00:02:432284#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:162285 for (typename __base::__map_pointer __i = __base::__map_.begin();
2286 __i != __base::__map_.end(); ++__i)
2287 __buf.push_back(*__i);
Howard Hinnantce48a112011-06-30 21:18:192288 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2289 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2290 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2291 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
Howard Hinnant3e519522010-05-11 19:42:162292 __base::__start_ = __base::__map_.size() == 1 ?
2293 __base::__block_size / 2 :
2294 __base::__start_ + __base::__block_size;
2295 }
2296}
2297
2298// Create front capacity for __n elements.
2299// Strong guarantee. Either do it or don't touch anything.
2300template <class _Tp, class _Allocator>
2301void
2302deque<_Tp, _Allocator>::__add_front_capacity(size_type __n)
2303{
2304 allocator_type& __a = __base::__alloc();
2305 size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
2306 // Number of unused blocks at back:
2307 size_type __back_capacity = __back_spare() / __base::__block_size;
Howard Hinnantce48a112011-06-30 21:18:192308 __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need
Howard Hinnant3e519522010-05-11 19:42:162309 __nb -= __back_capacity; // number of blocks need to allocate
2310 // If __nb == 0, then we have sufficient capacity.
2311 if (__nb == 0)
2312 {
2313 __base::__start_ += __base::__block_size * __back_capacity;
2314 for (; __back_capacity > 0; --__back_capacity)
2315 {
2316 pointer __pt = __base::__map_.back();
2317 __base::__map_.pop_back();
2318 __base::__map_.push_front(__pt);
2319 }
2320 }
2321 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2322 else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
2323 { // we can put the new buffers into the map, but don't shift things around
2324 // until all buffers are allocated. If we throw, we don't need to fix
2325 // anything up (any added buffers are undetectible)
2326 for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1))
2327 {
2328 if (__base::__map_.__front_spare() == 0)
2329 break;
2330 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2331 }
2332 for (; __nb > 0; --__nb, ++__back_capacity)
2333 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2334 // Done allocating, reorder capacity
2335 __base::__start_ += __back_capacity * __base::__block_size;
2336 for (; __back_capacity > 0; --__back_capacity)
2337 {
2338 pointer __pt = __base::__map_.back();
2339 __base::__map_.pop_back();
2340 __base::__map_.push_front(__pt);
2341 }
2342 }
2343 // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
2344 else
2345 {
2346 size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty();
2347 __split_buffer<pointer, typename __base::__pointer_allocator&>
2348 __buf(max<size_type>(2* __base::__map_.capacity(),
2349 __nb + __base::__map_.size()),
2350 0, __base::__map_.__alloc());
2351#ifndef _LIBCPP_NO_EXCEPTIONS
2352 try
2353 {
Howard Hinnantb3371f62010-08-22 00:02:432354#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:162355 for (; __nb > 0; --__nb)
2356 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2357#ifndef _LIBCPP_NO_EXCEPTIONS
2358 }
2359 catch (...)
2360 {
2361 for (typename __base::__map_pointer __i = __buf.begin();
2362 __i != __buf.end(); ++__i)
2363 __alloc_traits::deallocate(__a, *__i, __base::__block_size);
2364 throw;
2365 }
Howard Hinnantb3371f62010-08-22 00:02:432366#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:162367 for (; __back_capacity > 0; --__back_capacity)
2368 {
2369 __buf.push_back(__base::__map_.back());
2370 __base::__map_.pop_back();
2371 }
2372 for (typename __base::__map_pointer __i = __base::__map_.begin();
2373 __i != __base::__map_.end(); ++__i)
2374 __buf.push_back(*__i);
Howard Hinnantce48a112011-06-30 21:18:192375 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2376 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2377 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2378 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
Howard Hinnant3e519522010-05-11 19:42:162379 __base::__start_ += __ds;
2380 }
2381}
2382
2383// Create back capacity for one block of elements.
2384// Strong guarantee. Either do it or don't touch anything.
2385template <class _Tp, class _Allocator>
2386void
2387deque<_Tp, _Allocator>::__add_back_capacity()
2388{
2389 allocator_type& __a = __base::__alloc();
2390 if (__front_spare() >= __base::__block_size)
2391 {
2392 __base::__start_ -= __base::__block_size;
2393 pointer __pt = __base::__map_.front();
2394 __base::__map_.pop_front();
2395 __base::__map_.push_back(__pt);
2396 }
2397 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2398 else if (__base::__map_.size() < __base::__map_.capacity())
2399 { // we can put the new buffer into the map, but don't shift things around
2400 // until it is allocated. If we throw, we don't need to fix
2401 // anything up (any added buffers are undetectible)
2402 if (__base::__map_.__back_spare() != 0)
2403 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2404 else
2405 {
2406 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2407 // Done allocating, reorder capacity
2408 pointer __pt = __base::__map_.front();
2409 __base::__map_.pop_front();
2410 __base::__map_.push_back(__pt);
2411 }
2412 }
2413 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
2414 else
2415 {
2416 __split_buffer<pointer, typename __base::__pointer_allocator&>
2417 __buf(max<size_type>(2* __base::__map_.capacity(), 1),
2418 __base::__map_.size(),
2419 __base::__map_.__alloc());
2420#ifndef _LIBCPP_NO_EXCEPTIONS
2421 try
2422 {
Howard Hinnantb3371f62010-08-22 00:02:432423#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:162424 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2425#ifndef _LIBCPP_NO_EXCEPTIONS
2426 }
2427 catch (...)
2428 {
2429 __alloc_traits::deallocate(__a, __buf.back(), __base::__block_size);
2430 throw;
2431 }
Howard Hinnantb3371f62010-08-22 00:02:432432#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:162433 for (typename __base::__map_pointer __i = __base::__map_.end();
2434 __i != __base::__map_.begin();)
2435 __buf.push_front(*--__i);
Howard Hinnantce48a112011-06-30 21:18:192436 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2437 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2438 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2439 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
Howard Hinnant3e519522010-05-11 19:42:162440 }
2441}
2442
2443// Create back capacity for __n elements.
2444// Strong guarantee. Either do it or don't touch anything.
2445template <class _Tp, class _Allocator>
2446void
2447deque<_Tp, _Allocator>::__add_back_capacity(size_type __n)
2448{
2449 allocator_type& __a = __base::__alloc();
2450 size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
2451 // Number of unused blocks at front:
2452 size_type __front_capacity = __front_spare() / __base::__block_size;
Howard Hinnantce48a112011-06-30 21:18:192453 __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need
Howard Hinnant3e519522010-05-11 19:42:162454 __nb -= __front_capacity; // number of blocks need to allocate
2455 // If __nb == 0, then we have sufficient capacity.
2456 if (__nb == 0)
2457 {
2458 __base::__start_ -= __base::__block_size * __front_capacity;
2459 for (; __front_capacity > 0; --__front_capacity)
2460 {
2461 pointer __pt = __base::__map_.front();
2462 __base::__map_.pop_front();
2463 __base::__map_.push_back(__pt);
2464 }
2465 }
2466 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2467 else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
2468 { // we can put the new buffers into the map, but don't shift things around
2469 // until all buffers are allocated. If we throw, we don't need to fix
2470 // anything up (any added buffers are undetectible)
2471 for (; __nb > 0; --__nb)
2472 {
2473 if (__base::__map_.__back_spare() == 0)
2474 break;
2475 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2476 }
2477 for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ +=
2478 __base::__block_size - (__base::__map_.size() == 1))
2479 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2480 // Done allocating, reorder capacity
2481 __base::__start_ -= __base::__block_size * __front_capacity;
2482 for (; __front_capacity > 0; --__front_capacity)
2483 {
2484 pointer __pt = __base::__map_.front();
2485 __base::__map_.pop_front();
2486 __base::__map_.push_back(__pt);
2487 }
2488 }
2489 // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
2490 else
2491 {
2492 size_type __ds = __front_capacity * __base::__block_size;
2493 __split_buffer<pointer, typename __base::__pointer_allocator&>
2494 __buf(max<size_type>(2* __base::__map_.capacity(),
2495 __nb + __base::__map_.size()),
2496 __base::__map_.size() - __front_capacity,
2497 __base::__map_.__alloc());
2498#ifndef _LIBCPP_NO_EXCEPTIONS
2499 try
2500 {
Howard Hinnantb3371f62010-08-22 00:02:432501#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:162502 for (; __nb > 0; --__nb)
2503 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2504#ifndef _LIBCPP_NO_EXCEPTIONS
2505 }
2506 catch (...)
2507 {
2508 for (typename __base::__map_pointer __i = __buf.begin();
2509 __i != __buf.end(); ++__i)
2510 __alloc_traits::deallocate(__a, *__i, __base::__block_size);
2511 throw;
2512 }
Howard Hinnantb3371f62010-08-22 00:02:432513#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:162514 for (; __front_capacity > 0; --__front_capacity)
2515 {
2516 __buf.push_back(__base::__map_.front());
2517 __base::__map_.pop_front();
2518 }
2519 for (typename __base::__map_pointer __i = __base::__map_.end();
2520 __i != __base::__map_.begin();)
2521 __buf.push_front(*--__i);
Howard Hinnantce48a112011-06-30 21:18:192522 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2523 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2524 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2525 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
Howard Hinnant3e519522010-05-11 19:42:162526 __base::__start_ -= __ds;
2527 }
2528}
2529
2530template <class _Tp, class _Allocator>
2531void
2532deque<_Tp, _Allocator>::pop_front()
2533{
2534 allocator_type& __a = __base::__alloc();
Howard Hinnant14e200d2013-06-23 21:17:242535 __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
2536 __base::__start_ / __base::__block_size) +
2537 __base::__start_ % __base::__block_size));
Howard Hinnant3e519522010-05-11 19:42:162538 --__base::size();
2539 if (++__base::__start_ >= 2 * __base::__block_size)
2540 {
2541 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2542 __base::__map_.pop_front();
2543 __base::__start_ -= __base::__block_size;
2544 }
2545}
2546
2547template <class _Tp, class _Allocator>
2548void
2549deque<_Tp, _Allocator>::pop_back()
2550{
2551 allocator_type& __a = __base::__alloc();
2552 size_type __p = __base::size() + __base::__start_ - 1;
Howard Hinnant14e200d2013-06-23 21:17:242553 __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
2554 __p / __base::__block_size) +
2555 __p % __base::__block_size));
Howard Hinnant3e519522010-05-11 19:42:162556 --__base::size();
2557 if (__back_spare() >= 2 * __base::__block_size)
2558 {
2559 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2560 __base::__map_.pop_back();
2561 }
2562}
2563
2564// move assign [__f, __l) to [__r, __r + (__l-__f)).
2565// If __vt points into [__f, __l), then subtract (__f - __r) from __vt.
2566template <class _Tp, class _Allocator>
2567typename deque<_Tp, _Allocator>::iterator
2568deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r,
2569 const_pointer& __vt)
2570{
2571 // as if
2572 // for (; __f != __l; ++__f, ++__r)
Howard Hinnantce48a112011-06-30 21:18:192573 // *__r = _VSTD::move(*__f);
Howard Hinnant3e519522010-05-11 19:42:162574 difference_type __n = __l - __f;
2575 while (__n > 0)
2576 {
2577 pointer __fb = __f.__ptr_;
2578 pointer __fe = *__f.__m_iter_ + __base::__block_size;
2579 difference_type __bs = __fe - __fb;
2580 if (__bs > __n)
2581 {
2582 __bs = __n;
2583 __fe = __fb + __bs;
2584 }
2585 if (__fb <= __vt && __vt < __fe)
Howard Hinnant14e200d2013-06-23 21:17:242586 __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_;
Howard Hinnantce48a112011-06-30 21:18:192587 __r = _VSTD::move(__fb, __fe, __r);
Howard Hinnant3e519522010-05-11 19:42:162588 __n -= __bs;
2589 __f += __bs;
2590 }
2591 return __r;
2592}
2593
2594// move assign [__f, __l) to [__r - (__l-__f), __r) backwards.
2595// If __vt points into [__f, __l), then add (__r - __l) to __vt.
2596template <class _Tp, class _Allocator>
2597typename deque<_Tp, _Allocator>::iterator
2598deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r,
2599 const_pointer& __vt)
2600{
2601 // as if
2602 // while (__f != __l)
Howard Hinnantce48a112011-06-30 21:18:192603 // *--__r = _VSTD::move(*--__l);
Howard Hinnant3e519522010-05-11 19:42:162604 difference_type __n = __l - __f;
2605 while (__n > 0)
2606 {
2607 --__l;
2608 pointer __lb = *__l.__m_iter_;
2609 pointer __le = __l.__ptr_ + 1;
2610 difference_type __bs = __le - __lb;
2611 if (__bs > __n)
2612 {
2613 __bs = __n;
2614 __lb = __le - __bs;
2615 }
2616 if (__lb <= __vt && __vt < __le)
Howard Hinnant14e200d2013-06-23 21:17:242617 __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_;
Howard Hinnantce48a112011-06-30 21:18:192618 __r = _VSTD::move_backward(__lb, __le, __r);
Howard Hinnant3e519522010-05-11 19:42:162619 __n -= __bs;
2620 __l -= __bs - 1;
2621 }
2622 return __r;
2623}
2624
2625// move construct [__f, __l) to [__r, __r + (__l-__f)).
2626// If __vt points into [__f, __l), then add (__r - __f) to __vt.
2627template <class _Tp, class _Allocator>
2628void
2629deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l,
2630 iterator __r, const_pointer& __vt)
2631{
2632 allocator_type& __a = __base::__alloc();
2633 // as if
2634 // for (; __f != __l; ++__r, ++__f, ++__base::size())
Howard Hinnantce48a112011-06-30 21:18:192635 // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f));
Howard Hinnant3e519522010-05-11 19:42:162636 difference_type __n = __l - __f;
2637 while (__n > 0)
2638 {
2639 pointer __fb = __f.__ptr_;
2640 pointer __fe = *__f.__m_iter_ + __base::__block_size;
2641 difference_type __bs = __fe - __fb;
2642 if (__bs > __n)
2643 {
2644 __bs = __n;
2645 __fe = __fb + __bs;
2646 }
2647 if (__fb <= __vt && __vt < __fe)
Howard Hinnant14e200d2013-06-23 21:17:242648 __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_;
Howard Hinnant3e519522010-05-11 19:42:162649 for (; __fb != __fe; ++__fb, ++__r, ++__base::size())
Howard Hinnantce48a112011-06-30 21:18:192650 __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb));
Howard Hinnant3e519522010-05-11 19:42:162651 __n -= __bs;
2652 __f += __bs;
2653 }
2654}
2655
2656// move construct [__f, __l) to [__r - (__l-__f), __r) backwards.
2657// If __vt points into [__f, __l), then subtract (__l - __r) from __vt.
2658template <class _Tp, class _Allocator>
2659void
2660deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l,
2661 iterator __r, const_pointer& __vt)
2662{
2663 allocator_type& __a = __base::__alloc();
2664 // as if
2665 // for (iterator __j = __l; __j != __f;)
2666 // {
Howard Hinnantce48a112011-06-30 21:18:192667 // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j));
Howard Hinnant3e519522010-05-11 19:42:162668 // --__base::__start_;
2669 // ++__base::size();
2670 // }
2671 difference_type __n = __l - __f;
2672 while (__n > 0)
2673 {
2674 --__l;
2675 pointer __lb = *__l.__m_iter_;
2676 pointer __le = __l.__ptr_ + 1;
2677 difference_type __bs = __le - __lb;
2678 if (__bs > __n)
2679 {
2680 __bs = __n;
2681 __lb = __le - __bs;
2682 }
2683 if (__lb <= __vt && __vt < __le)
Howard Hinnant14e200d2013-06-23 21:17:242684 __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_;
Howard Hinnant3e519522010-05-11 19:42:162685 while (__le != __lb)
2686 {
Howard Hinnantce48a112011-06-30 21:18:192687 __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le));
Howard Hinnant3e519522010-05-11 19:42:162688 --__base::__start_;
2689 ++__base::size();
2690 }
2691 __n -= __bs;
2692 __l -= __bs - 1;
2693 }
2694}
2695
2696template <class _Tp, class _Allocator>
2697typename deque<_Tp, _Allocator>::iterator
2698deque<_Tp, _Allocator>::erase(const_iterator __f)
2699{
2700 difference_type __n = 1;
2701 iterator __b = __base::begin();
2702 difference_type __pos = __f - __b;
2703 iterator __p = __b + __pos;
2704 allocator_type& __a = __base::__alloc();
2705 if (__pos < (__base::size() - 1) / 2)
2706 { // erase from front
Howard Hinnantce48a112011-06-30 21:18:192707 _VSTD::move_backward(__b, __p, _VSTD::next(__p));
2708 __alloc_traits::destroy(__a, _VSTD::addressof(*__b));
Howard Hinnant3e519522010-05-11 19:42:162709 --__base::size();
2710 ++__base::__start_;
2711 if (__front_spare() >= 2 * __base::__block_size)
2712 {
2713 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2714 __base::__map_.pop_front();
2715 __base::__start_ -= __base::__block_size;
2716 }
2717 }
2718 else
2719 { // erase from back
Howard Hinnantce48a112011-06-30 21:18:192720 iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p);
2721 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
Howard Hinnant3e519522010-05-11 19:42:162722 --__base::size();
2723 if (__back_spare() >= 2 * __base::__block_size)
2724 {
2725 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2726 __base::__map_.pop_back();
2727 }
2728 }
2729 return __base::begin() + __pos;
2730}
2731
2732template <class _Tp, class _Allocator>
2733typename deque<_Tp, _Allocator>::iterator
2734deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l)
2735{
2736 difference_type __n = __l - __f;
2737 iterator __b = __base::begin();
2738 difference_type __pos = __f - __b;
2739 iterator __p = __b + __pos;
2740 if (__n > 0)
2741 {
2742 allocator_type& __a = __base::__alloc();
2743 if (__pos < (__base::size() - __n) / 2)
2744 { // erase from front
Howard Hinnantce48a112011-06-30 21:18:192745 iterator __i = _VSTD::move_backward(__b, __p, __p + __n);
Howard Hinnant3e519522010-05-11 19:42:162746 for (; __b != __i; ++__b)
Howard Hinnantce48a112011-06-30 21:18:192747 __alloc_traits::destroy(__a, _VSTD::addressof(*__b));
Howard Hinnant3e519522010-05-11 19:42:162748 __base::size() -= __n;
2749 __base::__start_ += __n;
2750 while (__front_spare() >= 2 * __base::__block_size)
2751 {
2752 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2753 __base::__map_.pop_front();
2754 __base::__start_ -= __base::__block_size;
2755 }
2756 }
2757 else
2758 { // erase from back
Howard Hinnantce48a112011-06-30 21:18:192759 iterator __i = _VSTD::move(__p + __n, __base::end(), __p);
Howard Hinnant3e519522010-05-11 19:42:162760 for (iterator __e = __base::end(); __i != __e; ++__i)
Howard Hinnantce48a112011-06-30 21:18:192761 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
Howard Hinnant3e519522010-05-11 19:42:162762 __base::size() -= __n;
2763 while (__back_spare() >= 2 * __base::__block_size)
2764 {
2765 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2766 __base::__map_.pop_back();
2767 }
2768 }
2769 }
2770 return __base::begin() + __pos;
2771}
2772
2773template <class _Tp, class _Allocator>
2774void
2775deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f)
2776{
2777 iterator __e = __base::end();
2778 difference_type __n = __e - __f;
2779 if (__n > 0)
2780 {
2781 allocator_type& __a = __base::__alloc();
2782 iterator __b = __base::begin();
2783 difference_type __pos = __f - __b;
2784 for (iterator __p = __b + __pos; __p != __e; ++__p)
Howard Hinnantce48a112011-06-30 21:18:192785 __alloc_traits::destroy(__a, _VSTD::addressof(*__p));
Howard Hinnant3e519522010-05-11 19:42:162786 __base::size() -= __n;
2787 while (__back_spare() >= 2 * __base::__block_size)
2788 {
2789 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2790 __base::__map_.pop_back();
2791 }
2792 }
2793}
2794
2795template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:232796inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:162797void
2798deque<_Tp, _Allocator>::swap(deque& __c)
Howard Hinnant9eebe112011-06-02 20:00:142799 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2800 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:162801{
2802 __base::swap(__c);
2803}
2804
2805template <class _Tp, class _Allocator>
Howard Hinnantfb100022010-09-21 21:28:232806inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:162807void
Howard Hinnanta87e8362011-06-02 16:10:222808deque<_Tp, _Allocator>::clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162809{
2810 __base::clear();
2811}
2812
2813template <class _Tp, class _Allocator>
Howard Hinnant3af48ef2013-10-04 22:09:002814inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:162815bool
2816operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2817{
2818 const typename deque<_Tp, _Allocator>::size_type __sz = __x.size();
Howard Hinnantce48a112011-06-30 21:18:192819 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnant3e519522010-05-11 19:42:162820}
2821
2822template <class _Tp, class _Allocator>
Howard Hinnant3af48ef2013-10-04 22:09:002823inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:162824bool
2825operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2826{
2827 return !(__x == __y);
2828}
2829
2830template <class _Tp, class _Allocator>
Howard Hinnant3af48ef2013-10-04 22:09:002831inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:162832bool
2833operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2834{
Howard Hinnantce48a112011-06-30 21:18:192835 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnant3e519522010-05-11 19:42:162836}
2837
2838template <class _Tp, class _Allocator>
Howard Hinnant3af48ef2013-10-04 22:09:002839inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:162840bool
2841operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2842{
2843 return __y < __x;
2844}
2845
2846template <class _Tp, class _Allocator>
Howard Hinnant3af48ef2013-10-04 22:09:002847inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:162848bool
2849operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2850{
2851 return !(__x < __y);
2852}
2853
2854template <class _Tp, class _Allocator>
Howard Hinnant3af48ef2013-10-04 22:09:002855inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:162856bool
2857operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2858{
2859 return !(__y < __x);
2860}
2861
2862template <class _Tp, class _Allocator>
Howard Hinnant3af48ef2013-10-04 22:09:002863inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:162864void
2865swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y)
Howard Hinnant9eebe112011-06-02 20:00:142866 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:162867{
2868 __x.swap(__y);
2869}
2870
2871_LIBCPP_END_NAMESPACE_STD
2872
2873#endif // _LIBCPP_DEQUE