2 //===---------------------------- deque -----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
20 template <class T, class Allocator = allocator<T> >
26 typedef Allocator allocator_type;
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;
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;
40 // construct/copy/destroy:
41 deque() noexcept(is_nothrow_default_constructible<allocator_type>::value);
42 explicit deque(const allocator_type& a);
43 explicit deque(size_type n);
44 explicit deque(size_type n, const allocator_type& a); // C++14
45 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);
53 noexcept(is_nothrow_move_constructible<allocator_type>::value);
54 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);
59 deque& operator=(const deque& c);
60 deque& operator=(deque&& c)
62 allocator_type::propagate_on_container_move_assignment::value &&
63 is_nothrow_move_assignable<allocator_type>::value);
64 deque& operator=(initializer_list<value_type> il);
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);
71 allocator_type get_allocator() const noexcept;
75 iterator begin() noexcept;
76 const_iterator begin() const noexcept;
77 iterator end() noexcept;
78 const_iterator end() const noexcept;
80 reverse_iterator rbegin() noexcept;
81 const_reverse_iterator rbegin() const noexcept;
82 reverse_iterator rend() noexcept;
83 const_reverse_iterator rend() const noexcept;
85 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;
91 size_type size() const noexcept;
92 size_type max_size() const noexcept;
93 void resize(size_type n);
94 void resize(size_type n, const value_type& v);
96 bool empty() const noexcept;
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;
104 const_reference front() const;
106 const_reference back() const;
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);
124 iterator erase(const_iterator p);
125 iterator erase(const_iterator f, const_iterator l);
127 noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
128 void clear() noexcept;
131 template <class T, class Allocator>
132 bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
133 template <class T, class Allocator>
134 bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
135 template <class T, class Allocator>
136 bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
137 template <class T, class Allocator>
138 bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
139 template <class T, class Allocator>
140 bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
141 template <class T, class Allocator>
142 bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
144 // specialized algorithms:
145 template <class T, class Allocator>
146 void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
147 noexcept(noexcept(x.swap(y)));
153 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
154 #pragma GCC system_header
158 #include <__split_buffer>
159 #include <type_traits>
160 #include <initializer_list>
165 #include <__undef_min_max>
167 _LIBCPP_BEGIN_NAMESPACE_STD
169 template <class _Tp, class _Allocator> class __deque_base;
170 template <class _Tp, class _Allocator = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY deque;
172 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
173 class _DiffType, _DiffType _BlockSize>
174 class _LIBCPP_TYPE_VIS_ONLY __deque_iterator;
176 template <class _RAIter,
177 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
178 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
181 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
182 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
184 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
185 class _OutputIterator>
187 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
188 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
189 _OutputIterator __r);
191 template <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>
194 copy(__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);
198 template <class _RAIter,
199 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
200 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
201 copy_backward(_RAIter __f,
203 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
204 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
206 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
207 class _OutputIterator>
209 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
210 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
211 _OutputIterator __r);
213 template <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>
216 copy_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);
220 template <class _RAIter,
221 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
222 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
225 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
226 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
228 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
229 class _OutputIterator>
231 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
232 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
233 _OutputIterator __r);
235 template <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>
238 move(__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);
242 template <class _RAIter,
243 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
244 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
245 move_backward(_RAIter __f,
247 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
248 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
250 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
251 class _OutputIterator>
253 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
254 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
255 _OutputIterator __r);
257 template <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>
260 move_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);
264 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
265 class _DiffType, _DiffType _BlockSize>
266 class _LIBCPP_TYPE_VIS_ONLY __deque_iterator
268 typedef _MapPointer __map_iterator;
270 typedef _Pointer pointer;
271 typedef _DiffType difference_type;
273 __map_iterator __m_iter_;
276 static const difference_type __block_size = _BlockSize;
278 typedef _ValueType value_type;
279 typedef random_access_iterator_tag iterator_category;
280 typedef _Reference reference;
282 _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT
283 #if _LIBCPP_STD_VER > 11
284 : __m_iter_(nullptr), __ptr_(nullptr)
288 template <class _Pp, class _Rp, class _MP>
289 _LIBCPP_INLINE_VISIBILITY
290 __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
292 : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {}
294 _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;}
295 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;}
297 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++()
299 if (++__ptr_ - *__m_iter_ == __block_size)
307 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int)
309 __deque_iterator __tmp = *this;
314 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--()
316 if (__ptr_ == *__m_iter_)
319 __ptr_ = *__m_iter_ + __block_size;
325 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int)
327 __deque_iterator __tmp = *this;
332 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n)
336 __n += __ptr_ - *__m_iter_;
339 __m_iter_ += __n / __block_size;
340 __ptr_ = *__m_iter_ + __n % __block_size;
344 difference_type __z = __block_size - 1 - __n;
345 __m_iter_ -= __z / __block_size;
346 __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size);
352 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n)
354 return *this += -__n;
357 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const
359 __deque_iterator __t(*this);
364 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const
366 __deque_iterator __t(*this);
371 _LIBCPP_INLINE_VISIBILITY
372 friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it)
375 _LIBCPP_INLINE_VISIBILITY
376 friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y)
379 return (__x.__m_iter_ - __y.__m_iter_) * __block_size
380 + (__x.__ptr_ - *__x.__m_iter_)
381 - (__y.__ptr_ - *__y.__m_iter_);
385 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
386 {return *(*this + __n);}
388 _LIBCPP_INLINE_VISIBILITY friend
389 bool operator==(const __deque_iterator& __x, const __deque_iterator& __y)
390 {return __x.__ptr_ == __y.__ptr_;}
392 _LIBCPP_INLINE_VISIBILITY friend
393 bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y)
394 {return !(__x == __y);}
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_);}
401 _LIBCPP_INLINE_VISIBILITY friend
402 bool operator>(const __deque_iterator& __x, const __deque_iterator& __y)
405 _LIBCPP_INLINE_VISIBILITY friend
406 bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y)
407 {return !(__y < __x);}
409 _LIBCPP_INLINE_VISIBILITY friend
410 bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y)
411 {return !(__x < __y);}
414 _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
415 : __m_iter_(__m), __ptr_(__p) {}
417 template <class _Tp, class _Ap> friend class __deque_base;
418 template <class _Tp, class _Ap> friend class _LIBCPP_TYPE_VIS_ONLY deque;
419 template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp>
420 friend class _LIBCPP_TYPE_VIS_ONLY __deque_iterator;
422 template <class _RAIter,
423 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
425 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
428 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
429 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
431 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
432 class _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);
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>
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);
447 template <class _RAIter,
448 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
450 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
451 copy_backward(_RAIter __f,
453 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
454 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
456 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
457 class _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);
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>
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);
472 template <class _RAIter,
473 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
475 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
478 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
479 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
481 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
482 class _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);
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>
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);
497 template <class _RAIter,
498 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
500 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
501 move_backward(_RAIter __f,
503 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
504 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
506 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
507 class _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);
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>
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);
525 template <class _RAIter,
526 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
527 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
530 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
531 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
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;
537 pointer __rb = __r.__ptr_;
538 pointer __re = *__r.__m_iter_ + _B2;
539 difference_type __bs = __re - __rb;
540 difference_type __n = __l - __f;
547 _VSTD::copy(__f, __m, __rb);
554 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
555 class _OutputIterator>
557 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
558 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
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;
566 pointer __fb = __f.__ptr_;
567 pointer __fe = *__f.__m_iter_ + _B1;
568 difference_type __bs = __fe - __fb;
574 __r = _VSTD::copy(__fb, __fe, __r);
581 template <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>
584 copy(__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)
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;
593 pointer __fb = __f.__ptr_;
594 pointer __fe = *__f.__m_iter_ + _B1;
595 difference_type __bs = __fe - __fb;
601 __r = _VSTD::copy(__fb, __fe, __r);
610 template <class _RAIter,
611 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
612 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
613 copy_backward(_RAIter __f,
615 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
616 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
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;
622 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r);
623 pointer __rb = *__rp.__m_iter_;
624 pointer __re = __rp.__ptr_ + 1;
625 difference_type __bs = __re - __rb;
626 difference_type __n = __l - __f;
633 _VSTD::copy_backward(__m, __l, __re);
640 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
641 class _OutputIterator>
643 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
644 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
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;
653 pointer __lb = *__l.__m_iter_;
654 pointer __le = __l.__ptr_ + 1;
655 difference_type __bs = __le - __lb;
661 __r = _VSTD::copy_backward(__lb, __le, __r);
668 template <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>
671 copy_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)
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;
681 pointer __lb = *__l.__m_iter_;
682 pointer __le = __l.__ptr_ + 1;
683 difference_type __bs = __le - __lb;
689 __r = _VSTD::copy_backward(__lb, __le, __r);
698 template <class _RAIter,
699 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
700 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
703 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
704 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
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;
710 pointer __rb = __r.__ptr_;
711 pointer __re = *__r.__m_iter_ + _B2;
712 difference_type __bs = __re - __rb;
713 difference_type __n = __l - __f;
720 _VSTD::move(__f, __m, __rb);
727 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
728 class _OutputIterator>
730 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
731 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
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;
739 pointer __fb = __f.__ptr_;
740 pointer __fe = *__f.__m_iter_ + _B1;
741 difference_type __bs = __fe - __fb;
747 __r = _VSTD::move(__fb, __fe, __r);
754 template <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>
757 move(__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)
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;
766 pointer __fb = __f.__ptr_;
767 pointer __fe = *__f.__m_iter_ + _B1;
768 difference_type __bs = __fe - __fb;
774 __r = _VSTD::move(__fb, __fe, __r);
783 template <class _RAIter,
784 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
785 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
786 move_backward(_RAIter __f,
788 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
789 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
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;
795 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r);
796 pointer __rb = *__rp.__m_iter_;
797 pointer __re = __rp.__ptr_ + 1;
798 difference_type __bs = __re - __rb;
799 difference_type __n = __l - __f;
806 _VSTD::move_backward(__m, __l, __re);
813 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
814 class _OutputIterator>
816 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
817 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
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;
826 pointer __lb = *__l.__m_iter_;
827 pointer __le = __l.__ptr_ + 1;
828 difference_type __bs = __le - __lb;
834 __r = _VSTD::move_backward(__lb, __le, __r);
841 template <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>
844 move_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)
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;
854 pointer __lb = *__l.__m_iter_;
855 pointer __le = __l.__ptr_ + 1;
856 difference_type __bs = __le - __lb;
862 __r = _VSTD::move_backward(__lb, __le, __r);
870 class __deque_base_common
873 void __throw_length_error() const;
874 void __throw_out_of_range() const;
879 __deque_base_common<__b>::__throw_length_error() const
881 #ifndef _LIBCPP_NO_EXCEPTIONS
882 throw length_error("deque");
888 __deque_base_common<__b>::__throw_out_of_range() const
890 #ifndef _LIBCPP_NO_EXCEPTIONS
891 throw out_of_range("deque");
895 template <class _Tp, class _Allocator>
897 : protected __deque_base_common<true>
899 __deque_base(const __deque_base& __c);
900 __deque_base& operator=(const __deque_base& __c);
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;
912 static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16;
914 typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator;
915 typedef allocator_traits<__pointer_allocator> __map_traits;
916 typedef typename __map_traits::pointer __map_pointer;
917 typedef typename __rebind_alloc_helper<__alloc_traits, const_pointer>::type __const_pointer_allocator;
918 typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer;
919 typedef __split_buffer<pointer, __pointer_allocator> __map;
921 typedef __deque_iterator<value_type, pointer, reference, __map_pointer,
922 difference_type, __block_size> iterator;
923 typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer,
924 difference_type, __block_size> const_iterator;
928 __compressed_pair<size_type, allocator_type> __size_;
930 iterator begin() _NOEXCEPT;
931 const_iterator begin() const _NOEXCEPT;
932 iterator end() _NOEXCEPT;
933 const_iterator end() const _NOEXCEPT;
935 _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();}
936 _LIBCPP_INLINE_VISIBILITY
937 const size_type& size() const _NOEXCEPT {return __size_.first();}
938 _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();}
939 _LIBCPP_INLINE_VISIBILITY
940 const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();}
943 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
944 explicit __deque_base(const allocator_type& __a);
948 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
950 __deque_base(__deque_base&& __c)
951 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
952 __deque_base(__deque_base&& __c, const allocator_type& __a);
954 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
955 void swap(__deque_base& __c)
956 #if _LIBCPP_STD_VER >= 14
959 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
960 __is_nothrow_swappable<allocator_type>::value);
963 void clear() _NOEXCEPT;
965 bool __invariants() const;
967 _LIBCPP_INLINE_VISIBILITY
968 void __move_assign(__deque_base& __c)
969 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
970 is_nothrow_move_assignable<allocator_type>::value)
972 __map_ = _VSTD::move(__c.__map_);
973 __start_ = __c.__start_;
975 __move_assign_alloc(__c);
976 __c.__start_ = __c.size() = 0;
979 _LIBCPP_INLINE_VISIBILITY
980 void __move_assign_alloc(__deque_base& __c)
981 _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value ||
982 is_nothrow_move_assignable<allocator_type>::value)
983 {__move_assign_alloc(__c, integral_constant<bool,
984 __alloc_traits::propagate_on_container_move_assignment::value>());}
987 _LIBCPP_INLINE_VISIBILITY
988 void __move_assign_alloc(__deque_base& __c, true_type)
989 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
991 __alloc() = _VSTD::move(__c.__alloc());
994 _LIBCPP_INLINE_VISIBILITY
995 void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT
999 template <class _Tp, class _Allocator>
1001 __deque_base<_Tp, _Allocator>::__invariants() const
1003 if (!__map_.__invariants())
1005 if (__map_.size() >= size_type(-1) / __block_size)
1007 for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end();
1009 if (*__i == nullptr)
1011 if (__map_.size() != 0)
1013 if (size() >= __map_.size() * __block_size)
1015 if (__start_ >= __map_.size() * __block_size - size())
1028 template <class _Tp, class _Allocator>
1029 typename __deque_base<_Tp, _Allocator>::iterator
1030 __deque_base<_Tp, _Allocator>::begin() _NOEXCEPT
1032 __map_pointer __mp = __map_.begin() + __start_ / __block_size;
1033 return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
1036 template <class _Tp, class _Allocator>
1037 typename __deque_base<_Tp, _Allocator>::const_iterator
1038 __deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT
1040 __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size);
1041 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
1044 template <class _Tp, class _Allocator>
1045 typename __deque_base<_Tp, _Allocator>::iterator
1046 __deque_base<_Tp, _Allocator>::end() _NOEXCEPT
1048 size_type __p = size() + __start_;
1049 __map_pointer __mp = __map_.begin() + __p / __block_size;
1050 return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
1053 template <class _Tp, class _Allocator>
1054 typename __deque_base<_Tp, _Allocator>::const_iterator
1055 __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT
1057 size_type __p = size() + __start_;
1058 __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size);
1059 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
1062 template <class _Tp, class _Allocator>
1063 inline _LIBCPP_INLINE_VISIBILITY
1064 __deque_base<_Tp, _Allocator>::__deque_base()
1065 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1066 : __start_(0), __size_(0) {}
1068 template <class _Tp, class _Allocator>
1069 inline _LIBCPP_INLINE_VISIBILITY
1070 __deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a)
1071 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {}
1073 template <class _Tp, class _Allocator>
1074 __deque_base<_Tp, _Allocator>::~__deque_base()
1077 typename __map::iterator __i = __map_.begin();
1078 typename __map::iterator __e = __map_.end();
1079 for (; __i != __e; ++__i)
1080 __alloc_traits::deallocate(__alloc(), *__i, __block_size);
1083 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1085 template <class _Tp, class _Allocator>
1086 __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c)
1087 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1088 : __map_(_VSTD::move(__c.__map_)),
1089 __start_(_VSTD::move(__c.__start_)),
1090 __size_(_VSTD::move(__c.__size_))
1096 template <class _Tp, class _Allocator>
1097 __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a)
1098 : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)),
1099 __start_(_VSTD::move(__c.__start_)),
1100 __size_(_VSTD::move(__c.size()), __a)
1102 if (__a == __c.__alloc())
1115 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1117 template <class _Tp, class _Allocator>
1119 __deque_base<_Tp, _Allocator>::swap(__deque_base& __c)
1120 #if _LIBCPP_STD_VER >= 14
1123 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1124 __is_nothrow_swappable<allocator_type>::value)
1127 __map_.swap(__c.__map_);
1128 _VSTD::swap(__start_, __c.__start_);
1129 _VSTD::swap(size(), __c.size());
1130 __swap_allocator(__alloc(), __c.__alloc());
1133 template <class _Tp, class _Allocator>
1135 __deque_base<_Tp, _Allocator>::clear() _NOEXCEPT
1137 allocator_type& __a = __alloc();
1138 for (iterator __i = begin(), __e = end(); __i != __e; ++__i)
1139 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
1141 while (__map_.size() > 2)
1143 __alloc_traits::deallocate(__a, __map_.front(), __block_size);
1146 switch (__map_.size())
1149 __start_ = __block_size / 2;
1152 __start_ = __block_size;
1157 template <class _Tp, class _Allocator /*= allocator<_Tp>*/>
1158 class _LIBCPP_TYPE_VIS_ONLY deque
1159 : private __deque_base<_Tp, _Allocator>
1164 typedef _Tp value_type;
1165 typedef _Allocator allocator_type;
1167 typedef __deque_base<value_type, allocator_type> __base;
1169 typedef typename __base::__alloc_traits __alloc_traits;
1170 typedef typename __base::reference reference;
1171 typedef typename __base::const_reference const_reference;
1172 typedef typename __base::iterator iterator;
1173 typedef typename __base::const_iterator const_iterator;
1174 typedef typename __base::size_type size_type;
1175 typedef typename __base::difference_type difference_type;
1177 typedef typename __base::pointer pointer;
1178 typedef typename __base::const_pointer const_pointer;
1179 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1180 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1182 // construct/copy/destroy:
1183 _LIBCPP_INLINE_VISIBILITY
1185 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1187 _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {}
1188 explicit deque(size_type __n);
1189 #if _LIBCPP_STD_VER > 11
1190 explicit deque(size_type __n, const _Allocator& __a);
1192 deque(size_type __n, const value_type& __v);
1193 deque(size_type __n, const value_type& __v, const allocator_type& __a);
1194 template <class _InputIter>
1195 deque(_InputIter __f, _InputIter __l,
1196 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
1197 template <class _InputIter>
1198 deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
1199 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
1200 deque(const deque& __c);
1201 deque(const deque& __c, const allocator_type& __a);
1202 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1203 deque(initializer_list<value_type> __il);
1204 deque(initializer_list<value_type> __il, const allocator_type& __a);
1205 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1207 deque& operator=(const deque& __c);
1208 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1209 _LIBCPP_INLINE_VISIBILITY
1210 deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;}
1211 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1213 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1214 deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value);
1215 deque(deque&& __c, const allocator_type& __a);
1216 deque& operator=(deque&& __c)
1217 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1218 is_nothrow_move_assignable<allocator_type>::value);
1219 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1221 template <class _InputIter>
1222 void assign(_InputIter __f, _InputIter __l,
1223 typename enable_if<__is_input_iterator<_InputIter>::value &&
1224 !__is_random_access_iterator<_InputIter>::value>::type* = 0);
1225 template <class _RAIter>
1226 void assign(_RAIter __f, _RAIter __l,
1227 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
1228 void assign(size_type __n, const value_type& __v);
1229 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1230 _LIBCPP_INLINE_VISIBILITY
1231 void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());}
1232 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1234 allocator_type get_allocator() const _NOEXCEPT;
1238 _LIBCPP_INLINE_VISIBILITY
1239 iterator begin() _NOEXCEPT {return __base::begin();}
1240 _LIBCPP_INLINE_VISIBILITY
1241 const_iterator begin() const _NOEXCEPT {return __base::begin();}
1242 _LIBCPP_INLINE_VISIBILITY
1243 iterator end() _NOEXCEPT {return __base::end();}
1244 _LIBCPP_INLINE_VISIBILITY
1245 const_iterator end() const _NOEXCEPT {return __base::end();}
1247 _LIBCPP_INLINE_VISIBILITY
1248 reverse_iterator rbegin() _NOEXCEPT
1249 {return reverse_iterator(__base::end());}
1250 _LIBCPP_INLINE_VISIBILITY
1251 const_reverse_iterator rbegin() const _NOEXCEPT
1252 {return const_reverse_iterator(__base::end());}
1253 _LIBCPP_INLINE_VISIBILITY
1254 reverse_iterator rend() _NOEXCEPT
1255 {return reverse_iterator(__base::begin());}
1256 _LIBCPP_INLINE_VISIBILITY
1257 const_reverse_iterator rend() const _NOEXCEPT
1258 {return const_reverse_iterator(__base::begin());}
1260 _LIBCPP_INLINE_VISIBILITY
1261 const_iterator cbegin() const _NOEXCEPT
1262 {return __base::begin();}
1263 _LIBCPP_INLINE_VISIBILITY
1264 const_iterator cend() const _NOEXCEPT
1265 {return __base::end();}
1266 _LIBCPP_INLINE_VISIBILITY
1267 const_reverse_iterator crbegin() const _NOEXCEPT
1268 {return const_reverse_iterator(__base::end());}
1269 _LIBCPP_INLINE_VISIBILITY
1270 const_reverse_iterator crend() const _NOEXCEPT
1271 {return const_reverse_iterator(__base::begin());}
1274 _LIBCPP_INLINE_VISIBILITY
1275 size_type size() const _NOEXCEPT {return __base::size();}
1276 _LIBCPP_INLINE_VISIBILITY
1277 size_type max_size() const _NOEXCEPT
1278 {return __alloc_traits::max_size(__base::__alloc());}
1279 void resize(size_type __n);
1280 void resize(size_type __n, const value_type& __v);
1281 void shrink_to_fit() _NOEXCEPT;
1282 _LIBCPP_INLINE_VISIBILITY
1283 bool empty() const _NOEXCEPT {return __base::size() == 0;}
1286 reference operator[](size_type __i);
1287 const_reference operator[](size_type __i) const;
1288 reference at(size_type __i);
1289 const_reference at(size_type __i) const;
1291 const_reference front() const;
1293 const_reference back() const;
1295 // 23.2.2.3 modifiers:
1296 void push_front(const value_type& __v);
1297 void push_back(const value_type& __v);
1298 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1299 #ifndef _LIBCPP_HAS_NO_VARIADICS
1300 template <class... _Args> void emplace_front(_Args&&... __args);
1301 template <class... _Args> void emplace_back(_Args&&... __args);
1302 template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args);
1303 #endif // _LIBCPP_HAS_NO_VARIADICS
1304 void push_front(value_type&& __v);
1305 void push_back(value_type&& __v);
1306 iterator insert(const_iterator __p, value_type&& __v);
1307 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1308 iterator insert(const_iterator __p, const value_type& __v);
1309 iterator insert(const_iterator __p, size_type __n, const value_type& __v);
1310 template <class _InputIter>
1311 iterator insert(const_iterator __p, _InputIter __f, _InputIter __l,
1312 typename enable_if<__is_input_iterator<_InputIter>::value
1313 &&!__is_forward_iterator<_InputIter>::value>::type* = 0);
1314 template <class _ForwardIterator>
1315 iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l,
1316 typename enable_if<__is_forward_iterator<_ForwardIterator>::value
1317 &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type* = 0);
1318 template <class _BiIter>
1319 iterator insert(const_iterator __p, _BiIter __f, _BiIter __l,
1320 typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0);
1321 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1322 _LIBCPP_INLINE_VISIBILITY
1323 iterator insert(const_iterator __p, initializer_list<value_type> __il)
1324 {return insert(__p, __il.begin(), __il.end());}
1325 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1328 iterator erase(const_iterator __p);
1329 iterator erase(const_iterator __f, const_iterator __l);
1331 void swap(deque& __c)
1332 #if _LIBCPP_STD_VER >= 14
1335 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1336 __is_nothrow_swappable<allocator_type>::value);
1338 void clear() _NOEXCEPT;
1340 _LIBCPP_INLINE_VISIBILITY
1341 bool __invariants() const {return __base::__invariants();}
1343 typedef typename __base::__map_const_pointer __map_const_pointer;
1345 _LIBCPP_INLINE_VISIBILITY
1346 static size_type __recommend_blocks(size_type __n)
1348 return __n / __base::__block_size + (__n % __base::__block_size != 0);
1350 _LIBCPP_INLINE_VISIBILITY
1351 size_type __capacity() const
1353 return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1;
1355 _LIBCPP_INLINE_VISIBILITY
1356 size_type __front_spare() const
1358 return __base::__start_;
1360 _LIBCPP_INLINE_VISIBILITY
1361 size_type __back_spare() const
1363 return __capacity() - (__base::__start_ + __base::size());
1366 template <class _InpIter>
1367 void __append(_InpIter __f, _InpIter __l,
1368 typename enable_if<__is_input_iterator<_InpIter>::value &&
1369 !__is_forward_iterator<_InpIter>::value>::type* = 0);
1370 template <class _ForIter>
1371 void __append(_ForIter __f, _ForIter __l,
1372 typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0);
1373 void __append(size_type __n);
1374 void __append(size_type __n, const value_type& __v);
1375 void __erase_to_end(const_iterator __f);
1376 void __add_front_capacity();
1377 void __add_front_capacity(size_type __n);
1378 void __add_back_capacity();
1379 void __add_back_capacity(size_type __n);
1380 iterator __move_and_check(iterator __f, iterator __l, iterator __r,
1381 const_pointer& __vt);
1382 iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r,
1383 const_pointer& __vt);
1384 void __move_construct_and_check(iterator __f, iterator __l,
1385 iterator __r, const_pointer& __vt);
1386 void __move_construct_backward_and_check(iterator __f, iterator __l,
1387 iterator __r, const_pointer& __vt);
1389 _LIBCPP_INLINE_VISIBILITY
1390 void __copy_assign_alloc(const deque& __c)
1391 {__copy_assign_alloc(__c, integral_constant<bool,
1392 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1394 _LIBCPP_INLINE_VISIBILITY
1395 void __copy_assign_alloc(const deque& __c, true_type)
1397 if (__base::__alloc() != __c.__alloc())
1402 __base::__alloc() = __c.__alloc();
1403 __base::__map_.__alloc() = __c.__map_.__alloc();
1406 _LIBCPP_INLINE_VISIBILITY
1407 void __copy_assign_alloc(const deque&, false_type)
1410 void __move_assign(deque& __c, true_type)
1411 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
1412 void __move_assign(deque& __c, false_type);
1415 template <class _Tp, class _Allocator>
1416 deque<_Tp, _Allocator>::deque(size_type __n)
1422 #if _LIBCPP_STD_VER > 11
1423 template <class _Tp, class _Allocator>
1424 deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a)
1432 template <class _Tp, class _Allocator>
1433 deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v)
1439 template <class _Tp, class _Allocator>
1440 deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a)
1447 template <class _Tp, class _Allocator>
1448 template <class _InputIter>
1449 deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l,
1450 typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
1455 template <class _Tp, class _Allocator>
1456 template <class _InputIter>
1457 deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
1458 typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
1464 template <class _Tp, class _Allocator>
1465 deque<_Tp, _Allocator>::deque(const deque& __c)
1466 : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc()))
1468 __append(__c.begin(), __c.end());
1471 template <class _Tp, class _Allocator>
1472 deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a)
1475 __append(__c.begin(), __c.end());
1478 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1480 template <class _Tp, class _Allocator>
1481 deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il)
1483 __append(__il.begin(), __il.end());
1486 template <class _Tp, class _Allocator>
1487 deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a)
1490 __append(__il.begin(), __il.end());
1493 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1495 template <class _Tp, class _Allocator>
1496 deque<_Tp, _Allocator>&
1497 deque<_Tp, _Allocator>::operator=(const deque& __c)
1501 __copy_assign_alloc(__c);
1502 assign(__c.begin(), __c.end());
1507 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1509 template <class _Tp, class _Allocator>
1510 inline _LIBCPP_INLINE_VISIBILITY
1511 deque<_Tp, _Allocator>::deque(deque&& __c)
1512 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1513 : __base(_VSTD::move(__c))
1517 template <class _Tp, class _Allocator>
1518 inline _LIBCPP_INLINE_VISIBILITY
1519 deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a)
1520 : __base(_VSTD::move(__c), __a)
1522 if (__a != __c.__alloc())
1524 typedef move_iterator<iterator> _Ip;
1525 assign(_Ip(__c.begin()), _Ip(__c.end()));
1529 template <class _Tp, class _Allocator>
1530 inline _LIBCPP_INLINE_VISIBILITY
1531 deque<_Tp, _Allocator>&
1532 deque<_Tp, _Allocator>::operator=(deque&& __c)
1533 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1534 is_nothrow_move_assignable<allocator_type>::value)
1536 __move_assign(__c, integral_constant<bool,
1537 __alloc_traits::propagate_on_container_move_assignment::value>());
1541 template <class _Tp, class _Allocator>
1543 deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type)
1545 if (__base::__alloc() != __c.__alloc())
1547 typedef move_iterator<iterator> _Ip;
1548 assign(_Ip(__c.begin()), _Ip(__c.end()));
1551 __move_assign(__c, true_type());
1554 template <class _Tp, class _Allocator>
1556 deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type)
1557 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1561 __base::__move_assign(__c);
1564 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1566 template <class _Tp, class _Allocator>
1567 template <class _InputIter>
1569 deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l,
1570 typename enable_if<__is_input_iterator<_InputIter>::value &&
1571 !__is_random_access_iterator<_InputIter>::value>::type*)
1573 iterator __i = __base::begin();
1574 iterator __e = __base::end();
1575 for (; __f != __l && __i != __e; ++__f, (void) ++__i)
1580 __erase_to_end(__i);
1583 template <class _Tp, class _Allocator>
1584 template <class _RAIter>
1586 deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l,
1587 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
1589 if (static_cast<size_type>(__l - __f) > __base::size())
1591 _RAIter __m = __f + __base::size();
1592 _VSTD::copy(__f, __m, __base::begin());
1596 __erase_to_end(_VSTD::copy(__f, __l, __base::begin()));
1599 template <class _Tp, class _Allocator>
1601 deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v)
1603 if (__n > __base::size())
1605 _VSTD::fill_n(__base::begin(), __base::size(), __v);
1606 __n -= __base::size();
1610 __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v));
1613 template <class _Tp, class _Allocator>
1614 inline _LIBCPP_INLINE_VISIBILITY
1616 deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT
1618 return __base::__alloc();
1621 template <class _Tp, class _Allocator>
1623 deque<_Tp, _Allocator>::resize(size_type __n)
1625 if (__n > __base::size())
1626 __append(__n - __base::size());
1627 else if (__n < __base::size())
1628 __erase_to_end(__base::begin() + __n);
1631 template <class _Tp, class _Allocator>
1633 deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v)
1635 if (__n > __base::size())
1636 __append(__n - __base::size(), __v);
1637 else if (__n < __base::size())
1638 __erase_to_end(__base::begin() + __n);
1641 template <class _Tp, class _Allocator>
1643 deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1645 allocator_type& __a = __base::__alloc();
1648 while (__base::__map_.size() > 0)
1650 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
1651 __base::__map_.pop_back();
1653 __base::__start_ = 0;
1657 if (__front_spare() >= __base::__block_size)
1659 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
1660 __base::__map_.pop_front();
1661 __base::__start_ -= __base::__block_size;
1663 if (__back_spare() >= __base::__block_size)
1665 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
1666 __base::__map_.pop_back();
1669 __base::__map_.shrink_to_fit();
1672 template <class _Tp, class _Allocator>
1673 inline _LIBCPP_INLINE_VISIBILITY
1674 typename deque<_Tp, _Allocator>::reference
1675 deque<_Tp, _Allocator>::operator[](size_type __i)
1677 size_type __p = __base::__start_ + __i;
1678 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1681 template <class _Tp, class _Allocator>
1682 inline _LIBCPP_INLINE_VISIBILITY
1683 typename deque<_Tp, _Allocator>::const_reference
1684 deque<_Tp, _Allocator>::operator[](size_type __i) const
1686 size_type __p = __base::__start_ + __i;
1687 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1690 template <class _Tp, class _Allocator>
1691 inline _LIBCPP_INLINE_VISIBILITY
1692 typename deque<_Tp, _Allocator>::reference
1693 deque<_Tp, _Allocator>::at(size_type __i)
1695 if (__i >= __base::size())
1696 __base::__throw_out_of_range();
1697 size_type __p = __base::__start_ + __i;
1698 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1701 template <class _Tp, class _Allocator>
1702 inline _LIBCPP_INLINE_VISIBILITY
1703 typename deque<_Tp, _Allocator>::const_reference
1704 deque<_Tp, _Allocator>::at(size_type __i) const
1706 if (__i >= __base::size())
1707 __base::__throw_out_of_range();
1708 size_type __p = __base::__start_ + __i;
1709 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1712 template <class _Tp, class _Allocator>
1713 inline _LIBCPP_INLINE_VISIBILITY
1714 typename deque<_Tp, _Allocator>::reference
1715 deque<_Tp, _Allocator>::front()
1717 return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
1718 + __base::__start_ % __base::__block_size);
1721 template <class _Tp, class _Allocator>
1722 inline _LIBCPP_INLINE_VISIBILITY
1723 typename deque<_Tp, _Allocator>::const_reference
1724 deque<_Tp, _Allocator>::front() const
1726 return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
1727 + __base::__start_ % __base::__block_size);
1730 template <class _Tp, class _Allocator>
1731 inline _LIBCPP_INLINE_VISIBILITY
1732 typename deque<_Tp, _Allocator>::reference
1733 deque<_Tp, _Allocator>::back()
1735 size_type __p = __base::size() + __base::__start_ - 1;
1736 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1739 template <class _Tp, class _Allocator>
1740 inline _LIBCPP_INLINE_VISIBILITY
1741 typename deque<_Tp, _Allocator>::const_reference
1742 deque<_Tp, _Allocator>::back() const
1744 size_type __p = __base::size() + __base::__start_ - 1;
1745 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1748 template <class _Tp, class _Allocator>
1750 deque<_Tp, _Allocator>::push_back(const value_type& __v)
1752 allocator_type& __a = __base::__alloc();
1753 if (__back_spare() == 0)
1754 __add_back_capacity();
1755 // __back_spare() >= 1
1756 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v);
1760 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1762 template <class _Tp, class _Allocator>
1764 deque<_Tp, _Allocator>::push_back(value_type&& __v)
1766 allocator_type& __a = __base::__alloc();
1767 if (__back_spare() == 0)
1768 __add_back_capacity();
1769 // __back_spare() >= 1
1770 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v));
1774 #ifndef _LIBCPP_HAS_NO_VARIADICS
1776 template <class _Tp, class _Allocator>
1777 template <class... _Args>
1779 deque<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1781 allocator_type& __a = __base::__alloc();
1782 if (__back_spare() == 0)
1783 __add_back_capacity();
1784 // __back_spare() >= 1
1785 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...);
1789 #endif // _LIBCPP_HAS_NO_VARIADICS
1790 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1792 template <class _Tp, class _Allocator>
1794 deque<_Tp, _Allocator>::push_front(const value_type& __v)
1796 allocator_type& __a = __base::__alloc();
1797 if (__front_spare() == 0)
1798 __add_front_capacity();
1799 // __front_spare() >= 1
1800 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v);
1805 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1807 template <class _Tp, class _Allocator>
1809 deque<_Tp, _Allocator>::push_front(value_type&& __v)
1811 allocator_type& __a = __base::__alloc();
1812 if (__front_spare() == 0)
1813 __add_front_capacity();
1814 // __front_spare() >= 1
1815 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v));
1820 #ifndef _LIBCPP_HAS_NO_VARIADICS
1822 template <class _Tp, class _Allocator>
1823 template <class... _Args>
1825 deque<_Tp, _Allocator>::emplace_front(_Args&&... __args)
1827 allocator_type& __a = __base::__alloc();
1828 if (__front_spare() == 0)
1829 __add_front_capacity();
1830 // __front_spare() >= 1
1831 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...);
1836 #endif // _LIBCPP_HAS_NO_VARIADICS
1837 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1839 template <class _Tp, class _Allocator>
1840 typename deque<_Tp, _Allocator>::iterator
1841 deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v)
1843 size_type __pos = __p - __base::begin();
1844 size_type __to_end = __base::size() - __pos;
1845 allocator_type& __a = __base::__alloc();
1846 if (__pos < __to_end)
1847 { // insert by shifting things backward
1848 if (__front_spare() == 0)
1849 __add_front_capacity();
1850 // __front_spare() >= 1
1853 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v);
1859 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
1860 iterator __b = __base::begin();
1861 iterator __bm1 = _VSTD::prev(__b);
1862 if (__vt == pointer_traits<const_pointer>::pointer_to(*__b))
1863 __vt = pointer_traits<const_pointer>::pointer_to(*__bm1);
1864 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
1868 __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt);
1873 { // insert by shifting things forward
1874 if (__back_spare() == 0)
1875 __add_back_capacity();
1876 // __back_capacity >= 1
1877 size_type __de = __base::size() - __pos;
1880 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v);
1885 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
1886 iterator __e = __base::end();
1887 iterator __em1 = _VSTD::prev(__e);
1888 if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1))
1889 __vt = pointer_traits<const_pointer>::pointer_to(*__e);
1890 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
1893 __e = __move_backward_and_check(__e - __de, __em1, __e, __vt);
1897 return __base::begin() + __pos;
1900 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1902 template <class _Tp, class _Allocator>
1903 typename deque<_Tp, _Allocator>::iterator
1904 deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v)
1906 size_type __pos = __p - __base::begin();
1907 size_type __to_end = __base::size() - __pos;
1908 allocator_type& __a = __base::__alloc();
1909 if (__pos < __to_end)
1910 { // insert by shifting things backward
1911 if (__front_spare() == 0)
1912 __add_front_capacity();
1913 // __front_spare() >= 1
1916 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v));
1922 iterator __b = __base::begin();
1923 iterator __bm1 = _VSTD::prev(__b);
1924 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
1928 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
1929 *__b = _VSTD::move(__v);
1933 { // insert by shifting things forward
1934 if (__back_spare() == 0)
1935 __add_back_capacity();
1936 // __back_capacity >= 1
1937 size_type __de = __base::size() - __pos;
1940 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v));
1945 iterator __e = __base::end();
1946 iterator __em1 = _VSTD::prev(__e);
1947 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
1950 __e = _VSTD::move_backward(__e - __de, __em1, __e);
1951 *--__e = _VSTD::move(__v);
1954 return __base::begin() + __pos;
1957 #ifndef _LIBCPP_HAS_NO_VARIADICS
1959 template <class _Tp, class _Allocator>
1960 template <class... _Args>
1961 typename deque<_Tp, _Allocator>::iterator
1962 deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args)
1964 size_type __pos = __p - __base::begin();
1965 size_type __to_end = __base::size() - __pos;
1966 allocator_type& __a = __base::__alloc();
1967 if (__pos < __to_end)
1968 { // insert by shifting things backward
1969 if (__front_spare() == 0)
1970 __add_front_capacity();
1971 // __front_spare() >= 1
1974 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...);
1980 value_type __tmp(_VSTD::forward<_Args>(__args)...);
1981 iterator __b = __base::begin();
1982 iterator __bm1 = _VSTD::prev(__b);
1983 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
1987 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
1988 *__b = _VSTD::move(__tmp);
1992 { // insert by shifting things forward
1993 if (__back_spare() == 0)
1994 __add_back_capacity();
1995 // __back_capacity >= 1
1996 size_type __de = __base::size() - __pos;
1999 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...);
2004 value_type __tmp(_VSTD::forward<_Args>(__args)...);
2005 iterator __e = __base::end();
2006 iterator __em1 = _VSTD::prev(__e);
2007 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
2010 __e = _VSTD::move_backward(__e - __de, __em1, __e);
2011 *--__e = _VSTD::move(__tmp);
2014 return __base::begin() + __pos;
2017 #endif // _LIBCPP_HAS_NO_VARIADICS
2018 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2020 template <class _Tp, class _Allocator>
2021 typename deque<_Tp, _Allocator>::iterator
2022 deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v)
2024 size_type __pos = __p - __base::begin();
2025 size_type __to_end = __base::size() - __pos;
2026 allocator_type& __a = __base::__alloc();
2027 if (__pos < __to_end)
2028 { // insert by shifting things backward
2029 if (__n > __front_spare())
2030 __add_front_capacity(__n - __front_spare());
2031 // __n <= __front_spare()
2032 iterator __old_begin = __base::begin();
2033 iterator __i = __old_begin;
2036 for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size())
2037 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v);
2042 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
2043 iterator __obn = __old_begin + __n;
2044 __move_construct_backward_and_check(__old_begin, __obn, __i, __vt);
2046 __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt);
2047 _VSTD::fill_n(__old_begin, __n, *__vt);
2051 { // insert by shifting things forward
2052 size_type __back_capacity = __back_spare();
2053 if (__n > __back_capacity)
2054 __add_back_capacity(__n - __back_capacity);
2055 // __n <= __back_capacity
2056 iterator __old_end = __base::end();
2057 iterator __i = __old_end;
2058 size_type __de = __base::size() - __pos;
2061 for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size())
2062 __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v);
2067 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
2068 iterator __oen = __old_end - __n;
2069 __move_construct_and_check(__oen, __old_end, __i, __vt);
2071 __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt);
2072 _VSTD::fill_n(__old_end - __n, __n, *__vt);
2075 return __base::begin() + __pos;
2078 template <class _Tp, class _Allocator>
2079 template <class _InputIter>
2080 typename deque<_Tp, _Allocator>::iterator
2081 deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l,
2082 typename enable_if<__is_input_iterator<_InputIter>::value
2083 &&!__is_forward_iterator<_InputIter>::value>::type*)
2085 __split_buffer<value_type, allocator_type&> __buf(__base::__alloc());
2086 __buf.__construct_at_end(__f, __l);
2087 typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi;
2088 return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end()));
2091 template <class _Tp, class _Allocator>
2092 template <class _ForwardIterator>
2093 typename deque<_Tp, _Allocator>::iterator
2094 deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l,
2095 typename enable_if<__is_forward_iterator<_ForwardIterator>::value
2096 &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type*)
2098 size_type __n = _VSTD::distance(__f, __l);
2099 __split_buffer<value_type, allocator_type&> __buf(__n, 0, __base::__alloc());
2100 __buf.__construct_at_end(__f, __l);
2101 typedef typename __split_buffer<value_type, allocator_type&>::iterator __fwd;
2102 return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end()));
2105 template <class _Tp, class _Allocator>
2106 template <class _BiIter>
2107 typename deque<_Tp, _Allocator>::iterator
2108 deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l,
2109 typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*)
2111 size_type __n = _VSTD::distance(__f, __l);
2112 size_type __pos = __p - __base::begin();
2113 size_type __to_end = __base::size() - __pos;
2114 allocator_type& __a = __base::__alloc();
2115 if (__pos < __to_end)
2116 { // insert by shifting things backward
2117 if (__n > __front_spare())
2118 __add_front_capacity(__n - __front_spare());
2119 // __n <= __front_spare()
2120 iterator __old_begin = __base::begin();
2121 iterator __i = __old_begin;
2125 __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos);
2126 for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size())
2127 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j);
2132 iterator __obn = __old_begin + __n;
2133 for (iterator __j = __obn; __j != __old_begin;)
2135 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j));
2140 __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin);
2141 _VSTD::copy(__m, __l, __old_begin);
2145 { // insert by shifting things forward
2146 size_type __back_capacity = __back_spare();
2147 if (__n > __back_capacity)
2148 __add_back_capacity(__n - __back_capacity);
2149 // __n <= __back_capacity
2150 iterator __old_end = __base::end();
2151 iterator __i = __old_end;
2153 size_type __de = __base::size() - __pos;
2156 __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de);
2157 for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size())
2158 __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j);
2163 iterator __oen = __old_end - __n;
2164 for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size())
2165 __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j));
2167 __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end);
2168 _VSTD::copy_backward(__f, __m, __old_end);
2171 return __base::begin() + __pos;
2174 template <class _Tp, class _Allocator>
2175 template <class _InpIter>
2177 deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l,
2178 typename enable_if<__is_input_iterator<_InpIter>::value &&
2179 !__is_forward_iterator<_InpIter>::value>::type*)
2181 for (; __f != __l; ++__f)
2185 template <class _Tp, class _Allocator>
2186 template <class _ForIter>
2188 deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l,
2189 typename enable_if<__is_forward_iterator<_ForIter>::value>::type*)
2191 size_type __n = _VSTD::distance(__f, __l);
2192 allocator_type& __a = __base::__alloc();
2193 size_type __back_capacity = __back_spare();
2194 if (__n > __back_capacity)
2195 __add_back_capacity(__n - __back_capacity);
2196 // __n <= __back_capacity
2197 for (iterator __i = __base::end(); __f != __l; ++__i, (void) ++__f, ++__base::size())
2198 __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__f);
2201 template <class _Tp, class _Allocator>
2203 deque<_Tp, _Allocator>::__append(size_type __n)
2205 allocator_type& __a = __base::__alloc();
2206 size_type __back_capacity = __back_spare();
2207 if (__n > __back_capacity)
2208 __add_back_capacity(__n - __back_capacity);
2209 // __n <= __back_capacity
2210 for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size())
2211 __alloc_traits::construct(__a, _VSTD::addressof(*__i));
2214 template <class _Tp, class _Allocator>
2216 deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v)
2218 allocator_type& __a = __base::__alloc();
2219 size_type __back_capacity = __back_spare();
2220 if (__n > __back_capacity)
2221 __add_back_capacity(__n - __back_capacity);
2222 // __n <= __back_capacity
2223 for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size())
2224 __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v);
2227 // Create front capacity for one block of elements.
2228 // Strong guarantee. Either do it or don't touch anything.
2229 template <class _Tp, class _Allocator>
2231 deque<_Tp, _Allocator>::__add_front_capacity()
2233 allocator_type& __a = __base::__alloc();
2234 if (__back_spare() >= __base::__block_size)
2236 __base::__start_ += __base::__block_size;
2237 pointer __pt = __base::__map_.back();
2238 __base::__map_.pop_back();
2239 __base::__map_.push_front(__pt);
2241 // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer
2242 else if (__base::__map_.size() < __base::__map_.capacity())
2243 { // we can put the new buffer into the map, but don't shift things around
2244 // until all buffers are allocated. If we throw, we don't need to fix
2245 // anything up (any added buffers are undetectible)
2246 if (__base::__map_.__front_spare() > 0)
2247 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2250 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2251 // Done allocating, reorder capacity
2252 pointer __pt = __base::__map_.back();
2253 __base::__map_.pop_back();
2254 __base::__map_.push_front(__pt);
2256 __base::__start_ = __base::__map_.size() == 1 ?
2257 __base::__block_size / 2 :
2258 __base::__start_ + __base::__block_size;
2260 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
2263 __split_buffer<pointer, typename __base::__pointer_allocator&>
2264 __buf(max<size_type>(2 * __base::__map_.capacity(), 1),
2265 0, __base::__map_.__alloc());
2267 typedef __allocator_destructor<_Allocator> _Dp;
2268 unique_ptr<pointer, _Dp> __hold(
2269 __alloc_traits::allocate(__a, __base::__block_size),
2270 _Dp(__a, __base::__block_size));
2271 __buf.push_back(__hold.get());
2274 for (typename __base::__map_pointer __i = __base::__map_.begin();
2275 __i != __base::__map_.end(); ++__i)
2276 __buf.push_back(*__i);
2277 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2278 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2279 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2280 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2281 __base::__start_ = __base::__map_.size() == 1 ?
2282 __base::__block_size / 2 :
2283 __base::__start_ + __base::__block_size;
2287 // Create front capacity for __n elements.
2288 // Strong guarantee. Either do it or don't touch anything.
2289 template <class _Tp, class _Allocator>
2291 deque<_Tp, _Allocator>::__add_front_capacity(size_type __n)
2293 allocator_type& __a = __base::__alloc();
2294 size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
2295 // Number of unused blocks at back:
2296 size_type __back_capacity = __back_spare() / __base::__block_size;
2297 __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need
2298 __nb -= __back_capacity; // number of blocks need to allocate
2299 // If __nb == 0, then we have sufficient capacity.
2302 __base::__start_ += __base::__block_size * __back_capacity;
2303 for (; __back_capacity > 0; --__back_capacity)
2305 pointer __pt = __base::__map_.back();
2306 __base::__map_.pop_back();
2307 __base::__map_.push_front(__pt);
2310 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2311 else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
2312 { // we can put the new buffers into the map, but don't shift things around
2313 // until all buffers are allocated. If we throw, we don't need to fix
2314 // anything up (any added buffers are undetectible)
2315 for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1))
2317 if (__base::__map_.__front_spare() == 0)
2319 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2321 for (; __nb > 0; --__nb, ++__back_capacity)
2322 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2323 // Done allocating, reorder capacity
2324 __base::__start_ += __back_capacity * __base::__block_size;
2325 for (; __back_capacity > 0; --__back_capacity)
2327 pointer __pt = __base::__map_.back();
2328 __base::__map_.pop_back();
2329 __base::__map_.push_front(__pt);
2332 // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
2335 size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty();
2336 __split_buffer<pointer, typename __base::__pointer_allocator&>
2337 __buf(max<size_type>(2* __base::__map_.capacity(),
2338 __nb + __base::__map_.size()),
2339 0, __base::__map_.__alloc());
2340 #ifndef _LIBCPP_NO_EXCEPTIONS
2343 #endif // _LIBCPP_NO_EXCEPTIONS
2344 for (; __nb > 0; --__nb)
2345 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2346 #ifndef _LIBCPP_NO_EXCEPTIONS
2350 for (typename __base::__map_pointer __i = __buf.begin();
2351 __i != __buf.end(); ++__i)
2352 __alloc_traits::deallocate(__a, *__i, __base::__block_size);
2355 #endif // _LIBCPP_NO_EXCEPTIONS
2356 for (; __back_capacity > 0; --__back_capacity)
2358 __buf.push_back(__base::__map_.back());
2359 __base::__map_.pop_back();
2361 for (typename __base::__map_pointer __i = __base::__map_.begin();
2362 __i != __base::__map_.end(); ++__i)
2363 __buf.push_back(*__i);
2364 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2365 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2366 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2367 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2368 __base::__start_ += __ds;
2372 // Create back capacity for one block of elements.
2373 // Strong guarantee. Either do it or don't touch anything.
2374 template <class _Tp, class _Allocator>
2376 deque<_Tp, _Allocator>::__add_back_capacity()
2378 allocator_type& __a = __base::__alloc();
2379 if (__front_spare() >= __base::__block_size)
2381 __base::__start_ -= __base::__block_size;
2382 pointer __pt = __base::__map_.front();
2383 __base::__map_.pop_front();
2384 __base::__map_.push_back(__pt);
2386 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2387 else if (__base::__map_.size() < __base::__map_.capacity())
2388 { // we can put the new buffer into the map, but don't shift things around
2389 // until it is allocated. If we throw, we don't need to fix
2390 // anything up (any added buffers are undetectible)
2391 if (__base::__map_.__back_spare() != 0)
2392 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2395 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2396 // Done allocating, reorder capacity
2397 pointer __pt = __base::__map_.front();
2398 __base::__map_.pop_front();
2399 __base::__map_.push_back(__pt);
2402 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
2405 __split_buffer<pointer, typename __base::__pointer_allocator&>
2406 __buf(max<size_type>(2* __base::__map_.capacity(), 1),
2407 __base::__map_.size(),
2408 __base::__map_.__alloc());
2410 typedef __allocator_destructor<_Allocator> _Dp;
2411 unique_ptr<pointer, _Dp> __hold(
2412 __alloc_traits::allocate(__a, __base::__block_size),
2413 _Dp(__a, __base::__block_size));
2414 __buf.push_back(__hold.get());
2417 for (typename __base::__map_pointer __i = __base::__map_.end();
2418 __i != __base::__map_.begin();)
2419 __buf.push_front(*--__i);
2420 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2421 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2422 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2423 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2427 // Create back capacity for __n elements.
2428 // Strong guarantee. Either do it or don't touch anything.
2429 template <class _Tp, class _Allocator>
2431 deque<_Tp, _Allocator>::__add_back_capacity(size_type __n)
2433 allocator_type& __a = __base::__alloc();
2434 size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
2435 // Number of unused blocks at front:
2436 size_type __front_capacity = __front_spare() / __base::__block_size;
2437 __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need
2438 __nb -= __front_capacity; // number of blocks need to allocate
2439 // If __nb == 0, then we have sufficient capacity.
2442 __base::__start_ -= __base::__block_size * __front_capacity;
2443 for (; __front_capacity > 0; --__front_capacity)
2445 pointer __pt = __base::__map_.front();
2446 __base::__map_.pop_front();
2447 __base::__map_.push_back(__pt);
2450 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2451 else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
2452 { // we can put the new buffers into the map, but don't shift things around
2453 // until all buffers are allocated. If we throw, we don't need to fix
2454 // anything up (any added buffers are undetectible)
2455 for (; __nb > 0; --__nb)
2457 if (__base::__map_.__back_spare() == 0)
2459 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2461 for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ +=
2462 __base::__block_size - (__base::__map_.size() == 1))
2463 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2464 // Done allocating, reorder capacity
2465 __base::__start_ -= __base::__block_size * __front_capacity;
2466 for (; __front_capacity > 0; --__front_capacity)
2468 pointer __pt = __base::__map_.front();
2469 __base::__map_.pop_front();
2470 __base::__map_.push_back(__pt);
2473 // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
2476 size_type __ds = __front_capacity * __base::__block_size;
2477 __split_buffer<pointer, typename __base::__pointer_allocator&>
2478 __buf(max<size_type>(2* __base::__map_.capacity(),
2479 __nb + __base::__map_.size()),
2480 __base::__map_.size() - __front_capacity,
2481 __base::__map_.__alloc());
2482 #ifndef _LIBCPP_NO_EXCEPTIONS
2485 #endif // _LIBCPP_NO_EXCEPTIONS
2486 for (; __nb > 0; --__nb)
2487 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2488 #ifndef _LIBCPP_NO_EXCEPTIONS
2492 for (typename __base::__map_pointer __i = __buf.begin();
2493 __i != __buf.end(); ++__i)
2494 __alloc_traits::deallocate(__a, *__i, __base::__block_size);
2497 #endif // _LIBCPP_NO_EXCEPTIONS
2498 for (; __front_capacity > 0; --__front_capacity)
2500 __buf.push_back(__base::__map_.front());
2501 __base::__map_.pop_front();
2503 for (typename __base::__map_pointer __i = __base::__map_.end();
2504 __i != __base::__map_.begin();)
2505 __buf.push_front(*--__i);
2506 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2507 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2508 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2509 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2510 __base::__start_ -= __ds;
2514 template <class _Tp, class _Allocator>
2516 deque<_Tp, _Allocator>::pop_front()
2518 allocator_type& __a = __base::__alloc();
2519 __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
2520 __base::__start_ / __base::__block_size) +
2521 __base::__start_ % __base::__block_size));
2523 if (++__base::__start_ >= 2 * __base::__block_size)
2525 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2526 __base::__map_.pop_front();
2527 __base::__start_ -= __base::__block_size;
2531 template <class _Tp, class _Allocator>
2533 deque<_Tp, _Allocator>::pop_back()
2535 allocator_type& __a = __base::__alloc();
2536 size_type __p = __base::size() + __base::__start_ - 1;
2537 __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
2538 __p / __base::__block_size) +
2539 __p % __base::__block_size));
2541 if (__back_spare() >= 2 * __base::__block_size)
2543 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2544 __base::__map_.pop_back();
2548 // move assign [__f, __l) to [__r, __r + (__l-__f)).
2549 // If __vt points into [__f, __l), then subtract (__f - __r) from __vt.
2550 template <class _Tp, class _Allocator>
2551 typename deque<_Tp, _Allocator>::iterator
2552 deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r,
2553 const_pointer& __vt)
2556 // for (; __f != __l; ++__f, ++__r)
2557 // *__r = _VSTD::move(*__f);
2558 difference_type __n = __l - __f;
2561 pointer __fb = __f.__ptr_;
2562 pointer __fe = *__f.__m_iter_ + __base::__block_size;
2563 difference_type __bs = __fe - __fb;
2569 if (__fb <= __vt && __vt < __fe)
2570 __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_;
2571 __r = _VSTD::move(__fb, __fe, __r);
2578 // move assign [__f, __l) to [__r - (__l-__f), __r) backwards.
2579 // If __vt points into [__f, __l), then add (__r - __l) to __vt.
2580 template <class _Tp, class _Allocator>
2581 typename deque<_Tp, _Allocator>::iterator
2582 deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r,
2583 const_pointer& __vt)
2586 // while (__f != __l)
2587 // *--__r = _VSTD::move(*--__l);
2588 difference_type __n = __l - __f;
2592 pointer __lb = *__l.__m_iter_;
2593 pointer __le = __l.__ptr_ + 1;
2594 difference_type __bs = __le - __lb;
2600 if (__lb <= __vt && __vt < __le)
2601 __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_;
2602 __r = _VSTD::move_backward(__lb, __le, __r);
2609 // move construct [__f, __l) to [__r, __r + (__l-__f)).
2610 // If __vt points into [__f, __l), then add (__r - __f) to __vt.
2611 template <class _Tp, class _Allocator>
2613 deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l,
2614 iterator __r, const_pointer& __vt)
2616 allocator_type& __a = __base::__alloc();
2618 // for (; __f != __l; ++__r, ++__f, ++__base::size())
2619 // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f));
2620 difference_type __n = __l - __f;
2623 pointer __fb = __f.__ptr_;
2624 pointer __fe = *__f.__m_iter_ + __base::__block_size;
2625 difference_type __bs = __fe - __fb;
2631 if (__fb <= __vt && __vt < __fe)
2632 __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_;
2633 for (; __fb != __fe; ++__fb, ++__r, ++__base::size())
2634 __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb));
2640 // move construct [__f, __l) to [__r - (__l-__f), __r) backwards.
2641 // If __vt points into [__f, __l), then subtract (__l - __r) from __vt.
2642 template <class _Tp, class _Allocator>
2644 deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l,
2645 iterator __r, const_pointer& __vt)
2647 allocator_type& __a = __base::__alloc();
2649 // for (iterator __j = __l; __j != __f;)
2651 // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j));
2652 // --__base::__start_;
2653 // ++__base::size();
2655 difference_type __n = __l - __f;
2659 pointer __lb = *__l.__m_iter_;
2660 pointer __le = __l.__ptr_ + 1;
2661 difference_type __bs = __le - __lb;
2667 if (__lb <= __vt && __vt < __le)
2668 __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_;
2669 while (__le != __lb)
2671 __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le));
2680 template <class _Tp, class _Allocator>
2681 typename deque<_Tp, _Allocator>::iterator
2682 deque<_Tp, _Allocator>::erase(const_iterator __f)
2684 iterator __b = __base::begin();
2685 difference_type __pos = __f - __b;
2686 iterator __p = __b + __pos;
2687 allocator_type& __a = __base::__alloc();
2688 if (__pos <= (__base::size() - 1) / 2)
2689 { // erase from front
2690 _VSTD::move_backward(__b, __p, _VSTD::next(__p));
2691 __alloc_traits::destroy(__a, _VSTD::addressof(*__b));
2694 if (__front_spare() >= 2 * __base::__block_size)
2696 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2697 __base::__map_.pop_front();
2698 __base::__start_ -= __base::__block_size;
2702 { // erase from back
2703 iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p);
2704 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
2706 if (__back_spare() >= 2 * __base::__block_size)
2708 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2709 __base::__map_.pop_back();
2712 return __base::begin() + __pos;
2715 template <class _Tp, class _Allocator>
2716 typename deque<_Tp, _Allocator>::iterator
2717 deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l)
2719 difference_type __n = __l - __f;
2720 iterator __b = __base::begin();
2721 difference_type __pos = __f - __b;
2722 iterator __p = __b + __pos;
2725 allocator_type& __a = __base::__alloc();
2726 if (__pos <= (__base::size() - __n) / 2)
2727 { // erase from front
2728 iterator __i = _VSTD::move_backward(__b, __p, __p + __n);
2729 for (; __b != __i; ++__b)
2730 __alloc_traits::destroy(__a, _VSTD::addressof(*__b));
2731 __base::size() -= __n;
2732 __base::__start_ += __n;
2733 while (__front_spare() >= 2 * __base::__block_size)
2735 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2736 __base::__map_.pop_front();
2737 __base::__start_ -= __base::__block_size;
2741 { // erase from back
2742 iterator __i = _VSTD::move(__p + __n, __base::end(), __p);
2743 for (iterator __e = __base::end(); __i != __e; ++__i)
2744 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
2745 __base::size() -= __n;
2746 while (__back_spare() >= 2 * __base::__block_size)
2748 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2749 __base::__map_.pop_back();
2753 return __base::begin() + __pos;
2756 template <class _Tp, class _Allocator>
2758 deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f)
2760 iterator __e = __base::end();
2761 difference_type __n = __e - __f;
2764 allocator_type& __a = __base::__alloc();
2765 iterator __b = __base::begin();
2766 difference_type __pos = __f - __b;
2767 for (iterator __p = __b + __pos; __p != __e; ++__p)
2768 __alloc_traits::destroy(__a, _VSTD::addressof(*__p));
2769 __base::size() -= __n;
2770 while (__back_spare() >= 2 * __base::__block_size)
2772 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2773 __base::__map_.pop_back();
2778 template <class _Tp, class _Allocator>
2779 inline _LIBCPP_INLINE_VISIBILITY
2781 deque<_Tp, _Allocator>::swap(deque& __c)
2782 #if _LIBCPP_STD_VER >= 14
2785 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2786 __is_nothrow_swappable<allocator_type>::value)
2792 template <class _Tp, class _Allocator>
2793 inline _LIBCPP_INLINE_VISIBILITY
2795 deque<_Tp, _Allocator>::clear() _NOEXCEPT
2800 template <class _Tp, class _Allocator>
2801 inline _LIBCPP_INLINE_VISIBILITY
2803 operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2805 const typename deque<_Tp, _Allocator>::size_type __sz = __x.size();
2806 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
2809 template <class _Tp, class _Allocator>
2810 inline _LIBCPP_INLINE_VISIBILITY
2812 operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2814 return !(__x == __y);
2817 template <class _Tp, class _Allocator>
2818 inline _LIBCPP_INLINE_VISIBILITY
2820 operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2822 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2825 template <class _Tp, class _Allocator>
2826 inline _LIBCPP_INLINE_VISIBILITY
2828 operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2833 template <class _Tp, class _Allocator>
2834 inline _LIBCPP_INLINE_VISIBILITY
2836 operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2838 return !(__x < __y);
2841 template <class _Tp, class _Allocator>
2842 inline _LIBCPP_INLINE_VISIBILITY
2844 operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2846 return !(__y < __x);
2849 template <class _Tp, class _Allocator>
2850 inline _LIBCPP_INLINE_VISIBILITY
2852 swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y)
2853 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2858 _LIBCPP_END_NAMESPACE_STD
2860 #endif // _LIBCPP_DEQUE