57 #define _STL_DEQUE_H 1 62 #if __cplusplus >= 201103L 69 namespace std _GLIBCXX_VISIBILITY(default)
71 _GLIBCXX_BEGIN_NAMESPACE_VERSION
72 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
88 #ifndef _GLIBCXX_DEQUE_BUF_SIZE 89 #define _GLIBCXX_DEQUE_BUF_SIZE 512 92 _GLIBCXX_CONSTEXPR
inline size_t 93 __deque_buf_size(
size_t __size)
109 template<
typename _Tp,
typename _Ref,
typename _Ptr>
112 #if __cplusplus < 201103L 115 typedef _Tp* _Elt_pointer;
116 typedef _Tp** _Map_pointer;
119 template<
typename _Up>
121 template<
typename _CvTp>
126 typedef __ptr_to<_Tp> _Elt_pointer;
127 typedef __ptr_to<_Elt_pointer> _Map_pointer;
130 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
131 {
return __deque_buf_size(
sizeof(_Tp)); }
134 typedef _Tp value_type;
135 typedef _Ptr pointer;
136 typedef _Ref reference;
137 typedef size_t size_type;
138 typedef ptrdiff_t difference_type;
142 _Elt_pointer _M_first;
143 _Elt_pointer _M_last;
144 _Map_pointer _M_node;
147 : _M_cur(__x), _M_first(*__y),
148 _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
151 : _M_cur(), _M_first(), _M_last(), _M_node() { }
153 #if __cplusplus < 201103L 156 : _M_cur(__x._M_cur), _M_first(__x._M_first),
157 _M_last(__x._M_last), _M_node(__x._M_node) { }
160 template<
typename _Iter,
161 typename = _Require<is_same<_Self, const_iterator>,
164 : _M_cur(__x._M_cur), _M_first(__x._M_first),
165 _M_last(__x._M_last), _M_node(__x._M_node) { }
172 _M_const_cast()
const _GLIBCXX_NOEXCEPT
173 {
return iterator(_M_cur, _M_node); }
176 operator*()
const _GLIBCXX_NOEXCEPT
180 operator->()
const _GLIBCXX_NOEXCEPT
184 operator++() _GLIBCXX_NOEXCEPT
187 if (_M_cur == _M_last)
196 operator++(
int) _GLIBCXX_NOEXCEPT
204 operator--() _GLIBCXX_NOEXCEPT
206 if (_M_cur == _M_first)
216 operator--(
int) _GLIBCXX_NOEXCEPT
224 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
226 const difference_type __offset = __n + (_M_cur - _M_first);
227 if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
231 const difference_type __node_offset =
232 __offset > 0 ? __offset / difference_type(_S_buffer_size())
233 : -difference_type((-__offset - 1)
234 / _S_buffer_size()) - 1;
236 _M_cur = _M_first + (__offset - __node_offset
237 * difference_type(_S_buffer_size()));
243 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
250 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
251 {
return *
this += -__n; }
254 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
261 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
262 {
return *(*
this + __n); }
272 _M_node = __new_node;
273 _M_first = *__new_node;
274 _M_last = _M_first + difference_type(_S_buffer_size());
281 template<
typename _Tp,
typename _Ref,
typename _Ptr>
283 operator==(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
284 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
285 {
return __x._M_cur == __y._M_cur; }
287 template<
typename _Tp,
typename _RefL,
typename _PtrL,
288 typename _RefR,
typename _PtrR>
290 operator==(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
291 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
292 {
return __x._M_cur == __y._M_cur; }
294 template<
typename _Tp,
typename _Ref,
typename _Ptr>
296 operator!=(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
297 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
298 {
return !(__x == __y); }
300 template<
typename _Tp,
typename _RefL,
typename _PtrL,
301 typename _RefR,
typename _PtrR>
303 operator!=(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
304 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
305 {
return !(__x == __y); }
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 (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
312 : (__x._M_node < __y._M_node); }
314 template<
typename _Tp,
typename _RefL,
typename _PtrL,
315 typename _RefR,
typename _PtrR>
317 operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
318 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
319 {
return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
320 : (__x._M_node < __y._M_node); }
322 template<
typename _Tp,
typename _Ref,
typename _Ptr>
324 operator>(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
325 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
326 {
return __y < __x; }
328 template<
typename _Tp,
typename _RefL,
typename _PtrL,
329 typename _RefR,
typename _PtrR>
331 operator>(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
332 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
333 {
return __y < __x; }
335 template<
typename _Tp,
typename _Ref,
typename _Ptr>
337 operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
338 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
339 {
return !(__y < __x); }
341 template<
typename _Tp,
typename _RefL,
typename _PtrL,
342 typename _RefR,
typename _PtrR>
344 operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
345 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
346 {
return !(__y < __x); }
348 template<
typename _Tp,
typename _Ref,
typename _Ptr>
350 operator>=(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
351 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
352 {
return !(__x < __y); }
354 template<
typename _Tp,
typename _RefL,
typename _PtrL,
355 typename _RefR,
typename _PtrR>
357 operator>=(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
358 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
359 {
return !(__x < __y); }
365 template<
typename _Tp,
typename _Ref,
typename _Ptr>
366 inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
367 operator-(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
368 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
370 return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
371 (_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size())
372 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
373 + (__y._M_last - __y._M_cur);
376 template<
typename _Tp,
typename _RefL,
typename _PtrL,
377 typename _RefR,
typename _PtrR>
378 inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
379 operator-(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
380 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
382 return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
383 (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size())
384 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
385 + (__y._M_last - __y._M_cur);
388 template<
typename _Tp,
typename _Ref,
typename _Ptr>
389 inline _Deque_iterator<_Tp, _Ref, _Ptr>
390 operator+(ptrdiff_t __n,
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
392 {
return __x + __n; }
394 template<
typename _Tp>
396 fill(
const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
397 const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
const _Tp&);
399 template<
typename _Tp>
400 _Deque_iterator<_Tp, _Tp&, _Tp*>
401 copy(_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(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
408 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
409 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
410 {
return std::copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
411 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
414 template<
typename _Tp>
415 _Deque_iterator<_Tp, _Tp&, _Tp*>
416 copy_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
417 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
418 _Deque_iterator<_Tp, _Tp&, _Tp*>);
420 template<
typename _Tp>
421 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
422 copy_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
423 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
424 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
425 {
return std::copy_backward(_Deque_iterator<_Tp,
426 const _Tp&,
const _Tp*>(__first),
428 const _Tp&,
const _Tp*>(__last),
431 #if __cplusplus >= 201103L 432 template<
typename _Tp>
433 _Deque_iterator<_Tp, _Tp&, _Tp*>
434 move(_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(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
441 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
442 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
443 {
return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
444 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
447 template<
typename _Tp>
448 _Deque_iterator<_Tp, _Tp&, _Tp*>
449 move_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
450 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
451 _Deque_iterator<_Tp, _Tp&, _Tp*>);
453 template<
typename _Tp>
454 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
455 move_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
456 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
457 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
458 {
return std::move_backward(_Deque_iterator<_Tp,
459 const _Tp&,
const _Tp*>(__first),
461 const _Tp&,
const _Tp*>(__last),
475 template<
typename _Tp,
typename _Alloc>
480 rebind<_Tp>::other _Tp_alloc_type;
483 #if __cplusplus < 201103L 485 typedef const _Tp* _Ptr_const;
487 typedef typename _Alloc_traits::pointer _Ptr;
488 typedef typename _Alloc_traits::const_pointer _Ptr_const;
491 typedef typename _Alloc_traits::template rebind<_Ptr>::other
496 typedef _Alloc allocator_type;
499 get_allocator()
const _GLIBCXX_NOEXCEPT
500 {
return allocator_type(_M_get_Tp_allocator()); }
513 _Deque_base(
const allocator_type& __a,
size_t __num_elements)
521 #if __cplusplus >= 201103L 523 : _M_impl(__x._M_move_impl())
527 : _M_impl(std::move(__x._M_get_Tp_allocator()))
530 if (__x._M_impl._M_map)
531 this->_M_impl._M_swap_data(__x._M_impl);
541 if (__x.get_allocator() == __a)
543 if (__x._M_impl._M_map)
546 this->_M_impl._M_swap_data(__x._M_impl);
559 typedef typename iterator::_Map_pointer _Map_pointer;
565 :
public _Tp_alloc_type
573 : _Tp_alloc_type(), _M_map(), _M_map_size(0),
574 _M_start(), _M_finish()
577 _Deque_impl(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
578 : _Tp_alloc_type(__a), _M_map(), _M_map_size(0),
579 _M_start(), _M_finish()
582 #if __cplusplus >= 201103L 583 _Deque_impl(_Deque_impl&&) =
default;
585 _Deque_impl(_Tp_alloc_type&& __a) noexcept
586 : _Tp_alloc_type(std::move(__a)), _M_map(), _M_map_size(0),
587 _M_start(), _M_finish()
591 void _M_swap_data(_Deque_impl& __x) _GLIBCXX_NOEXCEPT
594 swap(this->_M_start, __x._M_start);
595 swap(this->_M_finish, __x._M_finish);
596 swap(this->_M_map, __x._M_map);
597 swap(this->_M_map_size, __x._M_map_size);
602 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
603 {
return *
static_cast<_Tp_alloc_type*
>(&this->_M_impl); }
605 const _Tp_alloc_type&
606 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
607 {
return *
static_cast<const _Tp_alloc_type*
>(&this->_M_impl); }
610 _M_get_map_allocator()
const _GLIBCXX_NOEXCEPT
611 {
return _Map_alloc_type(_M_get_Tp_allocator()); }
617 return _Traits::allocate(_M_impl, __deque_buf_size(
sizeof(_Tp)));
621 _M_deallocate_node(_Ptr __p) _GLIBCXX_NOEXCEPT
624 _Traits::deallocate(_M_impl, __p, __deque_buf_size(
sizeof(_Tp)));
628 _M_allocate_map(
size_t __n)
630 _Map_alloc_type __map_alloc = _M_get_map_allocator();
635 _M_deallocate_map(_Map_pointer __p,
size_t __n) _GLIBCXX_NOEXCEPT
637 _Map_alloc_type __map_alloc = _M_get_map_allocator();
643 void _M_create_nodes(_Map_pointer __nstart, _Map_pointer __nfinish);
644 void _M_destroy_nodes(_Map_pointer __nstart,
645 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT;
646 enum { _S_initial_map_size = 8 };
650 #if __cplusplus >= 201103L 656 return std::move(_M_impl);
659 _Tp_alloc_type __alloc{_M_get_Tp_allocator()};
661 _Tp_alloc_type __sink __attribute((__unused__)) {std::move(__alloc)};
666 _Deque_impl __ret{std::move(_M_get_Tp_allocator())};
667 _M_impl._M_swap_data(__ret);
668 _M_impl._M_swap_data(__empty._M_impl);
674 template<
typename _Tp,
typename _Alloc>
675 _Deque_base<_Tp, _Alloc>::
676 ~_Deque_base() _GLIBCXX_NOEXCEPT
678 if (this->_M_impl._M_map)
680 _M_destroy_nodes(this->_M_impl._M_start._M_node,
681 this->_M_impl._M_finish._M_node + 1);
682 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
694 template<
typename _Tp,
typename _Alloc>
699 const size_t __num_nodes = (__num_elements/ __deque_buf_size(
sizeof(_Tp))
702 this->_M_impl._M_map_size =
std::max((
size_t) _S_initial_map_size,
703 size_t(__num_nodes + 2));
704 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
711 _Map_pointer __nstart = (this->_M_impl._M_map
712 + (this->_M_impl._M_map_size - __num_nodes) / 2);
713 _Map_pointer __nfinish = __nstart + __num_nodes;
716 { _M_create_nodes(__nstart, __nfinish); }
719 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
720 this->_M_impl._M_map = _Map_pointer();
721 this->_M_impl._M_map_size = 0;
722 __throw_exception_again;
725 this->_M_impl._M_start._M_set_node(__nstart);
726 this->_M_impl._M_finish._M_set_node(__nfinish - 1);
727 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
728 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
730 % __deque_buf_size(
sizeof(_Tp)));
733 template<
typename _Tp,
typename _Alloc>
741 for (__cur = __nstart; __cur < __nfinish; ++__cur)
742 *__cur = this->_M_allocate_node();
746 _M_destroy_nodes(__nstart, __cur);
747 __throw_exception_again;
751 template<
typename _Tp,
typename _Alloc>
753 _Deque_base<_Tp, _Alloc>::
754 _M_destroy_nodes(_Map_pointer __nstart,
755 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT
757 for (_Map_pointer __n = __nstart; __n < __nfinish; ++__n)
758 _M_deallocate_node(*__n);
845 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
848 #ifdef _GLIBCXX_CONCEPT_CHECKS 850 typedef typename _Alloc::value_type _Alloc_value_type;
851 # if __cplusplus < 201103L 852 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
854 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
857 #if __cplusplus >= 201103L 858 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
859 "std::deque must have a non-const, non-volatile value_type");
860 # ifdef __STRICT_ANSI__ 862 "std::deque must have the same value_type as its allocator");
867 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
869 typedef typename _Base::_Map_pointer _Map_pointer;
872 typedef _Tp value_type;
873 typedef typename _Alloc_traits::pointer pointer;
874 typedef typename _Alloc_traits::const_pointer const_pointer;
875 typedef typename _Alloc_traits::reference reference;
876 typedef typename _Alloc_traits::const_reference const_reference;
881 typedef size_t size_type;
882 typedef ptrdiff_t difference_type;
883 typedef _Alloc allocator_type;
886 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
887 {
return __deque_buf_size(
sizeof(_Tp)); }
891 using _Base::_M_create_nodes;
892 using _Base::_M_destroy_nodes;
893 using _Base::_M_allocate_node;
894 using _Base::_M_deallocate_node;
895 using _Base::_M_allocate_map;
896 using _Base::_M_deallocate_map;
897 using _Base::_M_get_Tp_allocator;
903 using _Base::_M_impl;
922 #if __cplusplus >= 201103L 933 :
_Base(__a, _S_check_init_len(__n, __a))
934 { _M_default_initialize(); }
944 deque(size_type __n,
const value_type& __value,
946 :
_Base(__a, _S_check_init_len(__n, __a))
958 deque(size_type __n,
const value_type& __value = value_type(),
959 const allocator_type& __a = allocator_type())
960 : _Base(__a, _S_check_init_len(__n, __a))
974 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
975 this->_M_impl._M_start,
976 _M_get_Tp_allocator()); }
978 #if __cplusplus >= 201103L 992 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
993 this->_M_impl._M_start,
994 _M_get_Tp_allocator()); }
1000 if (__x.get_allocator() != __a)
1002 std::__uninitialized_move_a(__x.begin(), __x.end(),
1003 this->_M_impl._M_start,
1004 _M_get_Tp_allocator());
1044 #if __cplusplus >= 201103L 1045 template<
typename _InputIterator,
1046 typename = std::_RequireInputIter<_InputIterator>>
1047 deque(_InputIterator __first, _InputIterator __last,
1050 { _M_initialize_dispatch(__first, __last, __false_type()); }
1052 template<
typename _InputIterator>
1053 deque(_InputIterator __first, _InputIterator __last,
1054 const allocator_type& __a = allocator_type())
1058 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1059 _M_initialize_dispatch(__first, __last, _Integral());
1069 { _M_destroy_data(
begin(),
end(), _M_get_Tp_allocator()); }
1083 #if __cplusplus >= 201103L 1096 _M_move_assign1(std::move(__x), __always_equal{});
1114 _M_assign_aux(__l.begin(), __l.end(),
1131 assign(size_type __n,
const value_type& __val)
1132 { _M_fill_assign(__n, __val); }
1146 #if __cplusplus >= 201103L 1147 template<
typename _InputIterator,
1148 typename = std::_RequireInputIter<_InputIterator>>
1150 assign(_InputIterator __first, _InputIterator __last)
1151 { _M_assign_dispatch(__first, __last, __false_type()); }
1153 template<
typename _InputIterator>
1155 assign(_InputIterator __first, _InputIterator __last)
1157 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1158 _M_assign_dispatch(__first, __last, _Integral());
1162 #if __cplusplus >= 201103L 1182 {
return _Base::get_allocator(); }
1191 {
return this->_M_impl._M_start; }
1199 {
return this->_M_impl._M_start; }
1208 {
return this->_M_impl._M_finish; }
1217 {
return this->_M_impl._M_finish; }
1233 const_reverse_iterator
1251 const_reverse_iterator
1255 #if __cplusplus >= 201103L 1262 {
return this->_M_impl._M_start; }
1271 {
return this->_M_impl._M_finish; }
1278 const_reverse_iterator
1287 const_reverse_iterator
1296 {
return this->_M_impl._M_finish - this->_M_impl._M_start; }
1301 {
return _S_max_size(_M_get_Tp_allocator()); }
1303 #if __cplusplus >= 201103L 1316 const size_type __len =
size();
1317 if (__new_size > __len)
1318 _M_default_append(__new_size - __len);
1319 else if (__new_size < __len)
1320 _M_erase_at_end(this->_M_impl._M_start
1321 + difference_type(__new_size));
1336 resize(size_type __new_size,
const value_type& __x)
1338 const size_type __len =
size();
1339 if (__new_size > __len)
1340 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1341 else if (__new_size < __len)
1342 _M_erase_at_end(this->_M_impl._M_start
1343 + difference_type(__new_size));
1358 resize(size_type __new_size, value_type __x = value_type())
1360 const size_type __len =
size();
1361 if (__new_size > __len)
1362 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1363 else if (__new_size < __len)
1364 _M_erase_at_end(this->_M_impl._M_start
1365 + difference_type(__new_size));
1369 #if __cplusplus >= 201103L 1373 { _M_shrink_to_fit(); }
1380 _GLIBCXX_NODISCARD
bool 1382 {
return this->_M_impl._M_finish == this->_M_impl._M_start; }
1399 __glibcxx_requires_subscript(__n);
1400 return this->_M_impl._M_start[difference_type(__n)];
1417 __glibcxx_requires_subscript(__n);
1418 return this->_M_impl._M_start[difference_type(__n)];
1426 if (__n >= this->
size())
1427 __throw_out_of_range_fmt(__N(
"deque::_M_range_check: __n " 1428 "(which is %zu)>= this->size() " 1449 return (*
this)[__n];
1467 return (*
this)[__n];
1477 __glibcxx_requires_nonempty();
1488 __glibcxx_requires_nonempty();
1499 __glibcxx_requires_nonempty();
1512 __glibcxx_requires_nonempty();
1531 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1533 _Alloc_traits::construct(this->_M_impl,
1534 this->_M_impl._M_start._M_cur - 1,
1536 --this->_M_impl._M_start._M_cur;
1542 #if __cplusplus >= 201103L 1545 { emplace_front(std::move(__x)); }
1547 template<
typename... _Args>
1548 #if __cplusplus > 201402L 1553 emplace_front(_Args&&... __args);
1568 if (this->_M_impl._M_finish._M_cur
1569 != this->_M_impl._M_finish._M_last - 1)
1571 _Alloc_traits::construct(this->_M_impl,
1572 this->_M_impl._M_finish._M_cur, __x);
1573 ++this->_M_impl._M_finish._M_cur;
1579 #if __cplusplus >= 201103L 1582 { emplace_back(std::move(__x)); }
1584 template<
typename... _Args>
1585 #if __cplusplus > 201402L 1590 emplace_back(_Args&&... __args);
1604 __glibcxx_requires_nonempty();
1605 if (this->_M_impl._M_start._M_cur
1606 != this->_M_impl._M_start._M_last - 1)
1608 _Alloc_traits::destroy(this->_M_impl,
1609 this->_M_impl._M_start._M_cur);
1610 ++this->_M_impl._M_start._M_cur;
1627 __glibcxx_requires_nonempty();
1628 if (this->_M_impl._M_finish._M_cur
1629 != this->_M_impl._M_finish._M_first)
1631 --this->_M_impl._M_finish._M_cur;
1632 _Alloc_traits::destroy(this->_M_impl,
1633 this->_M_impl._M_finish._M_cur);
1639 #if __cplusplus >= 201103L 1649 template<
typename... _Args>
1651 emplace(const_iterator __position, _Args&&... __args);
1663 insert(const_iterator __position,
const value_type& __x);
1678 #if __cplusplus >= 201103L 1690 {
return emplace(__position, std::move(__x)); }
1704 auto __offset = __p -
cbegin();
1705 _M_range_insert_aux(__p._M_const_cast(), __l.begin(), __l.end(),
1707 return begin() + __offset;
1711 #if __cplusplus >= 201103L 1725 difference_type __offset = __position -
cbegin();
1726 _M_fill_insert(__position._M_const_cast(), __n, __x);
1727 return begin() + __offset;
1740 insert(
iterator __position, size_type __n,
const value_type& __x)
1741 { _M_fill_insert(__position, __n, __x); }
1744 #if __cplusplus >= 201103L 1756 template<
typename _InputIterator,
1757 typename = std::_RequireInputIter<_InputIterator>>
1760 _InputIterator __last)
1762 difference_type __offset = __position -
cbegin();
1763 _M_insert_dispatch(__position._M_const_cast(),
1764 __first, __last, __false_type());
1765 return begin() + __offset;
1778 template<
typename _InputIterator>
1781 _InputIterator __last)
1784 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1785 _M_insert_dispatch(__position, __first, __last, _Integral());
1803 #if __cplusplus >= 201103L 1808 {
return _M_erase(__position._M_const_cast()); }
1827 #if __cplusplus >= 201103L 1832 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1848 #if __cplusplus >= 201103L 1849 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1850 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1852 _M_impl._M_swap_data(__x._M_impl);
1853 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1854 __x._M_get_Tp_allocator());
1865 { _M_erase_at_end(
begin()); }
1874 template<
typename _Integer>
1876 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1879 _M_get_Tp_allocator()));
1884 _S_check_init_len(
size_t __n,
const allocator_type& __a)
1886 if (__n > _S_max_size(__a))
1887 __throw_length_error(
1888 __N(
"cannot create std::deque larger than max_size()"));
1893 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1895 const size_t __diffmax = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max;
1897 return (
std::min)(__diffmax, __allocmax);
1901 template<
typename _InputIterator>
1903 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1922 template<
typename _InputIterator>
1928 template<
typename _ForwardIterator>
1947 #if __cplusplus >= 201103L 1950 _M_default_initialize();
1960 template<
typename _Integer>
1962 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1963 { _M_fill_assign(__n, __val); }
1966 template<
typename _InputIterator>
1968 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1973 template<
typename _InputIterator>
1975 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1979 template<
typename _ForwardIterator>
1981 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1987 _ForwardIterator __mid = __first;
1989 std::copy(__first, __mid,
begin());
1990 _M_range_insert_aux(
end(), __mid, __last,
1994 _M_erase_at_end(std::copy(__first, __last,
begin()));
2000 _M_fill_assign(size_type __n,
const value_type& __val)
2005 _M_fill_insert(
end(), __n -
size(), __val);
2009 _M_erase_at_end(
begin() + difference_type(__n));
2016 #if __cplusplus < 201103L 2021 template<
typename... _Args>
2024 template<
typename... _Args>
2040 template<
typename _Integer>
2042 _M_insert_dispatch(iterator __pos,
2043 _Integer __n, _Integer __x, __true_type)
2044 { _M_fill_insert(__pos, __n, __x); }
2047 template<
typename _InputIterator>
2049 _M_insert_dispatch(iterator __pos,
2050 _InputIterator __first, _InputIterator __last,
2053 _M_range_insert_aux(__pos, __first, __last,
2058 template<
typename _InputIterator>
2060 _M_range_insert_aux(iterator __pos, _InputIterator __first,
2064 template<
typename _ForwardIterator>
2066 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
2073 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
2076 #if __cplusplus < 201103L 2078 _M_insert_aux(iterator __pos,
const value_type& __x);
2080 template<
typename... _Args>
2082 _M_insert_aux(iterator __pos, _Args&&... __args);
2087 _M_insert_aux(iterator __pos, size_type __n,
const value_type& __x);
2090 template<
typename _ForwardIterator>
2092 _M_insert_aux(iterator __pos,
2093 _ForwardIterator __first, _ForwardIterator __last,
2100 _M_destroy_data_aux(iterator __first, iterator __last);
2104 template<
typename _Alloc1>
2106 _M_destroy_data(iterator __first, iterator __last,
const _Alloc1&)
2107 { _M_destroy_data_aux(__first, __last); }
2110 _M_destroy_data(iterator __first, iterator __last,
2113 if (!__has_trivial_destructor(value_type))
2114 _M_destroy_data_aux(__first, __last);
2119 _M_erase_at_begin(iterator __pos)
2121 _M_destroy_data(
begin(), __pos, _M_get_Tp_allocator());
2122 _M_destroy_nodes(this->
_M_impl._M_start._M_node, __pos._M_node);
2123 this->
_M_impl._M_start = __pos;
2129 _M_erase_at_end(iterator __pos)
2131 _M_destroy_data(__pos,
end(), _M_get_Tp_allocator());
2132 _M_destroy_nodes(__pos._M_node + 1,
2133 this->_M_impl._M_finish._M_node + 1);
2134 this->
_M_impl._M_finish = __pos;
2138 _M_erase(iterator __pos);
2141 _M_erase(iterator __first, iterator __last);
2143 #if __cplusplus >= 201103L 2146 _M_default_append(size_type __n);
2157 const size_type __vacancies = this->_M_impl._M_start._M_cur
2158 - this->_M_impl._M_start._M_first;
2159 if (__n > __vacancies)
2161 return this->_M_impl._M_start - difference_type(__n);
2167 const size_type __vacancies = (this->_M_impl._M_finish._M_last
2168 - this->_M_impl._M_finish._M_cur) - 1;
2169 if (__n > __vacancies)
2171 return this->_M_impl._M_finish + difference_type(__n);
2193 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
2194 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
2201 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
2202 - this->_M_impl._M_map))
2210 #if __cplusplus >= 201103L 2216 this->_M_impl._M_swap_data(__x._M_impl);
2218 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2227 constexpr
bool __move_storage =
2228 _Alloc_traits::_S_propagate_on_move_assign();
2229 _M_move_assign2(std::move(__x), __bool_constant<__move_storage>());
2234 template<
typename... _Args>
2236 _M_replace_map(_Args&&... __args)
2239 deque __newobj(std::forward<_Args>(__args)...);
2242 _M_deallocate_node(*
begin()._M_node);
2243 _M_deallocate_map(this->
_M_impl._M_map, this->_M_impl._M_map_size);
2244 this->
_M_impl._M_map =
nullptr;
2245 this->
_M_impl._M_map_size = 0;
2247 this->
_M_impl._M_swap_data(__newobj._M_impl);
2255 auto __alloc = __x._M_get_Tp_allocator();
2258 _M_replace_map(std::move(__x));
2260 _M_get_Tp_allocator() = std::move(__alloc);
2268 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2272 _M_replace_map(std::move(__x), __x.get_allocator());
2278 _M_assign_aux(std::__make_move_if_noexcept_iterator(__x.begin()),
2279 std::__make_move_if_noexcept_iterator(__x.end()),
2287 #if __cpp_deduction_guides >= 201606 2288 template<
typename _InputIterator,
typename _ValT
2289 =
typename iterator_traits<_InputIterator>::value_type,
2290 typename _Allocator = allocator<_ValT>,
2291 typename = _RequireInputIter<_InputIterator>,
2292 typename = _RequireAllocator<_Allocator>>
2293 deque(_InputIterator, _InputIterator, _Allocator = _Allocator())
2294 -> deque<_ValT, _Allocator>;
2307 template<
typename _Tp,
typename _Alloc>
2325 template<
typename _Tp,
typename _Alloc>
2327 operator<(const deque<_Tp, _Alloc>& __x,
2330 __y.begin(), __y.end()); }
2333 template<
typename _Tp,
typename _Alloc>
2337 {
return !(__x == __y); }
2340 template<
typename _Tp,
typename _Alloc>
2344 {
return __y < __x; }
2347 template<
typename _Tp,
typename _Alloc>
2349 operator<=(const deque<_Tp, _Alloc>& __x,
2351 {
return !(__y < __x); }
2354 template<
typename _Tp,
typename _Alloc>
2358 {
return !(__x < __y); }
2361 template<
typename _Tp,
typename _Alloc>
2364 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
2367 #undef _GLIBCXX_DEQUE_BUF_SIZE 2369 _GLIBCXX_END_NAMESPACE_CONTAINER
2371 #if __cplusplus >= 201103L 2375 struct __is_bitwise_relocatable<_GLIBCXX_STD_C::deque<_Tp>>
2379 _GLIBCXX_END_NAMESPACE_VERSION
#define _GLIBCXX_DEQUE_BUF_SIZE
This function controls the size of memory nodes.
deque(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a deque from an initializer list.
reference at(size_type __n)
Provides access to the data contained in the deque.
void assign(size_type __n, const value_type &__val)
Assigns a given value to a deque.
deque & operator=(deque &&__x) noexcept(_Alloc_traits::_S_always_equal())
Deque move assignment operator.
deque & operator=(const deque &__x)
Deque assignment operator.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
deque(size_type __n, const allocator_type &__a=allocator_type())
Creates a deque with default constructed elements.
Random-access iterators support a superset of bidirectional iterator operations.
void _M_set_node(_Map_pointer __new_node) noexcept
void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front)
Memory-handling helpers for the major map.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a deque.
const_reverse_iterator crbegin() const noexcept
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.
iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
deque(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a deque with copies of an exemplar element.
ISO C++ entities toplevel namespace is std.
iterator erase(const_iterator __position)
Remove element at given position.
The standard allocator, as per [20.4].
void push_back(const value_type &__x)
Add data to the end of the deque.
void push_front(const value_type &__x)
Add data to the front of the deque.
const_iterator begin() const noexcept
deque & operator=(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
void resize(size_type __new_size)
Resizes the deque to the specified number of elements.
const_iterator end() const noexcept
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
void pop_front() noexcept
Removes first element.
_GLIBCXX20_CONSTEXPR complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
void _M_pop_front_aux()
Helper functions for push_* and pop_*.
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.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
iterator insert(const_iterator __p, initializer_list< value_type > __l)
Inserts an initializer list into the deque.
reverse_iterator rbegin() noexcept
_GLIBCXX_NODISCARD bool empty() const noexcept
const_reference front() const noexcept
Uniform interface to C++98 and C++11 allocators.
iterator insert(const_iterator __position, const value_type &__x)
Inserts given value into deque before specified iterator.
__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 _M_reserve_map_at_front(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
deque(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a deque from a range.
void swap(deque &__x) noexcept
Swaps data with another deque.
iterator insert(const_iterator __position, size_type __n, const value_type &__x)
Inserts a number of copies of given data into the deque.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
deque(deque &&__x, const allocator_type &__a)
Move constructor with alternative allocator.
const_reverse_iterator rend() const noexcept
deque(const allocator_type &__a)
Creates a deque with no elements.
reference back() noexcept
void _M_range_initialize(_InputIterator __first, _InputIterator __last, std::input_iterator_tag)
Fills the deque with whatever is in [first,last).
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
static size_type max_size(const _Tp_alloc_type &__a) noexcept
The maximum supported allocation size.
void _M_fill_initialize(const value_type &__value)
Fills the deque with copies of value.
const_reference operator[](size_type __n) const noexcept
Subscript access to the data contained in the deque.
deque(const deque &__x)
Deque copy constructor.
void _M_initialize_map(size_t)
Layout storage.
A standard container using fixed-size memory allocation and constant-time manipulation of elements at...
void shrink_to_fit() noexcept
iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into deque before specified iterator.
const_iterator cbegin() const noexcept
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
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_*.
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
void _M_new_elements_at_front(size_type __new_elements)
Memory-handling helpers for the previous internal insert functions.
static _GLIBCXX_NODISCARD pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
iterator emplace(const_iterator __position, _Args &&... __args)
Inserts an object in deque before specified iterator.
void assign(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
size_type size() const noexcept
void _M_range_check(size_type __n) const
Safety check used only from at().
_GLIBCXX20_CONSTEXPR complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
deque()
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.
iterator _M_reserve_elements_at_back(size_type __n)
Memory-handling helpers for the previous internal insert functions.
void pop_back() noexcept
Removes last element.
size_type max_size() const noexcept
reverse_iterator rend() noexcept
const_reference back() const noexcept
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
deque(deque &&__x)
Deque move constructor.
void _M_pop_back_aux()
Helper functions for push_* and pop_*.
iterator _M_reserve_elements_at_front(size_type __n)
Memory-handling helpers for the previous internal insert functions.
iterator begin() noexcept
iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the deque.
Forward iterators support a superset of input iterator operations.
reference front() noexcept
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
const_reference at(size_type __n) const
Provides access to the data contained in the deque.
void _M_reserve_map_at_back(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
const_iterator cend() const noexcept
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
Uniform interface to all pointer-like types.
const_reverse_iterator rbegin() const noexcept