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> reference emplace_front(Args&&... args); // reference in C++17
114 template <class... Args> reference emplace_back(Args&&... args); // reference in C++17
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 InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
132 deque(InputIterator, InputIterator, Allocator = Allocator())
133 -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
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);
143 template <class T, class Allocator>
144 bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
145 template <class T, class Allocator>
146 bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
148 // specialized algorithms:
149 template <class T, class Allocator>
150 void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
151 noexcept(noexcept(x.swap(y)));
153 template <class T, class Allocator, class U>
154 void erase(deque<T, Allocator>& c, const U& value); // C++20
155 template <class T, class Allocator, class Predicate>
156 void erase_if(deque<T, Allocator>& c, Predicate pred); // C++20
163 #include <__split_buffer>
164 #include <type_traits>
165 #include <initializer_list>
171 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
172 #pragma GCC system_header
176 #include <__undef_macros>
179 _LIBCPP_BEGIN_NAMESPACE_STD
181 template <class _Tp, class _Allocator> class __deque_base;
182 template <class _Tp, class _Allocator = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS deque;
184 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
185 class _DiffType, _DiffType _BlockSize>
186 class _LIBCPP_TEMPLATE_VIS __deque_iterator;
188 template <class _RAIter,
189 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
190 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
193 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
194 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
196 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
197 class _OutputIterator>
199 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
200 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
201 _OutputIterator __r);
203 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
204 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
205 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
206 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
207 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
208 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
210 template <class _RAIter,
211 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
212 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
213 copy_backward(_RAIter __f,
215 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
216 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
218 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
219 class _OutputIterator>
221 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
222 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
223 _OutputIterator __r);
225 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
226 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
227 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
228 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
229 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
230 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
232 template <class _RAIter,
233 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
234 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
237 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
238 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
240 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
241 class _OutputIterator>
243 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
244 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
245 _OutputIterator __r);
247 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
248 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
249 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
250 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
251 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
252 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
254 template <class _RAIter,
255 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
256 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
257 move_backward(_RAIter __f,
259 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
260 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
262 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
263 class _OutputIterator>
265 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
266 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
267 _OutputIterator __r);
269 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
270 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
271 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
272 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
273 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
274 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
276 template <class _ValueType, class _DiffType>
277 struct __deque_block_size {
278 static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
281 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
282 class _DiffType, _DiffType _BS =
283 #ifdef _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
284 // Keep template parameter to avoid changing all template declarations thoughout
288 __deque_block_size<_ValueType, _DiffType>::value
291 class _LIBCPP_TEMPLATE_VIS __deque_iterator
293 typedef _MapPointer __map_iterator;
295 typedef _Pointer pointer;
296 typedef _DiffType difference_type;
298 __map_iterator __m_iter_;
301 static const difference_type __block_size;
303 typedef _ValueType value_type;
304 typedef random_access_iterator_tag iterator_category;
305 typedef _Reference reference;
307 _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT
308 #if _LIBCPP_STD_VER > 11
309 : __m_iter_(nullptr), __ptr_(nullptr)
313 template <class _Pp, class _Rp, class _MP>
314 _LIBCPP_INLINE_VISIBILITY
315 __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, _BS>& __it,
316 typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT
317 : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {}
319 _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;}
320 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;}
322 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++()
324 if (++__ptr_ - *__m_iter_ == __block_size)
332 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int)
334 __deque_iterator __tmp = *this;
339 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--()
341 if (__ptr_ == *__m_iter_)
344 __ptr_ = *__m_iter_ + __block_size;
350 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int)
352 __deque_iterator __tmp = *this;
357 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n)
361 __n += __ptr_ - *__m_iter_;
364 __m_iter_ += __n / __block_size;
365 __ptr_ = *__m_iter_ + __n % __block_size;
369 difference_type __z = __block_size - 1 - __n;
370 __m_iter_ -= __z / __block_size;
371 __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size);
377 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n)
379 return *this += -__n;
382 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const
384 __deque_iterator __t(*this);
389 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const
391 __deque_iterator __t(*this);
396 _LIBCPP_INLINE_VISIBILITY
397 friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it)
400 _LIBCPP_INLINE_VISIBILITY
401 friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y)
404 return (__x.__m_iter_ - __y.__m_iter_) * __block_size
405 + (__x.__ptr_ - *__x.__m_iter_)
406 - (__y.__ptr_ - *__y.__m_iter_);
410 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
411 {return *(*this + __n);}
413 _LIBCPP_INLINE_VISIBILITY friend
414 bool operator==(const __deque_iterator& __x, const __deque_iterator& __y)
415 {return __x.__ptr_ == __y.__ptr_;}
417 _LIBCPP_INLINE_VISIBILITY friend
418 bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y)
419 {return !(__x == __y);}
421 _LIBCPP_INLINE_VISIBILITY friend
422 bool operator<(const __deque_iterator& __x, const __deque_iterator& __y)
423 {return __x.__m_iter_ < __y.__m_iter_ ||
424 (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);}
426 _LIBCPP_INLINE_VISIBILITY friend
427 bool operator>(const __deque_iterator& __x, const __deque_iterator& __y)
430 _LIBCPP_INLINE_VISIBILITY friend
431 bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y)
432 {return !(__y < __x);}
434 _LIBCPP_INLINE_VISIBILITY friend
435 bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y)
436 {return !(__x < __y);}
439 _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
440 : __m_iter_(__m), __ptr_(__p) {}
442 template <class _Tp, class _Ap> friend class __deque_base;
443 template <class _Tp, class _Ap> friend class _LIBCPP_TEMPLATE_VIS deque;
444 template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp>
445 friend class _LIBCPP_TEMPLATE_VIS __deque_iterator;
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>
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(__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(__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>
476 copy_backward(_RAIter __f,
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 copy_backward(__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 copy_backward(__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>
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(__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(__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);
522 template <class _RAIter,
523 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
525 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
526 move_backward(_RAIter __f,
528 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
529 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
531 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
532 class _OutputIterator>
535 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
536 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
537 _OutputIterator __r);
539 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
540 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
542 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
543 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
544 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
545 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
548 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
549 class _DiffType, _DiffType _BlockSize>
550 const _DiffType __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer,
551 _DiffType, _BlockSize>::__block_size =
552 __deque_block_size<_ValueType, _DiffType>::value;
556 template <class _RAIter,
557 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
558 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
561 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
562 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
564 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
565 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
566 const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size;
569 pointer __rb = __r.__ptr_;
570 pointer __re = *__r.__m_iter_ + __block_size;
571 difference_type __bs = __re - __rb;
572 difference_type __n = __l - __f;
579 _VSTD::copy(__f, __m, __rb);
586 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
587 class _OutputIterator>
589 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
590 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
593 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
594 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
595 const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size;
596 difference_type __n = __l - __f;
599 pointer __fb = __f.__ptr_;
600 pointer __fe = *__f.__m_iter_ + __block_size;
601 difference_type __bs = __fe - __fb;
607 __r = _VSTD::copy(__fb, __fe, __r);
614 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
615 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
616 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
617 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
618 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
619 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
621 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
622 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
623 const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size;
624 difference_type __n = __l - __f;
627 pointer __fb = __f.__ptr_;
628 pointer __fe = *__f.__m_iter_ + __block_size;
629 difference_type __bs = __fe - __fb;
635 __r = _VSTD::copy(__fb, __fe, __r);
644 template <class _RAIter,
645 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
646 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
647 copy_backward(_RAIter __f,
649 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
650 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
652 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
653 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
656 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r);
657 pointer __rb = *__rp.__m_iter_;
658 pointer __re = __rp.__ptr_ + 1;
659 difference_type __bs = __re - __rb;
660 difference_type __n = __l - __f;
667 _VSTD::copy_backward(__m, __l, __re);
674 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
675 class _OutputIterator>
677 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
678 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
681 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
682 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
683 difference_type __n = __l - __f;
687 pointer __lb = *__l.__m_iter_;
688 pointer __le = __l.__ptr_ + 1;
689 difference_type __bs = __le - __lb;
695 __r = _VSTD::copy_backward(__lb, __le, __r);
702 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
703 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
704 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
705 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
706 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
707 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
709 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
710 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
711 difference_type __n = __l - __f;
715 pointer __lb = *__l.__m_iter_;
716 pointer __le = __l.__ptr_ + 1;
717 difference_type __bs = __le - __lb;
723 __r = _VSTD::copy_backward(__lb, __le, __r);
732 template <class _RAIter,
733 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
734 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
737 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
738 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
740 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
741 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
742 const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size;
745 pointer __rb = __r.__ptr_;
746 pointer __re = *__r.__m_iter_ + __block_size;
747 difference_type __bs = __re - __rb;
748 difference_type __n = __l - __f;
755 _VSTD::move(__f, __m, __rb);
762 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
763 class _OutputIterator>
765 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
766 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
769 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
770 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
771 const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size;
772 difference_type __n = __l - __f;
775 pointer __fb = __f.__ptr_;
776 pointer __fe = *__f.__m_iter_ + __block_size;
777 difference_type __bs = __fe - __fb;
783 __r = _VSTD::move(__fb, __fe, __r);
790 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
791 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
792 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
793 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
794 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
795 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
797 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
798 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
799 const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size;
800 difference_type __n = __l - __f;
803 pointer __fb = __f.__ptr_;
804 pointer __fe = *__f.__m_iter_ + __block_size;
805 difference_type __bs = __fe - __fb;
811 __r = _VSTD::move(__fb, __fe, __r);
820 template <class _RAIter,
821 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
822 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
823 move_backward(_RAIter __f,
825 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
826 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
828 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
829 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
832 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r);
833 pointer __rb = *__rp.__m_iter_;
834 pointer __re = __rp.__ptr_ + 1;
835 difference_type __bs = __re - __rb;
836 difference_type __n = __l - __f;
843 _VSTD::move_backward(__m, __l, __re);
850 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
851 class _OutputIterator>
853 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
854 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
857 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
858 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
859 difference_type __n = __l - __f;
863 pointer __lb = *__l.__m_iter_;
864 pointer __le = __l.__ptr_ + 1;
865 difference_type __bs = __le - __lb;
871 __r = _VSTD::move_backward(__lb, __le, __r);
878 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
879 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
880 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
881 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
882 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
883 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
885 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
886 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
887 difference_type __n = __l - __f;
891 pointer __lb = *__l.__m_iter_;
892 pointer __le = __l.__ptr_ + 1;
893 difference_type __bs = __le - __lb;
899 __r = _VSTD::move_backward(__lb, __le, __r);
907 class __deque_base_common
910 _LIBCPP_NORETURN void __throw_length_error() const;
911 _LIBCPP_NORETURN void __throw_out_of_range() const;
916 __deque_base_common<__b>::__throw_length_error() const
918 _VSTD::__throw_length_error("deque");
923 __deque_base_common<__b>::__throw_out_of_range() const
925 _VSTD::__throw_out_of_range("deque");
928 template <class _Tp, class _Allocator>
930 : protected __deque_base_common<true>
932 __deque_base(const __deque_base& __c);
933 __deque_base& operator=(const __deque_base& __c);
935 typedef _Allocator allocator_type;
936 typedef allocator_traits<allocator_type> __alloc_traits;
937 typedef typename __alloc_traits::size_type size_type;
939 typedef _Tp value_type;
940 typedef value_type& reference;
941 typedef const value_type& const_reference;
942 typedef typename __alloc_traits::difference_type difference_type;
943 typedef typename __alloc_traits::pointer pointer;
944 typedef typename __alloc_traits::const_pointer const_pointer;
946 static const difference_type __block_size;
948 typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator;
949 typedef allocator_traits<__pointer_allocator> __map_traits;
950 typedef typename __map_traits::pointer __map_pointer;
951 typedef typename __rebind_alloc_helper<__alloc_traits, const_pointer>::type __const_pointer_allocator;
952 typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer;
953 typedef __split_buffer<pointer, __pointer_allocator> __map;
955 typedef __deque_iterator<value_type, pointer, reference, __map_pointer,
956 difference_type> iterator;
957 typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer,
958 difference_type> const_iterator;
963 __compressed_pair<size_type, allocator_type> __size_;
965 iterator begin() _NOEXCEPT;
966 const_iterator begin() const _NOEXCEPT;
967 iterator end() _NOEXCEPT;
968 const_iterator end() const _NOEXCEPT;
970 _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();}
971 _LIBCPP_INLINE_VISIBILITY
972 const size_type& size() const _NOEXCEPT {return __size_.first();}
973 _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();}
974 _LIBCPP_INLINE_VISIBILITY
975 const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();}
977 _LIBCPP_INLINE_VISIBILITY
979 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
980 _LIBCPP_INLINE_VISIBILITY
981 explicit __deque_base(const allocator_type& __a);
985 #ifndef _LIBCPP_CXX03_LANG
986 __deque_base(__deque_base&& __c)
987 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
988 __deque_base(__deque_base&& __c, const allocator_type& __a);
989 #endif // _LIBCPP_CXX03_LANG
991 void swap(__deque_base& __c)
992 #if _LIBCPP_STD_VER >= 14
995 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
996 __is_nothrow_swappable<allocator_type>::value);
999 void clear() _NOEXCEPT;
1001 bool __invariants() const;
1003 _LIBCPP_INLINE_VISIBILITY
1004 void __move_assign(__deque_base& __c)
1005 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1006 is_nothrow_move_assignable<allocator_type>::value)
1008 __map_ = _VSTD::move(__c.__map_);
1009 __start_ = __c.__start_;
1010 size() = __c.size();
1011 __move_assign_alloc(__c);
1012 __c.__start_ = __c.size() = 0;
1015 _LIBCPP_INLINE_VISIBILITY
1016 void __move_assign_alloc(__deque_base& __c)
1017 _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value ||
1018 is_nothrow_move_assignable<allocator_type>::value)
1019 {__move_assign_alloc(__c, integral_constant<bool,
1020 __alloc_traits::propagate_on_container_move_assignment::value>());}
1023 _LIBCPP_INLINE_VISIBILITY
1024 void __move_assign_alloc(__deque_base& __c, true_type)
1025 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1027 __alloc() = _VSTD::move(__c.__alloc());
1030 _LIBCPP_INLINE_VISIBILITY
1031 void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT
1035 template <class _Tp, class _Allocator>
1036 const typename __deque_base<_Tp, _Allocator>::difference_type
1037 __deque_base<_Tp, _Allocator>::__block_size =
1038 __deque_block_size<value_type, difference_type>::value;
1040 template <class _Tp, class _Allocator>
1042 __deque_base<_Tp, _Allocator>::__invariants() const
1044 if (!__map_.__invariants())
1046 if (__map_.size() >= size_type(-1) / __block_size)
1048 for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end();
1050 if (*__i == nullptr)
1052 if (__map_.size() != 0)
1054 if (size() >= __map_.size() * __block_size)
1056 if (__start_ >= __map_.size() * __block_size - size())
1069 template <class _Tp, class _Allocator>
1070 typename __deque_base<_Tp, _Allocator>::iterator
1071 __deque_base<_Tp, _Allocator>::begin() _NOEXCEPT
1073 __map_pointer __mp = __map_.begin() + __start_ / __block_size;
1074 return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
1077 template <class _Tp, class _Allocator>
1078 typename __deque_base<_Tp, _Allocator>::const_iterator
1079 __deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT
1081 __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size);
1082 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
1085 template <class _Tp, class _Allocator>
1086 typename __deque_base<_Tp, _Allocator>::iterator
1087 __deque_base<_Tp, _Allocator>::end() _NOEXCEPT
1089 size_type __p = size() + __start_;
1090 __map_pointer __mp = __map_.begin() + __p / __block_size;
1091 return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
1094 template <class _Tp, class _Allocator>
1095 typename __deque_base<_Tp, _Allocator>::const_iterator
1096 __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT
1098 size_type __p = size() + __start_;
1099 __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size);
1100 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
1103 template <class _Tp, class _Allocator>
1105 __deque_base<_Tp, _Allocator>::__deque_base()
1106 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1107 : __start_(0), __size_(0) {}
1109 template <class _Tp, class _Allocator>
1111 __deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a)
1112 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {}
1114 template <class _Tp, class _Allocator>
1115 __deque_base<_Tp, _Allocator>::~__deque_base()
1118 typename __map::iterator __i = __map_.begin();
1119 typename __map::iterator __e = __map_.end();
1120 for (; __i != __e; ++__i)
1121 __alloc_traits::deallocate(__alloc(), *__i, __block_size);
1124 #ifndef _LIBCPP_CXX03_LANG
1126 template <class _Tp, class _Allocator>
1127 __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c)
1128 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1129 : __map_(_VSTD::move(__c.__map_)),
1130 __start_(_VSTD::move(__c.__start_)),
1131 __size_(_VSTD::move(__c.__size_))
1137 template <class _Tp, class _Allocator>
1138 __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a)
1139 : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)),
1140 __start_(_VSTD::move(__c.__start_)),
1141 __size_(_VSTD::move(__c.size()), __a)
1143 if (__a == __c.__alloc())
1156 #endif // _LIBCPP_CXX03_LANG
1158 template <class _Tp, class _Allocator>
1160 __deque_base<_Tp, _Allocator>::swap(__deque_base& __c)
1161 #if _LIBCPP_STD_VER >= 14
1164 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1165 __is_nothrow_swappable<allocator_type>::value)
1168 __map_.swap(__c.__map_);
1169 _VSTD::swap(__start_, __c.__start_);
1170 _VSTD::swap(size(), __c.size());
1171 __swap_allocator(__alloc(), __c.__alloc());
1174 template <class _Tp, class _Allocator>
1176 __deque_base<_Tp, _Allocator>::clear() _NOEXCEPT
1178 allocator_type& __a = __alloc();
1179 for (iterator __i = begin(), __e = end(); __i != __e; ++__i)
1180 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
1182 while (__map_.size() > 2)
1184 __alloc_traits::deallocate(__a, __map_.front(), __block_size);
1187 switch (__map_.size())
1190 __start_ = __block_size / 2;
1193 __start_ = __block_size;
1198 template <class _Tp, class _Allocator /*= allocator<_Tp>*/>
1199 class _LIBCPP_TEMPLATE_VIS deque
1200 : private __deque_base<_Tp, _Allocator>
1205 typedef _Tp value_type;
1206 typedef _Allocator allocator_type;
1208 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1209 "Allocator::value_type must be same type as value_type");
1211 typedef __deque_base<value_type, allocator_type> __base;
1213 typedef typename __base::__alloc_traits __alloc_traits;
1214 typedef typename __base::reference reference;
1215 typedef typename __base::const_reference const_reference;
1216 typedef typename __base::iterator iterator;
1217 typedef typename __base::const_iterator const_iterator;
1218 typedef typename __base::size_type size_type;
1219 typedef typename __base::difference_type difference_type;
1221 typedef typename __base::pointer pointer;
1222 typedef typename __base::const_pointer const_pointer;
1223 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1224 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1226 // construct/copy/destroy:
1227 _LIBCPP_INLINE_VISIBILITY
1229 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1231 _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {}
1232 explicit deque(size_type __n);
1233 #if _LIBCPP_STD_VER > 11
1234 explicit deque(size_type __n, const _Allocator& __a);
1236 deque(size_type __n, const value_type& __v);
1237 deque(size_type __n, const value_type& __v, const allocator_type& __a);
1238 template <class _InputIter>
1239 deque(_InputIter __f, _InputIter __l,
1240 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
1241 template <class _InputIter>
1242 deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
1243 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
1244 deque(const deque& __c);
1245 deque(const deque& __c, const allocator_type& __a);
1247 deque& operator=(const deque& __c);
1249 #ifndef _LIBCPP_CXX03_LANG
1250 deque(initializer_list<value_type> __il);
1251 deque(initializer_list<value_type> __il, const allocator_type& __a);
1253 _LIBCPP_INLINE_VISIBILITY
1254 deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;}
1256 _LIBCPP_INLINE_VISIBILITY
1257 deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value);
1258 _LIBCPP_INLINE_VISIBILITY
1259 deque(deque&& __c, const allocator_type& __a);
1260 _LIBCPP_INLINE_VISIBILITY
1261 deque& operator=(deque&& __c)
1262 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1263 is_nothrow_move_assignable<allocator_type>::value);
1265 _LIBCPP_INLINE_VISIBILITY
1266 void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());}
1267 #endif // _LIBCPP_CXX03_LANG
1269 template <class _InputIter>
1270 void assign(_InputIter __f, _InputIter __l,
1271 typename enable_if<__is_input_iterator<_InputIter>::value &&
1272 !__is_random_access_iterator<_InputIter>::value>::type* = 0);
1273 template <class _RAIter>
1274 void assign(_RAIter __f, _RAIter __l,
1275 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
1276 void assign(size_type __n, const value_type& __v);
1278 _LIBCPP_INLINE_VISIBILITY
1279 allocator_type get_allocator() const _NOEXCEPT;
1283 _LIBCPP_INLINE_VISIBILITY
1284 iterator begin() _NOEXCEPT {return __base::begin();}
1285 _LIBCPP_INLINE_VISIBILITY
1286 const_iterator begin() const _NOEXCEPT {return __base::begin();}
1287 _LIBCPP_INLINE_VISIBILITY
1288 iterator end() _NOEXCEPT {return __base::end();}
1289 _LIBCPP_INLINE_VISIBILITY
1290 const_iterator end() const _NOEXCEPT {return __base::end();}
1292 _LIBCPP_INLINE_VISIBILITY
1293 reverse_iterator rbegin() _NOEXCEPT
1294 {return reverse_iterator(__base::end());}
1295 _LIBCPP_INLINE_VISIBILITY
1296 const_reverse_iterator rbegin() const _NOEXCEPT
1297 {return const_reverse_iterator(__base::end());}
1298 _LIBCPP_INLINE_VISIBILITY
1299 reverse_iterator rend() _NOEXCEPT
1300 {return reverse_iterator(__base::begin());}
1301 _LIBCPP_INLINE_VISIBILITY
1302 const_reverse_iterator rend() const _NOEXCEPT
1303 {return const_reverse_iterator(__base::begin());}
1305 _LIBCPP_INLINE_VISIBILITY
1306 const_iterator cbegin() const _NOEXCEPT
1307 {return __base::begin();}
1308 _LIBCPP_INLINE_VISIBILITY
1309 const_iterator cend() const _NOEXCEPT
1310 {return __base::end();}
1311 _LIBCPP_INLINE_VISIBILITY
1312 const_reverse_iterator crbegin() const _NOEXCEPT
1313 {return const_reverse_iterator(__base::end());}
1314 _LIBCPP_INLINE_VISIBILITY
1315 const_reverse_iterator crend() const _NOEXCEPT
1316 {return const_reverse_iterator(__base::begin());}
1319 _LIBCPP_INLINE_VISIBILITY
1320 size_type size() const _NOEXCEPT {return __base::size();}
1321 _LIBCPP_INLINE_VISIBILITY
1322 size_type max_size() const _NOEXCEPT
1323 {return std::min<size_type>(
1324 __alloc_traits::max_size(__base::__alloc()),
1325 numeric_limits<difference_type>::max());}
1326 void resize(size_type __n);
1327 void resize(size_type __n, const value_type& __v);
1328 void shrink_to_fit() _NOEXCEPT;
1329 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1330 bool empty() const _NOEXCEPT {return __base::size() == 0;}
1333 _LIBCPP_INLINE_VISIBILITY
1334 reference operator[](size_type __i);
1335 _LIBCPP_INLINE_VISIBILITY
1336 const_reference operator[](size_type __i) const;
1337 _LIBCPP_INLINE_VISIBILITY
1338 reference at(size_type __i);
1339 _LIBCPP_INLINE_VISIBILITY
1340 const_reference at(size_type __i) const;
1341 _LIBCPP_INLINE_VISIBILITY
1343 _LIBCPP_INLINE_VISIBILITY
1344 const_reference front() const;
1345 _LIBCPP_INLINE_VISIBILITY
1347 _LIBCPP_INLINE_VISIBILITY
1348 const_reference back() const;
1350 // 23.2.2.3 modifiers:
1351 void push_front(const value_type& __v);
1352 void push_back(const value_type& __v);
1353 #ifndef _LIBCPP_CXX03_LANG
1354 #if _LIBCPP_STD_VER > 14
1355 template <class... _Args> reference emplace_front(_Args&&... __args);
1356 template <class... _Args> reference emplace_back (_Args&&... __args);
1358 template <class... _Args> void emplace_front(_Args&&... __args);
1359 template <class... _Args> void emplace_back (_Args&&... __args);
1361 template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args);
1363 void push_front(value_type&& __v);
1364 void push_back(value_type&& __v);
1365 iterator insert(const_iterator __p, value_type&& __v);
1367 _LIBCPP_INLINE_VISIBILITY
1368 iterator insert(const_iterator __p, initializer_list<value_type> __il)
1369 {return insert(__p, __il.begin(), __il.end());}
1370 #endif // _LIBCPP_CXX03_LANG
1371 iterator insert(const_iterator __p, const value_type& __v);
1372 iterator insert(const_iterator __p, size_type __n, const value_type& __v);
1373 template <class _InputIter>
1374 iterator insert(const_iterator __p, _InputIter __f, _InputIter __l,
1375 typename enable_if<__is_input_iterator<_InputIter>::value
1376 &&!__is_forward_iterator<_InputIter>::value>::type* = 0);
1377 template <class _ForwardIterator>
1378 iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l,
1379 typename enable_if<__is_forward_iterator<_ForwardIterator>::value
1380 &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type* = 0);
1381 template <class _BiIter>
1382 iterator insert(const_iterator __p, _BiIter __f, _BiIter __l,
1383 typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0);
1387 iterator erase(const_iterator __p);
1388 iterator erase(const_iterator __f, const_iterator __l);
1390 _LIBCPP_INLINE_VISIBILITY
1391 void swap(deque& __c)
1392 #if _LIBCPP_STD_VER >= 14
1395 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1396 __is_nothrow_swappable<allocator_type>::value);
1398 _LIBCPP_INLINE_VISIBILITY
1399 void clear() _NOEXCEPT;
1401 _LIBCPP_INLINE_VISIBILITY
1402 bool __invariants() const {return __base::__invariants();}
1404 typedef typename __base::__map_const_pointer __map_const_pointer;
1406 _LIBCPP_INLINE_VISIBILITY
1407 static size_type __recommend_blocks(size_type __n)
1409 return __n / __base::__block_size + (__n % __base::__block_size != 0);
1411 _LIBCPP_INLINE_VISIBILITY
1412 size_type __capacity() const
1414 return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1;
1416 _LIBCPP_INLINE_VISIBILITY
1417 size_type __front_spare() const
1419 return __base::__start_;
1421 _LIBCPP_INLINE_VISIBILITY
1422 size_type __back_spare() const
1424 return __capacity() - (__base::__start_ + __base::size());
1427 template <class _InpIter>
1428 void __append(_InpIter __f, _InpIter __l,
1429 typename enable_if<__is_input_iterator<_InpIter>::value &&
1430 !__is_forward_iterator<_InpIter>::value>::type* = 0);
1431 template <class _ForIter>
1432 void __append(_ForIter __f, _ForIter __l,
1433 typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0);
1434 void __append(size_type __n);
1435 void __append(size_type __n, const value_type& __v);
1436 void __erase_to_end(const_iterator __f);
1437 void __add_front_capacity();
1438 void __add_front_capacity(size_type __n);
1439 void __add_back_capacity();
1440 void __add_back_capacity(size_type __n);
1441 iterator __move_and_check(iterator __f, iterator __l, iterator __r,
1442 const_pointer& __vt);
1443 iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r,
1444 const_pointer& __vt);
1445 void __move_construct_and_check(iterator __f, iterator __l,
1446 iterator __r, const_pointer& __vt);
1447 void __move_construct_backward_and_check(iterator __f, iterator __l,
1448 iterator __r, const_pointer& __vt);
1450 _LIBCPP_INLINE_VISIBILITY
1451 void __copy_assign_alloc(const deque& __c)
1452 {__copy_assign_alloc(__c, integral_constant<bool,
1453 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1455 _LIBCPP_INLINE_VISIBILITY
1456 void __copy_assign_alloc(const deque& __c, true_type)
1458 if (__base::__alloc() != __c.__alloc())
1463 __base::__alloc() = __c.__alloc();
1464 __base::__map_.__alloc() = __c.__map_.__alloc();
1467 _LIBCPP_INLINE_VISIBILITY
1468 void __copy_assign_alloc(const deque&, false_type)
1471 void __move_assign(deque& __c, true_type)
1472 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
1473 void __move_assign(deque& __c, false_type);
1476 #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1477 template<class _InputIterator,
1478 class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>,
1479 class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
1481 deque(_InputIterator, _InputIterator)
1482 -> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
1484 template<class _InputIterator,
1486 class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
1488 deque(_InputIterator, _InputIterator, _Alloc)
1489 -> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
1493 template <class _Tp, class _Allocator>
1494 deque<_Tp, _Allocator>::deque(size_type __n)
1500 #if _LIBCPP_STD_VER > 11
1501 template <class _Tp, class _Allocator>
1502 deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a)
1510 template <class _Tp, class _Allocator>
1511 deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v)
1517 template <class _Tp, class _Allocator>
1518 deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a)
1525 template <class _Tp, class _Allocator>
1526 template <class _InputIter>
1527 deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l,
1528 typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
1533 template <class _Tp, class _Allocator>
1534 template <class _InputIter>
1535 deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
1536 typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
1542 template <class _Tp, class _Allocator>
1543 deque<_Tp, _Allocator>::deque(const deque& __c)
1544 : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc()))
1546 __append(__c.begin(), __c.end());
1549 template <class _Tp, class _Allocator>
1550 deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a)
1553 __append(__c.begin(), __c.end());
1556 template <class _Tp, class _Allocator>
1557 deque<_Tp, _Allocator>&
1558 deque<_Tp, _Allocator>::operator=(const deque& __c)
1562 __copy_assign_alloc(__c);
1563 assign(__c.begin(), __c.end());
1568 #ifndef _LIBCPP_CXX03_LANG
1570 template <class _Tp, class _Allocator>
1571 deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il)
1573 __append(__il.begin(), __il.end());
1576 template <class _Tp, class _Allocator>
1577 deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a)
1580 __append(__il.begin(), __il.end());
1583 template <class _Tp, class _Allocator>
1585 deque<_Tp, _Allocator>::deque(deque&& __c)
1586 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1587 : __base(_VSTD::move(__c))
1591 template <class _Tp, class _Allocator>
1593 deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a)
1594 : __base(_VSTD::move(__c), __a)
1596 if (__a != __c.__alloc())
1598 typedef move_iterator<iterator> _Ip;
1599 assign(_Ip(__c.begin()), _Ip(__c.end()));
1603 template <class _Tp, class _Allocator>
1605 deque<_Tp, _Allocator>&
1606 deque<_Tp, _Allocator>::operator=(deque&& __c)
1607 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1608 is_nothrow_move_assignable<allocator_type>::value)
1610 __move_assign(__c, integral_constant<bool,
1611 __alloc_traits::propagate_on_container_move_assignment::value>());
1615 template <class _Tp, class _Allocator>
1617 deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type)
1619 if (__base::__alloc() != __c.__alloc())
1621 typedef move_iterator<iterator> _Ip;
1622 assign(_Ip(__c.begin()), _Ip(__c.end()));
1625 __move_assign(__c, true_type());
1628 template <class _Tp, class _Allocator>
1630 deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type)
1631 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1635 __base::__move_assign(__c);
1638 #endif // _LIBCPP_CXX03_LANG
1640 template <class _Tp, class _Allocator>
1641 template <class _InputIter>
1643 deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l,
1644 typename enable_if<__is_input_iterator<_InputIter>::value &&
1645 !__is_random_access_iterator<_InputIter>::value>::type*)
1647 iterator __i = __base::begin();
1648 iterator __e = __base::end();
1649 for (; __f != __l && __i != __e; ++__f, (void) ++__i)
1654 __erase_to_end(__i);
1657 template <class _Tp, class _Allocator>
1658 template <class _RAIter>
1660 deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l,
1661 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
1663 if (static_cast<size_type>(__l - __f) > __base::size())
1665 _RAIter __m = __f + __base::size();
1666 _VSTD::copy(__f, __m, __base::begin());
1670 __erase_to_end(_VSTD::copy(__f, __l, __base::begin()));
1673 template <class _Tp, class _Allocator>
1675 deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v)
1677 if (__n > __base::size())
1679 _VSTD::fill_n(__base::begin(), __base::size(), __v);
1680 __n -= __base::size();
1684 __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v));
1687 template <class _Tp, class _Allocator>
1690 deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT
1692 return __base::__alloc();
1695 template <class _Tp, class _Allocator>
1697 deque<_Tp, _Allocator>::resize(size_type __n)
1699 if (__n > __base::size())
1700 __append(__n - __base::size());
1701 else if (__n < __base::size())
1702 __erase_to_end(__base::begin() + __n);
1705 template <class _Tp, class _Allocator>
1707 deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v)
1709 if (__n > __base::size())
1710 __append(__n - __base::size(), __v);
1711 else if (__n < __base::size())
1712 __erase_to_end(__base::begin() + __n);
1715 template <class _Tp, class _Allocator>
1717 deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1719 allocator_type& __a = __base::__alloc();
1722 while (__base::__map_.size() > 0)
1724 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
1725 __base::__map_.pop_back();
1727 __base::__start_ = 0;
1731 if (__front_spare() >= __base::__block_size)
1733 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
1734 __base::__map_.pop_front();
1735 __base::__start_ -= __base::__block_size;
1737 if (__back_spare() >= __base::__block_size)
1739 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
1740 __base::__map_.pop_back();
1743 __base::__map_.shrink_to_fit();
1746 template <class _Tp, class _Allocator>
1748 typename deque<_Tp, _Allocator>::reference
1749 deque<_Tp, _Allocator>::operator[](size_type __i)
1751 size_type __p = __base::__start_ + __i;
1752 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1755 template <class _Tp, class _Allocator>
1757 typename deque<_Tp, _Allocator>::const_reference
1758 deque<_Tp, _Allocator>::operator[](size_type __i) const
1760 size_type __p = __base::__start_ + __i;
1761 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1764 template <class _Tp, class _Allocator>
1766 typename deque<_Tp, _Allocator>::reference
1767 deque<_Tp, _Allocator>::at(size_type __i)
1769 if (__i >= __base::size())
1770 __base::__throw_out_of_range();
1771 size_type __p = __base::__start_ + __i;
1772 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1775 template <class _Tp, class _Allocator>
1777 typename deque<_Tp, _Allocator>::const_reference
1778 deque<_Tp, _Allocator>::at(size_type __i) const
1780 if (__i >= __base::size())
1781 __base::__throw_out_of_range();
1782 size_type __p = __base::__start_ + __i;
1783 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1786 template <class _Tp, class _Allocator>
1788 typename deque<_Tp, _Allocator>::reference
1789 deque<_Tp, _Allocator>::front()
1791 return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
1792 + __base::__start_ % __base::__block_size);
1795 template <class _Tp, class _Allocator>
1797 typename deque<_Tp, _Allocator>::const_reference
1798 deque<_Tp, _Allocator>::front() const
1800 return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
1801 + __base::__start_ % __base::__block_size);
1804 template <class _Tp, class _Allocator>
1806 typename deque<_Tp, _Allocator>::reference
1807 deque<_Tp, _Allocator>::back()
1809 size_type __p = __base::size() + __base::__start_ - 1;
1810 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1813 template <class _Tp, class _Allocator>
1815 typename deque<_Tp, _Allocator>::const_reference
1816 deque<_Tp, _Allocator>::back() const
1818 size_type __p = __base::size() + __base::__start_ - 1;
1819 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1822 template <class _Tp, class _Allocator>
1824 deque<_Tp, _Allocator>::push_back(const value_type& __v)
1826 allocator_type& __a = __base::__alloc();
1827 if (__back_spare() == 0)
1828 __add_back_capacity();
1829 // __back_spare() >= 1
1830 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v);
1834 template <class _Tp, class _Allocator>
1836 deque<_Tp, _Allocator>::push_front(const value_type& __v)
1838 allocator_type& __a = __base::__alloc();
1839 if (__front_spare() == 0)
1840 __add_front_capacity();
1841 // __front_spare() >= 1
1842 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v);
1847 #ifndef _LIBCPP_CXX03_LANG
1848 template <class _Tp, class _Allocator>
1850 deque<_Tp, _Allocator>::push_back(value_type&& __v)
1852 allocator_type& __a = __base::__alloc();
1853 if (__back_spare() == 0)
1854 __add_back_capacity();
1855 // __back_spare() >= 1
1856 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v));
1860 template <class _Tp, class _Allocator>
1861 template <class... _Args>
1862 #if _LIBCPP_STD_VER > 14
1863 typename deque<_Tp, _Allocator>::reference
1867 deque<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1869 allocator_type& __a = __base::__alloc();
1870 if (__back_spare() == 0)
1871 __add_back_capacity();
1872 // __back_spare() >= 1
1873 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()),
1874 _VSTD::forward<_Args>(__args)...);
1876 #if _LIBCPP_STD_VER > 14
1877 return *--__base::end();
1881 template <class _Tp, class _Allocator>
1883 deque<_Tp, _Allocator>::push_front(value_type&& __v)
1885 allocator_type& __a = __base::__alloc();
1886 if (__front_spare() == 0)
1887 __add_front_capacity();
1888 // __front_spare() >= 1
1889 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v));
1895 template <class _Tp, class _Allocator>
1896 template <class... _Args>
1897 #if _LIBCPP_STD_VER > 14
1898 typename deque<_Tp, _Allocator>::reference
1902 deque<_Tp, _Allocator>::emplace_front(_Args&&... __args)
1904 allocator_type& __a = __base::__alloc();
1905 if (__front_spare() == 0)
1906 __add_front_capacity();
1907 // __front_spare() >= 1
1908 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...);
1911 #if _LIBCPP_STD_VER > 14
1912 return *__base::begin();
1916 template <class _Tp, class _Allocator>
1917 typename deque<_Tp, _Allocator>::iterator
1918 deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v)
1920 size_type __pos = __p - __base::begin();
1921 size_type __to_end = __base::size() - __pos;
1922 allocator_type& __a = __base::__alloc();
1923 if (__pos < __to_end)
1924 { // insert by shifting things backward
1925 if (__front_spare() == 0)
1926 __add_front_capacity();
1927 // __front_spare() >= 1
1930 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v));
1936 iterator __b = __base::begin();
1937 iterator __bm1 = _VSTD::prev(__b);
1938 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
1942 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
1943 *__b = _VSTD::move(__v);
1947 { // insert by shifting things forward
1948 if (__back_spare() == 0)
1949 __add_back_capacity();
1950 // __back_capacity >= 1
1951 size_type __de = __base::size() - __pos;
1954 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v));
1959 iterator __e = __base::end();
1960 iterator __em1 = _VSTD::prev(__e);
1961 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
1964 __e = _VSTD::move_backward(__e - __de, __em1, __e);
1965 *--__e = _VSTD::move(__v);
1968 return __base::begin() + __pos;
1971 template <class _Tp, class _Allocator>
1972 template <class... _Args>
1973 typename deque<_Tp, _Allocator>::iterator
1974 deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args)
1976 size_type __pos = __p - __base::begin();
1977 size_type __to_end = __base::size() - __pos;
1978 allocator_type& __a = __base::__alloc();
1979 if (__pos < __to_end)
1980 { // insert by shifting things backward
1981 if (__front_spare() == 0)
1982 __add_front_capacity();
1983 // __front_spare() >= 1
1986 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...);
1992 __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
1993 iterator __b = __base::begin();
1994 iterator __bm1 = _VSTD::prev(__b);
1995 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
1999 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
2000 *__b = _VSTD::move(__tmp.get());
2004 { // insert by shifting things forward
2005 if (__back_spare() == 0)
2006 __add_back_capacity();
2007 // __back_capacity >= 1
2008 size_type __de = __base::size() - __pos;
2011 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...);
2016 __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
2017 iterator __e = __base::end();
2018 iterator __em1 = _VSTD::prev(__e);
2019 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
2022 __e = _VSTD::move_backward(__e - __de, __em1, __e);
2023 *--__e = _VSTD::move(__tmp.get());
2026 return __base::begin() + __pos;
2029 #endif // _LIBCPP_CXX03_LANG
2032 template <class _Tp, class _Allocator>
2033 typename deque<_Tp, _Allocator>::iterator
2034 deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v)
2036 size_type __pos = __p - __base::begin();
2037 size_type __to_end = __base::size() - __pos;
2038 allocator_type& __a = __base::__alloc();
2039 if (__pos < __to_end)
2040 { // insert by shifting things backward
2041 if (__front_spare() == 0)
2042 __add_front_capacity();
2043 // __front_spare() >= 1
2046 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v);
2052 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
2053 iterator __b = __base::begin();
2054 iterator __bm1 = _VSTD::prev(__b);
2055 if (__vt == pointer_traits<const_pointer>::pointer_to(*__b))
2056 __vt = pointer_traits<const_pointer>::pointer_to(*__bm1);
2057 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
2061 __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt);
2066 { // insert by shifting things forward
2067 if (__back_spare() == 0)
2068 __add_back_capacity();
2069 // __back_capacity >= 1
2070 size_type __de = __base::size() - __pos;
2073 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v);
2078 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
2079 iterator __e = __base::end();
2080 iterator __em1 = _VSTD::prev(__e);
2081 if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1))
2082 __vt = pointer_traits<const_pointer>::pointer_to(*__e);
2083 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
2086 __e = __move_backward_and_check(__e - __de, __em1, __e, __vt);
2090 return __base::begin() + __pos;
2093 template <class _Tp, class _Allocator>
2094 typename deque<_Tp, _Allocator>::iterator
2095 deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v)
2097 size_type __pos = __p - __base::begin();
2098 size_type __to_end = __base::size() - __pos;
2099 allocator_type& __a = __base::__alloc();
2100 if (__pos < __to_end)
2101 { // insert by shifting things backward
2102 if (__n > __front_spare())
2103 __add_front_capacity(__n - __front_spare());
2104 // __n <= __front_spare()
2105 iterator __old_begin = __base::begin();
2106 iterator __i = __old_begin;
2109 for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size())
2110 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v);
2115 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
2116 iterator __obn = __old_begin + __n;
2117 __move_construct_backward_and_check(__old_begin, __obn, __i, __vt);
2119 __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt);
2120 _VSTD::fill_n(__old_begin, __n, *__vt);
2124 { // insert by shifting things forward
2125 size_type __back_capacity = __back_spare();
2126 if (__n > __back_capacity)
2127 __add_back_capacity(__n - __back_capacity);
2128 // __n <= __back_capacity
2129 iterator __old_end = __base::end();
2130 iterator __i = __old_end;
2131 size_type __de = __base::size() - __pos;
2134 for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size())
2135 __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v);
2140 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
2141 iterator __oen = __old_end - __n;
2142 __move_construct_and_check(__oen, __old_end, __i, __vt);
2144 __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt);
2145 _VSTD::fill_n(__old_end - __n, __n, *__vt);
2148 return __base::begin() + __pos;
2151 template <class _Tp, class _Allocator>
2152 template <class _InputIter>
2153 typename deque<_Tp, _Allocator>::iterator
2154 deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l,
2155 typename enable_if<__is_input_iterator<_InputIter>::value
2156 &&!__is_forward_iterator<_InputIter>::value>::type*)
2158 __split_buffer<value_type, allocator_type&> __buf(__base::__alloc());
2159 __buf.__construct_at_end(__f, __l);
2160 typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi;
2161 return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end()));
2164 template <class _Tp, class _Allocator>
2165 template <class _ForwardIterator>
2166 typename deque<_Tp, _Allocator>::iterator
2167 deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l,
2168 typename enable_if<__is_forward_iterator<_ForwardIterator>::value
2169 &&!__is_bidirectional_iterator<_ForwardIterator>::value>::type*)
2171 size_type __n = _VSTD::distance(__f, __l);
2172 __split_buffer<value_type, allocator_type&> __buf(__n, 0, __base::__alloc());
2173 __buf.__construct_at_end(__f, __l);
2174 typedef typename __split_buffer<value_type, allocator_type&>::iterator __fwd;
2175 return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end()));
2178 template <class _Tp, class _Allocator>
2179 template <class _BiIter>
2180 typename deque<_Tp, _Allocator>::iterator
2181 deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l,
2182 typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*)
2184 size_type __n = _VSTD::distance(__f, __l);
2185 size_type __pos = __p - __base::begin();
2186 size_type __to_end = __base::size() - __pos;
2187 allocator_type& __a = __base::__alloc();
2188 if (__pos < __to_end)
2189 { // insert by shifting things backward
2190 if (__n > __front_spare())
2191 __add_front_capacity(__n - __front_spare());
2192 // __n <= __front_spare()
2193 iterator __old_begin = __base::begin();
2194 iterator __i = __old_begin;
2198 __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos);
2199 for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size())
2200 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j);
2205 iterator __obn = __old_begin + __n;
2206 for (iterator __j = __obn; __j != __old_begin;)
2208 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j));
2213 __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin);
2214 _VSTD::copy(__m, __l, __old_begin);
2218 { // insert by shifting things forward
2219 size_type __back_capacity = __back_spare();
2220 if (__n > __back_capacity)
2221 __add_back_capacity(__n - __back_capacity);
2222 // __n <= __back_capacity
2223 iterator __old_end = __base::end();
2224 iterator __i = __old_end;
2226 size_type __de = __base::size() - __pos;
2229 __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de);
2230 for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size())
2231 __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j);
2236 iterator __oen = __old_end - __n;
2237 for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size())
2238 __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j));
2240 __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end);
2241 _VSTD::copy_backward(__f, __m, __old_end);
2244 return __base::begin() + __pos;
2247 template <class _Tp, class _Allocator>
2248 template <class _InpIter>
2250 deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l,
2251 typename enable_if<__is_input_iterator<_InpIter>::value &&
2252 !__is_forward_iterator<_InpIter>::value>::type*)
2254 for (; __f != __l; ++__f)
2255 #ifdef _LIBCPP_CXX03_LANG
2262 template <class _Tp, class _Allocator>
2263 template <class _ForIter>
2265 deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l,
2266 typename enable_if<__is_forward_iterator<_ForIter>::value>::type*)
2268 size_type __n = _VSTD::distance(__f, __l);
2269 allocator_type& __a = __base::__alloc();
2270 size_type __back_capacity = __back_spare();
2271 if (__n > __back_capacity)
2272 __add_back_capacity(__n - __back_capacity);
2273 // __n <= __back_capacity
2274 for (iterator __i = __base::end(); __f != __l; ++__i, (void) ++__f, ++__base::size())
2275 __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__f);
2278 template <class _Tp, class _Allocator>
2280 deque<_Tp, _Allocator>::__append(size_type __n)
2282 allocator_type& __a = __base::__alloc();
2283 size_type __back_capacity = __back_spare();
2284 if (__n > __back_capacity)
2285 __add_back_capacity(__n - __back_capacity);
2286 // __n <= __back_capacity
2287 for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size())
2288 __alloc_traits::construct(__a, _VSTD::addressof(*__i));
2291 template <class _Tp, class _Allocator>
2293 deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v)
2295 allocator_type& __a = __base::__alloc();
2296 size_type __back_capacity = __back_spare();
2297 if (__n > __back_capacity)
2298 __add_back_capacity(__n - __back_capacity);
2299 // __n <= __back_capacity
2300 for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size())
2301 __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v);
2304 // Create front capacity for one block of elements.
2305 // Strong guarantee. Either do it or don't touch anything.
2306 template <class _Tp, class _Allocator>
2308 deque<_Tp, _Allocator>::__add_front_capacity()
2310 allocator_type& __a = __base::__alloc();
2311 if (__back_spare() >= __base::__block_size)
2313 __base::__start_ += __base::__block_size;
2314 pointer __pt = __base::__map_.back();
2315 __base::__map_.pop_back();
2316 __base::__map_.push_front(__pt);
2318 // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer
2319 else if (__base::__map_.size() < __base::__map_.capacity())
2320 { // we can put the new buffer into the map, but don't shift things around
2321 // until all buffers are allocated. If we throw, we don't need to fix
2322 // anything up (any added buffers are undetectible)
2323 if (__base::__map_.__front_spare() > 0)
2324 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2327 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2328 // Done allocating, reorder capacity
2329 pointer __pt = __base::__map_.back();
2330 __base::__map_.pop_back();
2331 __base::__map_.push_front(__pt);
2333 __base::__start_ = __base::__map_.size() == 1 ?
2334 __base::__block_size / 2 :
2335 __base::__start_ + __base::__block_size;
2337 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
2340 __split_buffer<pointer, typename __base::__pointer_allocator&>
2341 __buf(max<size_type>(2 * __base::__map_.capacity(), 1),
2342 0, __base::__map_.__alloc());
2344 typedef __allocator_destructor<_Allocator> _Dp;
2345 unique_ptr<pointer, _Dp> __hold(
2346 __alloc_traits::allocate(__a, __base::__block_size),
2347 _Dp(__a, __base::__block_size));
2348 __buf.push_back(__hold.get());
2351 for (typename __base::__map_pointer __i = __base::__map_.begin();
2352 __i != __base::__map_.end(); ++__i)
2353 __buf.push_back(*__i);
2354 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2355 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2356 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2357 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2358 __base::__start_ = __base::__map_.size() == 1 ?
2359 __base::__block_size / 2 :
2360 __base::__start_ + __base::__block_size;
2364 // Create front capacity for __n elements.
2365 // Strong guarantee. Either do it or don't touch anything.
2366 template <class _Tp, class _Allocator>
2368 deque<_Tp, _Allocator>::__add_front_capacity(size_type __n)
2370 allocator_type& __a = __base::__alloc();
2371 size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
2372 // Number of unused blocks at back:
2373 size_type __back_capacity = __back_spare() / __base::__block_size;
2374 __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need
2375 __nb -= __back_capacity; // number of blocks need to allocate
2376 // If __nb == 0, then we have sufficient capacity.
2379 __base::__start_ += __base::__block_size * __back_capacity;
2380 for (; __back_capacity > 0; --__back_capacity)
2382 pointer __pt = __base::__map_.back();
2383 __base::__map_.pop_back();
2384 __base::__map_.push_front(__pt);
2387 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2388 else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
2389 { // we can put the new buffers into the map, but don't shift things around
2390 // until all buffers are allocated. If we throw, we don't need to fix
2391 // anything up (any added buffers are undetectible)
2392 for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1))
2394 if (__base::__map_.__front_spare() == 0)
2396 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2398 for (; __nb > 0; --__nb, ++__back_capacity)
2399 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2400 // Done allocating, reorder capacity
2401 __base::__start_ += __back_capacity * __base::__block_size;
2402 for (; __back_capacity > 0; --__back_capacity)
2404 pointer __pt = __base::__map_.back();
2405 __base::__map_.pop_back();
2406 __base::__map_.push_front(__pt);
2409 // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
2412 size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty();
2413 __split_buffer<pointer, typename __base::__pointer_allocator&>
2414 __buf(max<size_type>(2* __base::__map_.capacity(),
2415 __nb + __base::__map_.size()),
2416 0, __base::__map_.__alloc());
2417 #ifndef _LIBCPP_NO_EXCEPTIONS
2420 #endif // _LIBCPP_NO_EXCEPTIONS
2421 for (; __nb > 0; --__nb)
2422 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2423 #ifndef _LIBCPP_NO_EXCEPTIONS
2427 for (typename __base::__map_pointer __i = __buf.begin();
2428 __i != __buf.end(); ++__i)
2429 __alloc_traits::deallocate(__a, *__i, __base::__block_size);
2432 #endif // _LIBCPP_NO_EXCEPTIONS
2433 for (; __back_capacity > 0; --__back_capacity)
2435 __buf.push_back(__base::__map_.back());
2436 __base::__map_.pop_back();
2438 for (typename __base::__map_pointer __i = __base::__map_.begin();
2439 __i != __base::__map_.end(); ++__i)
2440 __buf.push_back(*__i);
2441 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2442 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2443 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2444 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2445 __base::__start_ += __ds;
2449 // Create back capacity for one block of elements.
2450 // Strong guarantee. Either do it or don't touch anything.
2451 template <class _Tp, class _Allocator>
2453 deque<_Tp, _Allocator>::__add_back_capacity()
2455 allocator_type& __a = __base::__alloc();
2456 if (__front_spare() >= __base::__block_size)
2458 __base::__start_ -= __base::__block_size;
2459 pointer __pt = __base::__map_.front();
2460 __base::__map_.pop_front();
2461 __base::__map_.push_back(__pt);
2463 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2464 else if (__base::__map_.size() < __base::__map_.capacity())
2465 { // we can put the new buffer into the map, but don't shift things around
2466 // until it is allocated. If we throw, we don't need to fix
2467 // anything up (any added buffers are undetectible)
2468 if (__base::__map_.__back_spare() != 0)
2469 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2472 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2473 // Done allocating, reorder capacity
2474 pointer __pt = __base::__map_.front();
2475 __base::__map_.pop_front();
2476 __base::__map_.push_back(__pt);
2479 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
2482 __split_buffer<pointer, typename __base::__pointer_allocator&>
2483 __buf(max<size_type>(2* __base::__map_.capacity(), 1),
2484 __base::__map_.size(),
2485 __base::__map_.__alloc());
2487 typedef __allocator_destructor<_Allocator> _Dp;
2488 unique_ptr<pointer, _Dp> __hold(
2489 __alloc_traits::allocate(__a, __base::__block_size),
2490 _Dp(__a, __base::__block_size));
2491 __buf.push_back(__hold.get());
2494 for (typename __base::__map_pointer __i = __base::__map_.end();
2495 __i != __base::__map_.begin();)
2496 __buf.push_front(*--__i);
2497 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2498 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2499 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2500 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2504 // Create back capacity for __n elements.
2505 // Strong guarantee. Either do it or don't touch anything.
2506 template <class _Tp, class _Allocator>
2508 deque<_Tp, _Allocator>::__add_back_capacity(size_type __n)
2510 allocator_type& __a = __base::__alloc();
2511 size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
2512 // Number of unused blocks at front:
2513 size_type __front_capacity = __front_spare() / __base::__block_size;
2514 __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need
2515 __nb -= __front_capacity; // number of blocks need to allocate
2516 // If __nb == 0, then we have sufficient capacity.
2519 __base::__start_ -= __base::__block_size * __front_capacity;
2520 for (; __front_capacity > 0; --__front_capacity)
2522 pointer __pt = __base::__map_.front();
2523 __base::__map_.pop_front();
2524 __base::__map_.push_back(__pt);
2527 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2528 else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
2529 { // we can put the new buffers into the map, but don't shift things around
2530 // until all buffers are allocated. If we throw, we don't need to fix
2531 // anything up (any added buffers are undetectible)
2532 for (; __nb > 0; --__nb)
2534 if (__base::__map_.__back_spare() == 0)
2536 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2538 for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ +=
2539 __base::__block_size - (__base::__map_.size() == 1))
2540 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2541 // Done allocating, reorder capacity
2542 __base::__start_ -= __base::__block_size * __front_capacity;
2543 for (; __front_capacity > 0; --__front_capacity)
2545 pointer __pt = __base::__map_.front();
2546 __base::__map_.pop_front();
2547 __base::__map_.push_back(__pt);
2550 // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
2553 size_type __ds = __front_capacity * __base::__block_size;
2554 __split_buffer<pointer, typename __base::__pointer_allocator&>
2555 __buf(max<size_type>(2* __base::__map_.capacity(),
2556 __nb + __base::__map_.size()),
2557 __base::__map_.size() - __front_capacity,
2558 __base::__map_.__alloc());
2559 #ifndef _LIBCPP_NO_EXCEPTIONS
2562 #endif // _LIBCPP_NO_EXCEPTIONS
2563 for (; __nb > 0; --__nb)
2564 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2565 #ifndef _LIBCPP_NO_EXCEPTIONS
2569 for (typename __base::__map_pointer __i = __buf.begin();
2570 __i != __buf.end(); ++__i)
2571 __alloc_traits::deallocate(__a, *__i, __base::__block_size);
2574 #endif // _LIBCPP_NO_EXCEPTIONS
2575 for (; __front_capacity > 0; --__front_capacity)
2577 __buf.push_back(__base::__map_.front());
2578 __base::__map_.pop_front();
2580 for (typename __base::__map_pointer __i = __base::__map_.end();
2581 __i != __base::__map_.begin();)
2582 __buf.push_front(*--__i);
2583 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2584 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2585 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2586 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2587 __base::__start_ -= __ds;
2591 template <class _Tp, class _Allocator>
2593 deque<_Tp, _Allocator>::pop_front()
2595 allocator_type& __a = __base::__alloc();
2596 __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
2597 __base::__start_ / __base::__block_size) +
2598 __base::__start_ % __base::__block_size));
2600 if (++__base::__start_ >= 2 * __base::__block_size)
2602 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2603 __base::__map_.pop_front();
2604 __base::__start_ -= __base::__block_size;
2608 template <class _Tp, class _Allocator>
2610 deque<_Tp, _Allocator>::pop_back()
2612 _LIBCPP_ASSERT(!empty(), "deque::pop_back called for empty deque");
2613 allocator_type& __a = __base::__alloc();
2614 size_type __p = __base::size() + __base::__start_ - 1;
2615 __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
2616 __p / __base::__block_size) +
2617 __p % __base::__block_size));
2619 if (__back_spare() >= 2 * __base::__block_size)
2621 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2622 __base::__map_.pop_back();
2626 // move assign [__f, __l) to [__r, __r + (__l-__f)).
2627 // If __vt points into [__f, __l), then subtract (__f - __r) from __vt.
2628 template <class _Tp, class _Allocator>
2629 typename deque<_Tp, _Allocator>::iterator
2630 deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r,
2631 const_pointer& __vt)
2634 // for (; __f != __l; ++__f, ++__r)
2635 // *__r = _VSTD::move(*__f);
2636 difference_type __n = __l - __f;
2639 pointer __fb = __f.__ptr_;
2640 pointer __fe = *__f.__m_iter_ + __base::__block_size;
2641 difference_type __bs = __fe - __fb;
2647 if (__fb <= __vt && __vt < __fe)
2648 __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_;
2649 __r = _VSTD::move(__fb, __fe, __r);
2656 // move assign [__f, __l) to [__r - (__l-__f), __r) backwards.
2657 // If __vt points into [__f, __l), then add (__r - __l) to __vt.
2658 template <class _Tp, class _Allocator>
2659 typename deque<_Tp, _Allocator>::iterator
2660 deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r,
2661 const_pointer& __vt)
2664 // while (__f != __l)
2665 // *--__r = _VSTD::move(*--__l);
2666 difference_type __n = __l - __f;
2670 pointer __lb = *__l.__m_iter_;
2671 pointer __le = __l.__ptr_ + 1;
2672 difference_type __bs = __le - __lb;
2678 if (__lb <= __vt && __vt < __le)
2679 __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_;
2680 __r = _VSTD::move_backward(__lb, __le, __r);
2687 // move construct [__f, __l) to [__r, __r + (__l-__f)).
2688 // If __vt points into [__f, __l), then add (__r - __f) to __vt.
2689 template <class _Tp, class _Allocator>
2691 deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l,
2692 iterator __r, const_pointer& __vt)
2694 allocator_type& __a = __base::__alloc();
2696 // for (; __f != __l; ++__r, ++__f, ++__base::size())
2697 // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f));
2698 difference_type __n = __l - __f;
2701 pointer __fb = __f.__ptr_;
2702 pointer __fe = *__f.__m_iter_ + __base::__block_size;
2703 difference_type __bs = __fe - __fb;
2709 if (__fb <= __vt && __vt < __fe)
2710 __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_;
2711 for (; __fb != __fe; ++__fb, ++__r, ++__base::size())
2712 __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb));
2718 // move construct [__f, __l) to [__r - (__l-__f), __r) backwards.
2719 // If __vt points into [__f, __l), then subtract (__l - __r) from __vt.
2720 template <class _Tp, class _Allocator>
2722 deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l,
2723 iterator __r, const_pointer& __vt)
2725 allocator_type& __a = __base::__alloc();
2727 // for (iterator __j = __l; __j != __f;)
2729 // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j));
2730 // --__base::__start_;
2731 // ++__base::size();
2733 difference_type __n = __l - __f;
2737 pointer __lb = *__l.__m_iter_;
2738 pointer __le = __l.__ptr_ + 1;
2739 difference_type __bs = __le - __lb;
2745 if (__lb <= __vt && __vt < __le)
2746 __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_;
2747 while (__le != __lb)
2749 __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le));
2758 template <class _Tp, class _Allocator>
2759 typename deque<_Tp, _Allocator>::iterator
2760 deque<_Tp, _Allocator>::erase(const_iterator __f)
2762 iterator __b = __base::begin();
2763 difference_type __pos = __f - __b;
2764 iterator __p = __b + __pos;
2765 allocator_type& __a = __base::__alloc();
2766 if (static_cast<size_t>(__pos) <= (__base::size() - 1) / 2)
2767 { // erase from front
2768 _VSTD::move_backward(__b, __p, _VSTD::next(__p));
2769 __alloc_traits::destroy(__a, _VSTD::addressof(*__b));
2772 if (__front_spare() >= 2 * __base::__block_size)
2774 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2775 __base::__map_.pop_front();
2776 __base::__start_ -= __base::__block_size;
2780 { // erase from back
2781 iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p);
2782 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
2784 if (__back_spare() >= 2 * __base::__block_size)
2786 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2787 __base::__map_.pop_back();
2790 return __base::begin() + __pos;
2793 template <class _Tp, class _Allocator>
2794 typename deque<_Tp, _Allocator>::iterator
2795 deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l)
2797 difference_type __n = __l - __f;
2798 iterator __b = __base::begin();
2799 difference_type __pos = __f - __b;
2800 iterator __p = __b + __pos;
2803 allocator_type& __a = __base::__alloc();
2804 if (static_cast<size_t>(__pos) <= (__base::size() - __n) / 2)
2805 { // erase from front
2806 iterator __i = _VSTD::move_backward(__b, __p, __p + __n);
2807 for (; __b != __i; ++__b)
2808 __alloc_traits::destroy(__a, _VSTD::addressof(*__b));
2809 __base::size() -= __n;
2810 __base::__start_ += __n;
2811 while (__front_spare() >= 2 * __base::__block_size)
2813 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2814 __base::__map_.pop_front();
2815 __base::__start_ -= __base::__block_size;
2819 { // erase from back
2820 iterator __i = _VSTD::move(__p + __n, __base::end(), __p);
2821 for (iterator __e = __base::end(); __i != __e; ++__i)
2822 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
2823 __base::size() -= __n;
2824 while (__back_spare() >= 2 * __base::__block_size)
2826 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2827 __base::__map_.pop_back();
2831 return __base::begin() + __pos;
2834 template <class _Tp, class _Allocator>
2836 deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f)
2838 iterator __e = __base::end();
2839 difference_type __n = __e - __f;
2842 allocator_type& __a = __base::__alloc();
2843 iterator __b = __base::begin();
2844 difference_type __pos = __f - __b;
2845 for (iterator __p = __b + __pos; __p != __e; ++__p)
2846 __alloc_traits::destroy(__a, _VSTD::addressof(*__p));
2847 __base::size() -= __n;
2848 while (__back_spare() >= 2 * __base::__block_size)
2850 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2851 __base::__map_.pop_back();
2856 template <class _Tp, class _Allocator>
2859 deque<_Tp, _Allocator>::swap(deque& __c)
2860 #if _LIBCPP_STD_VER >= 14
2863 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2864 __is_nothrow_swappable<allocator_type>::value)
2870 template <class _Tp, class _Allocator>
2873 deque<_Tp, _Allocator>::clear() _NOEXCEPT
2878 template <class _Tp, class _Allocator>
2879 inline _LIBCPP_INLINE_VISIBILITY
2881 operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2883 const typename deque<_Tp, _Allocator>::size_type __sz = __x.size();
2884 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
2887 template <class _Tp, class _Allocator>
2888 inline _LIBCPP_INLINE_VISIBILITY
2890 operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2892 return !(__x == __y);
2895 template <class _Tp, class _Allocator>
2896 inline _LIBCPP_INLINE_VISIBILITY
2898 operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2900 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2903 template <class _Tp, class _Allocator>
2904 inline _LIBCPP_INLINE_VISIBILITY
2906 operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2911 template <class _Tp, class _Allocator>
2912 inline _LIBCPP_INLINE_VISIBILITY
2914 operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2916 return !(__x < __y);
2919 template <class _Tp, class _Allocator>
2920 inline _LIBCPP_INLINE_VISIBILITY
2922 operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2924 return !(__y < __x);
2927 template <class _Tp, class _Allocator>
2928 inline _LIBCPP_INLINE_VISIBILITY
2930 swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y)
2931 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2936 #if _LIBCPP_STD_VER > 17
2937 template <class _Tp, class _Allocator, class _Up>
2938 inline _LIBCPP_INLINE_VISIBILITY
2939 void erase(deque<_Tp, _Allocator>& __c, const _Up& __v)
2940 { __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); }
2942 template <class _Tp, class _Allocator, class _Predicate>
2943 inline _LIBCPP_INLINE_VISIBILITY
2944 void erase_if(deque<_Tp, _Allocator>& __c, _Predicate __pred)
2945 { __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); }
2949 _LIBCPP_END_NAMESPACE_STD
2953 #endif // _LIBCPP_DEQUE