827 class deque :
protected _Deque_base<_Tp, _Alloc>
829#ifdef _GLIBCXX_CONCEPT_CHECKS
831 typedef typename _Alloc::value_type _Alloc_value_type;
832# if __cplusplus < 201103L
833 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
835 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
838#if __cplusplus >= 201103L
840 "std::deque must have a non-const, non-volatile value_type");
841# if __cplusplus > 201703L || defined __STRICT_ANSI__
843 "std::deque must have the same value_type as its allocator");
847 typedef _Deque_base<_Tp, _Alloc> _Base;
848 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
849 typedef typename _Base::_Alloc_traits _Alloc_traits;
850 typedef typename _Base::_Map_pointer _Map_pointer;
853 typedef _Tp value_type;
854 typedef typename _Alloc_traits::pointer pointer;
855 typedef typename _Alloc_traits::const_pointer const_pointer;
856 typedef typename _Alloc_traits::reference reference;
857 typedef typename _Alloc_traits::const_reference const_reference;
858 typedef typename _Base::iterator iterator;
859 typedef typename _Base::const_iterator const_iterator;
862 typedef size_t size_type;
863 typedef ptrdiff_t difference_type;
864 typedef _Alloc allocator_type;
867 static size_t _S_buffer_size() _GLIBCXX_NOEXCEPT
868 {
return __deque_buf_size(
sizeof(_Tp)); }
872 using _Base::_M_create_nodes;
873 using _Base::_M_destroy_nodes;
874 using _Base::_M_allocate_node;
875 using _Base::_M_deallocate_node;
876 using _Base::_M_allocate_map;
877 using _Base::_M_deallocate_map;
878 using _Base::_M_get_Tp_allocator;
884 using _Base::_M_impl;
893#if __cplusplus >= 201103L
907#if __cplusplus >= 201103L
917 deque(size_type __n,
const allocator_type& __a = allocator_type())
918 : _Base(__a, _S_check_init_len(__n, __a))
919 { _M_default_initialize(); }
929 deque(size_type __n,
const value_type& __value,
930 const allocator_type& __a = allocator_type())
931 : _Base(__a, _S_check_init_len(__n, __a))
944 const allocator_type& __a = allocator_type())
945 : _Base(__a, _S_check_init_len(__n, __a))
957 : _Base(_Alloc_traits::_S_select_on_copy(__x._M_get_Tp_allocator()),
959 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
960 this->_M_impl._M_start,
961 _M_get_Tp_allocator()); }
963#if __cplusplus >= 201103L
975 deque(
const deque& __x,
const __type_identity_t<allocator_type>& __a)
976 : _Base(__a, __x.
size())
977 { std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
978 this->_M_impl._M_start,
979 _M_get_Tp_allocator()); }
982 deque(
deque&& __x,
const __type_identity_t<allocator_type>& __a)
983 :
deque(
std::
move(__x), __a, typename _Alloc_traits::is_always_equal{})
991 deque(deque&& __x,
const allocator_type& __a, false_type)
994 if (__x.get_allocator() != __a && !__x.empty())
996 std::__uninitialized_move_a(__x.begin(), __x.end(),
997 this->_M_impl._M_start,
998 _M_get_Tp_allocator());
1016 const allocator_type& __a = allocator_type())
1039#if __cplusplus >= 201103L
1040 template<
typename _InputIterator,
1041 typename = std::_RequireInputIter<_InputIterator>>
1042 deque(_InputIterator __first, _InputIterator __last,
1043 const allocator_type& __a = allocator_type())
1047 std::__iterator_category(__first));
1050 template<
typename _InputIterator>
1051 deque(_InputIterator __first, _InputIterator __last,
1052 const allocator_type& __a = allocator_type())
1056 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1057 _M_initialize_dispatch(__first, __last, _Integral());
1061#if __glibcxx_containers_ranges
1067 template<__detail::__container_compatible_range<_Tp> _Rg>
1068 deque(from_range_t, _Rg&& __rg,
const allocator_type& __a = _Alloc())
1079 { _M_destroy_data(
begin(),
end(), _M_get_Tp_allocator()); }
1093#if __cplusplus >= 201103L
1106 _M_move_assign1(
std::move(__x), __always_equal{});
1124 _M_assign_aux(__l.begin(), __l.end(),
1141 assign(size_type __n,
const value_type& __val)
1142 { _M_fill_assign(__n, __val); }
1156#if __cplusplus >= 201103L
1157 template<
typename _InputIterator,
1158 typename = std::_RequireInputIter<_InputIterator>>
1160 assign(_InputIterator __first, _InputIterator __last)
1161 { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
1163 template<
typename _InputIterator>
1165 assign(_InputIterator __first, _InputIterator __last)
1167 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1168 _M_assign_dispatch(__first, __last, _Integral());
1172#if __cplusplus >= 201103L
1189#if __glibcxx_containers_ranges
1196 template<__detail::__container_compatible_range<_Tp> _Rg>
1198 assign_range(_Rg&& __rg)
1204 const size_type __n(ranges::distance(__rg));
1207 auto __res = ranges::copy(__rg,
begin());
1208 return _M_erase_at_end(__res.out);
1211 auto __rest = ranges::copy_n(ranges::begin(__rg),
size(),
1213 _M_range_append(
std::move(__rest), ranges::end(__rg),
1218 auto __first = ranges::begin(__rg);
1219 const auto __last = ranges::end(__rg);
1220 for (iterator __it =
begin(), __end =
end();
1221 __it != __end; (void)++__first, ++__it)
1223 if (__first == __last)
1224 return _M_erase_at_end(__it);
1229 for (; __first != __last; ++__first)
1230 emplace_back(*__first);
1240 {
return _Base::get_allocator(); }
1250 {
return this->_M_impl._M_start; }
1259 {
return this->_M_impl._M_start; }
1269 {
return this->_M_impl._M_finish; }
1279 {
return this->_M_impl._M_finish; }
1289 {
return reverse_iterator(this->_M_impl._M_finish); }
1297 const_reverse_iterator
1299 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1309 {
return reverse_iterator(this->_M_impl._M_start); }
1317 const_reverse_iterator
1319 {
return const_reverse_iterator(this->_M_impl._M_start); }
1321#if __cplusplus >= 201103L
1329 {
return this->_M_impl._M_start; }
1339 {
return this->_M_impl._M_finish; }
1347 const_reverse_iterator
1349 {
return const_reverse_iterator(this->_M_impl._M_finish); }
1357 const_reverse_iterator
1359 {
return const_reverse_iterator(this->_M_impl._M_start); }
1368 size_type __sz = this->_M_impl._M_finish - this->_M_impl._M_start;
1370 __builtin_unreachable();
1378 {
return _S_max_size(_M_get_Tp_allocator()); }
1380#if __cplusplus >= 201103L
1393 const size_type __len =
size();
1394 if (__new_size > __len)
1395 _M_default_append(__new_size - __len);
1396 else if (__new_size < __len)
1397 _M_erase_at_end(this->_M_impl._M_start
1398 + difference_type(__new_size));
1413 resize(size_type __new_size,
const value_type& __x)
1427 resize(size_type __new_size, value_type __x = value_type())
1430 const size_type __len =
size();
1431 if (__new_size > __len)
1432 _M_fill_insert(this->_M_impl._M_finish, __new_size - __len, __x);
1433 else if (__new_size < __len)
1434 _M_erase_at_end(this->_M_impl._M_start
1435 + difference_type(__new_size));
1438#if __cplusplus >= 201103L
1442 { _M_shrink_to_fit(); }
1449 _GLIBCXX_NODISCARD
bool
1451 {
return this->_M_impl._M_finish == this->_M_impl._M_start; }
1469 __glibcxx_requires_subscript(__n);
1470 return this->_M_impl._M_start[difference_type(__n)];
1488 __glibcxx_requires_subscript(__n);
1489 return this->_M_impl._M_start[difference_type(__n)];
1497 if (__n >= this->
size())
1498 __throw_out_of_range_fmt(__N(
"deque::_M_range_check: __n "
1499 "(which is %zu)>= this->size() "
1520 return (*
this)[__n];
1538 return (*
this)[__n];
1549 __glibcxx_requires_nonempty();
1561 __glibcxx_requires_nonempty();
1573 __glibcxx_requires_nonempty();
1574 iterator __tmp =
end();
1587 __glibcxx_requires_nonempty();
1588 const_iterator __tmp =
end();
1606 if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1608 _Alloc_traits::construct(this->_M_impl,
1609 this->_M_impl._M_start._M_cur - 1,
1611 --this->_M_impl._M_start._M_cur;
1617#if __cplusplus >= 201103L
1622 template<
typename... _Args>
1623#if __cplusplus > 201402L
1628 emplace_front(_Args&&... __args);
1643 if (this->_M_impl._M_finish._M_cur
1644 != this->_M_impl._M_finish._M_last - 1)
1646 _Alloc_traits::construct(this->_M_impl,
1647 this->_M_impl._M_finish._M_cur, __x);
1648 ++this->_M_impl._M_finish._M_cur;
1654#if __cplusplus >= 201103L
1659 template<
typename... _Args>
1660#if __cplusplus > 201402L
1665 emplace_back(_Args&&... __args);
1679 __glibcxx_requires_nonempty();
1680 if (this->_M_impl._M_start._M_cur
1681 != this->_M_impl._M_start._M_last - 1)
1683 _Alloc_traits::destroy(_M_get_Tp_allocator(),
1684 this->_M_impl._M_start._M_cur);
1685 ++this->_M_impl._M_start._M_cur;
1702 __glibcxx_requires_nonempty();
1703 if (this->_M_impl._M_finish._M_cur
1704 != this->_M_impl._M_finish._M_first)
1706 --this->_M_impl._M_finish._M_cur;
1707 _Alloc_traits::destroy(_M_get_Tp_allocator(),
1708 this->_M_impl._M_finish._M_cur);
1714#if __cplusplus >= 201103L
1724 template<
typename... _Args>
1726 emplace(const_iterator __position, _Args&&... __args);
1738 insert(const_iterator __position,
const value_type& __x);
1750 insert(iterator __position,
const value_type& __x);
1753#if __cplusplus >= 201103L
1764 insert(const_iterator __position, value_type&& __x)
1780 auto __offset = __p -
cbegin();
1781 _M_range_insert_aux(__p._M_const_cast(), __l.begin(), __l.end(),
1783 return begin() + __offset;
1797 insert(const_iterator __position, size_type __n,
const value_type& __x)
1799 difference_type __offset = __position -
cbegin();
1800 _M_fill_insert(__position._M_const_cast(), __n, __x);
1801 return begin() + __offset;
1815 { _M_fill_insert(__position, __n, __x); }
1818#if __cplusplus >= 201103L
1830 template<
typename _InputIterator,
1831 typename = std::_RequireInputIter<_InputIterator>>
1833 insert(const_iterator __position, _InputIterator __first,
1834 _InputIterator __last)
1836 difference_type __offset = __position -
cbegin();
1837 _M_range_insert_aux(__position._M_const_cast(), __first, __last,
1838 std::__iterator_category(__first));
1839 return begin() + __offset;
1852 template<
typename _InputIterator>
1855 _InputIterator __last)
1858 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1859 _M_insert_dispatch(__position, __first, __last, _Integral());
1863#if __glibcxx_containers_ranges
1872 template<__detail::__container_compatible_range<_Tp> _Rg>
1874 insert_range(const_iterator __pos, _Rg&& __rg);
1881 template<__detail::__container_compatible_range<_Tp> _Rg>
1883 prepend_range(_Rg&& __rg);
1890 template<__detail::__container_compatible_range<_Tp> _Rg>
1892 append_range(_Rg&& __rg);
1909#if __cplusplus >= 201103L
1912 erase(iterator __position)
1914 {
return _M_erase(__position._M_const_cast()); }
1933#if __cplusplus >= 201103L
1934 erase(const_iterator __first, const_iterator __last)
1936 erase(iterator __first, iterator __last)
1938 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1954#if __cplusplus >= 201103L
1955 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1956 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1958 _M_impl._M_swap_data(__x._M_impl);
1959 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1960 __x._M_get_Tp_allocator());
1971 { _M_erase_at_end(
begin()); }
1976#if __cplusplus < 201103L
1981 template<
typename _Integer>
1983 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1985 _M_initialize_map(_S_check_init_len(
static_cast<size_type>(__n),
1986 _M_get_Tp_allocator()));
1991 template<
typename _InputIterator>
1993 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1997 std::__iterator_category(__first));
2002 _S_check_init_len(
size_t __n,
const allocator_type& __a)
2004 if (__n > _S_max_size(__a))
2005 __throw_length_error(
2006 __N(
"cannot create std::deque larger than max_size()"));
2011 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
2013 const size_t __diffmax = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max;
2015 return (
std::min)(__diffmax, __allocmax);
2029 template<
typename _InputIterator>
2035 template<
typename _ForwardIterator>
2053#if __cplusplus >= 201103L
2056 _M_default_initialize();
2062#if __cplusplus < 201103L
2067 template<
typename _Integer>
2069 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
2070 { _M_fill_assign(__n, __val); }
2073 template<
typename _InputIterator>
2075 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
2077 { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
2081 template<
typename _InputIterator>
2083 _M_assign_aux(_InputIterator __first, _InputIterator __last,
2087 template<
typename _ForwardIterator>
2089 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
2095 _ForwardIterator __mid = __first;
2097 std::copy(__first, __mid,
begin());
2098 _M_range_insert_aux(
end(), __mid, __last,
2099 std::__iterator_category(__first));
2102 _M_erase_at_end(std::copy(__first, __last,
begin()));
2108 _M_fill_assign(size_type __n,
const value_type& __val)
2113 _M_fill_insert(
end(), __n -
size(), __val);
2117 _M_erase_at_end(
begin() + difference_type(__n));
2124#if __cplusplus < 201103L
2129 template<
typename... _Args>
2132 template<
typename... _Args>
2144#if __cplusplus < 201103L
2149 template<
typename _Integer>
2151 _M_insert_dispatch(iterator __pos,
2152 _Integer __n, _Integer __x, __true_type)
2153 { _M_fill_insert(__pos, __n, __x); }
2156 template<
typename _InputIterator>
2159 _InputIterator __first, _InputIterator __last,
2162 _M_range_insert_aux(__pos, __first, __last,
2163 std::__iterator_category(__first));
2168 template<
typename _InputIterator,
typename _Sentinel>
2169 void _M_range_prepend(_InputIterator __first, _Sentinel __last,
2173 template<
typename _InputIterator,
typename _Sentinel>
2174 void _M_range_append(_InputIterator __first, _Sentinel __last,
2178 template<
typename _InputIterator>
2180 _M_range_insert_aux(iterator __pos, _InputIterator __first,
2184 template<
typename _ForwardIterator>
2186 _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
2193 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
2196#if __cplusplus < 201103L
2198 _M_insert_aux(iterator __pos,
const value_type& __x);
2200 struct _Temporary_value
2202 template<
typename... _Args>
2203 _GLIBCXX20_CONSTEXPR
explicit
2204 _Temporary_value(deque* __deque, _Args&&... __args) : _M_this(__deque)
2206 _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(),
2210 _GLIBCXX20_CONSTEXPR
2212 { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); }
2214 _GLIBCXX20_CONSTEXPR value_type&
2215 _M_val() noexcept {
return __tmp_val; }
2218 _GLIBCXX20_CONSTEXPR _Tp*
2230 _M_insert_aux(iterator __pos,
const value_type& __x)
2231 {
return _M_emplace_aux(__pos, __x); }
2233 template<
typename... _Args>
2235 _M_emplace_aux(iterator __pos, _Args&&... __args);
2240 _M_insert_aux(iterator __pos, size_type __n,
const value_type& __x);
2243 template<
typename _ForwardIterator>
2245 _M_insert_aux(iterator __pos,
2246 _ForwardIterator __first, _ForwardIterator __last,
2253 _M_destroy_data_aux(iterator __first, iterator __last);
2257 template<
typename _Alloc1>
2259 _M_destroy_data(iterator __first, iterator __last,
const _Alloc1&)
2260 { _M_destroy_data_aux(__first, __last); }
2263 _M_destroy_data(iterator __first, iterator __last,
2264 const std::allocator<_Tp>&)
2266 if (!__has_trivial_destructor(value_type))
2267 _M_destroy_data_aux(__first, __last);
2272 _M_erase_at_begin(iterator __pos)
2274 _M_destroy_data(
begin(), __pos, _M_get_Tp_allocator());
2275 _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
2276 this->_M_impl._M_start = __pos;
2282 _M_erase_at_end(iterator __pos)
2284 _M_destroy_data(__pos,
end(), _M_get_Tp_allocator());
2285 _M_destroy_nodes(__pos._M_node + 1,
2286 this->_M_impl._M_finish._M_node + 1);
2287 this->_M_impl._M_finish = __pos;
2291 _M_erase(iterator __pos);
2294 _M_erase(iterator __first, iterator __last);
2296#if __cplusplus >= 201103L
2299 _M_default_append(size_type __n);
2310 const size_type __vacancies = this->_M_impl._M_start._M_cur
2311 - this->_M_impl._M_start._M_first;
2312 if (__n > __vacancies)
2314 return this->_M_impl._M_start - difference_type(__n);
2320 const size_type __vacancies = (this->_M_impl._M_finish._M_last
2321 - this->_M_impl._M_finish._M_cur) - 1;
2322 if (__n > __vacancies)
2324 return this->_M_impl._M_finish + difference_type(__n);
2346 if (__nodes_to_add + 1 > this->_M_impl._M_map_size
2347 - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
2354 if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
2355 - this->_M_impl._M_map))
2363#if __cplusplus >= 201103L
2369 this->_M_impl._M_swap_data(__x._M_impl);
2371 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2380 if (_M_get_Tp_allocator() == __x._M_get_Tp_allocator())
2383 constexpr bool __move_storage =
2384 _Alloc_traits::_S_propagate_on_move_assign();
2385 _M_move_assign2(
std::move(__x), __bool_constant<__move_storage>());
2390 template<
typename... _Args>
2392 _M_replace_map(_Args&&... __args)
2398 _M_deallocate_node(*
begin()._M_node);
2399 _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
2400 this->_M_impl._M_map =
nullptr;
2401 this->_M_impl._M_map_size = 0;
2403 this->_M_impl._M_swap_data(__newobj._M_impl);
2411 auto __alloc = __x._M_get_Tp_allocator();
2416 _M_get_Tp_allocator() =
std::move(__alloc);
2424 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2428 _M_replace_map(
std::move(__x), __x.get_allocator());
2434 _M_assign_aux(std::make_move_iterator(__x.begin()),
2435 std::make_move_iterator(__x.end()),
2436 std::random_access_iterator_tag());