57 #define _STL_DEQUE_H 1 62 #if __cplusplus >= 201103L 66 #if __cplusplus > 201703L 69 #if __cplusplus > 202002L 75 namespace 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>
116 struct _Deque_iterator
118 #if __cplusplus < 201103L 119 typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator;
120 typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
121 typedef _Tp* _Elt_pointer;
122 typedef _Tp** _Map_pointer;
125 template<
typename _CvTp>
126 using __iter = _Deque_iterator<_Tp, _CvTp&, __ptr_rebind<_Ptr, _CvTp>>;
128 typedef __iter<_Tp> iterator;
129 typedef __iter<const _Tp> const_iterator;
130 typedef __ptr_rebind<_Ptr, _Tp> _Elt_pointer;
131 typedef __ptr_rebind<_Ptr, _Elt_pointer> _Map_pointer;
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;
143 typedef _Deque_iterator _Self;
146 _Elt_pointer _M_first;
147 _Elt_pointer _M_last;
148 _Map_pointer _M_node;
150 _Deque_iterator(_Elt_pointer __x, _Map_pointer __y) _GLIBCXX_NOEXCEPT
151 : _M_cur(__x), _M_first(*__y),
152 _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
154 _Deque_iterator() _GLIBCXX_NOEXCEPT
155 : _M_cur(), _M_first(), _M_last(), _M_node() { }
157 #if __cplusplus < 201103L 159 _Deque_iterator(
const iterator& __x) _GLIBCXX_NOEXCEPT
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>,
166 is_same<_Iter, iterator>>>
167 _Deque_iterator(
const _Iter& __x) noexcept
168 : _M_cur(__x._M_cur), _M_first(__x._M_first),
169 _M_last(__x._M_last), _M_node(__x._M_node) { }
171 _Deque_iterator(
const _Deque_iterator& __x) noexcept
172 : _M_cur(__x._M_cur), _M_first(__x._M_first),
173 _M_last(__x._M_last), _M_node(__x._M_node) { }
175 _Deque_iterator& operator=(
const _Deque_iterator&) =
default;
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,
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,
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>
323 operator<(
const _Self& __x,
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>
339 operator>(
const _Self& __x,
342 {
return __y < __x; }
346 operator<=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
347 {
return !(__y < __x); }
349 template<
typename _RefR,
typename _PtrR>
352 operator<=(
const _Self& __x,
355 {
return !(__y < __x); }
359 operator>=(
const _Self& __x,
const _Self& __y) _GLIBCXX_NOEXCEPT
360 {
return !(__x < __y); }
362 template<
typename _RefR,
typename _PtrR>
365 operator>=(
const _Self& __x,
368 {
return !(__x < __y); }
369 #endif // three-way comparison 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,
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()); }
463 { _M_initialize_map(0); }
467 { _M_initialize_map(__num_elements); }
469 _Deque_base(
const allocator_type& __a,
size_t __num_elements)
471 { _M_initialize_map(__num_elements); }
477 #if __cplusplus >= 201103L 479 : _M_impl(
std::move(__x._M_get_Tp_allocator()))
481 _M_initialize_map(0);
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)
497 _M_initialize_map(0);
498 this->_M_impl._M_swap_data(__x._M_impl);
503 _M_initialize_map(__n);
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();
600 return _Map_alloc_traits::allocate(__map_alloc, __n);
604 _M_deallocate_map(_Map_pointer __p,
size_t __n) _GLIBCXX_NOEXCEPT
606 _Map_alloc_type __map_alloc = _M_get_map_allocator();
607 _Map_alloc_traits::deallocate(__map_alloc, __p, __n);
610 void _M_initialize_map(
size_t);
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>
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);
639 template<
typename _Tp,
typename _Alloc>
644 const size_t __num_nodes = (__num_elements / __deque_buf_size(
sizeof(_Tp))
647 this->_M_impl._M_map_size =
std::max((
size_t) _S_initial_map_size,
648 size_t(__num_nodes + 2));
649 this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
656 _Map_pointer __nstart = (this->_M_impl._M_map
657 + (this->_M_impl._M_map_size - __num_nodes) / 2);
658 _Map_pointer __nfinish = __nstart + __num_nodes;
661 { _M_create_nodes(__nstart, __nfinish); }
664 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
665 this->_M_impl._M_map = _Map_pointer();
666 this->_M_impl._M_map_size = 0;
667 __throw_exception_again;
670 this->_M_impl._M_start._M_set_node(__nstart);
671 this->_M_impl._M_finish._M_set_node(__nfinish - 1);
672 this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
673 this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
675 % __deque_buf_size(
sizeof(_Tp)));
678 template<
typename _Tp,
typename _Alloc>
686 for (__cur = __nstart; __cur < __nfinish; ++__cur)
687 *__cur = this->_M_allocate_node();
691 _M_destroy_nodes(__nstart, __cur);
692 __throw_exception_again;
696 template<
typename _Tp,
typename _Alloc>
700 _Map_pointer __nfinish) _GLIBCXX_NOEXCEPT
702 for (_Map_pointer __n = __nstart; __n < __nfinish; ++__n)
703 _M_deallocate_node(*__n);
790 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
793 #ifdef _GLIBCXX_CONCEPT_CHECKS 795 typedef typename _Alloc::value_type _Alloc_value_type;
796 # if __cplusplus < 201103L 797 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
799 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
802 #if __cplusplus >= 201103L 803 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
804 "std::deque must have a non-const, non-volatile value_type");
805 # if __cplusplus > 201703L || defined __STRICT_ANSI__ 807 "std::deque must have the same value_type as its allocator");
812 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
814 typedef typename _Base::_Map_pointer _Map_pointer;
817 typedef _Tp value_type;
818 typedef typename _Alloc_traits::pointer pointer;
819 typedef typename _Alloc_traits::const_pointer const_pointer;
820 typedef typename _Alloc_traits::reference reference;
821 typedef typename _Alloc_traits::const_reference const_reference;
826 typedef size_t size_type;
827 typedef ptrdiff_t difference_type;
828 typedef _Alloc allocator_type;
831 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
832 {
return __deque_buf_size(
sizeof(_Tp)); }
835 using _Base::_M_initialize_map;
836 using _Base::_M_create_nodes;
837 using _Base::_M_destroy_nodes;
838 using _Base::_M_allocate_node;
839 using _Base::_M_deallocate_node;
840 using _Base::_M_allocate_map;
841 using _Base::_M_deallocate_map;
842 using _Base::_M_get_Tp_allocator;
848 using _Base::_M_impl;
857 #if __cplusplus >= 201103L 871 #if __cplusplus >= 201103L 881 deque(size_type __n,
const allocator_type& __a = allocator_type())
882 : _Base(__a, _S_check_init_len(__n, __a))
883 { _M_default_initialize(); }
893 deque(size_type __n,
const value_type& __value,
894 const allocator_type& __a = allocator_type())
895 : _Base(__a, _S_check_init_len(__n, __a))
896 { _M_fill_initialize(__value); }
907 deque(size_type __n,
const value_type& __value = value_type(),
908 const allocator_type& __a = allocator_type())
909 : _Base(__a, _S_check_init_len(__n, __a))
910 { _M_fill_initialize(__value); }
921 : _Base(_Alloc_traits::_S_select_on_copy(__x._M_get_Tp_allocator()),
923 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
924 this->_M_impl._M_start,
925 _M_get_Tp_allocator()); }
927 #if __cplusplus >= 201103L 939 deque(
const deque& __x,
const __type_identity_t<allocator_type>& __a)
940 : _Base(__a, __x.
size())
941 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
942 this->_M_impl._M_start,
943 _M_get_Tp_allocator()); }
946 deque(
deque&& __x,
const __type_identity_t<allocator_type>& __a)
947 :
deque(
std::
move(__x), __a, typename _Alloc_traits::is_always_equal{})
958 if (__x.get_allocator() != __a && !__x.empty())
960 std::__uninitialized_move_a(__x.begin(), __x.end(),
961 this->_M_impl._M_start,
962 _M_get_Tp_allocator());
980 const allocator_type& __a = allocator_type())
983 _M_range_initialize(__l.begin(), __l.end(),
1003 #if __cplusplus >= 201103L 1004 template<
typename _InputIterator,
1005 typename = std::_RequireInputIter<_InputIterator>>
1006 deque(_InputIterator __first, _InputIterator __last,
1007 const allocator_type& __a = allocator_type())
1010 _M_range_initialize(__first, __last,
1014 template<
typename _InputIterator>
1015 deque(_InputIterator __first, _InputIterator __last,
1016 const allocator_type& __a = allocator_type())
1020 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1021 _M_initialize_dispatch(__first, __last, _Integral());
1025 #if __glibcxx_containers_ranges // C++ >= 23 1031 template<__detail::__container_compatible_range<_Tp> _Rg>
1032 deque(from_range_t, _Rg&& __rg,
const allocator_type& __a = _Alloc())
1034 { append_range(std::forward<_Rg>(__rg)); }
1043 { _M_destroy_data(
begin(),
end(), _M_get_Tp_allocator()); }
1055 operator=(
const deque& __x);
1057 #if __cplusplus >= 201103L 1070 _M_move_assign1(
std::move(__x), __always_equal{});
1088 _M_assign_aux(__l.begin(), __l.end(),
1105 assign(size_type __n,
const value_type& __val)
1106 { _M_fill_assign(__n, __val); }
1120 #if __cplusplus >= 201103L 1121 template<
typename _InputIterator,
1122 typename = std::_RequireInputIter<_InputIterator>>
1124 assign(_InputIterator __first, _InputIterator __last)
1127 template<
typename _InputIterator>
1129 assign(_InputIterator __first, _InputIterator __last)
1131 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1132 _M_assign_dispatch(__first, __last, _Integral());
1136 #if __cplusplus >= 201103L 1153 #if __glibcxx_containers_ranges // C++ >= 23 1160 template<__detail::__container_compatible_range<_Tp> _Rg>
1162 assign_range(_Rg&& __rg)
1166 if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>)
1168 const size_type __n(ranges::distance(__rg));
1171 auto __res = ranges::copy(__rg,
begin());
1172 return _M_erase_at_end(__res.out);
1175 auto __rest = ranges::copy_n(ranges::begin(__rg),
size(),
1177 _M_range_append(
std::move(__rest), ranges::end(__rg),
1182 auto __first = ranges::begin(__rg);
1183 const auto __last = ranges::end(__rg);
1184 for (iterator __it =
begin(), __end =
end();
1185 __it != __end; (void)++__first, ++__it)
1187 if (__first == __last)
1188 return _M_erase_at_end(__it);
1193 for (; __first != __last; ++__first)
1194 emplace_back(*__first);
1197 #endif // containers_ranges 1204 {
return _Base::get_allocator(); }
1214 {
return this->_M_impl._M_start; }
1223 {
return this->_M_impl._M_start; }
1233 {
return this->_M_impl._M_finish; }
1243 {
return this->_M_impl._M_finish; }
1253 {
return reverse_iterator(this->_M_impl._M_finish); }
1261 const_reverse_iterator
1263 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1273 {
return reverse_iterator(this->_M_impl._M_start); }
1281 const_reverse_iterator
1283 {
return const_reverse_iterator(this->_M_impl._M_start); }
1285 #if __cplusplus >= 201103L 1293 {
return this->_M_impl._M_start; }
1303 {
return this->_M_impl._M_finish; }
1311 const_reverse_iterator
1313 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1321 const_reverse_iterator
1323 {
return const_reverse_iterator(this->_M_impl._M_start); }
1332 size_type __sz = this->_M_impl._M_finish - this->_M_impl._M_start;
1333 if (__sz > max_size ())
1334 __builtin_unreachable();
1342 {
return _S_max_size(_M_get_Tp_allocator()); }
1344 #if __cplusplus >= 201103L 1357 const size_type __len =
size();
1358 if (__new_size > __len)
1359 _M_default_append(__new_size - __len);
1360 else if (__new_size < __len)
1361 _M_erase_at_end(this->_M_impl._M_start
1362 + difference_type(__new_size));
1377 resize(size_type __new_size,
const value_type& __x)
1391 resize(size_type __new_size, value_type __x = value_type())
1394 const size_type __len =
size();
1395 if (__new_size > __len)
1396 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1397 else if (__new_size < __len)
1398 _M_erase_at_end(this->_M_impl._M_start
1399 + difference_type(__new_size));
1402 #if __cplusplus >= 201103L 1406 { _M_shrink_to_fit(); }
1413 _GLIBCXX_NODISCARD
bool 1415 {
return this->_M_impl._M_finish == this->_M_impl._M_start; }
1433 __glibcxx_requires_subscript(__n);
1434 return this->_M_impl._M_start[difference_type(__n)];
1452 __glibcxx_requires_subscript(__n);
1453 return this->_M_impl._M_start[difference_type(__n)];
1461 if (__n >= this->
size())
1462 __throw_out_of_range_fmt(__N(
"deque::_M_range_check: __n " 1463 "(which is %zu)>= this->size() " 1483 _M_range_check(__n);
1484 return (*
this)[__n];
1501 _M_range_check(__n);
1502 return (*
this)[__n];
1513 __glibcxx_requires_nonempty();
1525 __glibcxx_requires_nonempty();
1537 __glibcxx_requires_nonempty();
1538 iterator __tmp =
end();
1551 __glibcxx_requires_nonempty();
1552 const_iterator __tmp =
end();
1570 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1572 _Alloc_traits::construct(this->_M_impl,
1573 this->_M_impl._M_start._M_cur - 1,
1575 --this->_M_impl._M_start._M_cur;
1578 _M_push_front_aux(__x);
1581 #if __cplusplus >= 201103L 1583 push_front(value_type&& __x)
1586 template<
typename... _Args>
1587 #if __cplusplus > 201402L 1592 emplace_front(_Args&&... __args);
1607 if (this->_M_impl._M_finish._M_cur
1608 != this->_M_impl._M_finish._M_last - 1)
1610 _Alloc_traits::construct(this->_M_impl,
1611 this->_M_impl._M_finish._M_cur, __x);
1612 ++this->_M_impl._M_finish._M_cur;
1615 _M_push_back_aux(__x);
1618 #if __cplusplus >= 201103L 1620 push_back(value_type&& __x)
1623 template<
typename... _Args>
1624 #if __cplusplus > 201402L 1629 emplace_back(_Args&&... __args);
1643 __glibcxx_requires_nonempty();
1644 if (this->_M_impl._M_start._M_cur
1645 != this->_M_impl._M_start._M_last - 1)
1647 _Alloc_traits::destroy(_M_get_Tp_allocator(),
1648 this->_M_impl._M_start._M_cur);
1649 ++this->_M_impl._M_start._M_cur;
1666 __glibcxx_requires_nonempty();
1667 if (this->_M_impl._M_finish._M_cur
1668 != this->_M_impl._M_finish._M_first)
1670 --this->_M_impl._M_finish._M_cur;
1671 _Alloc_traits::destroy(_M_get_Tp_allocator(),
1672 this->_M_impl._M_finish._M_cur);
1678 #if __cplusplus >= 201103L 1688 template<
typename... _Args>
1690 emplace(const_iterator __position, _Args&&... __args);
1702 insert(const_iterator __position,
const value_type& __x);
1714 insert(iterator __position,
const value_type& __x);
1717 #if __cplusplus >= 201103L 1728 insert(const_iterator __position, value_type&& __x)
1729 {
return emplace(__position,
std::move(__x)); }
1744 auto __offset = __p -
cbegin();
1745 _M_range_insert_aux(__p._M_const_cast(), __l.begin(), __l.end(),
1747 return begin() + __offset;
1761 insert(const_iterator __position, size_type __n,
const value_type& __x)
1763 difference_type __offset = __position -
cbegin();
1764 _M_fill_insert(__position._M_const_cast(), __n, __x);
1765 return begin() + __offset;
1778 insert(iterator __position, size_type __n,
const value_type& __x)
1779 { _M_fill_insert(__position, __n, __x); }
1782 #if __cplusplus >= 201103L 1794 template<
typename _InputIterator,
1795 typename = std::_RequireInputIter<_InputIterator>>
1797 insert(const_iterator __position, _InputIterator __first,
1798 _InputIterator __last)
1800 difference_type __offset = __position -
cbegin();
1801 _M_range_insert_aux(__position._M_const_cast(), __first, __last,
1803 return begin() + __offset;
1816 template<
typename _InputIterator>
1818 insert(iterator __position, _InputIterator __first,
1819 _InputIterator __last)
1822 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1823 _M_insert_dispatch(__position, __first, __last, _Integral());
1827 #if __glibcxx_containers_ranges // C++ >= 23 1836 template<__detail::__container_compatible_range<_Tp> _Rg>
1838 insert_range(const_iterator __pos, _Rg&& __rg);
1845 template<__detail::__container_compatible_range<_Tp> _Rg>
1847 prepend_range(_Rg&& __rg);
1854 template<__detail::__container_compatible_range<_Tp> _Rg>
1856 append_range(_Rg&& __rg);
1857 #endif // containers_ranges 1873 #if __cplusplus >= 201103L 1876 erase(iterator __position)
1878 {
return _M_erase(__position._M_const_cast()); }
1897 #if __cplusplus >= 201103L 1898 erase(const_iterator __first, const_iterator __last)
1900 erase(iterator __first, iterator __last)
1902 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1918 #if __cplusplus >= 201103L 1919 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1920 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1922 _M_impl._M_swap_data(__x._M_impl);
1923 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1924 __x._M_get_Tp_allocator());
1935 { _M_erase_at_end(
begin()); }
1940 #if __cplusplus < 201103L 1945 template<
typename _Integer>
1947 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1949 _M_initialize_map(_S_check_init_len(static_cast<size_type>(__n),
1950 _M_get_Tp_allocator()));
1951 _M_fill_initialize(__x);
1955 template<
typename _InputIterator>
1957 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1960 _M_range_initialize(__first, __last,
1966 _S_check_init_len(
size_t __n,
const allocator_type& __a)
1968 if (__n > _S_max_size(__a))
1969 __throw_length_error(
1970 __N(
"cannot create std::deque larger than max_size()"));
1975 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1977 const size_t __diffmax = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max;
1978 const size_t __allocmax = _Alloc_traits::max_size(__a);
1979 return (
std::min)(__diffmax, __allocmax);
1994 template<
typename _InputIterator>
1996 _M_range_initialize(_InputIterator __first, _InputIterator __last,
2000 template<
typename _ForwardIterator>
2002 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
2017 _M_fill_initialize(
const value_type& __value);
2019 #if __cplusplus >= 201103L 2022 _M_default_initialize();
2028 #if __cplusplus < 201103L 2033 template<
typename _Integer>
2035 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
2036 { _M_fill_assign(__n, __val); }
2039 template<
typename _InputIterator>
2041 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
2047 template<
typename _InputIterator>
2049 _M_assign_aux(_InputIterator __first, _InputIterator __last,
2053 template<
typename _ForwardIterator>
2055 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
2061 _ForwardIterator __mid = __first;
2063 std::copy(__first, __mid,
begin());
2064 _M_range_insert_aux(
end(), __mid, __last,
2068 _M_erase_at_end(std::copy(__first, __last,
begin()));
2074 _M_fill_assign(size_type __n,
const value_type& __val)
2079 _M_fill_insert(
end(), __n -
size(), __val);
2083 _M_erase_at_end(
begin() + difference_type(__n));
2090 #if __cplusplus < 201103L 2091 void _M_push_back_aux(
const value_type&);
2093 void _M_push_front_aux(
const value_type&);
2095 template<
typename... _Args>
2096 void _M_push_back_aux(_Args&&... __args);
2098 template<
typename... _Args>
2099 void _M_push_front_aux(_Args&&... __args);
2102 void _M_pop_back_aux();
2104 void _M_pop_front_aux();
2110 #if __cplusplus < 201103L 2115 template<
typename _Integer>
2117 _M_insert_dispatch(iterator __pos,
2118 _Integer __n, _Integer __x, __true_type)
2119 { _M_fill_insert(__pos, __n, __x); }
2122 template<
typename _InputIterator>
2124 _M_insert_dispatch(iterator __pos,
2125 _InputIterator __first, _InputIterator __last,
2128 _M_range_insert_aux(__pos, __first, __last,
2134 template<
typename _InputIterator,
typename _Sentinel>
2135 void _M_range_prepend(_InputIterator __first, _Sentinel __last,
2139 template<
typename _InputIterator,
typename _Sentinel>
2140 void _M_range_append(_InputIterator __first, _Sentinel __last,
2144 template<
typename _InputIterator>
2146 _M_range_insert_aux(iterator __pos, _InputIterator __first,
2150 template<
typename _ForwardIterator>
2152 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
2159 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
2162 #if __cplusplus < 201103L 2164 _M_insert_aux(iterator __pos,
const value_type& __x);
2166 struct _Temporary_value
2168 template<
typename... _Args>
2169 _GLIBCXX20_CONSTEXPR
explicit 2170 _Temporary_value(
deque* __deque, _Args&&... __args) : _M_this(__deque)
2172 _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(),
2173 std::forward<_Args>(__args)...);
2176 _GLIBCXX20_CONSTEXPR
2178 { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); }
2180 _GLIBCXX20_CONSTEXPR value_type&
2181 _M_val() noexcept {
return __tmp_val; }
2184 _GLIBCXX20_CONSTEXPR _Tp*
2196 _M_insert_aux(iterator __pos,
const value_type& __x)
2197 {
return _M_emplace_aux(__pos, __x); }
2199 template<
typename... _Args>
2201 _M_emplace_aux(iterator __pos, _Args&&... __args);
2206 _M_insert_aux(iterator __pos, size_type __n,
const value_type& __x);
2209 template<
typename _ForwardIterator>
2211 _M_insert_aux(iterator __pos,
2212 _ForwardIterator __first, _ForwardIterator __last,
2219 _M_destroy_data_aux(iterator __first, iterator __last);
2223 template<
typename _Alloc1>
2225 _M_destroy_data(iterator __first, iterator __last,
const _Alloc1&)
2226 { _M_destroy_data_aux(__first, __last); }
2229 _M_destroy_data(iterator __first, iterator __last,
2232 if (!__has_trivial_destructor(value_type))
2233 _M_destroy_data_aux(__first, __last);
2238 _M_erase_at_begin(iterator __pos)
2240 _M_destroy_data(
begin(), __pos, _M_get_Tp_allocator());
2241 _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
2242 this->_M_impl._M_start = __pos;
2248 _M_erase_at_end(iterator __pos)
2250 _M_destroy_data(__pos,
end(), _M_get_Tp_allocator());
2251 _M_destroy_nodes(__pos._M_node + 1,
2252 this->_M_impl._M_finish._M_node + 1);
2253 this->_M_impl._M_finish = __pos;
2257 _M_erase(iterator __pos);
2260 _M_erase(iterator __first, iterator __last);
2262 #if __cplusplus >= 201103L 2265 _M_default_append(size_type __n);
2276 const size_type __vacancies = this->_M_impl._M_start._M_cur
2277 - this->_M_impl._M_start._M_first;
2278 if (__n > __vacancies)
2279 _M_new_elements_at_front(__n - __vacancies);
2280 return this->_M_impl._M_start - difference_type(__n);
2286 const size_type __vacancies = (this->_M_impl._M_finish._M_last
2287 - this->_M_impl._M_finish._M_cur) - 1;
2288 if (__n > __vacancies)
2289 _M_new_elements_at_back(__n - __vacancies);
2290 return this->_M_impl._M_finish + difference_type(__n);
2294 _M_new_elements_at_front(size_type __new_elements);
2297 _M_new_elements_at_back(size_type __new_elements);
2312 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
2313 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
2314 _M_reallocate_map(__nodes_to_add,
false);
2320 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
2321 - this->_M_impl._M_map))
2322 _M_reallocate_map(__nodes_to_add,
true);
2326 _M_reallocate_map(size_type __nodes_to_add,
bool __add_at_front);
2329 #if __cplusplus >= 201103L 2335 this->_M_impl._M_swap_data(__x._M_impl);
2337 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2346 if (_M_get_Tp_allocator() == __x._M_get_Tp_allocator())
2349 constexpr
bool __move_storage =
2350 _Alloc_traits::_S_propagate_on_move_assign();
2351 _M_move_assign2(
std::move(__x), __bool_constant<__move_storage>());
2356 template<
typename... _Args>
2358 _M_replace_map(_Args&&... __args)
2361 deque __newobj(std::forward<_Args>(__args)...);
2364 _M_deallocate_node(*
begin()._M_node);
2365 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
2366 this->_M_impl._M_map =
nullptr;
2367 this->_M_impl._M_map_size = 0;
2369 this->_M_impl._M_swap_data(__newobj._M_impl);
2377 auto __alloc = __x._M_get_Tp_allocator();
2382 _M_get_Tp_allocator() =
std::move(__alloc);
2390 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2394 _M_replace_map(
std::move(__x), __x.get_allocator());
2400 _M_assign_aux(std::make_move_iterator(__x.begin()),
2401 std::make_move_iterator(__x.end()),
2409 #if __cpp_deduction_guides >= 201606 2410 template<
typename _InputIterator,
typename _ValT
2413 typename = _RequireInputIter<_InputIterator>,
2414 typename = _RequireAllocator<_Allocator>>
2415 deque(_InputIterator, _InputIterator, _Allocator = _Allocator())
2418 #if __glibcxx_containers_ranges // C++ >= 23 2419 template<ranges::input_range _Rg,
2421 deque(from_range_t, _Rg&&, _Alloc = _Alloc())
2436 template<
typename _Tp,
typename _Alloc>
2443 #if __cpp_lib_three_way_comparison 2455 template<
typename _Tp,
typename _Alloc>
2457 inline __detail::__synth3way_t<_Tp>
2462 __detail::__synth3way);
2476 template<
typename _Tp,
typename _Alloc>
2481 __y.begin(), __y.end()); }
2484 template<
typename _Tp,
typename _Alloc>
2488 {
return !(__x == __y); }
2491 template<
typename _Tp,
typename _Alloc>
2495 {
return __y < __x; }
2498 template<
typename _Tp,
typename _Alloc>
2502 {
return !(__y < __x); }
2505 template<
typename _Tp,
typename _Alloc>
2509 {
return !(__x < __y); }
2510 #endif // three-way comparison 2513 template<
typename _Tp,
typename _Alloc>
2516 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.
swap(__y)))
2519 #undef _GLIBCXX_DEQUE_BUF_SIZE 2521 _GLIBCXX_END_NAMESPACE_CONTAINER
2523 #if __cplusplus >= 201103L 2527 struct __is_bitwise_relocatable<_GLIBCXX_STD_C::
deque<_Tp>>
2531 _GLIBCXX_END_NAMESPACE_VERSION
A standard container using fixed-size memory allocation and constant-time manipulation of elements at...
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
reference back() noexcept
void push_back(const value_type &__x)
Add data to the end of the deque.
void resize(size_type __new_size, const value_type &__x)
Resizes the deque to the specified number of elements.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
reference at(size_type __n)
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.
typename __detected_or_t< is_empty< _Tp_alloc_type >, __equal, _Tp_alloc_type >::type is_always_equal
Whether all instances of the allocator type compare equal.
const_iterator cbegin() const noexcept
deque & operator=(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
iterator begin() noexcept
deque(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a deque from a range.
reference operator[](size_type __n) noexcept
Subscript access to the data contained in the deque.
void push_front(const value_type &__x)
Add data to the front of the deque.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
Uniform interface to C++98 and C++11 allocators.
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
reverse_iterator rbegin() noexcept
deque(const deque &__x)
Deque copy constructor.
const_reverse_iterator crend() const noexcept
deque(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a deque with copies of an exemplar element.
deque(deque &&__x, const __type_identity_t< allocator_type > &__a)
Move constructor with alternative allocator.
constexpr void fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp &__value)
Fills the range [first,last) with copies of value.
bool empty() const noexcept
void _M_reserve_map_at_back(size_type __nodes_to_add=1)
Memory-handling helpers for the major map.
void shrink_to_fit() noexcept
void resize(size_type __new_size)
Resizes the deque to the specified number of elements.
const_iterator end() const noexcept
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
deque(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a deque from an initializer list.
ISO C++ entities toplevel namespace is std.
iterator insert(const_iterator __p, initializer_list< value_type > __l)
Inserts an initializer list into the deque.
constexpr auto cbegin(const _Container &__cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont))
Return an iterator pointing to the first element of the const container.
const_reference front() const noexcept
void _M_range_check(size_type __n) const
Safety check used only from at().
void assign(size_type __n, const value_type &__val)
Assigns a given value to a deque.
const_reference operator[](size_type __n) const noexcept
Subscript access to the data contained in the deque.
const_iterator begin() const noexcept
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
Forward iterators support a superset of input iterator operations.
iterator erase(const_iterator __position)
Remove element at given position.
iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the deque.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
void assign(initializer_list< value_type > __l)
Assigns an initializer list to a deque.
iterator _M_reserve_elements_at_back(size_type __n)
Memory-handling helpers for the previous internal insert functions.
reference front() noexcept
concept assignable_from
[concept.assignable], concept assignable_from
constexpr bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
constexpr bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
void pop_front() noexcept
Removes first element.
Random-access iterators support a superset of bidirectional iterator operations.
const_iterator cend() const noexcept
deque(const allocator_type &__a)
Creates a deque with no elements.
const_reverse_iterator rbegin() const noexcept
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.
void pop_back() noexcept
Removes last element.
iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into deque before specified iterator.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a deque.
The standard allocator, as per C++03 [20.4.1].
void swap(deque &__x) noexcept
Swaps data with another deque.
deque(size_type __n, const allocator_type &__a=allocator_type())
Creates a deque with default constructed elements.
const_reference back() const noexcept
void _M_set_node(_Map_pointer __new_node) noexcept
#define _GLIBCXX_DEQUE_BUF_SIZE
This function controls the size of memory nodes.
iterator _M_reserve_elements_at_front(size_type __n)
Memory-handling helpers for the previous internal insert functions.
is_nothrow_default_constructible
size_type max_size() const noexcept
size_type size() const noexcept
iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
const_reverse_iterator rend() const noexcept
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.
deque(const deque &__x, const __type_identity_t< allocator_type > &__a)
Copy constructor with alternative allocator.
Traits class for iterators.
void _M_initialize_map(size_t)
Layout storage.
const_reference at(size_type __n) const
Provides access to the data contained in the deque.
const_reverse_iterator crbegin() const noexcept
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
deque & operator=(deque &&__x) noexcept(_Alloc_traits::_S_always_equal())
Deque move assignment operator.
iterator insert(const_iterator __position, size_type __n, const value_type &__x)
Inserts a number of copies of given data into the deque.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
reverse_iterator rend() noexcept
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.