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) { }
168 : _M_cur(__x._M_cur), _M_first(__x._M_first),
169 _M_last(__x._M_last), _M_node(__x._M_node) { }
175 _M_const_cast()
const _GLIBCXX_NOEXCEPT
176 {
return iterator(_M_cur, _M_node); }
179 operator*()
const _GLIBCXX_NOEXCEPT
183 operator->()
const _GLIBCXX_NOEXCEPT
187 operator++() _GLIBCXX_NOEXCEPT
190 if (_M_cur == _M_last)
199 operator++(
int) _GLIBCXX_NOEXCEPT
207 operator--() _GLIBCXX_NOEXCEPT
209 if (_M_cur == _M_first)
219 operator--(
int) _GLIBCXX_NOEXCEPT
227 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
229 const difference_type __offset = __n + (_M_cur - _M_first);
230 if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
234 const difference_type __node_offset =
235 __offset > 0 ? __offset / difference_type(_S_buffer_size())
236 : -difference_type((-__offset - 1)
237 / _S_buffer_size()) - 1;
239 _M_cur = _M_first + (__offset - __node_offset
240 * difference_type(_S_buffer_size()));
246 operator+(difference_type __n)
const _GLIBCXX_NOEXCEPT
253 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
254 {
return *
this += -__n; }
257 operator-(difference_type __n)
const _GLIBCXX_NOEXCEPT
264 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
265 {
return *(*
this + __n); }
275 _M_node = __new_node;
276 _M_first = *__new_node;
277 _M_last = _M_first + difference_type(_S_buffer_size());
284 template<
typename _Tp,
typename _Ref,
typename _Ptr>
286 operator==(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
287 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
288 {
return __x._M_cur == __y._M_cur; }
290 template<
typename _Tp,
typename _RefL,
typename _PtrL,
291 typename _RefR,
typename _PtrR>
293 operator==(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
294 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
295 {
return __x._M_cur == __y._M_cur; }
297 template<
typename _Tp,
typename _Ref,
typename _Ptr>
299 operator!=(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
300 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
301 {
return !(__x == __y); }
303 template<
typename _Tp,
typename _RefL,
typename _PtrL,
304 typename _RefR,
typename _PtrR>
306 operator!=(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
307 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
308 {
return !(__x == __y); }
310 template<
typename _Tp,
typename _Ref,
typename _Ptr>
312 operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
313 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
314 {
return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
315 : (__x._M_node < __y._M_node); }
317 template<
typename _Tp,
typename _RefL,
typename _PtrL,
318 typename _RefR,
typename _PtrR>
320 operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
321 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
322 {
return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
323 : (__x._M_node < __y._M_node); }
325 template<
typename _Tp,
typename _Ref,
typename _Ptr>
327 operator>(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
328 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
329 {
return __y < __x; }
331 template<
typename _Tp,
typename _RefL,
typename _PtrL,
332 typename _RefR,
typename _PtrR>
334 operator>(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
335 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
336 {
return __y < __x; }
338 template<
typename _Tp,
typename _Ref,
typename _Ptr>
340 operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
341 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
342 {
return !(__y < __x); }
344 template<
typename _Tp,
typename _RefL,
typename _PtrL,
345 typename _RefR,
typename _PtrR>
347 operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
348 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
349 {
return !(__y < __x); }
351 template<
typename _Tp,
typename _Ref,
typename _Ptr>
353 operator>=(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
354 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
355 {
return !(__x < __y); }
357 template<
typename _Tp,
typename _RefL,
typename _PtrL,
358 typename _RefR,
typename _PtrR>
360 operator>=(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
361 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
362 {
return !(__x < __y); }
368 template<
typename _Tp,
typename _Ref,
typename _Ptr>
369 inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
370 operator-(
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
371 const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT
373 return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
374 (_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size())
375 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
376 + (__y._M_last - __y._M_cur);
379 template<
typename _Tp,
typename _RefL,
typename _PtrL,
380 typename _RefR,
typename _PtrR>
381 inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
382 operator-(
const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
383 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
385 return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
386 (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size())
387 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
388 + (__y._M_last - __y._M_cur);
391 template<
typename _Tp,
typename _Ref,
typename _Ptr>
392 inline _Deque_iterator<_Tp, _Ref, _Ptr>
393 operator+(ptrdiff_t __n,
const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
395 {
return __x + __n; }
397 template<
typename _Tp>
399 fill(
const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
400 const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
const _Tp&);
402 template<
typename _Tp>
403 _Deque_iterator<_Tp, _Tp&, _Tp*>
404 copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
405 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
406 _Deque_iterator<_Tp, _Tp&, _Tp*>);
408 template<
typename _Tp>
409 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
410 copy(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
411 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
412 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
413 {
return std::copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
414 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
417 template<
typename _Tp>
418 _Deque_iterator<_Tp, _Tp&, _Tp*>
419 copy_backward(_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 copy_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
426 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
427 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
428 {
return std::copy_backward(_Deque_iterator<_Tp,
429 const _Tp&,
const _Tp*>(__first),
431 const _Tp&,
const _Tp*>(__last),
434 #if __cplusplus >= 201103L 435 template<
typename _Tp>
436 _Deque_iterator<_Tp, _Tp&, _Tp*>
437 move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
438 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
439 _Deque_iterator<_Tp, _Tp&, _Tp*>);
441 template<
typename _Tp>
442 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
443 move(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
444 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
445 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
446 {
return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
447 _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
450 template<
typename _Tp>
451 _Deque_iterator<_Tp, _Tp&, _Tp*>
452 move_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
453 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
454 _Deque_iterator<_Tp, _Tp&, _Tp*>);
456 template<
typename _Tp>
457 inline _Deque_iterator<_Tp, _Tp&, _Tp*>
458 move_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
459 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
460 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
461 {
return std::move_backward(_Deque_iterator<_Tp,
462 const _Tp&,
const _Tp*>(__first),
464 const _Tp&,
const _Tp*>(__last),
478 template<
typename _Tp,
typename _Alloc>
483 rebind<_Tp>::other _Tp_alloc_type;
486 #if __cplusplus < 201103L 488 typedef const _Tp* _Ptr_const;
490 typedef typename _Alloc_traits::pointer _Ptr;
491 typedef typename _Alloc_traits::const_pointer _Ptr_const;
494 typedef typename _Alloc_traits::template rebind<_Ptr>::other
499 typedef _Alloc allocator_type;
502 get_allocator()
const _GLIBCXX_NOEXCEPT
503 {
return allocator_type(_M_get_Tp_allocator()); }
516 _Deque_base(
const allocator_type& __a,
size_t __num_elements)
524 #if __cplusplus >= 201103L 526 : _M_impl(__x._M_move_impl())
530 : _M_impl(std::move(__x._M_get_Tp_allocator()))
533 if (__x._M_impl._M_map)
534 this->_M_impl._M_swap_data(__x._M_impl);
544 if (__x.get_allocator() == __a)
546 if (__x._M_impl._M_map)
549 this->_M_impl._M_swap_data(__x._M_impl);
562 typedef typename iterator::_Map_pointer _Map_pointer;
568 :
public _Tp_alloc_type
576 : _Tp_alloc_type(), _M_map(), _M_map_size(0),
577 _M_start(), _M_finish()
580 _Deque_impl(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
581 : _Tp_alloc_type(__a), _M_map(), _M_map_size(0),
582 _M_start(), _M_finish()
585 #if __cplusplus >= 201103L 586 _Deque_impl(_Deque_impl&&) =
default;
588 _Deque_impl(_Tp_alloc_type&& __a) noexcept
589 : _Tp_alloc_type(std::move(__a)), _M_map(), _M_map_size(0),
590 _M_start(), _M_finish()
594 void _M_swap_data(_Deque_impl& __x) _GLIBCXX_NOEXCEPT
597 swap(this->_M_start, __x._M_start);
598 swap(this->_M_finish, __x._M_finish);
599 swap(this->_M_map, __x._M_map);
600 swap(this->_M_map_size, __x._M_map_size);
605 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
606 {
return *
static_cast<_Tp_alloc_type*
>(&this->_M_impl); }
608 const _Tp_alloc_type&
609 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
610 {
return *
static_cast<const _Tp_alloc_type*
>(&this->_M_impl); }
613 _M_get_map_allocator()
const _GLIBCXX_NOEXCEPT
614 {
return _Map_alloc_type(_M_get_Tp_allocator()); }
620 return _Traits::allocate(_M_impl, __deque_buf_size(
sizeof(_Tp)));
624 _M_deallocate_node(_Ptr __p) _GLIBCXX_NOEXCEPT
627 _Traits::deallocate(_M_impl, __p, __deque_buf_size(
sizeof(_Tp)));
631 _M_allocate_map(
size_t __n)
633 _Map_alloc_type __map_alloc = _M_get_map_allocator();
638 _M_deallocate_map(_Map_pointer __p,
size_t __n) _GLIBCXX_NOEXCEPT
640 _Map_alloc_type __map_alloc = _M_get_map_allocator();
646 void _M_create_nodes(_Map_pointer __nstart, _Map_pointer __nfinish);
647 void _M_destroy_nodes(_Map_pointer __nstart,
648 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT;
649 enum { _S_initial_map_size = 8 };
653 #if __cplusplus >= 201103L 659 return std::move(_M_impl);
662 _Tp_alloc_type __alloc{_M_get_Tp_allocator()};
664 _Tp_alloc_type __sink __attribute((__unused__)) {std::move(__alloc)};
669 _Deque_impl __ret{std::move(_M_get_Tp_allocator())};
670 _M_impl._M_swap_data(__ret);
671 _M_impl._M_swap_data(__empty._M_impl);
677 template<
typename _Tp,
typename _Alloc>
678 _Deque_base<_Tp, _Alloc>::
679 ~_Deque_base() _GLIBCXX_NOEXCEPT
681 if (this->_M_impl._M_map)
683 _M_destroy_nodes(this->_M_impl._M_start._M_node,
684 this->_M_impl._M_finish._M_node + 1);
685 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
697 template<
typename _Tp,
typename _Alloc>
702 const size_t __num_nodes = (__num_elements/ __deque_buf_size(
sizeof(_Tp))
705 this->_M_impl._M_map_size =
std::max((
size_t) _S_initial_map_size,
706 size_t(__num_nodes + 2));
707 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
714 _Map_pointer __nstart = (this->_M_impl._M_map
715 + (this->_M_impl._M_map_size - __num_nodes) / 2);
716 _Map_pointer __nfinish = __nstart + __num_nodes;
719 { _M_create_nodes(__nstart, __nfinish); }
722 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
723 this->_M_impl._M_map = _Map_pointer();
724 this->_M_impl._M_map_size = 0;
725 __throw_exception_again;
728 this->_M_impl._M_start._M_set_node(__nstart);
729 this->_M_impl._M_finish._M_set_node(__nfinish - 1);
730 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
731 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
733 % __deque_buf_size(
sizeof(_Tp)));
736 template<
typename _Tp,
typename _Alloc>
744 for (__cur = __nstart; __cur < __nfinish; ++__cur)
745 *__cur = this->_M_allocate_node();
749 _M_destroy_nodes(__nstart, __cur);
750 __throw_exception_again;
754 template<
typename _Tp,
typename _Alloc>
756 _Deque_base<_Tp, _Alloc>::
757 _M_destroy_nodes(_Map_pointer __nstart,
758 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT
760 for (_Map_pointer __n = __nstart; __n < __nfinish; ++__n)
761 _M_deallocate_node(*__n);
848 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
851 #ifdef _GLIBCXX_CONCEPT_CHECKS 853 typedef typename _Alloc::value_type _Alloc_value_type;
854 # if __cplusplus < 201103L 855 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
857 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
860 #if __cplusplus >= 201103L 861 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
862 "std::deque must have a non-const, non-volatile value_type");
863 # ifdef __STRICT_ANSI__ 865 "std::deque must have the same value_type as its allocator");
870 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
872 typedef typename _Base::_Map_pointer _Map_pointer;
875 typedef _Tp value_type;
876 typedef typename _Alloc_traits::pointer pointer;
877 typedef typename _Alloc_traits::const_pointer const_pointer;
878 typedef typename _Alloc_traits::reference reference;
879 typedef typename _Alloc_traits::const_reference const_reference;
884 typedef size_t size_type;
885 typedef ptrdiff_t difference_type;
886 typedef _Alloc allocator_type;
889 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
890 {
return __deque_buf_size(
sizeof(_Tp)); }
894 using _Base::_M_create_nodes;
895 using _Base::_M_destroy_nodes;
896 using _Base::_M_allocate_node;
897 using _Base::_M_deallocate_node;
898 using _Base::_M_allocate_map;
899 using _Base::_M_deallocate_map;
900 using _Base::_M_get_Tp_allocator;
906 using _Base::_M_impl;
925 #if __cplusplus >= 201103L 936 :
_Base(__a, _S_check_init_len(__n, __a))
937 { _M_default_initialize(); }
947 deque(size_type __n,
const value_type& __value,
949 :
_Base(__a, _S_check_init_len(__n, __a))
961 deque(size_type __n,
const value_type& __value = value_type(),
962 const allocator_type& __a = allocator_type())
963 : _Base(__a, _S_check_init_len(__n, __a))
977 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
978 this->_M_impl._M_start,
979 _M_get_Tp_allocator()); }
981 #if __cplusplus >= 201103L 995 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
996 this->_M_impl._M_start,
997 _M_get_Tp_allocator()); }
1003 if (__x.get_allocator() != __a)
1005 std::__uninitialized_move_a(__x.begin(), __x.end(),
1006 this->_M_impl._M_start,
1007 _M_get_Tp_allocator());
1047 #if __cplusplus >= 201103L 1048 template<
typename _InputIterator,
1049 typename = std::_RequireInputIter<_InputIterator>>
1050 deque(_InputIterator __first, _InputIterator __last,
1053 { _M_initialize_dispatch(__first, __last, __false_type()); }
1055 template<
typename _InputIterator>
1056 deque(_InputIterator __first, _InputIterator __last,
1057 const allocator_type& __a = allocator_type())
1061 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1062 _M_initialize_dispatch(__first, __last, _Integral());
1072 { _M_destroy_data(
begin(),
end(), _M_get_Tp_allocator()); }
1086 #if __cplusplus >= 201103L 1099 _M_move_assign1(std::move(__x), __always_equal{});
1117 _M_assign_aux(__l.begin(), __l.end(),
1134 assign(size_type __n,
const value_type& __val)
1135 { _M_fill_assign(__n, __val); }
1149 #if __cplusplus >= 201103L 1150 template<
typename _InputIterator,
1151 typename = std::_RequireInputIter<_InputIterator>>
1153 assign(_InputIterator __first, _InputIterator __last)
1154 { _M_assign_dispatch(__first, __last, __false_type()); }
1156 template<
typename _InputIterator>
1158 assign(_InputIterator __first, _InputIterator __last)
1160 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1161 _M_assign_dispatch(__first, __last, _Integral());
1165 #if __cplusplus >= 201103L 1185 {
return _Base::get_allocator(); }
1194 {
return this->_M_impl._M_start; }
1202 {
return this->_M_impl._M_start; }
1211 {
return this->_M_impl._M_finish; }
1220 {
return this->_M_impl._M_finish; }
1236 const_reverse_iterator
1254 const_reverse_iterator
1258 #if __cplusplus >= 201103L 1265 {
return this->_M_impl._M_start; }
1274 {
return this->_M_impl._M_finish; }
1281 const_reverse_iterator
1290 const_reverse_iterator
1299 {
return this->_M_impl._M_finish - this->_M_impl._M_start; }
1304 {
return _S_max_size(_M_get_Tp_allocator()); }
1306 #if __cplusplus >= 201103L 1319 const size_type __len =
size();
1320 if (__new_size > __len)
1321 _M_default_append(__new_size - __len);
1322 else if (__new_size < __len)
1323 _M_erase_at_end(this->_M_impl._M_start
1324 + difference_type(__new_size));
1339 resize(size_type __new_size,
const value_type& __x)
1341 const size_type __len =
size();
1342 if (__new_size > __len)
1343 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1344 else if (__new_size < __len)
1345 _M_erase_at_end(this->_M_impl._M_start
1346 + difference_type(__new_size));
1361 resize(size_type __new_size, value_type __x = value_type())
1363 const size_type __len =
size();
1364 if (__new_size > __len)
1365 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1366 else if (__new_size < __len)
1367 _M_erase_at_end(this->_M_impl._M_start
1368 + difference_type(__new_size));
1372 #if __cplusplus >= 201103L 1376 { _M_shrink_to_fit(); }
1383 _GLIBCXX_NODISCARD
bool 1385 {
return this->_M_impl._M_finish == this->_M_impl._M_start; }
1402 __glibcxx_requires_subscript(__n);
1403 return this->_M_impl._M_start[difference_type(__n)];
1420 __glibcxx_requires_subscript(__n);
1421 return this->_M_impl._M_start[difference_type(__n)];
1429 if (__n >= this->
size())
1430 __throw_out_of_range_fmt(__N(
"deque::_M_range_check: __n " 1431 "(which is %zu)>= this->size() " 1452 return (*
this)[__n];
1470 return (*
this)[__n];
1480 __glibcxx_requires_nonempty();
1491 __glibcxx_requires_nonempty();
1502 __glibcxx_requires_nonempty();
1515 __glibcxx_requires_nonempty();
1534 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1536 _Alloc_traits::construct(this->_M_impl,
1537 this->_M_impl._M_start._M_cur - 1,
1539 --this->_M_impl._M_start._M_cur;
1545 #if __cplusplus >= 201103L 1548 { emplace_front(std::move(__x)); }
1550 template<
typename... _Args>
1551 #if __cplusplus > 201402L 1556 emplace_front(_Args&&... __args);
1571 if (this->_M_impl._M_finish._M_cur
1572 != this->_M_impl._M_finish._M_last - 1)
1574 _Alloc_traits::construct(this->_M_impl,
1575 this->_M_impl._M_finish._M_cur, __x);
1576 ++this->_M_impl._M_finish._M_cur;
1582 #if __cplusplus >= 201103L 1585 { emplace_back(std::move(__x)); }
1587 template<
typename... _Args>
1588 #if __cplusplus > 201402L 1593 emplace_back(_Args&&... __args);
1607 __glibcxx_requires_nonempty();
1608 if (this->_M_impl._M_start._M_cur
1609 != this->_M_impl._M_start._M_last - 1)
1611 _Alloc_traits::destroy(this->_M_impl,
1612 this->_M_impl._M_start._M_cur);
1613 ++this->_M_impl._M_start._M_cur;
1630 __glibcxx_requires_nonempty();
1631 if (this->_M_impl._M_finish._M_cur
1632 != this->_M_impl._M_finish._M_first)
1634 --this->_M_impl._M_finish._M_cur;
1635 _Alloc_traits::destroy(this->_M_impl,
1636 this->_M_impl._M_finish._M_cur);
1642 #if __cplusplus >= 201103L 1652 template<
typename... _Args>
1654 emplace(const_iterator __position, _Args&&... __args);
1666 insert(const_iterator __position,
const value_type& __x);
1681 #if __cplusplus >= 201103L 1693 {
return emplace(__position, std::move(__x)); }
1707 auto __offset = __p -
cbegin();
1708 _M_range_insert_aux(__p._M_const_cast(), __l.begin(), __l.end(),
1710 return begin() + __offset;
1714 #if __cplusplus >= 201103L 1728 difference_type __offset = __position -
cbegin();
1729 _M_fill_insert(__position._M_const_cast(), __n, __x);
1730 return begin() + __offset;
1743 insert(
iterator __position, size_type __n,
const value_type& __x)
1744 { _M_fill_insert(__position, __n, __x); }
1747 #if __cplusplus >= 201103L 1759 template<
typename _InputIterator,
1760 typename = std::_RequireInputIter<_InputIterator>>
1763 _InputIterator __last)
1765 difference_type __offset = __position -
cbegin();
1766 _M_insert_dispatch(__position._M_const_cast(),
1767 __first, __last, __false_type());
1768 return begin() + __offset;
1781 template<
typename _InputIterator>
1784 _InputIterator __last)
1787 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1788 _M_insert_dispatch(__position, __first, __last, _Integral());
1806 #if __cplusplus >= 201103L 1811 {
return _M_erase(__position._M_const_cast()); }
1830 #if __cplusplus >= 201103L 1835 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1851 #if __cplusplus >= 201103L 1852 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1853 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1855 _M_impl._M_swap_data(__x._M_impl);
1856 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1857 __x._M_get_Tp_allocator());
1868 { _M_erase_at_end(
begin()); }
1877 template<
typename _Integer>
1879 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1882 _M_get_Tp_allocator()));
1887 _S_check_init_len(
size_t __n,
const allocator_type& __a)
1889 if (__n > _S_max_size(__a))
1890 __throw_length_error(
1891 __N(
"cannot create std::deque larger than max_size()"));
1896 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1898 const size_t __diffmax = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max;
1900 return (
std::min)(__diffmax, __allocmax);
1904 template<
typename _InputIterator>
1906 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1925 template<
typename _InputIterator>
1931 template<
typename _ForwardIterator>
1950 #if __cplusplus >= 201103L 1953 _M_default_initialize();
1963 template<
typename _Integer>
1965 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1966 { _M_fill_assign(__n, __val); }
1969 template<
typename _InputIterator>
1971 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1976 template<
typename _InputIterator>
1978 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1982 template<
typename _ForwardIterator>
1984 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1990 _ForwardIterator __mid = __first;
1992 std::copy(__first, __mid,
begin());
1993 _M_range_insert_aux(
end(), __mid, __last,
1997 _M_erase_at_end(std::copy(__first, __last,
begin()));
2003 _M_fill_assign(size_type __n,
const value_type& __val)
2008 _M_fill_insert(
end(), __n -
size(), __val);
2012 _M_erase_at_end(
begin() + difference_type(__n));
2019 #if __cplusplus < 201103L 2024 template<
typename... _Args>
2027 template<
typename... _Args>
2043 template<
typename _Integer>
2045 _M_insert_dispatch(iterator __pos,
2046 _Integer __n, _Integer __x, __true_type)
2047 { _M_fill_insert(__pos, __n, __x); }
2050 template<
typename _InputIterator>
2052 _M_insert_dispatch(iterator __pos,
2053 _InputIterator __first, _InputIterator __last,
2056 _M_range_insert_aux(__pos, __first, __last,
2061 template<
typename _InputIterator>
2063 _M_range_insert_aux(iterator __pos, _InputIterator __first,
2067 template<
typename _ForwardIterator>
2069 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
2076 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
2079 #if __cplusplus < 201103L 2081 _M_insert_aux(iterator __pos,
const value_type& __x);
2083 template<
typename... _Args>
2085 _M_insert_aux(iterator __pos, _Args&&... __args);
2090 _M_insert_aux(iterator __pos, size_type __n,
const value_type& __x);
2093 template<
typename _ForwardIterator>
2095 _M_insert_aux(iterator __pos,
2096 _ForwardIterator __first, _ForwardIterator __last,
2103 _M_destroy_data_aux(iterator __first, iterator __last);
2107 template<
typename _Alloc1>
2109 _M_destroy_data(iterator __first, iterator __last,
const _Alloc1&)
2110 { _M_destroy_data_aux(__first, __last); }
2113 _M_destroy_data(iterator __first, iterator __last,
2116 if (!__has_trivial_destructor(value_type))
2117 _M_destroy_data_aux(__first, __last);
2122 _M_erase_at_begin(iterator __pos)
2124 _M_destroy_data(
begin(), __pos, _M_get_Tp_allocator());
2125 _M_destroy_nodes(this->
_M_impl._M_start._M_node, __pos._M_node);
2126 this->
_M_impl._M_start = __pos;
2132 _M_erase_at_end(iterator __pos)
2134 _M_destroy_data(__pos,
end(), _M_get_Tp_allocator());
2135 _M_destroy_nodes(__pos._M_node + 1,
2136 this->_M_impl._M_finish._M_node + 1);
2137 this->
_M_impl._M_finish = __pos;
2141 _M_erase(iterator __pos);
2144 _M_erase(iterator __first, iterator __last);
2146 #if __cplusplus >= 201103L 2149 _M_default_append(size_type __n);
2160 const size_type __vacancies = this->_M_impl._M_start._M_cur
2161 - this->_M_impl._M_start._M_first;
2162 if (__n > __vacancies)
2164 return this->_M_impl._M_start - difference_type(__n);
2170 const size_type __vacancies = (this->_M_impl._M_finish._M_last
2171 - this->_M_impl._M_finish._M_cur) - 1;
2172 if (__n > __vacancies)
2174 return this->_M_impl._M_finish + difference_type(__n);
2196 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
2197 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
2204 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
2205 - this->_M_impl._M_map))
2213 #if __cplusplus >= 201103L 2219 this->_M_impl._M_swap_data(__x._M_impl);
2221 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2230 constexpr
bool __move_storage =
2231 _Alloc_traits::_S_propagate_on_move_assign();
2232 _M_move_assign2(std::move(__x), __bool_constant<__move_storage>());
2237 template<
typename... _Args>
2239 _M_replace_map(_Args&&... __args)
2242 deque __newobj(std::forward<_Args>(__args)...);
2245 _M_deallocate_node(*
begin()._M_node);
2246 _M_deallocate_map(this->
_M_impl._M_map, this->_M_impl._M_map_size);
2247 this->
_M_impl._M_map =
nullptr;
2248 this->
_M_impl._M_map_size = 0;
2250 this->
_M_impl._M_swap_data(__newobj._M_impl);
2258 auto __alloc = __x._M_get_Tp_allocator();
2261 _M_replace_map(std::move(__x));
2263 _M_get_Tp_allocator() = std::move(__alloc);
2271 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2275 _M_replace_map(std::move(__x), __x.get_allocator());
2281 _M_assign_aux(std::__make_move_if_noexcept_iterator(__x.begin()),
2282 std::__make_move_if_noexcept_iterator(__x.end()),
2290 #if __cpp_deduction_guides >= 201606 2291 template<
typename _InputIterator,
typename _ValT
2292 =
typename iterator_traits<_InputIterator>::value_type,
2293 typename _Allocator = allocator<_ValT>,
2294 typename = _RequireInputIter<_InputIterator>,
2295 typename = _RequireAllocator<_Allocator>>
2296 deque(_InputIterator, _InputIterator, _Allocator = _Allocator())
2297 -> deque<_ValT, _Allocator>;
2310 template<
typename _Tp,
typename _Alloc>
2328 template<
typename _Tp,
typename _Alloc>
2330 operator<(const deque<_Tp, _Alloc>& __x,
2333 __y.begin(), __y.end()); }
2336 template<
typename _Tp,
typename _Alloc>
2340 {
return !(__x == __y); }
2343 template<
typename _Tp,
typename _Alloc>
2347 {
return __y < __x; }
2350 template<
typename _Tp,
typename _Alloc>
2352 operator<=(const deque<_Tp, _Alloc>& __x,
2354 {
return !(__y < __x); }
2357 template<
typename _Tp,
typename _Alloc>
2361 {
return !(__x < __y); }
2364 template<
typename _Tp,
typename _Alloc>
2367 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
2370 #undef _GLIBCXX_DEQUE_BUF_SIZE 2372 _GLIBCXX_END_NAMESPACE_CONTAINER
2374 #if __cplusplus >= 201103L 2378 struct __is_bitwise_relocatable<_GLIBCXX_STD_C::deque<_Tp>>
2382 _GLIBCXX_END_NAMESPACE_VERSION
#define _GLIBCXX_DEQUE_BUF_SIZE
This function controls the size of memory nodes.
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
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
static _GLIBCXX_NODISCARD pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
void pop_back() noexcept
Removes last element.
size_type max_size() const noexcept
void _M_pop_front_aux()
Helper functions for push_* and pop_*.
reverse_iterator rend() noexcept
const_reference front() const noexcept
ISO C++ entities toplevel namespace is std.
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.
deque(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a deque from a range.
Forward iterators support a superset of input iterator operations.
void swap(deque &__x) noexcept
Swaps data with another deque.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
reference back() noexcept
_GLIBCXX20_CONSTEXPR complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
void _M_reserve_map_at_back(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
const_iterator cend() const noexcept
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
void _M_fill_initialize(const value_type &__value)
Fills the deque with copies of value.
reference at(size_type __n)
Provides 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.
const_iterator cbegin() const noexcept
void _M_initialize_map(size_t)
Layout storage.
void _M_push_front_aux(_Args &&... __args)
Helper functions for push_* and pop_*.
deque & operator=(const deque &__x)
Deque assignment operator.
The standard allocator, as per [20.4].
deque(size_type __n, const allocator_type &__a=allocator_type())
Creates a deque with default constructed elements.
void assign(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
size_type size() const noexcept
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a deque.
const_reverse_iterator crbegin() const noexcept
deque()
Creates a deque with no elements.
void resize(size_type __new_size, const value_type &__x)
Resizes the deque to the specified number of elements.
void _M_new_elements_at_back(size_type __new_elements)
Memory-handling helpers for the previous internal insert functions.
iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
iterator _M_reserve_elements_at_back(size_type __n)
Memory-handling helpers for the previous internal insert functions.
iterator erase(const_iterator __position)
Remove element at given position.
const_reference back() const noexcept
Uniform interface to all pointer-like types.
deque(deque &&__x)
Deque move constructor.
__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.
iterator begin() noexcept
iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the deque.
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
void pop_front() noexcept
Removes first element.
reference front() noexcept
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.
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
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.
const_reference at(size_type __n) const
Provides access to the data contained in the deque.
void _M_reserve_map_at_front(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
iterator insert(const_iterator __position, size_type __n, const value_type &__x)
Inserts a number of copies of given data into the deque.
deque(deque &&__x, const allocator_type &__a)
Move constructor with alternative allocator.
const_reverse_iterator rbegin() const noexcept
const_reverse_iterator rend() const noexcept
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
deque(const allocator_type &__a)
Creates a deque with no elements.
deque(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a deque from an initializer list.
void _M_range_initialize(_InputIterator __first, _InputIterator __last, std::input_iterator_tag)
Fills the deque with whatever is in [first,last).
void assign(size_type __n, const value_type &__val)
Assigns a given value to a deque.
Random-access iterators support a superset of bidirectional iterator operations.
static size_type max_size(const _Tp_alloc_type &__a) noexcept
The maximum supported allocation size.
deque & operator=(deque &&__x) noexcept(_Alloc_traits::_S_always_equal())
Deque move assignment operator.
_GLIBCXX20_CONSTEXPR complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
const_reference operator[](size_type __n) const noexcept
Subscript access to the data contained in the deque.
deque(const deque &__x)
Deque copy constructor.
A standard container using fixed-size memory allocation and constant-time manipulation of elements at...
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
void shrink_to_fit() noexcept
iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into deque before specified iterator.
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.
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.
const_reverse_iterator crend() const noexcept
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
void _M_new_elements_at_front(size_type __new_elements)
Memory-handling helpers for the previous internal insert functions.
deque(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a deque with copies of an exemplar element.
iterator emplace(const_iterator __position, _Args &&... __args)
Inserts an object in deque before specified iterator.
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
void _M_range_check(size_type __n) const
Safety check used only from at().