62#if __cplusplus >= 201103L
66#if __cplusplus > 201703L
69#if __cplusplus > 202002L
75namespace std _GLIBCXX_VISIBILITY(default)
77_GLIBCXX_BEGIN_NAMESPACE_VERSION
78_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
94#ifndef _GLIBCXX_DEQUE_BUF_SIZE
95#define _GLIBCXX_DEQUE_BUF_SIZE 512
98 _GLIBCXX_CONSTEXPR
inline size_t
99 __deque_buf_size(
size_t __size)
115 template<
typename _Tp,
typename _Ref,
typename _Ptr>
118#if __cplusplus < 201103L
121 typedef _Tp* _Elt_pointer;
122 typedef _Tp** _Map_pointer;
125 template<
typename _CvTp>
128 typedef __iter<_Tp> iterator;
129 typedef __iter<const _Tp> const_iterator;
134 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
135 {
return __deque_buf_size(
sizeof(_Tp)); }
138 typedef _Tp value_type;
139 typedef _Ptr pointer;
140 typedef _Ref reference;
141 typedef size_t size_type;
142 typedef ptrdiff_t difference_type;
146 _Elt_pointer _M_first;
147 _Elt_pointer _M_last;
148 _Map_pointer _M_node;
151 : _M_cur(__x), _M_first(*__y),
152 _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
155 : _M_cur(), _M_first(), _M_last(), _M_node() { }
157#if __cplusplus < 201103L
160 : _M_cur(__x._M_cur), _M_first(__x._M_first),
161 _M_last(__x._M_last), _M_node(__x._M_node) { }
164 template<
typename _Iter,
165 typename = _Require<is_same<_Self, const_iterator>,
168 : _M_cur(__x._M_cur), _M_first(__x._M_first),
169 _M_last(__x._M_last), _M_node(__x._M_node) { }
172 : _M_cur(__x._M_cur), _M_first(__x._M_first),
173 _M_last(__x._M_last), _M_node(__x._M_node) { }
179 _M_const_cast()
const _GLIBCXX_NOEXCEPT
180 {
return iterator(_M_cur, _M_node); }
184 operator*()
const _GLIBCXX_NOEXCEPT
189 operator->()
const _GLIBCXX_NOEXCEPT
193 operator++() _GLIBCXX_NOEXCEPT
196 if (_M_cur == _M_last)
205 operator++(
int) _GLIBCXX_NOEXCEPT
213 operator--() _GLIBCXX_NOEXCEPT
215 if (_M_cur == _M_first)
225 operator--(
int) _GLIBCXX_NOEXCEPT
233 operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
235 const difference_type __offset = __n + (_M_cur - _M_first);
236 if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
240 const difference_type __node_offset =
241 __offset > 0 ? __offset / difference_type(_S_buffer_size())
242 : -difference_type((-__offset - 1)
243 / _S_buffer_size()) - 1;
245 _M_cur = _M_first + (__offset - __node_offset
246 * difference_type(_S_buffer_size()));
252 operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
253 {
return *
this += -__n; }
257 operator[](difference_type __n)
const _GLIBCXX_NOEXCEPT
258 {
return *(*
this + __n); }
268 _M_node = __new_node;
269 _M_first = *__new_node;
270 _M_last = _M_first + difference_type(_S_buffer_size());
275 operator==(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
276 {
return __x._M_cur == __y._M_cur; }
281 template<
typename _RefR,
typename _PtrR>
284 operator==(
const _Self& __x,
285 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
287 {
return __x._M_cur == __y._M_cur; }
289#if __cpp_lib_three_way_comparison
291 friend strong_ordering
292 operator<=>(
const _Self& __x,
const _Self& __y)
noexcept
294 if (
const auto __cmp = __x._M_node <=> __y._M_node; __cmp != 0)
296 return __x._M_cur <=> __y._M_cur;
301 operator!=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
302 {
return !(__x == __y); }
304 template<
typename _RefR,
typename _PtrR>
307 operator!=(
const _Self& __x,
308 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
310 {
return !(__x == __y); }
314 operator<(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
316 return (__x._M_node == __y._M_node)
317 ? (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node);
320 template<
typename _RefR,
typename _PtrR>
324 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
327 return (__x._M_node == __y._M_node)
328 ? (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node);
333 operator>(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
334 {
return __y < __x; }
336 template<
typename _RefR,
typename _PtrR>
340 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
342 {
return __y < __x; }
346 operator<=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
347 {
return !(__y < __x); }
349 template<
typename _RefR,
typename _PtrR>
353 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
355 {
return !(__y < __x); }
359 operator>=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
360 {
return !(__x < __y); }
362 template<
typename _RefR,
typename _PtrR>
366 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
368 {
return !(__x < __y); }
372 friend difference_type
373 operator-(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
375 return difference_type(_S_buffer_size())
376 * (__x._M_node - __y._M_node - bool(__x._M_node))
377 + (__x._M_cur - __x._M_first)
378 + (__y._M_last - __y._M_cur);
385 template<
typename _RefR,
typename _PtrR>
387 friend difference_type
388 operator-(
const _Self& __x,
389 const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
392 return difference_type(_S_buffer_size())
393 * (__x._M_node - __y._M_node - bool(__x._M_node))
394 + (__x._M_cur - __x._M_first)
395 + (__y._M_last - __y._M_cur);
400 operator+(
const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT
409 operator-(
const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT
418 operator+(difference_type __n,
const _Self& __x) _GLIBCXX_NOEXCEPT
419 {
return __x + __n; }
432 template<
typename _Tp,
typename _Alloc>
437 rebind<_Tp>::other _Tp_alloc_type;
440#if __cplusplus < 201103L
442 typedef const _Tp* _Ptr_const;
444 typedef typename _Alloc_traits::pointer _Ptr;
445 typedef typename _Alloc_traits::const_pointer _Ptr_const;
448 typedef typename _Alloc_traits::template rebind<_Ptr>::other
452 typedef _Alloc allocator_type;
455 get_allocator()
const _GLIBCXX_NOEXCEPT
456 {
return allocator_type(_M_get_Tp_allocator()); }
469 _Deque_base(
const allocator_type& __a,
size_t __num_elements)
477#if __cplusplus >= 201103L
479 : _M_impl(
std::move(__x._M_get_Tp_allocator()))
482 if (__x._M_impl._M_map)
483 this->_M_impl._M_swap_data(__x._M_impl);
487 : _M_impl(
std::move(__x._M_impl), _Tp_alloc_type(__a))
488 { __x._M_initialize_map(0); }
493 if (__x.get_allocator() == __a)
495 if (__x._M_impl._M_map)
498 this->_M_impl._M_swap_data(__x._M_impl);
510 typedef typename iterator::_Map_pointer _Map_pointer;
512 struct _Deque_impl_data
519 _Deque_impl_data() _GLIBCXX_NOEXCEPT
520 : _M_map(), _M_map_size(), _M_start(), _M_finish()
523#if __cplusplus >= 201103L
524 _Deque_impl_data(
const _Deque_impl_data&) =
default;
526 operator=(
const _Deque_impl_data&) =
default;
528 _Deque_impl_data(_Deque_impl_data&& __x) noexcept
529 : _Deque_impl_data(__x)
530 { __x = _Deque_impl_data(); }
534 _M_swap_data(_Deque_impl_data& __x) _GLIBCXX_NOEXCEPT
538 std::swap(*
this, __x);
546 :
public _Tp_alloc_type,
public _Deque_impl_data
548 _Deque_impl() _GLIBCXX_NOEXCEPT_IF(
553 _Deque_impl(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
554 : _Tp_alloc_type(__a)
557#if __cplusplus >= 201103L
558 _Deque_impl(_Deque_impl&&) =
default;
560 _Deque_impl(_Tp_alloc_type&& __a) noexcept
564 _Deque_impl(_Deque_impl&& __d, _Tp_alloc_type&& __a)
571 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
572 {
return this->_M_impl; }
574 const _Tp_alloc_type&
575 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
576 {
return this->_M_impl; }
579 _M_get_map_allocator()
const _GLIBCXX_NOEXCEPT
580 {
return _Map_alloc_type(_M_get_Tp_allocator()); }
586 return _Traits::allocate(_M_impl, __deque_buf_size(
sizeof(_Tp)));
590 _M_deallocate_node(_Ptr __p) _GLIBCXX_NOEXCEPT
593 _Traits::deallocate(_M_impl, __p, __deque_buf_size(
sizeof(_Tp)));
597 _M_allocate_map(
size_t __n)
599 _Map_alloc_type __map_alloc = _M_get_map_allocator();
604 _M_deallocate_map(_Map_pointer __p,
size_t __n) _GLIBCXX_NOEXCEPT
606 _Map_alloc_type __map_alloc = _M_get_map_allocator();
611 void _M_create_nodes(_Map_pointer __nstart, _Map_pointer __nfinish);
612 void _M_destroy_nodes(_Map_pointer __nstart,
613 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT;
614 enum { _S_initial_map_size = 8 };
619 template<
typename _Tp,
typename _Alloc>
620 _Deque_base<_Tp, _Alloc>::
621 ~_Deque_base() _GLIBCXX_NOEXCEPT
623 if (this->_M_impl._M_map)
625 _M_destroy_nodes(this->_M_impl._M_start._M_node,
626 this->_M_impl._M_finish._M_node + 1);
627 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
638 template<
typename _Tp,
typename _Alloc>
643 const size_t __num_nodes = (__num_elements / __deque_buf_size(
sizeof(_Tp))
646 this->_M_impl._M_map_size =
std::max((
size_t) _S_initial_map_size,
647 size_t(__num_nodes + 2));
648 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
655 _Map_pointer __nstart = (this->_M_impl._M_map
656 + (this->_M_impl._M_map_size - __num_nodes) / 2);
657 _Map_pointer __nfinish = __nstart + __num_nodes;
660 { _M_create_nodes(__nstart, __nfinish); }
663 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
664 this->_M_impl._M_map = _Map_pointer();
665 this->_M_impl._M_map_size = 0;
666 __throw_exception_again;
669 this->_M_impl._M_start._M_set_node(__nstart);
670 this->_M_impl._M_finish._M_set_node(__nfinish - 1);
671 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
672 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
674 % __deque_buf_size(
sizeof(_Tp)));
677 template<
typename _Tp,
typename _Alloc>
685 for (__cur = __nstart; __cur < __nfinish; ++__cur)
686 *__cur = this->_M_allocate_node();
690 _M_destroy_nodes(__nstart, __cur);
691 __throw_exception_again;
695 template<
typename _Tp,
typename _Alloc>
697 _Deque_base<_Tp, _Alloc>::
698 _M_destroy_nodes(_Map_pointer __nstart,
699 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT
701 for (_Map_pointer __n = __nstart; __n < __nfinish; ++__n)
702 _M_deallocate_node(*__n);
789 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
792#ifdef _GLIBCXX_CONCEPT_CHECKS
794 typedef typename _Alloc::value_type _Alloc_value_type;
795# if __cplusplus < 201103L
796 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
798 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
801#if __cplusplus >= 201103L
803 "std::deque must have a non-const, non-volatile value_type");
804# if __cplusplus > 201703L || defined __STRICT_ANSI__
806 "std::deque must have the same value_type as its allocator");
811 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
813 typedef typename _Base::_Map_pointer _Map_pointer;
816 typedef _Tp value_type;
817 typedef typename _Alloc_traits::pointer pointer;
818 typedef typename _Alloc_traits::const_pointer const_pointer;
819 typedef typename _Alloc_traits::reference reference;
820 typedef typename _Alloc_traits::const_reference const_reference;
825 typedef size_t size_type;
826 typedef ptrdiff_t difference_type;
827 typedef _Alloc allocator_type;
830 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
831 {
return __deque_buf_size(
sizeof(_Tp)); }
835 using _Base::_M_create_nodes;
836 using _Base::_M_destroy_nodes;
837 using _Base::_M_allocate_node;
838 using _Base::_M_deallocate_node;
839 using _Base::_M_allocate_map;
840 using _Base::_M_deallocate_map;
841 using _Base::_M_get_Tp_allocator;
847 using _Base::_M_impl;
856#if __cplusplus >= 201103L
870#if __cplusplus >= 201103L
880 deque(size_type __n,
const allocator_type& __a = allocator_type())
881 :
_Base(__a, _S_check_init_len(__n, __a))
882 { _M_default_initialize(); }
892 deque(size_type __n,
const value_type& __value,
893 const allocator_type& __a = allocator_type())
894 :
_Base(__a, _S_check_init_len(__n, __a))
906 deque(size_type __n,
const value_type& __value = value_type(),
907 const allocator_type& __a = allocator_type())
908 : _Base(__a, _S_check_init_len(__n, __a))
922 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
923 this->_M_impl._M_start,
924 _M_get_Tp_allocator()); }
926#if __cplusplus >= 201103L
938 deque(
const deque& __x,
const __type_identity_t<allocator_type>& __a)
940 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
941 this->_M_impl._M_start,
942 _M_get_Tp_allocator()); }
945 deque(
deque&& __x,
const __type_identity_t<allocator_type>& __a)
957 if (__x.get_allocator() != __a && !__x.empty())
959 std::__uninitialized_move_a(__x.begin(), __x.end(),
960 this->_M_impl._M_start,
961 _M_get_Tp_allocator());
979 const allocator_type& __a = allocator_type())
1002#if __cplusplus >= 201103L
1003 template<
typename _InputIterator,
1004 typename = std::_RequireInputIter<_InputIterator>>
1005 deque(_InputIterator __first, _InputIterator __last,
1006 const allocator_type& __a = allocator_type())
1013 template<
typename _InputIterator>
1014 deque(_InputIterator __first, _InputIterator __last,
1015 const allocator_type& __a = allocator_type())
1019 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1020 _M_initialize_dispatch(__first, __last, _Integral());
1024#if __glibcxx_containers_ranges
1030 template<__detail::__container_compatible_range<_Tp> _Rg>
1031 deque(from_range_t, _Rg&& __rg,
const allocator_type& __a = _Alloc())
1042 { _M_destroy_data(
begin(),
end(), _M_get_Tp_allocator()); }
1056#if __cplusplus >= 201103L
1069 _M_move_assign1(
std::move(__x), __always_equal{});
1087 _M_assign_aux(__l.begin(), __l.end(),
1104 assign(size_type __n,
const value_type& __val)
1105 { _M_fill_assign(__n, __val); }
1119#if __cplusplus >= 201103L
1120 template<
typename _InputIterator,
1121 typename = std::_RequireInputIter<_InputIterator>>
1123 assign(_InputIterator __first, _InputIterator __last)
1126 template<
typename _InputIterator>
1128 assign(_InputIterator __first, _InputIterator __last)
1130 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1131 _M_assign_dispatch(__first, __last, _Integral());
1135#if __cplusplus >= 201103L
1152#if __glibcxx_containers_ranges
1159 template<__detail::__container_compatible_range<_Tp> _Rg>
1167 const size_type __n(ranges::distance(__rg));
1170 auto __res = ranges::copy(__rg,
begin());
1171 return _M_erase_at_end(__res.out);
1174 auto __rest = ranges::copy_n(ranges::begin(__rg),
size(),
1176 _M_range_append(
std::move(__rest), ranges::end(__rg),
1181 auto __first = ranges::begin(__rg);
1182 const auto __last = ranges::end(__rg);
1184 __it != __end; (void)++__first, ++__it)
1186 if (__first == __last)
1187 return _M_erase_at_end(__it);
1192 for (; __first != __last; ++__first)
1193 emplace_back(*__first);
1203 {
return _Base::get_allocator(); }
1213 {
return this->_M_impl._M_start; }
1222 {
return this->_M_impl._M_start; }
1232 {
return this->_M_impl._M_finish; }
1242 {
return this->_M_impl._M_finish; }
1260 const_reverse_iterator
1280 const_reverse_iterator
1284#if __cplusplus >= 201103L
1292 {
return this->_M_impl._M_start; }
1302 {
return this->_M_impl._M_finish; }
1310 const_reverse_iterator
1320 const_reverse_iterator
1331 size_type __sz = this->_M_impl._M_finish - this->_M_impl._M_start;
1333 __builtin_unreachable();
1341 {
return _S_max_size(_M_get_Tp_allocator()); }
1343#if __cplusplus >= 201103L
1356 const size_type __len =
size();
1357 if (__new_size > __len)
1358 _M_default_append(__new_size - __len);
1359 else if (__new_size < __len)
1360 _M_erase_at_end(this->_M_impl._M_start
1361 + difference_type(__new_size));
1376 resize(size_type __new_size,
const value_type& __x)
1390 resize(size_type __new_size, value_type __x = value_type())
1393 const size_type __len =
size();
1394 if (__new_size > __len)
1395 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1396 else if (__new_size < __len)
1397 _M_erase_at_end(this->_M_impl._M_start
1398 + difference_type(__new_size));
1401#if __cplusplus >= 201103L
1405 { _M_shrink_to_fit(); }
1412 _GLIBCXX_NODISCARD
bool
1414 {
return this->_M_impl._M_finish == this->_M_impl._M_start; }
1432 __glibcxx_requires_subscript(__n);
1433 return this->_M_impl._M_start[difference_type(__n)];
1451 __glibcxx_requires_subscript(__n);
1452 return this->_M_impl._M_start[difference_type(__n)];
1460 if (__n >= this->
size())
1461 __throw_out_of_range_fmt(__N(
"deque::_M_range_check: __n "
1462 "(which is %zu)>= this->size() "
1483 return (*
this)[__n];
1501 return (*
this)[__n];
1512 __glibcxx_requires_nonempty();
1524 __glibcxx_requires_nonempty();
1536 __glibcxx_requires_nonempty();
1550 __glibcxx_requires_nonempty();
1569 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1571 _Alloc_traits::construct(this->_M_impl,
1572 this->_M_impl._M_start._M_cur - 1,
1574 --this->_M_impl._M_start._M_cur;
1580#if __cplusplus >= 201103L
1585 template<
typename... _Args>
1586#if __cplusplus > 201402L
1591 emplace_front(_Args&&... __args);
1606 if (this->_M_impl._M_finish._M_cur
1607 != this->_M_impl._M_finish._M_last - 1)
1609 _Alloc_traits::construct(this->_M_impl,
1610 this->_M_impl._M_finish._M_cur, __x);
1611 ++this->_M_impl._M_finish._M_cur;
1617#if __cplusplus >= 201103L
1622 template<
typename... _Args>
1623#if __cplusplus > 201402L
1628 emplace_back(_Args&&... __args);
1642 __glibcxx_requires_nonempty();
1643 if (this->_M_impl._M_start._M_cur
1644 != this->_M_impl._M_start._M_last - 1)
1646 _Alloc_traits::destroy(_M_get_Tp_allocator(),
1647 this->_M_impl._M_start._M_cur);
1648 ++this->_M_impl._M_start._M_cur;
1665 __glibcxx_requires_nonempty();
1666 if (this->_M_impl._M_finish._M_cur
1667 != this->_M_impl._M_finish._M_first)
1669 --this->_M_impl._M_finish._M_cur;
1670 _Alloc_traits::destroy(_M_get_Tp_allocator(),
1671 this->_M_impl._M_finish._M_cur);
1677#if __cplusplus >= 201103L
1687 template<
typename... _Args>
1689 emplace(const_iterator __position, _Args&&... __args);
1701 insert(const_iterator __position,
const value_type& __x);
1716#if __cplusplus >= 201103L
1743 auto __offset = __p -
cbegin();
1744 _M_range_insert_aux(__p._M_const_cast(), __l.begin(), __l.end(),
1746 return begin() + __offset;
1762 difference_type __offset = __position -
cbegin();
1763 _M_fill_insert(__position._M_const_cast(), __n, __x);
1764 return begin() + __offset;
1777 insert(
iterator __position, size_type __n,
const value_type& __x)
1778 { _M_fill_insert(__position, __n, __x); }
1781#if __cplusplus >= 201103L
1793 template<
typename _InputIterator,
1794 typename = std::_RequireInputIter<_InputIterator>>
1797 _InputIterator __last)
1799 difference_type __offset = __position -
cbegin();
1800 _M_range_insert_aux(__position._M_const_cast(), __first, __last,
1802 return begin() + __offset;
1815 template<
typename _InputIterator>
1818 _InputIterator __last)
1821 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1822 _M_insert_dispatch(__position, __first, __last, _Integral());
1826#if __glibcxx_containers_ranges
1835 template<__detail::__container_compatible_range<_Tp> _Rg>
1844 template<__detail::__container_compatible_range<_Tp> _Rg>
1853 template<__detail::__container_compatible_range<_Tp> _Rg>
1872#if __cplusplus >= 201103L
1877 {
return _M_erase(__position._M_const_cast()); }
1896#if __cplusplus >= 201103L
1901 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1917#if __cplusplus >= 201103L
1918 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1919 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1921 _M_impl._M_swap_data(__x._M_impl);
1922 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1923 __x._M_get_Tp_allocator());
1934 { _M_erase_at_end(
begin()); }
1939#if __cplusplus < 201103L
1944 template<
typename _Integer>
1946 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1948 _M_initialize_map(_S_check_init_len(
static_cast<size_type
>(__n),
1949 _M_get_Tp_allocator()));
1954 template<
typename _InputIterator>
1956 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1965 _S_check_init_len(
size_t __n,
const allocator_type& __a)
1967 if (__n > _S_max_size(__a))
1968 __throw_length_error(
1969 __N(
"cannot create std::deque larger than max_size()"));
1974 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1976 const size_t __diffmax = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max;
1978 return (std::min)(__diffmax, __allocmax);
1992 template<
typename _InputIterator>
1998 template<
typename _ForwardIterator>
2016#if __cplusplus >= 201103L
2019 _M_default_initialize();
2025#if __cplusplus < 201103L
2030 template<
typename _Integer>
2032 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
2033 { _M_fill_assign(__n, __val); }
2036 template<
typename _InputIterator>
2038 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
2044 template<
typename _InputIterator>
2046 _M_assign_aux(_InputIterator __first, _InputIterator __last,
2050 template<
typename _ForwardIterator>
2052 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
2058 _ForwardIterator __mid = __first;
2060 std::copy(__first, __mid,
begin());
2061 _M_range_insert_aux(
end(), __mid, __last,
2065 _M_erase_at_end(std::copy(__first, __last,
begin()));
2071 _M_fill_assign(size_type __n,
const value_type& __val)
2076 _M_fill_insert(
end(), __n -
size(), __val);
2080 _M_erase_at_end(
begin() + difference_type(__n));
2087#if __cplusplus < 201103L
2092 template<
typename... _Args>
2095 template<
typename... _Args>
2107#if __cplusplus < 201103L
2112 template<
typename _Integer>
2114 _M_insert_dispatch(iterator __pos,
2115 _Integer __n, _Integer __x, __true_type)
2116 { _M_fill_insert(__pos, __n, __x); }
2119 template<
typename _InputIterator>
2121 _M_insert_dispatch(iterator __pos,
2122 _InputIterator __first, _InputIterator __last,
2125 _M_range_insert_aux(__pos, __first, __last,
2131 template<
typename _InputIterator,
typename _Sentinel>
2132 void _M_range_prepend(_InputIterator __first, _Sentinel __last,
2136 template<
typename _InputIterator,
typename _Sentinel>
2137 void _M_range_append(_InputIterator __first, _Sentinel __last,
2141 template<
typename _InputIterator>
2143 _M_range_insert_aux(iterator __pos, _InputIterator __first,
2147 template<
typename _ForwardIterator>
2149 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
2156 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
2159#if __cplusplus < 201103L
2161 _M_insert_aux(iterator __pos,
const value_type& __x);
2163 struct _Temporary_value
2165 template<
typename... _Args>
2166 _GLIBCXX20_CONSTEXPR
explicit
2167 _Temporary_value(
deque* __deque, _Args&&... __args) : _M_this(__deque)
2169 _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(),
2170 std::forward<_Args>(__args)...);
2173 _GLIBCXX20_CONSTEXPR
2175 { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); }
2177 _GLIBCXX20_CONSTEXPR value_type&
2178 _M_val() noexcept {
return __tmp_val; }
2181 _GLIBCXX20_CONSTEXPR _Tp*
2193 _M_insert_aux(iterator __pos,
const value_type& __x)
2194 {
return _M_emplace_aux(__pos, __x); }
2196 template<
typename... _Args>
2198 _M_emplace_aux(iterator __pos, _Args&&... __args);
2203 _M_insert_aux(iterator __pos, size_type __n,
const value_type& __x);
2206 template<
typename _ForwardIterator>
2208 _M_insert_aux(iterator __pos,
2209 _ForwardIterator __first, _ForwardIterator __last,
2216 _M_destroy_data_aux(iterator __first, iterator __last);
2220 template<
typename _Alloc1>
2222 _M_destroy_data(iterator __first, iterator __last,
const _Alloc1&)
2223 { _M_destroy_data_aux(__first, __last); }
2226 _M_destroy_data(iterator __first, iterator __last,
2229 if (!__has_trivial_destructor(value_type))
2230 _M_destroy_data_aux(__first, __last);
2235 _M_erase_at_begin(iterator __pos)
2237 _M_destroy_data(
begin(), __pos, _M_get_Tp_allocator());
2238 _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
2239 this->_M_impl._M_start = __pos;
2245 _M_erase_at_end(iterator __pos)
2247 _M_destroy_data(__pos,
end(), _M_get_Tp_allocator());
2248 _M_destroy_nodes(__pos._M_node + 1,
2249 this->_M_impl._M_finish._M_node + 1);
2250 this->_M_impl._M_finish = __pos;
2254 _M_erase(iterator __pos);
2257 _M_erase(iterator __first, iterator __last);
2259#if __cplusplus >= 201103L
2262 _M_default_append(size_type __n);
2273 const size_type __vacancies = this->_M_impl._M_start._M_cur
2274 - this->_M_impl._M_start._M_first;
2275 if (__n > __vacancies)
2277 return this->_M_impl._M_start - difference_type(__n);
2283 const size_type __vacancies = (this->_M_impl._M_finish._M_last
2284 - this->_M_impl._M_finish._M_cur) - 1;
2285 if (__n > __vacancies)
2287 return this->_M_impl._M_finish + difference_type(__n);
2309 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
2310 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
2317 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
2318 - this->_M_impl._M_map))
2326#if __cplusplus >= 201103L
2332 this->_M_impl._M_swap_data(__x._M_impl);
2334 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2343 if (_M_get_Tp_allocator() == __x._M_get_Tp_allocator())
2346 constexpr bool __move_storage =
2347 _Alloc_traits::_S_propagate_on_move_assign();
2348 _M_move_assign2(
std::move(__x), __bool_constant<__move_storage>());
2353 template<
typename... _Args>
2355 _M_replace_map(_Args&&... __args)
2358 deque __newobj(std::forward<_Args>(__args)...);
2361 _M_deallocate_node(*
begin()._M_node);
2362 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
2363 this->_M_impl._M_map =
nullptr;
2364 this->_M_impl._M_map_size = 0;
2366 this->_M_impl._M_swap_data(__newobj._M_impl);
2374 auto __alloc = __x._M_get_Tp_allocator();
2379 _M_get_Tp_allocator() =
std::move(__alloc);
2387 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2391 _M_replace_map(
std::move(__x), __x.get_allocator());
2397 _M_assign_aux(std::make_move_iterator(__x.begin()),
2398 std::make_move_iterator(__x.end()),
2406#if __cpp_deduction_guides >= 201606
2407 template<
typename _InputIterator,
typename _ValT
2408 =
typename iterator_traits<_InputIterator>::value_type,
2409 typename _Allocator = allocator<_ValT>,
2410 typename = _RequireInputIter<_InputIterator>,
2411 typename = _RequireAllocator<_Allocator>>
2412 deque(_InputIterator, _InputIterator, _Allocator = _Allocator())
2413 -> deque<_ValT, _Allocator>;
2415#if __glibcxx_containers_ranges
2416 template<ranges::input_range _Rg,
2417 typename _Alloc = allocator<ranges::range_value_t<_Rg>>>
2418 deque(from_range_t, _Rg&&, _Alloc = _Alloc())
2419 -> deque<ranges::range_value_t<_Rg>, _Alloc>;
2433 template<
typename _Tp,
typename _Alloc>
2437 {
return __x.
size() == __y.size()
2438 && std::equal(__x.
begin(), __x.
end(), __y.begin()); }
2440#if __cpp_lib_three_way_comparison
2452 template<
typename _Tp,
typename _Alloc>
2454 inline __detail::__synth3way_t<_Tp>
2455 operator<=>(
const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
2458 __y.begin(), __y.end(),
2459 __detail::__synth3way);
2473 template<
typename _Tp,
typename _Alloc>
2476 operator<(
const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
2477 {
return std::lexicographical_compare(__x.begin(), __x.end(),
2478 __y.begin(), __y.end()); }
2481 template<
typename _Tp,
typename _Alloc>
2484 operator!=(
const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
2485 {
return !(__x == __y); }
2488 template<
typename _Tp,
typename _Alloc>
2491 operator>(
const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
2492 {
return __y < __x; }
2495 template<
typename _Tp,
typename _Alloc>
2498 operator<=(
const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
2499 {
return !(__y < __x); }
2502 template<
typename _Tp,
typename _Alloc>
2505 operator>=(
const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y)
2506 {
return !(__x < __y); }
2510 template<
typename _Tp,
typename _Alloc>
2513 _GLIBCXX_NOEXCEPT_IF(
noexcept(__x.swap(__y)))
2516#undef _GLIBCXX_DEQUE_BUF_SIZE
2518_GLIBCXX_END_NAMESPACE_CONTAINER
2520#if __cplusplus >= 201103L
2524 struct __is_bitwise_relocatable<_GLIBCXX_STD_C::deque<_Tp>>
2528_GLIBCXX_END_NAMESPACE_VERSION
#define _GLIBCXX_DEQUE_BUF_SIZE
This function controls the size of memory nodes.
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
__bool_constant< 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 _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr auto lexicographical_compare_three_way(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _Comp __comp) -> decltype(__comp(*__first1, *__first2))
Performs dictionary comparison on ranges.
constexpr const _Tp & max(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.
typename pointer_traits< _Ptr >::template rebind< _Tp > __ptr_rebind
Convenience alias for rebinding pointers.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
is_nothrow_default_constructible
typename __detected_or_t< is_empty< _Alloc >, __equal, _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.
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 append_range(_Rg &&__rg)
Append a range at the end of the deque.
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
iterator insert_range(const_iterator __pos, _Rg &&__rg)
Insert a range into the deque.
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.
deque & operator=(initializer_list< value_type > __l)
Assigns an initializer list 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.
deque(const deque &__x, const __type_identity_t< allocator_type > &__a)
Copy constructor with alternative allocator.
void _M_new_elements_at_back(size_type __new_elements)
Memory-handling helpers for the previous internal insert functions.
iterator insert(const_iterator __p, initializer_list< value_type > __l)
Inserts an initializer list into the deque.
void prepend_range(_Rg &&__rg)
Prepend a range at the begining of the deque.
deque(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a deque with copies of an exemplar element.
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_*.
deque & operator=(deque &&__x) noexcept(_Alloc_traits::_S_always_equal())
Deque move assignment operator.
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
constexpr void assign_range(_Rg &&__rg)
Assign a range to the deque.
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.
deque(from_range_t, _Rg &&__rg, const allocator_type &__a=_Alloc())
Construct a deque from a range.
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
deque(deque &&__x, const __type_identity_t< allocator_type > &__a)
Move constructor with alternative allocator.
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.
[concept.assignable], concept assignable_from
[range.sized] The sized_range concept.
A range for which ranges::begin returns a forward iterator.