791 class deque :
protected _Deque_base<_Tp, _Alloc>
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
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");
811 typedef _Deque_base<_Tp, _Alloc> _Base;
812 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
813 typedef typename _Base::_Alloc_traits _Alloc_traits;
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;
822 typedef typename _Base::iterator iterator;
823 typedef typename _Base::const_iterator const_iterator;
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)); }
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))
908 const allocator_type& __a = allocator_type())
909 : _Base(__a, _S_check_init_len(__n, __a))
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{})
955 deque(deque&& __x,
const allocator_type& __a, false_type)
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())
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())
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
1031 template<__detail::__container_compatible_range<_Tp> _Rg>
1032 deque(from_range_t, _Rg&& __rg,
const allocator_type& __a = _Alloc())
1043 { _M_destroy_data(
begin(),
end(), _M_get_Tp_allocator()); }
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
1160 template<__detail::__container_compatible_range<_Tp> _Rg>
1162 assign_range(_Rg&& __rg)
1164 static_assert(assignable_from<_Tp&, ranges::range_reference_t<_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);
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;
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() "
1484 return (*
this)[__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;
1581#if __cplusplus >= 201103L
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;
1618#if __cplusplus >= 201103L
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)
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;
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>
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
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);
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()));
1955 template<
typename _InputIterator>
1957 _M_initialize_dispatch(_InputIterator __first, _InputIterator __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;
1979 return (
std::min)(__diffmax, __allocmax);
1994 template<
typename _InputIterator>
2000 template<
typename _ForwardIterator>
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
2095 template<
typename... _Args>
2098 template<
typename... _Args>
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>
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);
2167 _M_insert_aux(iterator __pos,
const value_type& __x)
2168 {
return _M_emplace_aux(__pos, __x); }
2170 template<
typename... _Args>
2172 _M_emplace_aux(iterator __pos, _Args&&... __args);
2177 _M_insert_aux(iterator __pos, size_type __n,
const value_type& __x);
2180 template<
typename _ForwardIterator>
2182 _M_insert_aux(iterator __pos,
2183 _ForwardIterator __first, _ForwardIterator __last,
2190 _M_destroy_data_aux(iterator __first, iterator __last);
2194 template<
typename _Alloc1>
2196 _M_destroy_data(iterator __first, iterator __last,
const _Alloc1&)
2197 { _M_destroy_data_aux(__first, __last); }
2200 _M_destroy_data(iterator __first, iterator __last,
2201 const std::allocator<_Tp>&)
2203 if (!__has_trivial_destructor(value_type))
2204 _M_destroy_data_aux(__first, __last);
2209 _M_erase_at_begin(iterator __pos)
2211 _M_destroy_data(
begin(), __pos, _M_get_Tp_allocator());
2212 _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
2213 this->_M_impl._M_start = __pos;
2219 _M_erase_at_end(iterator __pos)
2221 _M_destroy_data(__pos,
end(), _M_get_Tp_allocator());
2222 _M_destroy_nodes(__pos._M_node + 1,
2223 this->_M_impl._M_finish._M_node + 1);
2224 this->_M_impl._M_finish = __pos;
2228 _M_erase(iterator __pos);
2231 _M_erase(iterator __first, iterator __last);
2233#if __cplusplus >= 201103L
2236 _M_default_append(size_type __n);
2247 const size_type __vacancies = this->_M_impl._M_start._M_cur
2248 - this->_M_impl._M_start._M_first;
2249 if (__n > __vacancies)
2251 return this->_M_impl._M_start - difference_type(__n);
2257 const size_type __vacancies = (this->_M_impl._M_finish._M_last
2258 - this->_M_impl._M_finish._M_cur) - 1;
2259 if (__n > __vacancies)
2261 return this->_M_impl._M_finish + difference_type(__n);
2283 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
2284 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
2291 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
2292 - this->_M_impl._M_map))
2300#if __cplusplus >= 201103L
2306 this->_M_impl._M_swap_data(__x._M_impl);
2308 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2317 if (_M_get_Tp_allocator() == __x._M_get_Tp_allocator())
2320 constexpr bool __move_storage =
2321 _Alloc_traits::_S_propagate_on_move_assign();
2322 _M_move_assign2(
std::move(__x), __bool_constant<__move_storage>());
2327 template<
typename... _Args>
2329 _M_replace_map(_Args&&... __args)
2335 _M_deallocate_node(*
begin()._M_node);
2336 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
2337 this->_M_impl._M_map =
nullptr;
2338 this->_M_impl._M_map_size = 0;
2340 this->_M_impl._M_swap_data(__newobj._M_impl);
2348 auto __alloc = __x._M_get_Tp_allocator();
2353 _M_get_Tp_allocator() =
std::move(__alloc);
2361 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2365 _M_replace_map(
std::move(__x), __x.get_allocator());
2371 _M_assign_aux(std::make_move_iterator(__x.begin()),
2372 std::make_move_iterator(__x.end()),
2373 std::random_access_iterator_tag());