790 class deque :
protected _Deque_base<_Tp, _Alloc>
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");
810 typedef _Deque_base<_Tp, _Alloc> _Base;
811 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
812 typedef typename _Base::_Alloc_traits _Alloc_traits;
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;
821 typedef typename _Base::iterator iterator;
822 typedef typename _Base::const_iterator const_iterator;
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))
907 const allocator_type& __a = allocator_type())
908 : _Base(__a, _S_check_init_len(__n, __a))
920 : _Base(_Alloc_traits::_S_select_on_copy(__x._M_get_Tp_allocator()),
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)
939 : _Base(__a, __x.
size())
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)
946 :
deque(
std::
move(__x), __a, typename _Alloc_traits::is_always_equal{})
954 deque(deque&& __x,
const allocator_type& __a, false_type)
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>
1161 assign_range(_Rg&& __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);
1183 for (iterator __it =
begin(), __end =
end();
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; }
1252 {
return reverse_iterator(this->_M_impl._M_finish); }
1260 const_reverse_iterator
1262 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1272 {
return reverse_iterator(this->_M_impl._M_start); }
1280 const_reverse_iterator
1282 {
return const_reverse_iterator(this->_M_impl._M_start); }
1284#if __cplusplus >= 201103L
1292 {
return this->_M_impl._M_start; }
1302 {
return this->_M_impl._M_finish; }
1310 const_reverse_iterator
1312 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1320 const_reverse_iterator
1322 {
return const_reverse_iterator(this->_M_impl._M_start); }
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();
1537 iterator __tmp =
end();
1550 __glibcxx_requires_nonempty();
1551 const_iterator __tmp =
end();
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);
1713 insert(iterator __position,
const value_type& __x);
1716#if __cplusplus >= 201103L
1727 insert(const_iterator __position, value_type&& __x)
1743 auto __offset = __p -
cbegin();
1744 _M_range_insert_aux(__p._M_const_cast(), __l.begin(), __l.end(),
1746 return begin() + __offset;
1760 insert(const_iterator __position, size_type __n,
const value_type& __x)
1762 difference_type __offset = __position -
cbegin();
1763 _M_fill_insert(__position._M_const_cast(), __n, __x);
1764 return begin() + __offset;
1778 { _M_fill_insert(__position, __n, __x); }
1781#if __cplusplus >= 201103L
1793 template<
typename _InputIterator,
1794 typename = std::_RequireInputIter<_InputIterator>>
1796 insert(const_iterator __position, _InputIterator __first,
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>
1837 insert_range(const_iterator __pos, _Rg&& __rg);
1844 template<__detail::__container_compatible_range<_Tp> _Rg>
1846 prepend_range(_Rg&& __rg);
1853 template<__detail::__container_compatible_range<_Tp> _Rg>
1855 append_range(_Rg&& __rg);
1872#if __cplusplus >= 201103L
1875 erase(iterator __position)
1877 {
return _M_erase(__position._M_const_cast()); }
1896#if __cplusplus >= 201103L
1897 erase(const_iterator __first, const_iterator __last)
1899 erase(iterator __first, iterator __last)
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>
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(),
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,
2227 const std::allocator<_Tp>&)
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)
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()),
2399 std::random_access_iterator_tag());