57 #define _STL_DEQUE_H 1
62 #if __cplusplus >= 201103L
66 #if __cplusplus > 201703L
72 namespace std _GLIBCXX_VISIBILITY(default)
74 _GLIBCXX_BEGIN_NAMESPACE_VERSION
75 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
91 #ifndef _GLIBCXX_DEQUE_BUF_SIZE
92 #define _GLIBCXX_DEQUE_BUF_SIZE 512
95 _GLIBCXX_CONSTEXPR
inline size_t
96 __deque_buf_size(
size_t __size)
112 template<
typename _Tp,
typename _Ref,
typename _Ptr>
115 #if __cplusplus < 201103L
118 typedef _Tp* _Elt_pointer;
119 typedef _Tp** _Map_pointer;
122 template<
typename _CvTp>
131 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
132 {
return __deque_buf_size(
sizeof(_Tp)); }
135 typedef _Tp value_type;
136 typedef _Ptr pointer;
137 typedef _Ref reference;
138 typedef size_t size_type;
139 typedef ptrdiff_t difference_type;
143 _Elt_pointer _M_first;
144 _Elt_pointer _M_last;
145 _Map_pointer _M_node;
148 : _M_cur(__x), _M_first(*__y),
149 _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
152 : _M_cur(), _M_first(), _M_last(), _M_node() { }
154 #if __cplusplus < 201103L
157 : _M_cur(__x._M_cur), _M_first(__x._M_first),
158 _M_last(__x._M_last), _M_node(__x._M_node) { }
161 template<
typename _Iter,
162 typename = _Require<is_same<_Self, const_iterator>,
165 : _M_cur(__x._M_cur), _M_first(__x._M_first),
166 _M_last(__x._M_last), _M_node(__x._M_node) { }
169 : _M_cur(__x._M_cur), _M_first(__x._M_first),
170 _M_last(__x._M_last), _M_node(__x._M_node) { }
176 _M_const_cast()
const _GLIBCXX_NOEXCEPT
177 {
return iterator(_M_cur, _M_node); }
180 operator*()
const _GLIBCXX_NOEXCEPT
184 operator->()
const _GLIBCXX_NOEXCEPT
188 operator++() _GLIBCXX_NOEXCEPT
191 if (_M_cur == _M_last)
200 operator++(
int) _GLIBCXX_NOEXCEPT
208 operator--() _GLIBCXX_NOEXCEPT
210 if (_M_cur == _M_first)
220 operator--(
int) _GLIBCXX_NOEXCEPT
228 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
230 const difference_type __offset = __n + (_M_cur - _M_first);
231 if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
235 const difference_type __node_offset =
236 __offset > 0 ? __offset / difference_type(_S_buffer_size())
237 : -difference_type((-__offset - 1)
238 / _S_buffer_size()) - 1;
240 _M_cur = _M_first + (__offset - __node_offset
241 * difference_type(_S_buffer_size()));
247 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
248 {
return *
this += -__n; }
251 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
252 {
return *(*
this + __n); }
262 _M_node = __new_node;
263 _M_first = *__new_node;
264 _M_last = _M_first + difference_type(_S_buffer_size());
268 operator==(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
269 {
return __x._M_cur == __y._M_cur; }
274 template<
typename _RefR,
typename _PtrR>
276 operator==(
const _Self& __x,
277 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
279 {
return __x._M_cur == __y._M_cur; }
281 #if __cpp_lib_three_way_comparison
282 friend strong_ordering
283 operator<=>(
const _Self& __x,
const _Self& __y) noexcept
285 if (
const auto __cmp = __x._M_node <=> __y._M_node; __cmp != 0)
287 return __x._M_cur <=> __y._M_cur;
291 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
292 {
return !(__x == __y); }
294 template<
typename _RefR,
typename _PtrR>
296 operator!=(
const _Self& __x,
297 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
299 {
return !(__x == __y); }
302 operator<(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
304 return (__x._M_node == __y._M_node)
305 ? (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node);
308 template<
typename _RefR,
typename _PtrR>
310 operator<(
const _Self& __x,
311 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
314 return (__x._M_node == __y._M_node)
315 ? (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node);
319 operator>(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
320 {
return __y < __x; }
322 template<
typename _RefR,
typename _PtrR>
324 operator>(
const _Self& __x,
325 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
327 {
return __y < __x; }
330 operator<=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
331 {
return !(__y < __x); }
333 template<
typename _RefR,
typename _PtrR>
335 operator<=(
const _Self& __x,
336 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
338 {
return !(__y < __x); }
341 operator>=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
342 {
return !(__x < __y); }
344 template<
typename _RefR,
typename _PtrR>
346 operator>=(
const _Self& __x,
347 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
349 {
return !(__x < __y); }
352 friend difference_type
353 operator-(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
355 return difference_type(_S_buffer_size())
356 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
357 + (__y._M_last - __y._M_cur);
364 template<
typename _RefR,
typename _PtrR>
365 friend difference_type
366 operator-(
const _Self& __x,
367 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT
369 return difference_type(_S_buffer_size())
370 * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
371 + (__y._M_last - __y._M_cur);
375 operator+(
const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT
383 operator-(
const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT
391 operator+(difference_type __n,
const _Self& __x) _GLIBCXX_NOEXCEPT
392 {
return __x + __n; }
405 template<
typename _Tp,
typename _Alloc>
410 rebind<_Tp>::other _Tp_alloc_type;
413 #if __cplusplus < 201103L
415 typedef const _Tp* _Ptr_const;
417 typedef typename _Alloc_traits::pointer _Ptr;
418 typedef typename _Alloc_traits::const_pointer _Ptr_const;
421 typedef typename _Alloc_traits::template rebind<_Ptr>::other
425 typedef _Alloc allocator_type;
428 get_allocator()
const _GLIBCXX_NOEXCEPT
429 {
return allocator_type(_M_get_Tp_allocator()); }
442 _Deque_base(
const allocator_type& __a,
size_t __num_elements)
450 #if __cplusplus >= 201103L
452 : _M_impl(
std::move(__x._M_get_Tp_allocator()))
455 if (__x._M_impl._M_map)
456 this->_M_impl._M_swap_data(__x._M_impl);
460 : _M_impl(
std::move(__x._M_impl), _Tp_alloc_type(__a))
461 { __x._M_initialize_map(0); }
466 if (__x.get_allocator() == __a)
468 if (__x._M_impl._M_map)
471 this->_M_impl._M_swap_data(__x._M_impl);
483 typedef typename iterator::_Map_pointer _Map_pointer;
485 struct _Deque_impl_data
492 _Deque_impl_data() _GLIBCXX_NOEXCEPT
493 : _M_map(), _M_map_size(), _M_start(), _M_finish()
496 #if __cplusplus >= 201103L
497 _Deque_impl_data(
const _Deque_impl_data&) =
default;
499 operator=(
const _Deque_impl_data&) =
default;
501 _Deque_impl_data(_Deque_impl_data&& __x) noexcept
502 : _Deque_impl_data(__x)
503 { __x = _Deque_impl_data(); }
507 _M_swap_data(_Deque_impl_data& __x) _GLIBCXX_NOEXCEPT
511 std::swap(*
this, __x);
519 :
public _Tp_alloc_type,
public _Deque_impl_data
521 _Deque_impl() _GLIBCXX_NOEXCEPT_IF(
526 _Deque_impl(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
527 : _Tp_alloc_type(__a)
530 #if __cplusplus >= 201103L
531 _Deque_impl(_Deque_impl&&) =
default;
533 _Deque_impl(_Tp_alloc_type&& __a) noexcept
537 _Deque_impl(_Deque_impl&& __d, _Tp_alloc_type&& __a)
544 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
545 {
return this->_M_impl; }
547 const _Tp_alloc_type&
548 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
549 {
return this->_M_impl; }
552 _M_get_map_allocator()
const _GLIBCXX_NOEXCEPT
553 {
return _Map_alloc_type(_M_get_Tp_allocator()); }
559 return _Traits::allocate(_M_impl, __deque_buf_size(
sizeof(_Tp)));
563 _M_deallocate_node(_Ptr __p) _GLIBCXX_NOEXCEPT
566 _Traits::deallocate(_M_impl, __p, __deque_buf_size(
sizeof(_Tp)));
570 _M_allocate_map(
size_t __n)
572 _Map_alloc_type __map_alloc = _M_get_map_allocator();
577 _M_deallocate_map(_Map_pointer __p,
size_t __n) _GLIBCXX_NOEXCEPT
579 _Map_alloc_type __map_alloc = _M_get_map_allocator();
584 void _M_create_nodes(_Map_pointer __nstart, _Map_pointer __nfinish);
585 void _M_destroy_nodes(_Map_pointer __nstart,
586 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT;
587 enum { _S_initial_map_size = 8 };
592 template<
typename _Tp,
typename _Alloc>
593 _Deque_base<_Tp, _Alloc>::
594 ~_Deque_base() _GLIBCXX_NOEXCEPT
596 if (this->_M_impl._M_map)
598 _M_destroy_nodes(this->_M_impl._M_start._M_node,
599 this->_M_impl._M_finish._M_node + 1);
600 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
612 template<
typename _Tp,
typename _Alloc>
617 const size_t __num_nodes = (__num_elements / __deque_buf_size(
sizeof(_Tp))
620 this->_M_impl._M_map_size =
std::max((
size_t) _S_initial_map_size,
621 size_t(__num_nodes + 2));
622 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
629 _Map_pointer __nstart = (this->_M_impl._M_map
630 + (this->_M_impl._M_map_size - __num_nodes) / 2);
631 _Map_pointer __nfinish = __nstart + __num_nodes;
634 { _M_create_nodes(__nstart, __nfinish); }
637 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
638 this->_M_impl._M_map = _Map_pointer();
639 this->_M_impl._M_map_size = 0;
640 __throw_exception_again;
643 this->_M_impl._M_start._M_set_node(__nstart);
644 this->_M_impl._M_finish._M_set_node(__nfinish - 1);
645 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
646 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
648 % __deque_buf_size(
sizeof(_Tp)));
651 template<
typename _Tp,
typename _Alloc>
659 for (__cur = __nstart; __cur < __nfinish; ++__cur)
660 *__cur = this->_M_allocate_node();
664 _M_destroy_nodes(__nstart, __cur);
665 __throw_exception_again;
669 template<
typename _Tp,
typename _Alloc>
671 _Deque_base<_Tp, _Alloc>::
672 _M_destroy_nodes(_Map_pointer __nstart,
673 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT
675 for (_Map_pointer __n = __nstart; __n < __nfinish; ++__n)
676 _M_deallocate_node(*__n);
763 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
766 #ifdef _GLIBCXX_CONCEPT_CHECKS
768 typedef typename _Alloc::value_type _Alloc_value_type;
769 # if __cplusplus < 201103L
770 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
772 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
775 #if __cplusplus >= 201103L
776 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
777 "std::deque must have a non-const, non-volatile value_type");
778 # if __cplusplus > 201703L || defined __STRICT_ANSI__
780 "std::deque must have the same value_type as its allocator");
785 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
787 typedef typename _Base::_Map_pointer _Map_pointer;
790 typedef _Tp value_type;
791 typedef typename _Alloc_traits::pointer pointer;
792 typedef typename _Alloc_traits::const_pointer const_pointer;
793 typedef typename _Alloc_traits::reference reference;
794 typedef typename _Alloc_traits::const_reference const_reference;
799 typedef size_t size_type;
800 typedef ptrdiff_t difference_type;
801 typedef _Alloc allocator_type;
804 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
805 {
return __deque_buf_size(
sizeof(_Tp)); }
809 using _Base::_M_create_nodes;
810 using _Base::_M_destroy_nodes;
811 using _Base::_M_allocate_node;
812 using _Base::_M_deallocate_node;
813 using _Base::_M_allocate_map;
814 using _Base::_M_deallocate_map;
815 using _Base::_M_get_Tp_allocator;
821 using _Base::_M_impl;
830 #if __cplusplus >= 201103L
844 #if __cplusplus >= 201103L
854 deque(size_type __n,
const allocator_type& __a = allocator_type())
855 :
_Base(__a, _S_check_init_len(__n, __a))
856 { _M_default_initialize(); }
866 deque(size_type __n,
const value_type& __value,
867 const allocator_type& __a = allocator_type())
868 :
_Base(__a, _S_check_init_len(__n, __a))
880 deque(size_type __n,
const value_type& __value = value_type(),
881 const allocator_type& __a = allocator_type())
882 : _Base(__a, _S_check_init_len(__n, __a))
896 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
897 this->_M_impl._M_start,
898 _M_get_Tp_allocator()); }
900 #if __cplusplus >= 201103L
914 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
915 this->_M_impl._M_start,
916 _M_get_Tp_allocator()); }
931 if (__x.get_allocator() != __a && !__x.empty())
933 std::__uninitialized_move_a(__x.begin(), __x.end(),
934 this->_M_impl._M_start,
935 _M_get_Tp_allocator());
953 const allocator_type& __a = allocator_type())
976 #if __cplusplus >= 201103L
977 template<
typename _InputIterator,
978 typename = std::_RequireInputIter<_InputIterator>>
979 deque(_InputIterator __first, _InputIterator __last,
980 const allocator_type& __a = allocator_type())
987 template<
typename _InputIterator>
988 deque(_InputIterator __first, _InputIterator __last,
989 const allocator_type& __a = allocator_type())
993 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
994 _M_initialize_dispatch(__first, __last, _Integral());
1004 { _M_destroy_data(
begin(),
end(), _M_get_Tp_allocator()); }
1018 #if __cplusplus >= 201103L
1031 _M_move_assign1(
std::move(__x), __always_equal{});
1049 _M_assign_aux(__l.begin(), __l.end(),
1066 assign(size_type __n,
const value_type& __val)
1067 { _M_fill_assign(__n, __val); }
1081 #if __cplusplus >= 201103L
1082 template<
typename _InputIterator,
1083 typename = std::_RequireInputIter<_InputIterator>>
1085 assign(_InputIterator __first, _InputIterator __last)
1088 template<
typename _InputIterator>
1090 assign(_InputIterator __first, _InputIterator __last)
1092 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1093 _M_assign_dispatch(__first, __last, _Integral());
1097 #if __cplusplus >= 201103L
1117 {
return _Base::get_allocator(); }
1126 {
return this->_M_impl._M_start; }
1134 {
return this->_M_impl._M_start; }
1143 {
return this->_M_impl._M_finish; }
1152 {
return this->_M_impl._M_finish; }
1168 const_reverse_iterator
1186 const_reverse_iterator
1190 #if __cplusplus >= 201103L
1197 {
return this->_M_impl._M_start; }
1206 {
return this->_M_impl._M_finish; }
1213 const_reverse_iterator
1222 const_reverse_iterator
1231 {
return this->_M_impl._M_finish - this->_M_impl._M_start; }
1236 {
return _S_max_size(_M_get_Tp_allocator()); }
1238 #if __cplusplus >= 201103L
1251 const size_type __len =
size();
1252 if (__new_size > __len)
1253 _M_default_append(__new_size - __len);
1254 else if (__new_size < __len)
1255 _M_erase_at_end(this->_M_impl._M_start
1256 + difference_type(__new_size));
1271 resize(size_type __new_size,
const value_type& __x)
1285 resize(size_type __new_size, value_type __x = value_type())
1288 const size_type __len =
size();
1289 if (__new_size > __len)
1290 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1291 else if (__new_size < __len)
1292 _M_erase_at_end(this->_M_impl._M_start
1293 + difference_type(__new_size));
1296 #if __cplusplus >= 201103L
1300 { _M_shrink_to_fit(); }
1307 _GLIBCXX_NODISCARD
bool
1309 {
return this->_M_impl._M_finish == this->_M_impl._M_start; }
1326 __glibcxx_requires_subscript(__n);
1327 return this->_M_impl._M_start[difference_type(__n)];
1344 __glibcxx_requires_subscript(__n);
1345 return this->_M_impl._M_start[difference_type(__n)];
1353 if (__n >= this->
size())
1354 __throw_out_of_range_fmt(__N(
"deque::_M_range_check: __n "
1355 "(which is %zu)>= this->size() "
1376 return (*
this)[__n];
1394 return (*
this)[__n];
1404 __glibcxx_requires_nonempty();
1415 __glibcxx_requires_nonempty();
1426 __glibcxx_requires_nonempty();
1439 __glibcxx_requires_nonempty();
1458 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1460 _Alloc_traits::construct(this->_M_impl,
1461 this->_M_impl._M_start._M_cur - 1,
1463 --this->_M_impl._M_start._M_cur;
1469 #if __cplusplus >= 201103L
1474 template<
typename... _Args>
1475 #if __cplusplus > 201402L
1480 emplace_front(_Args&&... __args);
1495 if (this->_M_impl._M_finish._M_cur
1496 != this->_M_impl._M_finish._M_last - 1)
1498 _Alloc_traits::construct(this->_M_impl,
1499 this->_M_impl._M_finish._M_cur, __x);
1500 ++this->_M_impl._M_finish._M_cur;
1506 #if __cplusplus >= 201103L
1511 template<
typename... _Args>
1512 #if __cplusplus > 201402L
1517 emplace_back(_Args&&... __args);
1531 __glibcxx_requires_nonempty();
1532 if (this->_M_impl._M_start._M_cur
1533 != this->_M_impl._M_start._M_last - 1)
1535 _Alloc_traits::destroy(_M_get_Tp_allocator(),
1536 this->_M_impl._M_start._M_cur);
1537 ++this->_M_impl._M_start._M_cur;
1554 __glibcxx_requires_nonempty();
1555 if (this->_M_impl._M_finish._M_cur
1556 != this->_M_impl._M_finish._M_first)
1558 --this->_M_impl._M_finish._M_cur;
1559 _Alloc_traits::destroy(_M_get_Tp_allocator(),
1560 this->_M_impl._M_finish._M_cur);
1566 #if __cplusplus >= 201103L
1576 template<
typename... _Args>
1578 emplace(const_iterator __position, _Args&&... __args);
1590 insert(const_iterator __position,
const value_type& __x);
1605 #if __cplusplus >= 201103L
1632 auto __offset = __p -
cbegin();
1633 _M_range_insert_aux(__p._M_const_cast(), __l.begin(), __l.end(),
1635 return begin() + __offset;
1651 difference_type __offset = __position -
cbegin();
1652 _M_fill_insert(__position._M_const_cast(), __n, __x);
1653 return begin() + __offset;
1666 insert(
iterator __position, size_type __n,
const value_type& __x)
1667 { _M_fill_insert(__position, __n, __x); }
1670 #if __cplusplus >= 201103L
1682 template<
typename _InputIterator,
1683 typename = std::_RequireInputIter<_InputIterator>>
1686 _InputIterator __last)
1688 difference_type __offset = __position -
cbegin();
1689 _M_range_insert_aux(__position._M_const_cast(), __first, __last,
1691 return begin() + __offset;
1704 template<
typename _InputIterator>
1707 _InputIterator __last)
1710 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1711 _M_insert_dispatch(__position, __first, __last, _Integral());
1729 #if __cplusplus >= 201103L
1734 {
return _M_erase(__position._M_const_cast()); }
1753 #if __cplusplus >= 201103L
1758 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1774 #if __cplusplus >= 201103L
1775 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1776 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1778 _M_impl._M_swap_data(__x._M_impl);
1779 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1780 __x._M_get_Tp_allocator());
1791 { _M_erase_at_end(
begin()); }
1796 #if __cplusplus < 201103L
1801 template<
typename _Integer>
1803 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1805 _M_initialize_map(_S_check_init_len(
static_cast<size_type
>(__n),
1806 _M_get_Tp_allocator()));
1811 template<
typename _InputIterator>
1813 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1822 _S_check_init_len(
size_t __n,
const allocator_type& __a)
1824 if (__n > _S_max_size(__a))
1825 __throw_length_error(
1826 __N(
"cannot create std::deque larger than max_size()"));
1831 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1833 const size_t __diffmax = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max;
1835 return (
std::min)(__diffmax, __allocmax);
1850 template<
typename _InputIterator>
1856 template<
typename _ForwardIterator>
1875 #if __cplusplus >= 201103L
1878 _M_default_initialize();
1884 #if __cplusplus < 201103L
1889 template<
typename _Integer>
1891 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1892 { _M_fill_assign(__n, __val); }
1895 template<
typename _InputIterator>
1897 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1903 template<
typename _InputIterator>
1905 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1909 template<
typename _ForwardIterator>
1911 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1917 _ForwardIterator __mid = __first;
1919 std::copy(__first, __mid,
begin());
1920 _M_range_insert_aux(
end(), __mid, __last,
1924 _M_erase_at_end(std::copy(__first, __last,
begin()));
1930 _M_fill_assign(size_type __n,
const value_type& __val)
1935 _M_fill_insert(
end(), __n -
size(), __val);
1939 _M_erase_at_end(
begin() + difference_type(__n));
1946 #if __cplusplus < 201103L
1951 template<
typename... _Args>
1954 template<
typename... _Args>
1966 #if __cplusplus < 201103L
1971 template<
typename _Integer>
1973 _M_insert_dispatch(iterator __pos,
1974 _Integer __n, _Integer __x, __true_type)
1975 { _M_fill_insert(__pos, __n, __x); }
1978 template<
typename _InputIterator>
1980 _M_insert_dispatch(iterator __pos,
1981 _InputIterator __first, _InputIterator __last,
1984 _M_range_insert_aux(__pos, __first, __last,
1990 template<
typename _InputIterator>
1992 _M_range_insert_aux(iterator __pos, _InputIterator __first,
1996 template<
typename _ForwardIterator>
1998 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
2005 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
2008 #if __cplusplus < 201103L
2010 _M_insert_aux(iterator __pos,
const value_type& __x);
2012 template<
typename... _Args>
2014 _M_insert_aux(iterator __pos, _Args&&... __args);
2019 _M_insert_aux(iterator __pos, size_type __n,
const value_type& __x);
2022 template<
typename _ForwardIterator>
2024 _M_insert_aux(iterator __pos,
2025 _ForwardIterator __first, _ForwardIterator __last,
2032 _M_destroy_data_aux(iterator __first, iterator __last);
2036 template<
typename _Alloc1>
2038 _M_destroy_data(iterator __first, iterator __last,
const _Alloc1&)
2039 { _M_destroy_data_aux(__first, __last); }
2042 _M_destroy_data(iterator __first, iterator __last,
2045 if (!__has_trivial_destructor(value_type))
2046 _M_destroy_data_aux(__first, __last);
2051 _M_erase_at_begin(iterator __pos)
2053 _M_destroy_data(
begin(), __pos, _M_get_Tp_allocator());
2054 _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
2055 this->_M_impl._M_start = __pos;
2061 _M_erase_at_end(iterator __pos)
2063 _M_destroy_data(__pos,
end(), _M_get_Tp_allocator());
2064 _M_destroy_nodes(__pos._M_node + 1,
2065 this->_M_impl._M_finish._M_node + 1);
2066 this->_M_impl._M_finish = __pos;
2070 _M_erase(iterator __pos);
2073 _M_erase(iterator __first, iterator __last);
2075 #if __cplusplus >= 201103L
2078 _M_default_append(size_type __n);
2089 const size_type __vacancies = this->_M_impl._M_start._M_cur
2090 - this->_M_impl._M_start._M_first;
2091 if (__n > __vacancies)
2093 return this->_M_impl._M_start - difference_type(__n);
2099 const size_type __vacancies = (this->_M_impl._M_finish._M_last
2100 - this->_M_impl._M_finish._M_cur) - 1;
2101 if (__n > __vacancies)
2103 return this->_M_impl._M_finish + difference_type(__n);
2125 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
2126 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
2133 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
2134 - this->_M_impl._M_map))
2142 #if __cplusplus >= 201103L
2148 this->_M_impl._M_swap_data(__x._M_impl);
2150 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2159 constexpr
bool __move_storage =
2160 _Alloc_traits::_S_propagate_on_move_assign();
2161 _M_move_assign2(
std::move(__x), __bool_constant<__move_storage>());
2166 template<
typename... _Args>
2168 _M_replace_map(_Args&&... __args)
2171 deque __newobj(std::forward<_Args>(__args)...);
2174 _M_deallocate_node(*
begin()._M_node);
2175 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
2176 this->_M_impl._M_map =
nullptr;
2177 this->_M_impl._M_map_size = 0;
2179 this->_M_impl._M_swap_data(__newobj._M_impl);
2187 auto __alloc = __x._M_get_Tp_allocator();
2192 _M_get_Tp_allocator() =
std::move(__alloc);
2200 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2204 _M_replace_map(
std::move(__x), __x.get_allocator());
2210 _M_assign_aux(std::make_move_iterator(__x.begin()),
2211 std::make_move_iterator(__x.end()),
2219 #if __cpp_deduction_guides >= 201606
2220 template<
typename _InputIterator,
typename _ValT
2221 =
typename iterator_traits<_InputIterator>::value_type,
2222 typename _Allocator = allocator<_ValT>,
2223 typename = _RequireInputIter<_InputIterator>,
2224 typename = _RequireAllocator<_Allocator>>
2225 deque(_InputIterator, _InputIterator, _Allocator = _Allocator())
2226 -> deque<_ValT, _Allocator>;
2239 template<
typename _Tp,
typename _Alloc>
2245 #if __cpp_lib_three_way_comparison
2257 template<
typename _Tp,
typename _Alloc>
2258 inline __detail::__synth3way_t<_Tp>
2259 operator<=>(
const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
2261 return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
2262 __y.begin(), __y.end(),
2263 __detail::__synth3way);
2277 template<
typename _Tp,
typename _Alloc>
2280 {
return std::lexicographical_compare(__x.
begin(), __x.
end(),
2284 template<
typename _Tp,
typename _Alloc>
2287 {
return !(__x == __y); }
2290 template<
typename _Tp,
typename _Alloc>
2293 {
return __y < __x; }
2296 template<
typename _Tp,
typename _Alloc>
2299 {
return !(__y < __x); }
2302 template<
typename _Tp,
typename _Alloc>
2305 {
return !(__x < __y); }
2309 template<
typename _Tp,
typename _Alloc>
2312 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
2315 #undef _GLIBCXX_DEQUE_BUF_SIZE
2317 _GLIBCXX_END_NAMESPACE_CONTAINER
2319 #if __cplusplus >= 201103L
2323 struct __is_bitwise_relocatable<_GLIBCXX_STD_C::deque<_Tp>>
2327 _GLIBCXX_END_NAMESPACE_VERSION
#define _GLIBCXX_DEQUE_BUF_SIZE
This function controls the size of memory nodes.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
typename pointer_traits< _Ptr >::template rebind< _Tp > __ptr_rebind
Convenience alias for rebinding pointers.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
is_nothrow_default_constructible
__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.
The standard allocator, as per C++03 [20.4.1].
void _M_set_node(_Map_pointer __new_node) noexcept
void _M_initialize_map(size_t)
Layout storage.
A standard container using fixed-size memory allocation and constant-time manipulation of elements at...
reverse_iterator rbegin() noexcept
deque(const deque &__x)
Deque copy constructor.
const_reference at(size_type __n) const
Provides access to the data contained in the deque.
deque(const deque &__x, const allocator_type &__a)
Copy constructor with alternative allocator.
deque(deque &&__x, const allocator_type &__a)
Move constructor with alternative allocator.
reverse_iterator rend() noexcept
iterator erase(const_iterator __position)
Remove element at given position.
const_reference back() const noexcept
const_reverse_iterator crend() const noexcept
void _M_pop_front_aux()
Helper functions for push_* and pop_*.
void pop_back() noexcept
Removes last element.
size_type size() const noexcept
void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front)
Memory-handling helpers for the major map.
const_iterator cbegin() const noexcept
void resize(size_type __new_size)
Resizes the deque to the specified number of elements.
const_reverse_iterator rend() const noexcept
iterator _M_reserve_elements_at_front(size_type __n)
Memory-handling helpers for the previous internal insert functions.
iterator emplace(const_iterator __position, _Args &&... __args)
Inserts an object in deque before specified iterator.
void pop_front() noexcept
Removes first element.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
void swap(deque &__x) noexcept
Swaps data with another deque.
reference operator[](size_type __n) noexcept
Subscript access to the data contained in the deque.
reference at(size_type __n)
Provides access to the data contained in the deque.
deque(size_type __n, const allocator_type &__a=allocator_type())
Creates a deque with default constructed elements.
bool empty() const noexcept
const_reference operator[](size_type __n) const noexcept
Subscript access to the data contained in the deque.
size_type max_size() const noexcept
void push_front(const value_type &__x)
Add data to the front of the deque.
void resize(size_type __new_size, const value_type &__x)
Resizes the deque to the specified number of elements.
const_reference front() const noexcept
void assign(size_type __n, const value_type &__val)
Assigns a given value to a deque.
void _M_fill_initialize(const value_type &__value)
Fills the deque with copies of value.
iterator insert(const_iterator __position, const value_type &__x)
Inserts given value into deque before specified iterator.
void _M_new_elements_at_back(size_type __new_elements)
Memory-handling helpers for the previous internal insert functions.
deque & operator=(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
iterator insert(const_iterator __p, initializer_list< value_type > __l)
Inserts an initializer list into the deque.
deque & operator=(deque &&__x) noexcept(_Alloc_traits::_S_always_equal())
Deque move assignment operator.
deque(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a deque with copies of an exemplar element.
const_reverse_iterator crbegin() const noexcept
void _M_reserve_map_at_back(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
reference back() noexcept
void _M_new_elements_at_front(size_type __new_elements)
Memory-handling helpers for the previous internal insert functions.
deque()=default
Creates a deque with no elements.
void _M_push_back_aux(_Args &&... __args)
Helper functions for push_* and pop_*.
void push_back(const value_type &__x)
Add data to the end of the deque.
deque(const allocator_type &__a)
Creates a deque with no elements.
void _M_reserve_map_at_front(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
void _M_push_front_aux(_Args &&... __args)
Helper functions for push_* and pop_*.
void _M_range_check(size_type __n) const
Safety check used only from at().
void assign(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
deque(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a deque from an initializer list.
void shrink_to_fit() noexcept
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a deque.
deque(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a deque from a range.
const_iterator begin() const noexcept
deque & operator=(const deque &__x)
Deque assignment operator.
const_iterator end() 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.
iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into deque before specified iterator.
void _M_pop_back_aux()
Helper functions for push_* and pop_*.
void _M_range_initialize(_InputIterator __first, _InputIterator __last, std::input_iterator_tag)
Fills the deque with whatever is in [first,last).
reference front() noexcept
iterator _M_reserve_elements_at_back(size_type __n)
Memory-handling helpers for the previous internal insert functions.
const_iterator cend() const noexcept
iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the deque.
const_reverse_iterator rbegin() const noexcept
iterator begin() noexcept
iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
deque(deque &&)=default
Deque move constructor.
Forward iterators support a superset of input iterator operations.
Random-access iterators support a superset of bidirectional iterator operations.
Uniform interface to C++98 and C++11 allocators.
static constexpr pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
static constexpr void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
static constexpr size_type max_size(const _Tp_alloc_type &__a) noexcept
The maximum supported allocation size.