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 deque(size_type n, const value_type& v);
45 deque(size_type n, const value_type& v, const allocator_type& a);
46 template <class InputIterator>
47 deque(InputIterator f, InputIterator l);
48 template <class InputIterator>
49 deque(InputIterator f, InputIterator l, const allocator_type& a);
50 deque(const deque& c);
52 noexcept(is_nothrow_move_constructible<allocator_type>::value);
53 deque(initializer_list<value_type> il, const Allocator& a = allocator_type());
54 deque(const deque& c, const allocator_type& a);
55 deque(deque&& c, const allocator_type& a);
58 deque& operator=(const deque& c);
59 deque& operator=(deque&& c)
61 allocator_type::propagate_on_container_move_assignment::value &&
62 is_nothrow_move_assignable<allocator_type>::value);
63 deque& operator=(initializer_list<value_type> il);
65 template <class InputIterator>
66 void assign(InputIterator f, InputIterator l);
67 void assign(size_type n, const value_type& v);
68 void assign(initializer_list<value_type> il);
70 allocator_type get_allocator() const noexcept;
74 iterator begin() noexcept;
75 const_iterator begin() const noexcept;
76 iterator end() noexcept;
77 const_iterator end() const noexcept;
79 reverse_iterator rbegin() noexcept;
80 const_reverse_iterator rbegin() const noexcept;
81 reverse_iterator rend() noexcept;
82 const_reverse_iterator rend() const noexcept;
84 const_iterator cbegin() const noexcept;
85 const_iterator cend() const noexcept;
86 const_reverse_iterator crbegin() const noexcept;
87 const_reverse_iterator crend() const noexcept;
90 size_type size() const noexcept;
91 size_type max_size() const noexcept;
92 void resize(size_type n);
93 void resize(size_type n, const value_type& v);
95 bool empty() const noexcept;
98 reference operator[](size_type i);
99 const_reference operator[](size_type i) const;
100 reference at(size_type i);
101 const_reference at(size_type i) const;
103 const_reference front() const;
105 const_reference back() const;
108 void push_front(const value_type& v);
109 void push_front(value_type&& v);
110 void push_back(const value_type& v);
111 void push_back(value_type&& v);
112 template <class... Args> void emplace_front(Args&&... args);
113 template <class... Args> void emplace_back(Args&&... args);
114 template <class... Args> iterator emplace(const_iterator p, Args&&... args);
115 iterator insert(const_iterator p, const value_type& v);
116 iterator insert(const_iterator p, value_type&& v);
117 iterator insert(const_iterator p, size_type n, const value_type& v);
118 template <class InputIterator>
119 iterator insert (const_iterator p, InputIterator f, InputIterator l);
120 iterator insert(const_iterator p, initializer_list<value_type> il);
123 iterator erase(const_iterator p);
124 iterator erase(const_iterator f, const_iterator l);
126 noexcept(!allocator_type::propagate_on_container_swap::value ||
127 __is_nothrow_swappable<allocator_type>::value);
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;
171 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
172 class _DiffType, _DiffType _BlockSize>
173 class _LIBCPP_TYPE_VIS __deque_iterator;
175 template <class _RAIter,
176 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
177 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
180 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
181 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
183 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
184 class _OutputIterator>
186 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
187 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
188 _OutputIterator __r);
190 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
191 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
192 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
193 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
194 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
195 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
197 template <class _RAIter,
198 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
199 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
200 copy_backward(_RAIter __f,
202 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
203 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
205 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
206 class _OutputIterator>
208 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
209 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
210 _OutputIterator __r);
212 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
213 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
214 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
215 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
216 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
217 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
219 template <class _RAIter,
220 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
221 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
224 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
225 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
227 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
228 class _OutputIterator>
230 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
231 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
232 _OutputIterator __r);
234 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
235 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
236 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
237 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
238 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
239 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
241 template <class _RAIter,
242 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
243 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
244 move_backward(_RAIter __f,
246 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
247 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
249 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
250 class _OutputIterator>
252 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
253 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
254 _OutputIterator __r);
256 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
257 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
258 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
259 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
260 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
261 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
263 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
264 class _DiffType, _DiffType _BlockSize>
265 class _LIBCPP_TYPE_VIS __deque_iterator
267 typedef _MapPointer __map_iterator;
269 typedef _Pointer pointer;
270 typedef _DiffType difference_type;
272 __map_iterator __m_iter_;
275 static const difference_type __block_size = _BlockSize;
277 typedef _ValueType value_type;
278 typedef random_access_iterator_tag iterator_category;
279 typedef _Reference reference;
281 _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT {}
283 template <class _Pp, class _Rp, class _MP>
284 _LIBCPP_INLINE_VISIBILITY
285 __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, __block_size>& __it,
286 typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT
287 : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {}
289 _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;}
290 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;}
292 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++()
294 if (++__ptr_ - *__m_iter_ == __block_size)
302 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int)
304 __deque_iterator __tmp = *this;
309 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--()
311 if (__ptr_ == *__m_iter_)
314 __ptr_ = *__m_iter_ + __block_size;
320 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int)
322 __deque_iterator __tmp = *this;
327 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n)
331 __n += __ptr_ - *__m_iter_;
334 __m_iter_ += __n / __block_size;
335 __ptr_ = *__m_iter_ + __n % __block_size;
339 difference_type __z = __block_size - 1 - __n;
340 __m_iter_ -= __z / __block_size;
341 __ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size);
347 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n)
349 return *this += -__n;
352 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const
354 __deque_iterator __t(*this);
359 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const
361 __deque_iterator __t(*this);
366 _LIBCPP_INLINE_VISIBILITY
367 friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it)
370 _LIBCPP_INLINE_VISIBILITY
371 friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y)
374 return (__x.__m_iter_ - __y.__m_iter_) * __block_size
375 + (__x.__ptr_ - *__x.__m_iter_)
376 - (__y.__ptr_ - *__y.__m_iter_);
380 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
381 {return *(*this + __n);}
383 _LIBCPP_INLINE_VISIBILITY friend
384 bool operator==(const __deque_iterator& __x, const __deque_iterator& __y)
385 {return __x.__ptr_ == __y.__ptr_;}
387 _LIBCPP_INLINE_VISIBILITY friend
388 bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y)
389 {return !(__x == __y);}
391 _LIBCPP_INLINE_VISIBILITY friend
392 bool operator<(const __deque_iterator& __x, const __deque_iterator& __y)
393 {return __x.__m_iter_ < __y.__m_iter_ ||
394 (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);}
396 _LIBCPP_INLINE_VISIBILITY friend
397 bool operator>(const __deque_iterator& __x, const __deque_iterator& __y)
400 _LIBCPP_INLINE_VISIBILITY friend
401 bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y)
402 {return !(__y < __x);}
404 _LIBCPP_INLINE_VISIBILITY friend
405 bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y)
406 {return !(__x < __y);}
409 _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
410 : __m_iter_(__m), __ptr_(__p) {}
412 template <class _Tp, class _Ap> friend class __deque_base;
413 template <class _Tp, class _Ap> friend class _LIBCPP_TYPE_VIS deque;
414 template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp>
415 friend class _LIBCPP_TYPE_VIS __deque_iterator;
417 template <class _RAIter,
418 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
420 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
423 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
424 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
426 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
427 class _OutputIterator>
430 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
431 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
432 _OutputIterator __r);
434 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
435 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
437 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
438 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
439 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
440 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
442 template <class _RAIter,
443 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
445 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
446 copy_backward(_RAIter __f,
448 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
449 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
451 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
452 class _OutputIterator>
455 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
456 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
457 _OutputIterator __r);
459 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
460 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
462 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
463 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
464 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
465 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
467 template <class _RAIter,
468 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
470 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
473 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
474 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
476 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
477 class _OutputIterator>
480 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
481 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
482 _OutputIterator __r);
484 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
485 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
487 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
488 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
489 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
490 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
492 template <class _RAIter,
493 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
495 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
496 move_backward(_RAIter __f,
498 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
499 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
501 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
502 class _OutputIterator>
505 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
506 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
507 _OutputIterator __r);
509 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
510 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
512 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
513 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
514 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
515 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
520 template <class _RAIter,
521 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
522 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
525 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
526 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
528 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
529 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
532 pointer __rb = __r.__ptr_;
533 pointer __re = *__r.__m_iter_ + _B2;
534 difference_type __bs = __re - __rb;
535 difference_type __n = __l - __f;
542 _VSTD::copy(__f, __m, __rb);
549 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
550 class _OutputIterator>
552 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
553 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
556 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
557 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
558 difference_type __n = __l - __f;
561 pointer __fb = __f.__ptr_;
562 pointer __fe = *__f.__m_iter_ + _B1;
563 difference_type __bs = __fe - __fb;
569 __r = _VSTD::copy(__fb, __fe, __r);
576 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
577 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
578 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
579 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
580 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
581 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
583 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
584 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
585 difference_type __n = __l - __f;
588 pointer __fb = __f.__ptr_;
589 pointer __fe = *__f.__m_iter_ + _B1;
590 difference_type __bs = __fe - __fb;
596 __r = _VSTD::copy(__fb, __fe, __r);
605 template <class _RAIter,
606 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
607 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
608 copy_backward(_RAIter __f,
610 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
611 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
613 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
614 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
617 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r);
618 pointer __rb = *__rp.__m_iter_;
619 pointer __re = __rp.__ptr_ + 1;
620 difference_type __bs = __re - __rb;
621 difference_type __n = __l - __f;
628 _VSTD::copy_backward(__m, __l, __re);
635 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
636 class _OutputIterator>
638 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
639 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
642 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
643 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
644 difference_type __n = __l - __f;
648 pointer __lb = *__l.__m_iter_;
649 pointer __le = __l.__ptr_ + 1;
650 difference_type __bs = __le - __lb;
656 __r = _VSTD::copy_backward(__lb, __le, __r);
663 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
664 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
665 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
666 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
667 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
668 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
670 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
671 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
672 difference_type __n = __l - __f;
676 pointer __lb = *__l.__m_iter_;
677 pointer __le = __l.__ptr_ + 1;
678 difference_type __bs = __le - __lb;
684 __r = _VSTD::copy_backward(__lb, __le, __r);
693 template <class _RAIter,
694 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
695 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
698 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
699 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
701 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
702 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
705 pointer __rb = __r.__ptr_;
706 pointer __re = *__r.__m_iter_ + _B2;
707 difference_type __bs = __re - __rb;
708 difference_type __n = __l - __f;
715 _VSTD::move(__f, __m, __rb);
722 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
723 class _OutputIterator>
725 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
726 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
729 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
730 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
731 difference_type __n = __l - __f;
734 pointer __fb = __f.__ptr_;
735 pointer __fe = *__f.__m_iter_ + _B1;
736 difference_type __bs = __fe - __fb;
742 __r = _VSTD::move(__fb, __fe, __r);
749 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
750 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
751 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
752 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
753 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
754 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
756 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
757 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
758 difference_type __n = __l - __f;
761 pointer __fb = __f.__ptr_;
762 pointer __fe = *__f.__m_iter_ + _B1;
763 difference_type __bs = __fe - __fb;
769 __r = _VSTD::move(__fb, __fe, __r);
778 template <class _RAIter,
779 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
780 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
781 move_backward(_RAIter __f,
783 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
784 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
786 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
787 typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
790 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r);
791 pointer __rb = *__rp.__m_iter_;
792 pointer __re = __rp.__ptr_ + 1;
793 difference_type __bs = __re - __rb;
794 difference_type __n = __l - __f;
801 _VSTD::move_backward(__m, __l, __re);
808 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
809 class _OutputIterator>
811 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
812 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
815 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
816 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
817 difference_type __n = __l - __f;
821 pointer __lb = *__l.__m_iter_;
822 pointer __le = __l.__ptr_ + 1;
823 difference_type __bs = __le - __lb;
829 __r = _VSTD::move_backward(__lb, __le, __r);
836 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
837 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
838 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
839 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
840 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
841 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
843 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
844 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
845 difference_type __n = __l - __f;
849 pointer __lb = *__l.__m_iter_;
850 pointer __le = __l.__ptr_ + 1;
851 difference_type __bs = __le - __lb;
857 __r = _VSTD::move_backward(__lb, __le, __r);
865 class __deque_base_common
868 void __throw_length_error() const;
869 void __throw_out_of_range() const;
874 __deque_base_common<__b>::__throw_length_error() const
876 #ifndef _LIBCPP_NO_EXCEPTIONS
877 throw length_error("deque");
883 __deque_base_common<__b>::__throw_out_of_range() const
885 #ifndef _LIBCPP_NO_EXCEPTIONS
886 throw out_of_range("deque");
890 template <class _Tp, class _Allocator>
892 : protected __deque_base_common<true>
894 __deque_base(const __deque_base& __c);
895 __deque_base& operator=(const __deque_base& __c);
897 typedef _Tp value_type;
898 typedef _Allocator allocator_type;
899 typedef allocator_traits<allocator_type> __alloc_traits;
900 typedef value_type& reference;
901 typedef const value_type& const_reference;
902 typedef typename __alloc_traits::size_type size_type;
903 typedef typename __alloc_traits::difference_type difference_type;
904 typedef typename __alloc_traits::pointer pointer;
905 typedef typename __alloc_traits::const_pointer const_pointer;
907 static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16;
909 typedef typename __alloc_traits::template
910 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
911 rebind_alloc<pointer>
913 rebind_alloc<pointer>::other
916 typedef allocator_traits<__pointer_allocator> __map_traits;
917 typedef typename __map_traits::pointer __map_pointer;
918 typedef typename __alloc_traits::template
919 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
920 rebind_alloc<const_pointer>
922 rebind_alloc<const_pointer>::other
924 __const_pointer_allocator;
925 typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer;
926 typedef __split_buffer<pointer, __pointer_allocator> __map;
928 typedef __deque_iterator<value_type, pointer, reference, __map_pointer,
929 difference_type, __block_size> iterator;
930 typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer,
931 difference_type, __block_size> const_iterator;
935 __compressed_pair<size_type, allocator_type> __size_;
937 iterator begin() _NOEXCEPT;
938 const_iterator begin() const _NOEXCEPT;
939 iterator end() _NOEXCEPT;
940 const_iterator end() const _NOEXCEPT;
942 _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();}
943 _LIBCPP_INLINE_VISIBILITY
944 const size_type& size() const _NOEXCEPT {return __size_.first();}
945 _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();}
946 _LIBCPP_INLINE_VISIBILITY
947 const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();}
950 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
951 explicit __deque_base(const allocator_type& __a);
955 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
957 __deque_base(__deque_base&& __c)
958 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
959 __deque_base(__deque_base&& __c, const allocator_type& __a);
961 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
962 void swap(__deque_base& __c)
963 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
964 __is_nothrow_swappable<allocator_type>::value);
966 void clear() _NOEXCEPT;
968 bool __invariants() const;
970 _LIBCPP_INLINE_VISIBILITY
971 void __move_assign(__deque_base& __c)
972 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
973 is_nothrow_move_assignable<allocator_type>::value)
975 __map_ = _VSTD::move(__c.__map_);
976 __start_ = __c.__start_;
978 __move_assign_alloc(__c);
979 __c.__start_ = __c.size() = 0;
982 _LIBCPP_INLINE_VISIBILITY
983 void __move_assign_alloc(__deque_base& __c)
984 _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value ||
985 is_nothrow_move_assignable<allocator_type>::value)
986 {__move_assign_alloc(__c, integral_constant<bool,
987 __alloc_traits::propagate_on_container_move_assignment::value>());}
990 _LIBCPP_INLINE_VISIBILITY
991 void __move_assign_alloc(__deque_base& __c, true_type)
992 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
994 __alloc() = _VSTD::move(__c.__alloc());
997 _LIBCPP_INLINE_VISIBILITY
998 void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT
1001 _LIBCPP_INLINE_VISIBILITY
1002 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
1003 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1004 __is_nothrow_swappable<allocator_type>::value)
1005 {__swap_alloc(__x, __y, integral_constant<bool,
1006 __alloc_traits::propagate_on_container_swap::value>());}
1008 _LIBCPP_INLINE_VISIBILITY
1009 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1010 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
1016 _LIBCPP_INLINE_VISIBILITY
1017 static void __swap_alloc(allocator_type&, allocator_type&, false_type)
1022 template <class _Tp, class _Allocator>
1024 __deque_base<_Tp, _Allocator>::__invariants() const
1026 if (!__map_.__invariants())
1028 if (__map_.size() >= size_type(-1) / __block_size)
1030 for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end();
1032 if (*__i == nullptr)
1034 if (__map_.size() != 0)
1036 if (size() >= __map_.size() * __block_size)
1038 if (__start_ >= __map_.size() * __block_size - size())
1051 template <class _Tp, class _Allocator>
1052 typename __deque_base<_Tp, _Allocator>::iterator
1053 __deque_base<_Tp, _Allocator>::begin() _NOEXCEPT
1055 __map_pointer __mp = __map_.begin() + __start_ / __block_size;
1056 return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
1059 template <class _Tp, class _Allocator>
1060 typename __deque_base<_Tp, _Allocator>::const_iterator
1061 __deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT
1063 __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size);
1064 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
1067 template <class _Tp, class _Allocator>
1068 typename __deque_base<_Tp, _Allocator>::iterator
1069 __deque_base<_Tp, _Allocator>::end() _NOEXCEPT
1071 size_type __p = size() + __start_;
1072 __map_pointer __mp = __map_.begin() + __p / __block_size;
1073 return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
1076 template <class _Tp, class _Allocator>
1077 typename __deque_base<_Tp, _Allocator>::const_iterator
1078 __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT
1080 size_type __p = size() + __start_;
1081 __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size);
1082 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
1085 template <class _Tp, class _Allocator>
1086 inline _LIBCPP_INLINE_VISIBILITY
1087 __deque_base<_Tp, _Allocator>::__deque_base()
1088 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1089 : __start_(0), __size_(0) {}
1091 template <class _Tp, class _Allocator>
1092 inline _LIBCPP_INLINE_VISIBILITY
1093 __deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a)
1094 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {}
1096 template <class _Tp, class _Allocator>
1097 __deque_base<_Tp, _Allocator>::~__deque_base()
1100 typename __map::iterator __i = __map_.begin();
1101 typename __map::iterator __e = __map_.end();
1102 for (; __i != __e; ++__i)
1103 __alloc_traits::deallocate(__alloc(), *__i, __block_size);
1106 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1108 template <class _Tp, class _Allocator>
1109 __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c)
1110 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1111 : __map_(_VSTD::move(__c.__map_)),
1112 __start_(_VSTD::move(__c.__start_)),
1113 __size_(_VSTD::move(__c.__size_))
1119 template <class _Tp, class _Allocator>
1120 __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a)
1121 : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)),
1122 __start_(_VSTD::move(__c.__start_)),
1123 __size_(_VSTD::move(__c.size()), __a)
1125 if (__a == __c.__alloc())
1138 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1140 template <class _Tp, class _Allocator>
1142 __deque_base<_Tp, _Allocator>::swap(__deque_base& __c)
1143 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
1144 __is_nothrow_swappable<allocator_type>::value)
1146 __map_.swap(__c.__map_);
1147 _VSTD::swap(__start_, __c.__start_);
1148 _VSTD::swap(size(), __c.size());
1149 __swap_alloc(__alloc(), __c.__alloc());
1152 template <class _Tp, class _Allocator>
1154 __deque_base<_Tp, _Allocator>::clear() _NOEXCEPT
1156 allocator_type& __a = __alloc();
1157 for (iterator __i = begin(), __e = end(); __i != __e; ++__i)
1158 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
1160 while (__map_.size() > 2)
1162 __alloc_traits::deallocate(__a, __map_.front(), __block_size);
1165 switch (__map_.size())
1168 __start_ = __block_size / 2;
1171 __start_ = __block_size;
1176 template <class _Tp, class _Allocator = allocator<_Tp> >
1177 class _LIBCPP_TYPE_VIS deque
1178 : private __deque_base<_Tp, _Allocator>
1183 typedef _Tp value_type;
1184 typedef _Allocator allocator_type;
1186 typedef __deque_base<value_type, allocator_type> __base;
1188 typedef typename __base::__alloc_traits __alloc_traits;
1189 typedef typename __base::reference reference;
1190 typedef typename __base::const_reference const_reference;
1191 typedef typename __base::iterator iterator;
1192 typedef typename __base::const_iterator const_iterator;
1193 typedef typename __base::size_type size_type;
1194 typedef typename __base::difference_type difference_type;
1196 typedef typename __base::pointer pointer;
1197 typedef typename __base::const_pointer const_pointer;
1198 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1199 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1201 // construct/copy/destroy:
1202 _LIBCPP_INLINE_VISIBILITY
1204 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1206 _LIBCPP_INLINE_VISIBILITY deque(const allocator_type& __a) : __base(__a) {}
1207 explicit deque(size_type __n);
1208 deque(size_type __n, const value_type& __v);
1209 deque(size_type __n, const value_type& __v, const allocator_type& __a);
1210 template <class _InputIter>
1211 deque(_InputIter __f, _InputIter __l,
1212 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
1213 template <class _InputIter>
1214 deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
1215 typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
1216 deque(const deque& __c);
1217 deque(const deque& __c, const allocator_type& __a);
1218 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1219 deque(initializer_list<value_type> __il);
1220 deque(initializer_list<value_type> __il, const allocator_type& __a);
1221 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1223 deque& operator=(const deque& __c);
1224 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1225 _LIBCPP_INLINE_VISIBILITY
1226 deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;}
1227 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1229 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1230 deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value);
1231 deque(deque&& __c, const allocator_type& __a);
1232 deque& operator=(deque&& __c)
1233 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1234 is_nothrow_move_assignable<allocator_type>::value);
1235 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1237 template <class _InputIter>
1238 void assign(_InputIter __f, _InputIter __l,
1239 typename enable_if<__is_input_iterator<_InputIter>::value &&
1240 !__is_random_access_iterator<_InputIter>::value>::type* = 0);
1241 template <class _RAIter>
1242 void assign(_RAIter __f, _RAIter __l,
1243 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
1244 void assign(size_type __n, const value_type& __v);
1245 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1246 _LIBCPP_INLINE_VISIBILITY
1247 void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());}
1248 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1250 allocator_type get_allocator() const _NOEXCEPT;
1254 _LIBCPP_INLINE_VISIBILITY
1255 iterator begin() _NOEXCEPT {return __base::begin();}
1256 _LIBCPP_INLINE_VISIBILITY
1257 const_iterator begin() const _NOEXCEPT {return __base::begin();}
1258 _LIBCPP_INLINE_VISIBILITY
1259 iterator end() _NOEXCEPT {return __base::end();}
1260 _LIBCPP_INLINE_VISIBILITY
1261 const_iterator end() const _NOEXCEPT {return __base::end();}
1263 _LIBCPP_INLINE_VISIBILITY
1264 reverse_iterator rbegin() _NOEXCEPT
1265 {return reverse_iterator(__base::end());}
1266 _LIBCPP_INLINE_VISIBILITY
1267 const_reverse_iterator rbegin() const _NOEXCEPT
1268 {return const_reverse_iterator(__base::end());}
1269 _LIBCPP_INLINE_VISIBILITY
1270 reverse_iterator rend() _NOEXCEPT
1271 {return reverse_iterator(__base::begin());}
1272 _LIBCPP_INLINE_VISIBILITY
1273 const_reverse_iterator rend() const _NOEXCEPT
1274 {return const_reverse_iterator(__base::begin());}
1276 _LIBCPP_INLINE_VISIBILITY
1277 const_iterator cbegin() const _NOEXCEPT
1278 {return __base::begin();}
1279 _LIBCPP_INLINE_VISIBILITY
1280 const_iterator cend() const _NOEXCEPT
1281 {return __base::end();}
1282 _LIBCPP_INLINE_VISIBILITY
1283 const_reverse_iterator crbegin() const _NOEXCEPT
1284 {return const_reverse_iterator(__base::end());}
1285 _LIBCPP_INLINE_VISIBILITY
1286 const_reverse_iterator crend() const _NOEXCEPT
1287 {return const_reverse_iterator(__base::begin());}
1290 _LIBCPP_INLINE_VISIBILITY
1291 size_type size() const _NOEXCEPT {return __base::size();}
1292 _LIBCPP_INLINE_VISIBILITY
1293 size_type max_size() const _NOEXCEPT
1294 {return __alloc_traits::max_size(__base::__alloc());}
1295 void resize(size_type __n);
1296 void resize(size_type __n, const value_type& __v);
1297 void shrink_to_fit() _NOEXCEPT;
1298 _LIBCPP_INLINE_VISIBILITY
1299 bool empty() const _NOEXCEPT {return __base::size() == 0;}
1302 reference operator[](size_type __i);
1303 const_reference operator[](size_type __i) const;
1304 reference at(size_type __i);
1305 const_reference at(size_type __i) const;
1307 const_reference front() const;
1309 const_reference back() const;
1311 // 23.2.2.3 modifiers:
1312 void push_front(const value_type& __v);
1313 void push_back(const value_type& __v);
1314 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1315 #ifndef _LIBCPP_HAS_NO_VARIADICS
1316 template <class... _Args> void emplace_front(_Args&&... __args);
1317 template <class... _Args> void emplace_back(_Args&&... __args);
1318 template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args);
1319 #endif // _LIBCPP_HAS_NO_VARIADICS
1320 void push_front(value_type&& __v);
1321 void push_back(value_type&& __v);
1322 iterator insert(const_iterator __p, value_type&& __v);
1323 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1324 iterator insert(const_iterator __p, const value_type& __v);
1325 iterator insert(const_iterator __p, size_type __n, const value_type& __v);
1326 template <class _InputIter>
1327 iterator insert (const_iterator __p, _InputIter __f, _InputIter __l,
1328 typename enable_if<__is_input_iterator<_InputIter>::value
1329 &&!__is_bidirectional_iterator<_InputIter>::value>::type* = 0);
1330 template <class _BiIter>
1331 iterator insert (const_iterator __p, _BiIter __f, _BiIter __l,
1332 typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0);
1333 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1334 _LIBCPP_INLINE_VISIBILITY
1335 iterator insert(const_iterator __p, initializer_list<value_type> __il)
1336 {return insert(__p, __il.begin(), __il.end());}
1337 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1340 iterator erase(const_iterator __p);
1341 iterator erase(const_iterator __f, const_iterator __l);
1343 void swap(deque& __c)
1344 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1345 __is_nothrow_swappable<allocator_type>::value);
1346 void clear() _NOEXCEPT;
1348 _LIBCPP_INLINE_VISIBILITY
1349 bool __invariants() const {return __base::__invariants();}
1351 typedef typename __base::__map_const_pointer __map_const_pointer;
1353 _LIBCPP_INLINE_VISIBILITY
1354 static size_type __recommend_blocks(size_type __n)
1356 return __n / __base::__block_size + (__n % __base::__block_size != 0);
1358 _LIBCPP_INLINE_VISIBILITY
1359 size_type __capacity() const
1361 return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1;
1363 _LIBCPP_INLINE_VISIBILITY
1364 size_type __front_spare() const
1366 return __base::__start_;
1368 _LIBCPP_INLINE_VISIBILITY
1369 size_type __back_spare() const
1371 return __capacity() - (__base::__start_ + __base::size());
1374 template <class _InpIter>
1375 void __append(_InpIter __f, _InpIter __l,
1376 typename enable_if<__is_input_iterator<_InpIter>::value &&
1377 !__is_forward_iterator<_InpIter>::value>::type* = 0);
1378 template <class _ForIter>
1379 void __append(_ForIter __f, _ForIter __l,
1380 typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0);
1381 void __append(size_type __n);
1382 void __append(size_type __n, const value_type& __v);
1383 void __erase_to_end(const_iterator __f);
1384 void __add_front_capacity();
1385 void __add_front_capacity(size_type __n);
1386 void __add_back_capacity();
1387 void __add_back_capacity(size_type __n);
1388 iterator __move_and_check(iterator __f, iterator __l, iterator __r,
1389 const_pointer& __vt);
1390 iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r,
1391 const_pointer& __vt);
1392 void __move_construct_and_check(iterator __f, iterator __l,
1393 iterator __r, const_pointer& __vt);
1394 void __move_construct_backward_and_check(iterator __f, iterator __l,
1395 iterator __r, const_pointer& __vt);
1397 _LIBCPP_INLINE_VISIBILITY
1398 void __copy_assign_alloc(const deque& __c)
1399 {__copy_assign_alloc(__c, integral_constant<bool,
1400 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1402 _LIBCPP_INLINE_VISIBILITY
1403 void __copy_assign_alloc(const deque& __c, true_type)
1405 if (__base::__alloc() != __c.__alloc())
1410 __base::__alloc() = __c.__alloc();
1411 __base::__map_.__alloc() = __c.__map_.__alloc();
1414 _LIBCPP_INLINE_VISIBILITY
1415 void __copy_assign_alloc(const deque&, false_type)
1418 void __move_assign(deque& __c, true_type)
1419 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
1420 void __move_assign(deque& __c, false_type);
1423 template <class _Tp, class _Allocator>
1424 deque<_Tp, _Allocator>::deque(size_type __n)
1430 template <class _Tp, class _Allocator>
1431 deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v)
1437 template <class _Tp, class _Allocator>
1438 deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a)
1445 template <class _Tp, class _Allocator>
1446 template <class _InputIter>
1447 deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l,
1448 typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
1453 template <class _Tp, class _Allocator>
1454 template <class _InputIter>
1455 deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
1456 typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
1462 template <class _Tp, class _Allocator>
1463 deque<_Tp, _Allocator>::deque(const deque& __c)
1464 : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc()))
1466 __append(__c.begin(), __c.end());
1469 template <class _Tp, class _Allocator>
1470 deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a)
1473 __append(__c.begin(), __c.end());
1476 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1478 template <class _Tp, class _Allocator>
1479 deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il)
1481 __append(__il.begin(), __il.end());
1484 template <class _Tp, class _Allocator>
1485 deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a)
1488 __append(__il.begin(), __il.end());
1491 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1493 template <class _Tp, class _Allocator>
1494 deque<_Tp, _Allocator>&
1495 deque<_Tp, _Allocator>::operator=(const deque& __c)
1499 __copy_assign_alloc(__c);
1500 assign(__c.begin(), __c.end());
1505 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1507 template <class _Tp, class _Allocator>
1508 inline _LIBCPP_INLINE_VISIBILITY
1509 deque<_Tp, _Allocator>::deque(deque&& __c)
1510 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1511 : __base(_VSTD::move(__c))
1515 template <class _Tp, class _Allocator>
1516 inline _LIBCPP_INLINE_VISIBILITY
1517 deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a)
1518 : __base(_VSTD::move(__c), __a)
1520 if (__a != __c.__alloc())
1522 typedef move_iterator<iterator> _Ip;
1523 assign(_Ip(__c.begin()), _Ip(__c.end()));
1527 template <class _Tp, class _Allocator>
1528 inline _LIBCPP_INLINE_VISIBILITY
1529 deque<_Tp, _Allocator>&
1530 deque<_Tp, _Allocator>::operator=(deque&& __c)
1531 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1532 is_nothrow_move_assignable<allocator_type>::value)
1534 __move_assign(__c, integral_constant<bool,
1535 __alloc_traits::propagate_on_container_move_assignment::value>());
1539 template <class _Tp, class _Allocator>
1541 deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type)
1543 if (__base::__alloc() != __c.__alloc())
1545 typedef move_iterator<iterator> _Ip;
1546 assign(_Ip(__c.begin()), _Ip(__c.end()));
1549 __move_assign(__c, true_type());
1552 template <class _Tp, class _Allocator>
1554 deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type)
1555 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1559 __base::__move_assign(__c);
1562 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1564 template <class _Tp, class _Allocator>
1565 template <class _InputIter>
1567 deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l,
1568 typename enable_if<__is_input_iterator<_InputIter>::value &&
1569 !__is_random_access_iterator<_InputIter>::value>::type*)
1571 iterator __i = __base::begin();
1572 iterator __e = __base::end();
1573 for (; __f != __l && __i != __e; ++__f, ++__i)
1578 __erase_to_end(__i);
1581 template <class _Tp, class _Allocator>
1582 template <class _RAIter>
1584 deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l,
1585 typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
1587 if (static_cast<size_type>(__l - __f) > __base::size())
1589 _RAIter __m = __f + __base::size();
1590 _VSTD::copy(__f, __m, __base::begin());
1594 __erase_to_end(_VSTD::copy(__f, __l, __base::begin()));
1597 template <class _Tp, class _Allocator>
1599 deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v)
1601 if (__n > __base::size())
1603 _VSTD::fill_n(__base::begin(), __base::size(), __v);
1604 __n -= __base::size();
1608 __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v));
1611 template <class _Tp, class _Allocator>
1612 inline _LIBCPP_INLINE_VISIBILITY
1614 deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT
1616 return __base::__alloc();
1619 template <class _Tp, class _Allocator>
1621 deque<_Tp, _Allocator>::resize(size_type __n)
1623 if (__n > __base::size())
1624 __append(__n - __base::size());
1625 else if (__n < __base::size())
1626 __erase_to_end(__base::begin() + __n);
1629 template <class _Tp, class _Allocator>
1631 deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v)
1633 if (__n > __base::size())
1634 __append(__n - __base::size(), __v);
1635 else if (__n < __base::size())
1636 __erase_to_end(__base::begin() + __n);
1639 template <class _Tp, class _Allocator>
1641 deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1643 allocator_type& __a = __base::__alloc();
1646 while (__base::__map_.size() > 0)
1648 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
1649 __base::__map_.pop_back();
1651 __base::__start_ = 0;
1655 if (__front_spare() >= __base::__block_size)
1657 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
1658 __base::__map_.pop_front();
1659 __base::__start_ -= __base::__block_size;
1661 if (__back_spare() >= __base::__block_size)
1663 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
1664 __base::__map_.pop_back();
1667 __base::__map_.shrink_to_fit();
1670 template <class _Tp, class _Allocator>
1671 inline _LIBCPP_INLINE_VISIBILITY
1672 typename deque<_Tp, _Allocator>::reference
1673 deque<_Tp, _Allocator>::operator[](size_type __i)
1675 size_type __p = __base::__start_ + __i;
1676 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1679 template <class _Tp, class _Allocator>
1680 inline _LIBCPP_INLINE_VISIBILITY
1681 typename deque<_Tp, _Allocator>::const_reference
1682 deque<_Tp, _Allocator>::operator[](size_type __i) const
1684 size_type __p = __base::__start_ + __i;
1685 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1688 template <class _Tp, class _Allocator>
1689 inline _LIBCPP_INLINE_VISIBILITY
1690 typename deque<_Tp, _Allocator>::reference
1691 deque<_Tp, _Allocator>::at(size_type __i)
1693 if (__i >= __base::size())
1694 __base::__throw_out_of_range();
1695 size_type __p = __base::__start_ + __i;
1696 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1699 template <class _Tp, class _Allocator>
1700 inline _LIBCPP_INLINE_VISIBILITY
1701 typename deque<_Tp, _Allocator>::const_reference
1702 deque<_Tp, _Allocator>::at(size_type __i) const
1704 if (__i >= __base::size())
1705 __base::__throw_out_of_range();
1706 size_type __p = __base::__start_ + __i;
1707 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1710 template <class _Tp, class _Allocator>
1711 inline _LIBCPP_INLINE_VISIBILITY
1712 typename deque<_Tp, _Allocator>::reference
1713 deque<_Tp, _Allocator>::front()
1715 return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
1716 + __base::__start_ % __base::__block_size);
1719 template <class _Tp, class _Allocator>
1720 inline _LIBCPP_INLINE_VISIBILITY
1721 typename deque<_Tp, _Allocator>::const_reference
1722 deque<_Tp, _Allocator>::front() const
1724 return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
1725 + __base::__start_ % __base::__block_size);
1728 template <class _Tp, class _Allocator>
1729 inline _LIBCPP_INLINE_VISIBILITY
1730 typename deque<_Tp, _Allocator>::reference
1731 deque<_Tp, _Allocator>::back()
1733 size_type __p = __base::size() + __base::__start_ - 1;
1734 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1737 template <class _Tp, class _Allocator>
1738 inline _LIBCPP_INLINE_VISIBILITY
1739 typename deque<_Tp, _Allocator>::const_reference
1740 deque<_Tp, _Allocator>::back() const
1742 size_type __p = __base::size() + __base::__start_ - 1;
1743 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
1746 template <class _Tp, class _Allocator>
1748 deque<_Tp, _Allocator>::push_back(const value_type& __v)
1750 allocator_type& __a = __base::__alloc();
1751 if (__back_spare() == 0)
1752 __add_back_capacity();
1753 // __back_spare() >= 1
1754 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v);
1758 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1760 template <class _Tp, class _Allocator>
1762 deque<_Tp, _Allocator>::push_back(value_type&& __v)
1764 allocator_type& __a = __base::__alloc();
1765 if (__back_spare() == 0)
1766 __add_back_capacity();
1767 // __back_spare() >= 1
1768 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v));
1772 #ifndef _LIBCPP_HAS_NO_VARIADICS
1774 template <class _Tp, class _Allocator>
1775 template <class... _Args>
1777 deque<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1779 allocator_type& __a = __base::__alloc();
1780 if (__back_spare() == 0)
1781 __add_back_capacity();
1782 // __back_spare() >= 1
1783 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...);
1787 #endif // _LIBCPP_HAS_NO_VARIADICS
1788 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1790 template <class _Tp, class _Allocator>
1792 deque<_Tp, _Allocator>::push_front(const value_type& __v)
1794 allocator_type& __a = __base::__alloc();
1795 if (__front_spare() == 0)
1796 __add_front_capacity();
1797 // __front_spare() >= 1
1798 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v);
1803 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1805 template <class _Tp, class _Allocator>
1807 deque<_Tp, _Allocator>::push_front(value_type&& __v)
1809 allocator_type& __a = __base::__alloc();
1810 if (__front_spare() == 0)
1811 __add_front_capacity();
1812 // __front_spare() >= 1
1813 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v));
1818 #ifndef _LIBCPP_HAS_NO_VARIADICS
1820 template <class _Tp, class _Allocator>
1821 template <class... _Args>
1823 deque<_Tp, _Allocator>::emplace_front(_Args&&... __args)
1825 allocator_type& __a = __base::__alloc();
1826 if (__front_spare() == 0)
1827 __add_front_capacity();
1828 // __front_spare() >= 1
1829 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...);
1834 #endif // _LIBCPP_HAS_NO_VARIADICS
1835 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1837 template <class _Tp, class _Allocator>
1838 typename deque<_Tp, _Allocator>::iterator
1839 deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v)
1841 size_type __pos = __p - __base::begin();
1842 size_type __to_end = __base::size() - __pos;
1843 allocator_type& __a = __base::__alloc();
1844 if (__pos < __to_end)
1845 { // insert by shifting things backward
1846 if (__front_spare() == 0)
1847 __add_front_capacity();
1848 // __front_spare() >= 1
1851 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v);
1857 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
1858 iterator __b = __base::begin();
1859 iterator __bm1 = _VSTD::prev(__b);
1860 if (__vt == pointer_traits<const_pointer>::pointer_to(*__b))
1861 __vt = pointer_traits<const_pointer>::pointer_to(*__bm1);
1862 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
1866 __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt);
1871 { // insert by shifting things forward
1872 if (__back_spare() == 0)
1873 __add_back_capacity();
1874 // __back_capacity >= 1
1875 size_type __de = __base::size() - __pos;
1878 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v);
1883 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
1884 iterator __e = __base::end();
1885 iterator __em1 = _VSTD::prev(__e);
1886 if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1))
1887 __vt = pointer_traits<const_pointer>::pointer_to(*__e);
1888 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
1891 __e = __move_backward_and_check(__e - __de, __em1, __e, __vt);
1895 return __base::begin() + __pos;
1898 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1900 template <class _Tp, class _Allocator>
1901 typename deque<_Tp, _Allocator>::iterator
1902 deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v)
1904 size_type __pos = __p - __base::begin();
1905 size_type __to_end = __base::size() - __pos;
1906 allocator_type& __a = __base::__alloc();
1907 if (__pos < __to_end)
1908 { // insert by shifting things backward
1909 if (__front_spare() == 0)
1910 __add_front_capacity();
1911 // __front_spare() >= 1
1914 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v));
1920 iterator __b = __base::begin();
1921 iterator __bm1 = _VSTD::prev(__b);
1922 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
1926 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
1927 *__b = _VSTD::move(__v);
1931 { // insert by shifting things forward
1932 if (__back_spare() == 0)
1933 __add_back_capacity();
1934 // __back_capacity >= 1
1935 size_type __de = __base::size() - __pos;
1938 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v));
1943 iterator __e = __base::end();
1944 iterator __em1 = _VSTD::prev(__e);
1945 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
1948 __e = _VSTD::move_backward(__e - __de, __em1, __e);
1949 *--__e = _VSTD::move(__v);
1952 return __base::begin() + __pos;
1955 #ifndef _LIBCPP_HAS_NO_VARIADICS
1957 template <class _Tp, class _Allocator>
1958 template <class... _Args>
1959 typename deque<_Tp, _Allocator>::iterator
1960 deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args)
1962 size_type __pos = __p - __base::begin();
1963 size_type __to_end = __base::size() - __pos;
1964 allocator_type& __a = __base::__alloc();
1965 if (__pos < __to_end)
1966 { // insert by shifting things backward
1967 if (__front_spare() == 0)
1968 __add_front_capacity();
1969 // __front_spare() >= 1
1972 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...);
1978 value_type __tmp(_VSTD::forward<_Args>(__args)...);
1979 iterator __b = __base::begin();
1980 iterator __bm1 = _VSTD::prev(__b);
1981 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
1985 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
1986 *__b = _VSTD::move(__tmp);
1990 { // insert by shifting things forward
1991 if (__back_spare() == 0)
1992 __add_back_capacity();
1993 // __back_capacity >= 1
1994 size_type __de = __base::size() - __pos;
1997 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...);
2002 value_type __tmp(_VSTD::forward<_Args>(__args)...);
2003 iterator __e = __base::end();
2004 iterator __em1 = _VSTD::prev(__e);
2005 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
2008 __e = _VSTD::move_backward(__e - __de, __em1, __e);
2009 *--__e = _VSTD::move(__tmp);
2012 return __base::begin() + __pos;
2015 #endif // _LIBCPP_HAS_NO_VARIADICS
2016 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2018 template <class _Tp, class _Allocator>
2019 typename deque<_Tp, _Allocator>::iterator
2020 deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v)
2022 size_type __pos = __p - __base::begin();
2023 size_type __to_end = __base::size() - __pos;
2024 allocator_type& __a = __base::__alloc();
2025 if (__pos < __to_end)
2026 { // insert by shifting things backward
2027 if (__n > __front_spare())
2028 __add_front_capacity(__n - __front_spare());
2029 // __n <= __front_spare()
2030 size_type __old_n = __n;
2031 iterator __old_begin = __base::begin();
2032 iterator __i = __old_begin;
2035 for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size())
2036 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v);
2041 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
2042 iterator __obn = __old_begin + __n;
2043 __move_construct_backward_and_check(__old_begin, __obn, __i, __vt);
2045 __old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt);
2046 _VSTD::fill_n(__old_begin, __n, *__vt);
2050 { // insert by shifting things forward
2051 size_type __back_capacity = __back_spare();
2052 if (__n > __back_capacity)
2053 __add_back_capacity(__n - __back_capacity);
2054 // __n <= __back_capacity
2055 size_type __old_n = __n;
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_bidirectional_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 _BiIter>
2093 typename deque<_Tp, _Allocator>::iterator
2094 deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l,
2095 typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*)
2097 size_type __n = _VSTD::distance(__f, __l);
2098 size_type __pos = __p - __base::begin();
2099 size_type __to_end = __base::size() - __pos;
2100 allocator_type& __a = __base::__alloc();
2101 if (__pos < __to_end)
2102 { // insert by shifting things backward
2103 if (__n > __front_spare())
2104 __add_front_capacity(__n - __front_spare());
2105 // __n <= __front_spare()
2106 size_type __old_n = __n;
2107 iterator __old_begin = __base::begin();
2108 iterator __i = __old_begin;
2112 __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos);
2113 for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size())
2114 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j);
2119 iterator __obn = __old_begin + __n;
2120 for (iterator __j = __obn; __j != __old_begin;)
2122 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j));
2127 __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin);
2128 _VSTD::copy(__m, __l, __old_begin);
2132 { // insert by shifting things forward
2133 size_type __back_capacity = __back_spare();
2134 if (__n > __back_capacity)
2135 __add_back_capacity(__n - __back_capacity);
2136 // __n <= __back_capacity
2137 size_type __old_n = __n;
2138 iterator __old_end = __base::end();
2139 iterator __i = __old_end;
2141 size_type __de = __base::size() - __pos;
2144 __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de);
2145 for (_BiIter __j = __m; __j != __l; ++__i, ++__j, ++__base::size())
2146 __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j);
2151 iterator __oen = __old_end - __n;
2152 for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size())
2153 __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j));
2155 __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end);
2156 _VSTD::copy_backward(__f, __m, __old_end);
2159 return __base::begin() + __pos;
2162 template <class _Tp, class _Allocator>
2163 template <class _InpIter>
2165 deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l,
2166 typename enable_if<__is_input_iterator<_InpIter>::value &&
2167 !__is_forward_iterator<_InpIter>::value>::type*)
2169 for (; __f != __l; ++__f)
2173 template <class _Tp, class _Allocator>
2174 template <class _ForIter>
2176 deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l,
2177 typename enable_if<__is_forward_iterator<_ForIter>::value>::type*)
2179 size_type __n = _VSTD::distance(__f, __l);
2180 allocator_type& __a = __base::__alloc();
2181 size_type __back_capacity = __back_spare();
2182 if (__n > __back_capacity)
2183 __add_back_capacity(__n - __back_capacity);
2184 // __n <= __back_capacity
2185 for (iterator __i = __base::end(); __f != __l; ++__i, ++__f, ++__base::size())
2186 __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__f);
2189 template <class _Tp, class _Allocator>
2191 deque<_Tp, _Allocator>::__append(size_type __n)
2193 allocator_type& __a = __base::__alloc();
2194 size_type __back_capacity = __back_spare();
2195 if (__n > __back_capacity)
2196 __add_back_capacity(__n - __back_capacity);
2197 // __n <= __back_capacity
2198 for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size())
2199 __alloc_traits::construct(__a, _VSTD::addressof(*__i));
2202 template <class _Tp, class _Allocator>
2204 deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v)
2206 allocator_type& __a = __base::__alloc();
2207 size_type __back_capacity = __back_spare();
2208 if (__n > __back_capacity)
2209 __add_back_capacity(__n - __back_capacity);
2210 // __n <= __back_capacity
2211 for (iterator __i = __base::end(); __n; --__n, ++__i, ++__base::size())
2212 __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v);
2215 // Create front capacity for one block of elements.
2216 // Strong guarantee. Either do it or don't touch anything.
2217 template <class _Tp, class _Allocator>
2219 deque<_Tp, _Allocator>::__add_front_capacity()
2221 allocator_type& __a = __base::__alloc();
2222 if (__back_spare() >= __base::__block_size)
2224 __base::__start_ += __base::__block_size;
2225 pointer __pt = __base::__map_.back();
2226 __base::__map_.pop_back();
2227 __base::__map_.push_front(__pt);
2229 // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer
2230 else if (__base::__map_.size() < __base::__map_.capacity())
2231 { // we can put the new buffer into the map, but don't shift things around
2232 // until all buffers are allocated. If we throw, we don't need to fix
2233 // anything up (any added buffers are undetectible)
2234 if (__base::__map_.__front_spare() > 0)
2235 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2238 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2239 // Done allocating, reorder capacity
2240 pointer __pt = __base::__map_.back();
2241 __base::__map_.pop_back();
2242 __base::__map_.push_front(__pt);
2244 __base::__start_ = __base::__map_.size() == 1 ?
2245 __base::__block_size / 2 :
2246 __base::__start_ + __base::__block_size;
2248 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
2251 __split_buffer<pointer, typename __base::__pointer_allocator&>
2252 __buf(max<size_type>(2 * __base::__map_.capacity(), 1),
2253 0, __base::__map_.__alloc());
2254 #ifndef _LIBCPP_NO_EXCEPTIONS
2257 #endif // _LIBCPP_NO_EXCEPTIONS
2258 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2259 #ifndef _LIBCPP_NO_EXCEPTIONS
2263 __alloc_traits::deallocate(__a, __buf.front(), __base::__block_size);
2266 #endif // _LIBCPP_NO_EXCEPTIONS
2267 for (typename __base::__map_pointer __i = __base::__map_.begin();
2268 __i != __base::__map_.end(); ++__i)
2269 __buf.push_back(*__i);
2270 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2271 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2272 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2273 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2274 __base::__start_ = __base::__map_.size() == 1 ?
2275 __base::__block_size / 2 :
2276 __base::__start_ + __base::__block_size;
2280 // Create front capacity for __n elements.
2281 // Strong guarantee. Either do it or don't touch anything.
2282 template <class _Tp, class _Allocator>
2284 deque<_Tp, _Allocator>::__add_front_capacity(size_type __n)
2286 allocator_type& __a = __base::__alloc();
2287 size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
2288 // Number of unused blocks at back:
2289 size_type __back_capacity = __back_spare() / __base::__block_size;
2290 __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need
2291 __nb -= __back_capacity; // number of blocks need to allocate
2292 // If __nb == 0, then we have sufficient capacity.
2295 __base::__start_ += __base::__block_size * __back_capacity;
2296 for (; __back_capacity > 0; --__back_capacity)
2298 pointer __pt = __base::__map_.back();
2299 __base::__map_.pop_back();
2300 __base::__map_.push_front(__pt);
2303 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2304 else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
2305 { // we can put the new buffers into the map, but don't shift things around
2306 // until all buffers are allocated. If we throw, we don't need to fix
2307 // anything up (any added buffers are undetectible)
2308 for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1))
2310 if (__base::__map_.__front_spare() == 0)
2312 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2314 for (; __nb > 0; --__nb, ++__back_capacity)
2315 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2316 // Done allocating, reorder capacity
2317 __base::__start_ += __back_capacity * __base::__block_size;
2318 for (; __back_capacity > 0; --__back_capacity)
2320 pointer __pt = __base::__map_.back();
2321 __base::__map_.pop_back();
2322 __base::__map_.push_front(__pt);
2325 // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
2328 size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty();
2329 __split_buffer<pointer, typename __base::__pointer_allocator&>
2330 __buf(max<size_type>(2* __base::__map_.capacity(),
2331 __nb + __base::__map_.size()),
2332 0, __base::__map_.__alloc());
2333 #ifndef _LIBCPP_NO_EXCEPTIONS
2336 #endif // _LIBCPP_NO_EXCEPTIONS
2337 for (; __nb > 0; --__nb)
2338 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2339 #ifndef _LIBCPP_NO_EXCEPTIONS
2343 for (typename __base::__map_pointer __i = __buf.begin();
2344 __i != __buf.end(); ++__i)
2345 __alloc_traits::deallocate(__a, *__i, __base::__block_size);
2348 #endif // _LIBCPP_NO_EXCEPTIONS
2349 for (; __back_capacity > 0; --__back_capacity)
2351 __buf.push_back(__base::__map_.back());
2352 __base::__map_.pop_back();
2354 for (typename __base::__map_pointer __i = __base::__map_.begin();
2355 __i != __base::__map_.end(); ++__i)
2356 __buf.push_back(*__i);
2357 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2358 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2359 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2360 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2361 __base::__start_ += __ds;
2365 // Create back capacity for one block of elements.
2366 // Strong guarantee. Either do it or don't touch anything.
2367 template <class _Tp, class _Allocator>
2369 deque<_Tp, _Allocator>::__add_back_capacity()
2371 allocator_type& __a = __base::__alloc();
2372 if (__front_spare() >= __base::__block_size)
2374 __base::__start_ -= __base::__block_size;
2375 pointer __pt = __base::__map_.front();
2376 __base::__map_.pop_front();
2377 __base::__map_.push_back(__pt);
2379 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2380 else if (__base::__map_.size() < __base::__map_.capacity())
2381 { // we can put the new buffer into the map, but don't shift things around
2382 // until it is allocated. If we throw, we don't need to fix
2383 // anything up (any added buffers are undetectible)
2384 if (__base::__map_.__back_spare() != 0)
2385 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2388 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2389 // Done allocating, reorder capacity
2390 pointer __pt = __base::__map_.front();
2391 __base::__map_.pop_front();
2392 __base::__map_.push_back(__pt);
2395 // Else need to allocate 1 buffer, *and* we need to reallocate __map_.
2398 __split_buffer<pointer, typename __base::__pointer_allocator&>
2399 __buf(max<size_type>(2* __base::__map_.capacity(), 1),
2400 __base::__map_.size(),
2401 __base::__map_.__alloc());
2402 #ifndef _LIBCPP_NO_EXCEPTIONS
2405 #endif // _LIBCPP_NO_EXCEPTIONS
2406 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2407 #ifndef _LIBCPP_NO_EXCEPTIONS
2411 __alloc_traits::deallocate(__a, __buf.back(), __base::__block_size);
2414 #endif // _LIBCPP_NO_EXCEPTIONS
2415 for (typename __base::__map_pointer __i = __base::__map_.end();
2416 __i != __base::__map_.begin();)
2417 __buf.push_front(*--__i);
2418 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2419 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2420 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2421 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2425 // Create back capacity for __n elements.
2426 // Strong guarantee. Either do it or don't touch anything.
2427 template <class _Tp, class _Allocator>
2429 deque<_Tp, _Allocator>::__add_back_capacity(size_type __n)
2431 allocator_type& __a = __base::__alloc();
2432 size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
2433 // Number of unused blocks at front:
2434 size_type __front_capacity = __front_spare() / __base::__block_size;
2435 __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need
2436 __nb -= __front_capacity; // number of blocks need to allocate
2437 // If __nb == 0, then we have sufficient capacity.
2440 __base::__start_ -= __base::__block_size * __front_capacity;
2441 for (; __front_capacity > 0; --__front_capacity)
2443 pointer __pt = __base::__map_.front();
2444 __base::__map_.pop_front();
2445 __base::__map_.push_back(__pt);
2448 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
2449 else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
2450 { // we can put the new buffers into the map, but don't shift things around
2451 // until all buffers are allocated. If we throw, we don't need to fix
2452 // anything up (any added buffers are undetectible)
2453 for (; __nb > 0; --__nb)
2455 if (__base::__map_.__back_spare() == 0)
2457 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2459 for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ +=
2460 __base::__block_size - (__base::__map_.size() == 1))
2461 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
2462 // Done allocating, reorder capacity
2463 __base::__start_ -= __base::__block_size * __front_capacity;
2464 for (; __front_capacity > 0; --__front_capacity)
2466 pointer __pt = __base::__map_.front();
2467 __base::__map_.pop_front();
2468 __base::__map_.push_back(__pt);
2471 // Else need to allocate __nb buffers, *and* we need to reallocate __map_.
2474 size_type __ds = __front_capacity * __base::__block_size;
2475 __split_buffer<pointer, typename __base::__pointer_allocator&>
2476 __buf(max<size_type>(2* __base::__map_.capacity(),
2477 __nb + __base::__map_.size()),
2478 __base::__map_.size() - __front_capacity,
2479 __base::__map_.__alloc());
2480 #ifndef _LIBCPP_NO_EXCEPTIONS
2483 #endif // _LIBCPP_NO_EXCEPTIONS
2484 for (; __nb > 0; --__nb)
2485 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
2486 #ifndef _LIBCPP_NO_EXCEPTIONS
2490 for (typename __base::__map_pointer __i = __buf.begin();
2491 __i != __buf.end(); ++__i)
2492 __alloc_traits::deallocate(__a, *__i, __base::__block_size);
2495 #endif // _LIBCPP_NO_EXCEPTIONS
2496 for (; __front_capacity > 0; --__front_capacity)
2498 __buf.push_back(__base::__map_.front());
2499 __base::__map_.pop_front();
2501 for (typename __base::__map_pointer __i = __base::__map_.end();
2502 __i != __base::__map_.begin();)
2503 __buf.push_front(*--__i);
2504 _VSTD::swap(__base::__map_.__first_, __buf.__first_);
2505 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
2506 _VSTD::swap(__base::__map_.__end_, __buf.__end_);
2507 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
2508 __base::__start_ -= __ds;
2512 template <class _Tp, class _Allocator>
2514 deque<_Tp, _Allocator>::pop_front()
2516 allocator_type& __a = __base::__alloc();
2517 __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
2518 __base::__start_ / __base::__block_size) +
2519 __base::__start_ % __base::__block_size));
2521 if (++__base::__start_ >= 2 * __base::__block_size)
2523 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2524 __base::__map_.pop_front();
2525 __base::__start_ -= __base::__block_size;
2529 template <class _Tp, class _Allocator>
2531 deque<_Tp, _Allocator>::pop_back()
2533 allocator_type& __a = __base::__alloc();
2534 size_type __p = __base::size() + __base::__start_ - 1;
2535 __alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
2536 __p / __base::__block_size) +
2537 __p % __base::__block_size));
2539 if (__back_spare() >= 2 * __base::__block_size)
2541 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2542 __base::__map_.pop_back();
2546 // move assign [__f, __l) to [__r, __r + (__l-__f)).
2547 // If __vt points into [__f, __l), then subtract (__f - __r) from __vt.
2548 template <class _Tp, class _Allocator>
2549 typename deque<_Tp, _Allocator>::iterator
2550 deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r,
2551 const_pointer& __vt)
2554 // for (; __f != __l; ++__f, ++__r)
2555 // *__r = _VSTD::move(*__f);
2556 difference_type __n = __l - __f;
2559 pointer __fb = __f.__ptr_;
2560 pointer __fe = *__f.__m_iter_ + __base::__block_size;
2561 difference_type __bs = __fe - __fb;
2567 if (__fb <= __vt && __vt < __fe)
2568 __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_;
2569 __r = _VSTD::move(__fb, __fe, __r);
2576 // move assign [__f, __l) to [__r - (__l-__f), __r) backwards.
2577 // If __vt points into [__f, __l), then add (__r - __l) to __vt.
2578 template <class _Tp, class _Allocator>
2579 typename deque<_Tp, _Allocator>::iterator
2580 deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r,
2581 const_pointer& __vt)
2584 // while (__f != __l)
2585 // *--__r = _VSTD::move(*--__l);
2586 difference_type __n = __l - __f;
2590 pointer __lb = *__l.__m_iter_;
2591 pointer __le = __l.__ptr_ + 1;
2592 difference_type __bs = __le - __lb;
2598 if (__lb <= __vt && __vt < __le)
2599 __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_;
2600 __r = _VSTD::move_backward(__lb, __le, __r);
2607 // move construct [__f, __l) to [__r, __r + (__l-__f)).
2608 // If __vt points into [__f, __l), then add (__r - __f) to __vt.
2609 template <class _Tp, class _Allocator>
2611 deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l,
2612 iterator __r, const_pointer& __vt)
2614 allocator_type& __a = __base::__alloc();
2616 // for (; __f != __l; ++__r, ++__f, ++__base::size())
2617 // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f));
2618 difference_type __n = __l - __f;
2621 pointer __fb = __f.__ptr_;
2622 pointer __fe = *__f.__m_iter_ + __base::__block_size;
2623 difference_type __bs = __fe - __fb;
2629 if (__fb <= __vt && __vt < __fe)
2630 __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_;
2631 for (; __fb != __fe; ++__fb, ++__r, ++__base::size())
2632 __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb));
2638 // move construct [__f, __l) to [__r - (__l-__f), __r) backwards.
2639 // If __vt points into [__f, __l), then subtract (__l - __r) from __vt.
2640 template <class _Tp, class _Allocator>
2642 deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l,
2643 iterator __r, const_pointer& __vt)
2645 allocator_type& __a = __base::__alloc();
2647 // for (iterator __j = __l; __j != __f;)
2649 // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j));
2650 // --__base::__start_;
2651 // ++__base::size();
2653 difference_type __n = __l - __f;
2657 pointer __lb = *__l.__m_iter_;
2658 pointer __le = __l.__ptr_ + 1;
2659 difference_type __bs = __le - __lb;
2665 if (__lb <= __vt && __vt < __le)
2666 __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_;
2667 while (__le != __lb)
2669 __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le));
2678 template <class _Tp, class _Allocator>
2679 typename deque<_Tp, _Allocator>::iterator
2680 deque<_Tp, _Allocator>::erase(const_iterator __f)
2682 difference_type __n = 1;
2683 iterator __b = __base::begin();
2684 difference_type __pos = __f - __b;
2685 iterator __p = __b + __pos;
2686 allocator_type& __a = __base::__alloc();
2687 if (__pos < (__base::size() - 1) / 2)
2688 { // erase from front
2689 _VSTD::move_backward(__b, __p, _VSTD::next(__p));
2690 __alloc_traits::destroy(__a, _VSTD::addressof(*__b));
2693 if (__front_spare() >= 2 * __base::__block_size)
2695 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2696 __base::__map_.pop_front();
2697 __base::__start_ -= __base::__block_size;
2701 { // erase from back
2702 iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p);
2703 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
2705 if (__back_spare() >= 2 * __base::__block_size)
2707 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2708 __base::__map_.pop_back();
2711 return __base::begin() + __pos;
2714 template <class _Tp, class _Allocator>
2715 typename deque<_Tp, _Allocator>::iterator
2716 deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l)
2718 difference_type __n = __l - __f;
2719 iterator __b = __base::begin();
2720 difference_type __pos = __f - __b;
2721 iterator __p = __b + __pos;
2724 allocator_type& __a = __base::__alloc();
2725 if (__pos < (__base::size() - __n) / 2)
2726 { // erase from front
2727 iterator __i = _VSTD::move_backward(__b, __p, __p + __n);
2728 for (; __b != __i; ++__b)
2729 __alloc_traits::destroy(__a, _VSTD::addressof(*__b));
2730 __base::size() -= __n;
2731 __base::__start_ += __n;
2732 while (__front_spare() >= 2 * __base::__block_size)
2734 __alloc_traits::deallocate(__a, __base::__map_.front(), __base::__block_size);
2735 __base::__map_.pop_front();
2736 __base::__start_ -= __base::__block_size;
2740 { // erase from back
2741 iterator __i = _VSTD::move(__p + __n, __base::end(), __p);
2742 for (iterator __e = __base::end(); __i != __e; ++__i)
2743 __alloc_traits::destroy(__a, _VSTD::addressof(*__i));
2744 __base::size() -= __n;
2745 while (__back_spare() >= 2 * __base::__block_size)
2747 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2748 __base::__map_.pop_back();
2752 return __base::begin() + __pos;
2755 template <class _Tp, class _Allocator>
2757 deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f)
2759 iterator __e = __base::end();
2760 difference_type __n = __e - __f;
2763 allocator_type& __a = __base::__alloc();
2764 iterator __b = __base::begin();
2765 difference_type __pos = __f - __b;
2766 for (iterator __p = __b + __pos; __p != __e; ++__p)
2767 __alloc_traits::destroy(__a, _VSTD::addressof(*__p));
2768 __base::size() -= __n;
2769 while (__back_spare() >= 2 * __base::__block_size)
2771 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
2772 __base::__map_.pop_back();
2777 template <class _Tp, class _Allocator>
2778 inline _LIBCPP_INLINE_VISIBILITY
2780 deque<_Tp, _Allocator>::swap(deque& __c)
2781 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2782 __is_nothrow_swappable<allocator_type>::value)
2787 template <class _Tp, class _Allocator>
2788 inline _LIBCPP_INLINE_VISIBILITY
2790 deque<_Tp, _Allocator>::clear() _NOEXCEPT
2795 template <class _Tp, class _Allocator>
2796 _LIBCPP_INLINE_VISIBILITY inline
2798 operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2800 const typename deque<_Tp, _Allocator>::size_type __sz = __x.size();
2801 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
2804 template <class _Tp, class _Allocator>
2805 _LIBCPP_INLINE_VISIBILITY inline
2807 operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2809 return !(__x == __y);
2812 template <class _Tp, class _Allocator>
2813 _LIBCPP_INLINE_VISIBILITY inline
2815 operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2817 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2820 template <class _Tp, class _Allocator>
2821 _LIBCPP_INLINE_VISIBILITY inline
2823 operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2828 template <class _Tp, class _Allocator>
2829 _LIBCPP_INLINE_VISIBILITY inline
2831 operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2833 return !(__x < __y);
2836 template <class _Tp, class _Allocator>
2837 _LIBCPP_INLINE_VISIBILITY inline
2839 operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
2841 return !(__y < __x);
2844 template <class _Tp, class _Allocator>
2845 _LIBCPP_INLINE_VISIBILITY inline
2847 swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y)
2848 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2853 _LIBCPP_END_NAMESPACE_STD
2855 #endif // _LIBCPP_DEQUE