57 #define _STL_DEQUE_H 1 62 #if __cplusplus >= 201103L 68 namespace std _GLIBCXX_VISIBILITY(default)
70 _GLIBCXX_BEGIN_NAMESPACE_VERSION
71 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
87 #ifndef _GLIBCXX_DEQUE_BUF_SIZE 88 #define _GLIBCXX_DEQUE_BUF_SIZE 512 91 _GLIBCXX_CONSTEXPR
inline size_t 92 __deque_buf_size(
size_t __size)
108 template<
typename _Tp,
typename _Ref,
typename _Ptr>
111 #if __cplusplus < 201103L 114 typedef _Tp* _Elt_pointer;
115 typedef _Tp** _Map_pointer;
118 template<
typename _Up>
120 template<
typename _CvTp>
125 typedef __ptr_to<_Tp> _Elt_pointer;
126 typedef __ptr_to<_Elt_pointer> _Map_pointer;
129 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
130 {
return __deque_buf_size(
sizeof(_Tp)); }
133 typedef _Tp value_type;
134 typedef _Ptr pointer;
135 typedef _Ref reference;
136 typedef size_t size_type;
137 typedef ptrdiff_t difference_type;
141 _Elt_pointer _M_first;
142 _Elt_pointer _M_last;
143 _Map_pointer _M_node;
146 : _M_cur(__x), _M_first(*__y),
147 _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
150 : _M_cur(), _M_first(), _M_last(), _M_node() { }
153 : _M_cur(__x._M_cur), _M_first(__x._M_first),
154 _M_last(__x._M_last), _M_node(__x._M_node) { }
157 _M_const_cast()
const _GLIBCXX_NOEXCEPT
158 {
return iterator(_M_cur, _M_node); }
161 operator*()
const _GLIBCXX_NOEXCEPT
165 operator->()
const _GLIBCXX_NOEXCEPT
169 operator++() _GLIBCXX_NOEXCEPT
172 if (_M_cur == _M_last)
181 operator++(
int) _GLIBCXX_NOEXCEPT
189 operator--() _GLIBCXX_NOEXCEPT
191 if (_M_cur == _M_first)
201 operator--(
int) _GLIBCXX_NOEXCEPT
209 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
211 const difference_type __offset = __n + (_M_cur - _M_first);
212 if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
216 const difference_type __node_offset =
217 __offset > 0 ? __offset / difference_type(_S_buffer_size())
218 : -difference_type((-__offset - 1)
219 / _S_buffer_size()) - 1;
221 _M_cur = _M_first + (__offset - __node_offset
222 * difference_type(_S_buffer_size()));
228 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
235 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
236 {
return *
this += -__n; }
239 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
246 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
247 {
return *(*
this + __n); }
257 _M_node = __new_node;
258 _M_first = *__new_node;
259 _M_last = _M_first + difference_type(_S_buffer_size());
266 template<
typename _Tp,
typename _Ref,
typename _Ptr>
268 operator==(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
269 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
270 {
return __x._M_cur == __y._M_cur; }
272 template<
typename _Tp,
typename _RefL,
typename _PtrL,
273 typename _RefR,
typename _PtrR>
275 operator==(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
276 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
277 {
return __x._M_cur == __y._M_cur; }
279 template<
typename _Tp,
typename _Ref,
typename _Ptr>
281 operator!=(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
282 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
283 {
return !(__x == __y); }
285 template<
typename _Tp,
typename _RefL,
typename _PtrL,
286 typename _RefR,
typename _PtrR>
288 operator!=(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
289 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
290 {
return !(__x == __y); }
292 template<
typename _Tp,
typename _Ref,
typename _Ptr>
294 operator<(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
295 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
296 {
return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
297 : (__x._M_node < __y._M_node); }
299 template<
typename _Tp,
typename _RefL,
typename _PtrL,
300 typename _RefR,
typename _PtrR>
302 operator<(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
303 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
304 {
return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
305 : (__x._M_node < __y._M_node); }
307 template<
typename _Tp,
typename _Ref,
typename _Ptr>
309 operator>(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
310 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
311 {
return __y < __x; }
313 template<
typename _Tp,
typename _RefL,
typename _PtrL,
314 typename _RefR,
typename _PtrR>
316 operator>(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
317 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
318 {
return __y < __x; }
320 template<
typename _Tp,
typename _Ref,
typename _Ptr>
322 operator<=(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
323 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
324 {
return !(__y < __x); }
326 template<
typename _Tp,
typename _RefL,
typename _PtrL,
327 typename _RefR,
typename _PtrR>
329 operator<=(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
330 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
331 {
return !(__y < __x); }
333 template<
typename _Tp,
typename _Ref,
typename _Ptr>
335 operator>=(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
336 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
337 {
return !(__x < __y); }
339 template<
typename _Tp,
typename _RefL,
typename _PtrL,
340 typename _RefR,
typename _PtrR>
342 operator>=(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
343 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
344 {
return !(__x < __y); }
350 template<
typename _Tp,
typename _Ref,
typename _Ptr>
351 inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
352 operator-(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
353 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
355 return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
356 (_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size())
357 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
358 + (__y._M_last - __y._M_cur);
361 template<
typename _Tp,
typename _RefL,
typename _PtrL,
362 typename _RefR,
typename _PtrR>
363 inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
364 operator-(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
365 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
367 return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
368 (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size())
369 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
370 + (__y._M_last - __y._M_cur);
373 template<
typename _Tp,
typename _Ref,
typename _Ptr>
374 inline _Deque_iterator<_Tp, _Ref, _Ptr>
375 operator+(ptrdiff_t __n,
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
377 {
return __x + __n; }
379 template<
typename _Tp>
381 fill(
const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
382 const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
const _Tp&);
384 template<
typename _Tp>
385 _Deque_iterator<_Tp, _Tp&, _Tp*>
386 copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
387 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
388 _Deque_iterator<_Tp, _Tp&, _Tp*>);
390 template<
typename _Tp>
391 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
392 copy(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
393 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
394 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
395 {
return std::copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
396 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
399 template<
typename _Tp>
400 _Deque_iterator<_Tp, _Tp&, _Tp*>
401 copy_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
402 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
403 _Deque_iterator<_Tp, _Tp&, _Tp*>);
405 template<
typename _Tp>
406 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
407 copy_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
408 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
409 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
410 {
return std::copy_backward(_Deque_iterator<_Tp,
411 const _Tp&,
const _Tp*>(__first),
413 const _Tp&,
const _Tp*>(__last),
416 #if __cplusplus >= 201103L 417 template<
typename _Tp>
418 _Deque_iterator<_Tp, _Tp&, _Tp*>
419 move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
420 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
421 _Deque_iterator<_Tp, _Tp&, _Tp*>);
423 template<
typename _Tp>
424 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
425 move(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
426 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
427 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
428 {
return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
429 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
432 template<
typename _Tp>
433 _Deque_iterator<_Tp, _Tp&, _Tp*>
434 move_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
435 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
436 _Deque_iterator<_Tp, _Tp&, _Tp*>);
438 template<
typename _Tp>
439 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
440 move_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
441 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
442 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
443 {
return std::move_backward(_Deque_iterator<_Tp,
444 const _Tp&,
const _Tp*>(__first),
446 const _Tp&,
const _Tp*>(__last),
460 template<
typename _Tp,
typename _Alloc>
465 rebind<_Tp>::other _Tp_alloc_type;
468 #if __cplusplus < 201103L 470 typedef const _Tp* _Ptr_const;
472 typedef typename _Alloc_traits::pointer _Ptr;
473 typedef typename _Alloc_traits::const_pointer _Ptr_const;
476 typedef typename _Alloc_traits::template rebind<_Ptr>::other
481 typedef _Alloc allocator_type;
482 typedef typename _Alloc_traits::size_type size_type;
485 get_allocator()
const _GLIBCXX_NOEXCEPT
486 {
return allocator_type(_M_get_Tp_allocator()); }
499 _Deque_base(
const allocator_type& __a,
size_t __num_elements)
507 #if __cplusplus >= 201103L 509 : _M_impl(__x._M_move_impl())
513 : _M_impl(std::move(__x._M_get_Tp_allocator()))
516 if (__x._M_impl._M_map)
517 this->_M_impl._M_swap_data(__x._M_impl);
527 if (__x.get_allocator() == __a)
529 if (__x._M_impl._M_map)
532 this->_M_impl._M_swap_data(__x._M_impl);
545 typedef typename iterator::_Map_pointer _Map_pointer;
551 :
public _Tp_alloc_type
559 : _Tp_alloc_type(), _M_map(), _M_map_size(0),
560 _M_start(), _M_finish()
563 _Deque_impl(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
564 : _Tp_alloc_type(__a), _M_map(), _M_map_size(0),
565 _M_start(), _M_finish()
568 #if __cplusplus >= 201103L 569 _Deque_impl(_Deque_impl&&) =
default;
571 _Deque_impl(_Tp_alloc_type&& __a) noexcept
572 : _Tp_alloc_type(std::move(__a)), _M_map(), _M_map_size(0),
573 _M_start(), _M_finish()
577 void _M_swap_data(_Deque_impl& __x) _GLIBCXX_NOEXCEPT
580 swap(this->_M_start, __x._M_start);
581 swap(this->_M_finish, __x._M_finish);
582 swap(this->_M_map, __x._M_map);
583 swap(this->_M_map_size, __x._M_map_size);
588 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
589 {
return *static_cast<_Tp_alloc_type*>(&this->_M_impl); }
591 const _Tp_alloc_type&
592 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
593 {
return *static_cast<const _Tp_alloc_type*>(&this->_M_impl); }
596 _M_get_map_allocator()
const _GLIBCXX_NOEXCEPT
597 {
return _Map_alloc_type(_M_get_Tp_allocator()); }
603 return _Traits::allocate(_M_impl, __deque_buf_size(
sizeof(_Tp)));
607 _M_deallocate_node(_Ptr __p) _GLIBCXX_NOEXCEPT
610 _Traits::deallocate(_M_impl, __p, __deque_buf_size(
sizeof(_Tp)));
614 _M_allocate_map(
size_t __n)
616 _Map_alloc_type __map_alloc = _M_get_map_allocator();
621 _M_deallocate_map(_Map_pointer __p,
size_t __n) _GLIBCXX_NOEXCEPT
623 _Map_alloc_type __map_alloc = _M_get_map_allocator();
629 void _M_create_nodes(_Map_pointer __nstart, _Map_pointer __nfinish);
630 void _M_destroy_nodes(_Map_pointer __nstart,
631 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT;
632 enum { _S_initial_map_size = 8 };
636 #if __cplusplus >= 201103L 642 return std::move(_M_impl);
645 _Tp_alloc_type __alloc{_M_get_Tp_allocator()};
647 _Tp_alloc_type __sink __attribute((__unused__)) {std::move(__alloc)};
652 _Deque_impl __ret{std::move(_M_get_Tp_allocator())};
653 _M_impl._M_swap_data(__ret);
654 _M_impl._M_swap_data(__empty._M_impl);
660 template<
typename _Tp,
typename _Alloc>
661 _Deque_base<_Tp, _Alloc>::
662 ~_Deque_base() _GLIBCXX_NOEXCEPT
664 if (this->_M_impl._M_map)
666 _M_destroy_nodes(this->_M_impl._M_start._M_node,
667 this->_M_impl._M_finish._M_node + 1);
668 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
680 template<
typename _Tp,
typename _Alloc>
685 const size_t __num_nodes = (__num_elements/ __deque_buf_size(
sizeof(_Tp))
688 this->_M_impl._M_map_size =
std::max((
size_t) _S_initial_map_size,
689 size_t(__num_nodes + 2));
690 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
697 _Map_pointer __nstart = (this->_M_impl._M_map
698 + (this->_M_impl._M_map_size - __num_nodes) / 2);
699 _Map_pointer __nfinish = __nstart + __num_nodes;
702 { _M_create_nodes(__nstart, __nfinish); }
705 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
706 this->_M_impl._M_map = _Map_pointer();
707 this->_M_impl._M_map_size = 0;
708 __throw_exception_again;
711 this->_M_impl._M_start._M_set_node(__nstart);
712 this->_M_impl._M_finish._M_set_node(__nfinish - 1);
713 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
714 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
716 % __deque_buf_size(
sizeof(_Tp)));
719 template<
typename _Tp,
typename _Alloc>
727 for (__cur = __nstart; __cur < __nfinish; ++__cur)
728 *__cur = this->_M_allocate_node();
732 _M_destroy_nodes(__nstart, __cur);
733 __throw_exception_again;
737 template<
typename _Tp,
typename _Alloc>
739 _Deque_base<_Tp, _Alloc>::
740 _M_destroy_nodes(_Map_pointer __nstart,
741 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT
743 for (_Map_pointer __n = __nstart; __n < __nfinish; ++__n)
744 _M_deallocate_node(*__n);
831 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
834 #ifdef _GLIBCXX_CONCEPT_CHECKS 836 typedef typename _Alloc::value_type _Alloc_value_type;
837 # if __cplusplus < 201103L 838 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
840 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
843 #if __cplusplus >= 201103L 844 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
845 "std::deque must have a non-const, non-volatile value_type");
846 # ifdef __STRICT_ANSI__ 848 "std::deque must have the same value_type as its allocator");
853 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
855 typedef typename _Base::_Map_pointer _Map_pointer;
858 typedef _Tp value_type;
859 typedef typename _Alloc_traits::pointer pointer;
860 typedef typename _Alloc_traits::const_pointer const_pointer;
861 typedef typename _Alloc_traits::reference reference;
862 typedef typename _Alloc_traits::const_reference const_reference;
867 typedef size_t size_type;
868 typedef ptrdiff_t difference_type;
869 typedef _Alloc allocator_type;
872 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
873 {
return __deque_buf_size(
sizeof(_Tp)); }
877 using _Base::_M_create_nodes;
878 using _Base::_M_destroy_nodes;
879 using _Base::_M_allocate_node;
880 using _Base::_M_deallocate_node;
881 using _Base::_M_allocate_map;
882 using _Base::_M_deallocate_map;
883 using _Base::_M_get_Tp_allocator;
889 using _Base::_M_impl;
908 #if __cplusplus >= 201103L 920 { _M_default_initialize(); }
930 deque(size_type __n,
const value_type& __value,
944 deque(size_type __n,
const value_type& __value = value_type(),
945 const allocator_type& __a = allocator_type())
960 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
961 this->_M_impl._M_start,
962 _M_get_Tp_allocator()); }
964 #if __cplusplus >= 201103L 978 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
979 this->_M_impl._M_start,
980 _M_get_Tp_allocator()); }
986 if (__x.get_allocator() != __a)
988 std::__uninitialized_move_a(__x.begin(), __x.end(),
989 this->_M_impl._M_start,
990 _M_get_Tp_allocator());
1030 #if __cplusplus >= 201103L 1031 template<
typename _InputIterator,
1032 typename = std::_RequireInputIter<_InputIterator>>
1033 deque(_InputIterator __first, _InputIterator __last,
1036 { _M_initialize_dispatch(__first, __last, __false_type()); }
1038 template<
typename _InputIterator>
1039 deque(_InputIterator __first, _InputIterator __last,
1040 const allocator_type& __a = allocator_type())
1044 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1045 _M_initialize_dispatch(__first, __last, _Integral());
1055 { _M_destroy_data(
begin(),
end(), _M_get_Tp_allocator()); }
1069 #if __cplusplus >= 201103L 1082 _M_move_assign1(std::move(__x), __always_equal{});
1100 _M_assign_aux(__l.begin(), __l.end(),
1117 assign(size_type __n,
const value_type& __val)
1118 { _M_fill_assign(__n, __val); }
1132 #if __cplusplus >= 201103L 1133 template<
typename _InputIterator,
1134 typename = std::_RequireInputIter<_InputIterator>>
1136 assign(_InputIterator __first, _InputIterator __last)
1137 { _M_assign_dispatch(__first, __last, __false_type()); }
1139 template<
typename _InputIterator>
1141 assign(_InputIterator __first, _InputIterator __last)
1143 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1144 _M_assign_dispatch(__first, __last, _Integral());
1148 #if __cplusplus >= 201103L 1168 {
return _Base::get_allocator(); }
1177 {
return this->_M_impl._M_start; }
1185 {
return this->_M_impl._M_start; }
1194 {
return this->_M_impl._M_finish; }
1203 {
return this->_M_impl._M_finish; }
1219 const_reverse_iterator
1237 const_reverse_iterator
1241 #if __cplusplus >= 201103L 1248 {
return this->_M_impl._M_start; }
1257 {
return this->_M_impl._M_finish; }
1264 const_reverse_iterator
1273 const_reverse_iterator
1282 {
return this->_M_impl._M_finish - this->_M_impl._M_start; }
1289 #if __cplusplus >= 201103L 1302 const size_type __len =
size();
1303 if (__new_size > __len)
1304 _M_default_append(__new_size - __len);
1305 else if (__new_size < __len)
1306 _M_erase_at_end(this->_M_impl._M_start
1307 + difference_type(__new_size));
1322 resize(size_type __new_size,
const value_type& __x)
1324 const size_type __len =
size();
1325 if (__new_size > __len)
1326 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1327 else if (__new_size < __len)
1328 _M_erase_at_end(this->_M_impl._M_start
1329 + difference_type(__new_size));
1344 resize(size_type __new_size, value_type __x = value_type())
1346 const size_type __len =
size();
1347 if (__new_size > __len)
1348 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1349 else if (__new_size < __len)
1350 _M_erase_at_end(this->_M_impl._M_start
1351 + difference_type(__new_size));
1355 #if __cplusplus >= 201103L 1359 { _M_shrink_to_fit(); }
1368 {
return this->_M_impl._M_finish == this->_M_impl._M_start; }
1385 __glibcxx_requires_subscript(__n);
1386 return this->_M_impl._M_start[difference_type(__n)];
1403 __glibcxx_requires_subscript(__n);
1404 return this->_M_impl._M_start[difference_type(__n)];
1412 if (__n >= this->
size())
1413 __throw_out_of_range_fmt(__N(
"deque::_M_range_check: __n " 1414 "(which is %zu)>= this->size() " 1435 return (*
this)[__n];
1453 return (*
this)[__n];
1463 __glibcxx_requires_nonempty();
1474 __glibcxx_requires_nonempty();
1485 __glibcxx_requires_nonempty();
1498 __glibcxx_requires_nonempty();
1517 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1519 _Alloc_traits::construct(this->_M_impl,
1520 this->_M_impl._M_start._M_cur - 1,
1522 --this->_M_impl._M_start._M_cur;
1528 #if __cplusplus >= 201103L 1531 { emplace_front(std::move(__x)); }
1533 template<
typename... _Args>
1534 #if __cplusplus > 201402L 1539 emplace_front(_Args&&... __args);
1554 if (this->_M_impl._M_finish._M_cur
1555 != this->_M_impl._M_finish._M_last - 1)
1557 _Alloc_traits::construct(this->_M_impl,
1558 this->_M_impl._M_finish._M_cur, __x);
1559 ++this->_M_impl._M_finish._M_cur;
1565 #if __cplusplus >= 201103L 1568 { emplace_back(std::move(__x)); }
1570 template<
typename... _Args>
1571 #if __cplusplus > 201402L 1576 emplace_back(_Args&&... __args);
1590 __glibcxx_requires_nonempty();
1591 if (this->_M_impl._M_start._M_cur
1592 != this->_M_impl._M_start._M_last - 1)
1594 _Alloc_traits::destroy(this->_M_impl,
1595 this->_M_impl._M_start._M_cur);
1596 ++this->_M_impl._M_start._M_cur;
1613 __glibcxx_requires_nonempty();
1614 if (this->_M_impl._M_finish._M_cur
1615 != this->_M_impl._M_finish._M_first)
1617 --this->_M_impl._M_finish._M_cur;
1618 _Alloc_traits::destroy(this->_M_impl,
1619 this->_M_impl._M_finish._M_cur);
1625 #if __cplusplus >= 201103L 1635 template<
typename... _Args>
1637 emplace(const_iterator __position, _Args&&... __args);
1649 insert(const_iterator __position,
const value_type& __x);
1664 #if __cplusplus >= 201103L 1676 {
return emplace(__position, std::move(__x)); }
1690 auto __offset = __p -
cbegin();
1691 _M_range_insert_aux(__p._M_const_cast(), __l.begin(), __l.end(),
1693 return begin() + __offset;
1697 #if __cplusplus >= 201103L 1711 difference_type __offset = __position -
cbegin();
1712 _M_fill_insert(__position._M_const_cast(), __n, __x);
1713 return begin() + __offset;
1726 insert(
iterator __position, size_type __n,
const value_type& __x)
1727 { _M_fill_insert(__position, __n, __x); }
1730 #if __cplusplus >= 201103L 1742 template<
typename _InputIterator,
1743 typename = std::_RequireInputIter<_InputIterator>>
1746 _InputIterator __last)
1748 difference_type __offset = __position -
cbegin();
1749 _M_insert_dispatch(__position._M_const_cast(),
1750 __first, __last, __false_type());
1751 return begin() + __offset;
1764 template<
typename _InputIterator>
1767 _InputIterator __last)
1770 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1771 _M_insert_dispatch(__position, __first, __last, _Integral());
1789 #if __cplusplus >= 201103L 1794 {
return _M_erase(__position._M_const_cast()); }
1813 #if __cplusplus >= 201103L 1818 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1834 #if __cplusplus >= 201103L 1835 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1836 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1838 _M_impl._M_swap_data(__x._M_impl);
1839 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1840 __x._M_get_Tp_allocator());
1851 { _M_erase_at_end(
begin()); }
1860 template<
typename _Integer>
1862 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1869 template<
typename _InputIterator>
1871 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1890 template<
typename _InputIterator>
1896 template<
typename _ForwardIterator>
1915 #if __cplusplus >= 201103L 1918 _M_default_initialize();
1928 template<
typename _Integer>
1930 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1931 { _M_fill_assign(__n, __val); }
1934 template<
typename _InputIterator>
1936 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1941 template<
typename _InputIterator>
1943 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1947 template<
typename _ForwardIterator>
1949 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1955 _ForwardIterator __mid = __first;
1957 std::copy(__first, __mid,
begin());
1958 _M_range_insert_aux(
end(), __mid, __last,
1962 _M_erase_at_end(std::copy(__first, __last,
begin()));
1968 _M_fill_assign(size_type __n,
const value_type& __val)
1973 _M_fill_insert(
end(), __n -
size(), __val);
1977 _M_erase_at_end(
begin() + difference_type(__n));
1984 #if __cplusplus < 201103L 1989 template<
typename... _Args>
1992 template<
typename... _Args>
2008 template<
typename _Integer>
2010 _M_insert_dispatch(iterator __pos,
2011 _Integer __n, _Integer __x, __true_type)
2012 { _M_fill_insert(__pos, __n, __x); }
2015 template<
typename _InputIterator>
2017 _M_insert_dispatch(iterator __pos,
2018 _InputIterator __first, _InputIterator __last,
2021 _M_range_insert_aux(__pos, __first, __last,
2026 template<
typename _InputIterator>
2028 _M_range_insert_aux(iterator __pos, _InputIterator __first,
2032 template<
typename _ForwardIterator>
2034 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
2041 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
2044 #if __cplusplus < 201103L 2046 _M_insert_aux(iterator __pos,
const value_type& __x);
2048 template<
typename... _Args>
2050 _M_insert_aux(iterator __pos, _Args&&... __args);
2055 _M_insert_aux(iterator __pos, size_type __n,
const value_type& __x);
2058 template<
typename _ForwardIterator>
2060 _M_insert_aux(iterator __pos,
2061 _ForwardIterator __first, _ForwardIterator __last,
2068 _M_destroy_data_aux(iterator __first, iterator __last);
2072 template<
typename _Alloc1>
2074 _M_destroy_data(iterator __first, iterator __last,
const _Alloc1&)
2075 { _M_destroy_data_aux(__first, __last); }
2078 _M_destroy_data(iterator __first, iterator __last,
2081 if (!__has_trivial_destructor(value_type))
2082 _M_destroy_data_aux(__first, __last);
2087 _M_erase_at_begin(iterator __pos)
2089 _M_destroy_data(
begin(), __pos, _M_get_Tp_allocator());
2090 _M_destroy_nodes(this->
_M_impl._M_start._M_node, __pos._M_node);
2091 this->
_M_impl._M_start = __pos;
2097 _M_erase_at_end(iterator __pos)
2099 _M_destroy_data(__pos,
end(), _M_get_Tp_allocator());
2100 _M_destroy_nodes(__pos._M_node + 1,
2101 this->_M_impl._M_finish._M_node + 1);
2102 this->
_M_impl._M_finish = __pos;
2106 _M_erase(iterator __pos);
2109 _M_erase(iterator __first, iterator __last);
2111 #if __cplusplus >= 201103L 2114 _M_default_append(size_type __n);
2125 const size_type __vacancies = this->_M_impl._M_start._M_cur
2126 - this->_M_impl._M_start._M_first;
2127 if (__n > __vacancies)
2129 return this->_M_impl._M_start - difference_type(__n);
2135 const size_type __vacancies = (this->_M_impl._M_finish._M_last
2136 - this->_M_impl._M_finish._M_cur) - 1;
2137 if (__n > __vacancies)
2139 return this->_M_impl._M_finish + difference_type(__n);
2161 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
2162 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
2169 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
2170 - this->_M_impl._M_map))
2178 #if __cplusplus >= 201103L 2184 this->_M_impl._M_swap_data(__x._M_impl);
2186 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2195 constexpr
bool __move_storage =
2196 _Alloc_traits::_S_propagate_on_move_assign();
2197 _M_move_assign2(std::move(__x), __bool_constant<__move_storage>());
2202 template<
typename... _Args>
2204 _M_replace_map(_Args&&... __args)
2207 deque __newobj(std::forward<_Args>(__args)...);
2210 _M_deallocate_node(*
begin()._M_node);
2211 _M_deallocate_map(this->
_M_impl._M_map, this->_M_impl._M_map_size);
2212 this->
_M_impl._M_map =
nullptr;
2213 this->
_M_impl._M_map_size = 0;
2215 this->
_M_impl._M_swap_data(__newobj._M_impl);
2223 auto __alloc = __x._M_get_Tp_allocator();
2226 _M_replace_map(std::move(__x));
2228 _M_get_Tp_allocator() = std::move(__alloc);
2236 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2240 _M_replace_map(std::move(__x), __x.get_allocator());
2246 _M_assign_aux(std::__make_move_if_noexcept_iterator(__x.begin()),
2247 std::__make_move_if_noexcept_iterator(__x.end()),
2255 #if __cpp_deduction_guides >= 201606 2256 template<
typename _InputIterator,
typename _ValT
2257 =
typename iterator_traits<_InputIterator>::value_type,
2258 typename _Allocator = allocator<_ValT>,
2259 typename = _RequireInputIter<_InputIterator>,
2260 typename = _RequireAllocator<_Allocator>>
2261 deque(_InputIterator, _InputIterator, _Allocator = _Allocator())
2262 -> deque<_ValT, _Allocator>;
2275 template<
typename _Tp,
typename _Alloc>
2293 template<
typename _Tp,
typename _Alloc>
2301 template<
typename _Tp,
typename _Alloc>
2305 {
return !(__x == __y); }
2308 template<
typename _Tp,
typename _Alloc>
2312 {
return __y < __x; }
2315 template<
typename _Tp,
typename _Alloc>
2319 {
return !(__y < __x); }
2322 template<
typename _Tp,
typename _Alloc>
2326 {
return !(__x < __y); }
2329 template<
typename _Tp,
typename _Alloc>
2332 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
2335 #undef _GLIBCXX_DEQUE_BUF_SIZE 2337 _GLIBCXX_END_NAMESPACE_CONTAINER
2338 _GLIBCXX_END_NAMESPACE_VERSION
void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front)
Memory-handling helpers for the major map.
const_iterator cend() const noexcept
complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
const_reverse_iterator rbegin() const noexcept
void _M_pop_front_aux()
Helper functions for push_* and pop_*.
deque(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a deque from a range.
void _M_range_check(size_type __n) const
Safety check used only from at().
deque(const deque &__x)
Deque copy constructor.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
The standard allocator, as per [20.4].
static size_type max_size(const _Tp_alloc_type &__a) noexcept
The maximum supported allocation size.
void _M_reserve_map_at_front(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
const_reverse_iterator crend() const noexcept
void resize(size_type __new_size, const value_type &__x)
Resizes the deque to the specified number of elements.
const_reference back() const noexcept
__detected_or_t< typename is_empty< _Tp_alloc_type >::type, __equal, _Tp_alloc_type > is_always_equal
Whether all instances of the allocator type compare equal.
void pop_back() noexcept
Removes last element.
Forward iterators support a superset of input iterator operations.
static pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
const_iterator begin() const noexcept
void _M_pop_back_aux()
Helper functions for push_* and pop_*.
void _M_fill_initialize(const value_type &__value)
Fills the deque with copies of value.
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into deque before specified iterator.
reverse_iterator rbegin() noexcept
deque()
Creates a deque with no elements.
void assign(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
deque & operator=(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
void swap(deque &__x) noexcept
Swaps data with another deque.
void _M_push_back_aux(_Args &&... __args)
Helper functions for push_* and pop_*.
reference operator[](size_type __n) noexcept
Subscript access to the data contained in the deque.
size_type max_size() const noexcept
iterator insert(const_iterator __position, const value_type &__x)
Inserts given value into deque before specified iterator.
bool empty() const noexcept
const_reference front() const noexcept
deque(const deque &__x, const allocator_type &__a)
Copy constructor with alternative allocator.
void _M_push_front_aux(_Args &&... __args)
Helper functions for push_* and pop_*.
ISO C++ entities toplevel namespace is std.
const_reverse_iterator rend() const noexcept
deque(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a deque from an initializer list.
deque & operator=(const deque &__x)
Deque assignment operator.
size_type size() const noexcept
void _M_range_initialize(_InputIterator __first, _InputIterator __last, std::input_iterator_tag)
Fills the deque with whatever is in [first,last).
reverse_iterator rend() noexcept
void assign(size_type __n, const value_type &__val)
Assigns a given value to a deque.
reference at(size_type __n)
Provides access to the data contained in the deque.
const_reference at(size_type __n) const
Provides access to the data contained in the deque.
#define _GLIBCXX_DEQUE_BUF_SIZE
This function controls the size of memory nodes.
void pop_front() noexcept
Removes first element.
void _M_initialize_map(size_t)
Layout storage.
deque(deque &&__x, const allocator_type &__a)
Move constructor with alternative allocator.
const_iterator cbegin() const noexcept
iterator _M_reserve_elements_at_back(size_type __n)
Memory-handling helpers for the previous internal insert functions.
deque(deque &&__x)
Deque move constructor.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
deque(const allocator_type &__a)
Creates a deque with no elements.
void _M_new_elements_at_back(size_type __new_elements)
Memory-handling helpers for the previous internal insert functions.
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
reference back() noexcept
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
iterator erase(const_iterator __position)
Remove element at given position.
void _M_set_node(_Map_pointer __new_node) noexcept
void _M_new_elements_at_front(size_type __new_elements)
Memory-handling helpers for the previous internal insert functions.
iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the deque.
deque & operator=(deque &&__x) noexcept(_Alloc_traits::_S_always_equal())
Deque move assignment operator.
deque(size_type __n, const allocator_type &__a=allocator_type())
Creates a deque with default constructed elements.
Uniform interface to all pointer-like types.
iterator emplace(const_iterator __position, _Args &&... __args)
Inserts an object in deque before specified iterator.
Uniform interface to C++98 and C++11 allocators.
void push_back(const value_type &__x)
Add data to the end of the deque.
A standard container using fixed-size memory allocation and constant-time manipulation of elements at...
Random-access iterators support a superset of bidirectional iterator operations.
reference front() noexcept
iterator _M_reserve_elements_at_front(size_type __n)
Memory-handling helpers for the previous internal insert functions.
iterator begin() noexcept
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
const_reference operator[](size_type __n) const noexcept
Subscript access to the data contained in the deque.
void push_front(const value_type &__x)
Add data to the front of the deque.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a deque.
const_reverse_iterator crbegin() const noexcept
iterator insert(const_iterator __position, size_type __n, const value_type &__x)
Inserts a number of copies of given data into the deque.
deque(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a deque with copies of an exemplar element.
void resize(size_type __new_size)
Resizes the deque to the specified number of elements.
const_iterator end() const noexcept
void shrink_to_fit() noexcept
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
iterator insert(const_iterator __p, initializer_list< value_type > __l)
Inserts an initializer list into the deque.
void _M_reserve_map_at_back(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.