863 using _Base::get_allocator;
871 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
874 {
return iterator(this->_M_impl._M_start); }
881 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
884 {
return const_iterator(this->_M_impl._M_start); }
891 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
894 {
return iterator(this->_M_impl._M_finish); }
901 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
903 end() const _GLIBCXX_NOEXCEPT
904 {
return const_iterator(this->_M_impl._M_finish); }
911 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
921 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
922 const_reverse_iterator
931 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
941 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
942 const_reverse_iterator
946#if __cplusplus >= 201103L
952 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
955 {
return const_iterator(this->_M_impl._M_start); }
962 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
965 {
return const_iterator(this->_M_impl._M_finish); }
972 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
973 const_reverse_iterator
982 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
983 const_reverse_iterator
990 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
993 {
return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
996 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
999 {
return _S_max_size(_M_get_Tp_allocator()); }
1001#if __cplusplus >= 201103L
1011 _GLIBCXX20_CONSTEXPR
1015 if (__new_size >
size())
1016 _M_default_append(__new_size -
size());
1017 else if (__new_size <
size())
1018 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1032 _GLIBCXX20_CONSTEXPR
1034 resize(size_type __new_size,
const value_type& __x)
1036 if (__new_size >
size())
1037 _M_fill_insert(
end(), __new_size -
size(), __x);
1038 else if (__new_size <
size())
1039 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1053 _GLIBCXX20_CONSTEXPR
1055 resize(size_type __new_size, value_type __x = value_type())
1057 if (__new_size >
size())
1058 _M_fill_insert(
end(), __new_size -
size(), __x);
1059 else if (__new_size <
size())
1060 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1064#if __cplusplus >= 201103L
1066 _GLIBCXX20_CONSTEXPR
1069 { _M_shrink_to_fit(); }
1076 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1079 {
return size_type(this->_M_impl._M_end_of_storage
1080 - this->_M_impl._M_start); }
1086 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1108 _GLIBCXX20_CONSTEXPR
1124 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1128 __glibcxx_requires_subscript(__n);
1129 return *(this->_M_impl._M_start + __n);
1143 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1147 __glibcxx_requires_subscript(__n);
1148 return *(this->_M_impl._M_start + __n);
1153 _GLIBCXX20_CONSTEXPR
1157 if (__n >= this->
size())
1158 __throw_out_of_range_fmt(__N(
"vector::_M_range_check: __n "
1159 "(which is %zu) >= this->size() "
1176 _GLIBCXX20_CONSTEXPR
1181 return (*
this)[__n];
1195 _GLIBCXX20_CONSTEXPR
1200 return (*
this)[__n];
1207 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1211 __glibcxx_requires_nonempty();
1219 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1223 __glibcxx_requires_nonempty();
1231 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1235 __glibcxx_requires_nonempty();
1236 return *(
end() - 1);
1243 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1247 __glibcxx_requires_nonempty();
1248 return *(
end() - 1);
1258 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1261 {
return _M_data_ptr(this->_M_impl._M_start); }
1263 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1265 data() const _GLIBCXX_NOEXCEPT
1266 {
return _M_data_ptr(this->_M_impl._M_start); }
1279 _GLIBCXX20_CONSTEXPR
1283 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
1285 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
1286 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
1288 ++this->_M_impl._M_finish;
1289 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
1292 _M_realloc_insert(
end(), __x);
1295#if __cplusplus >= 201103L
1296 _GLIBCXX20_CONSTEXPR
1301 template<
typename... _Args>
1302#if __cplusplus > 201402L
1303 _GLIBCXX20_CONSTEXPR
1308 emplace_back(_Args&&... __args);
1320 _GLIBCXX20_CONSTEXPR
1324 __glibcxx_requires_nonempty();
1325 --this->_M_impl._M_finish;
1326 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
1327 _GLIBCXX_ASAN_ANNOTATE_SHRINK(1);
1330#if __cplusplus >= 201103L
1343 template<
typename... _Args>
1344 _GLIBCXX20_CONSTEXPR
1346 emplace(const_iterator __position, _Args&&... __args)
1347 {
return _M_emplace_aux(__position, std::forward<_Args>(__args)...); }
1360 _GLIBCXX20_CONSTEXPR
1362 insert(const_iterator __position,
const value_type& __x);
1379#if __cplusplus >= 201103L
1391 _GLIBCXX20_CONSTEXPR
1393 insert(const_iterator __position, value_type&& __x)
1394 {
return _M_insert_rval(__position,
std::move(__x)); }
1409 _GLIBCXX20_CONSTEXPR
1413 auto __offset = __position -
cbegin();
1414 _M_range_insert(
begin() + __offset, __l.begin(), __l.end(),
1416 return begin() + __offset;
1420#if __cplusplus >= 201103L
1435 _GLIBCXX20_CONSTEXPR
1437 insert(const_iterator __position, size_type __n,
const value_type& __x)
1439 difference_type __offset = __position -
cbegin();
1440 _M_fill_insert(
begin() + __offset, __n, __x);
1441 return begin() + __offset;
1458 insert(
iterator __position, size_type __n,
const value_type& __x)
1459 { _M_fill_insert(__position, __n, __x); }
1462#if __cplusplus >= 201103L
1478 template<
typename _InputIterator,
1479 typename = std::_RequireInputIter<_InputIterator>>
1480 _GLIBCXX20_CONSTEXPR
1482 insert(const_iterator __position, _InputIterator __first,
1483 _InputIterator __last)
1485 difference_type __offset = __position -
cbegin();
1486 _M_range_insert(
begin() + __offset, __first, __last,
1488 return begin() + __offset;
1505 template<
typename _InputIterator>
1508 _InputIterator __last)
1511 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1512 _M_insert_dispatch(__position, __first, __last, _Integral());
1531 _GLIBCXX20_CONSTEXPR
1533#if __cplusplus >= 201103L
1535 {
return _M_erase(
begin() + (__position -
cbegin())); }
1538 {
return _M_erase(__position); }
1559 _GLIBCXX20_CONSTEXPR
1561#if __cplusplus >= 201103L
1562 erase(const_iterator __first, const_iterator __last)
1564 const auto __beg =
begin();
1565 const auto __cbeg =
cbegin();
1566 return _M_erase(__beg + (__first - __cbeg), __beg + (__last - __cbeg));
1570 {
return _M_erase(__first, __last); }
1584 _GLIBCXX20_CONSTEXPR
1588#if __cplusplus >= 201103L
1589 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1590 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1592 this->_M_impl._M_swap_data(__x._M_impl);
1593 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1594 __x._M_get_Tp_allocator());
1603 _GLIBCXX20_CONSTEXPR
1606 { _M_erase_at_end(this->_M_impl._M_start); }
1613 template<
typename _ForwardIterator>
1614 _GLIBCXX20_CONSTEXPR
1617 _ForwardIterator __first, _ForwardIterator __last)
1619 pointer __result = this->_M_allocate(__n);
1622 std::__uninitialized_copy_a(__first, __last, __result,
1623 _M_get_Tp_allocator());
1628 _M_deallocate(__result, __n);
1629 __throw_exception_again;
1638#if __cplusplus < 201103L
1641 template<
typename _Integer>
1643 _M_initialize_dispatch(_Integer __n, _Integer __value, __true_type)
1645 this->_M_impl._M_start = _M_allocate(_S_check_init_len(
1646 static_cast<size_type
>(__n), _M_get_Tp_allocator()));
1647 this->_M_impl._M_end_of_storage =
1648 this->_M_impl._M_start +
static_cast<size_type
>(__n);
1649 _M_fill_initialize(
static_cast<size_type
>(__n), __value);
1653 template<
typename _InputIterator>
1655 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1658 _M_range_initialize(__first, __last,
1664 template<
typename _InputIterator>
1665 _GLIBCXX20_CONSTEXPR
1667 _M_range_initialize(_InputIterator __first, _InputIterator __last,
1671 for (; __first != __last; ++__first)
1672#
if __cplusplus >= 201103L
1673 emplace_back(*__first);
1679 __throw_exception_again;
1684 template<
typename _ForwardIterator>
1685 _GLIBCXX20_CONSTEXPR
1687 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
1691 this->_M_impl._M_start
1692 = this->_M_allocate(_S_check_init_len(__n, _M_get_Tp_allocator()));
1693 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
1694 this->_M_impl._M_finish =
1695 std::__uninitialized_copy_a(__first, __last,
1696 this->_M_impl._M_start,
1697 _M_get_Tp_allocator());
1702 _GLIBCXX20_CONSTEXPR
1704 _M_fill_initialize(size_type __n,
const value_type& __value)
1706 this->_M_impl._M_finish =
1707 std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value,
1708 _M_get_Tp_allocator());
1711#if __cplusplus >= 201103L
1713 _GLIBCXX20_CONSTEXPR
1715 _M_default_initialize(size_type __n)
1717 this->_M_impl._M_finish =
1718 std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
1719 _M_get_Tp_allocator());
1730 template<
typename _Integer>
1731 _GLIBCXX20_CONSTEXPR
1733 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1734 { _M_fill_assign(__n, __val); }
1737 template<
typename _InputIterator>
1738 _GLIBCXX20_CONSTEXPR
1740 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1745 template<
typename _InputIterator>
1746 _GLIBCXX20_CONSTEXPR
1748 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1752 template<
typename _ForwardIterator>
1753 _GLIBCXX20_CONSTEXPR
1755 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1760 _GLIBCXX20_CONSTEXPR
1762 _M_fill_assign(size_type __n,
const value_type& __val);
1770 template<
typename _Integer>
1771 _GLIBCXX20_CONSTEXPR
1773 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
1775 { _M_fill_insert(__pos, __n, __val); }
1778 template<
typename _InputIterator>
1779 _GLIBCXX20_CONSTEXPR
1781 _M_insert_dispatch(iterator __pos, _InputIterator __first,
1782 _InputIterator __last, __false_type)
1784 _M_range_insert(__pos, __first, __last,
1789 template<
typename _InputIterator>
1790 _GLIBCXX20_CONSTEXPR
1792 _M_range_insert(iterator __pos, _InputIterator __first,
1796 template<
typename _ForwardIterator>
1797 _GLIBCXX20_CONSTEXPR
1799 _M_range_insert(iterator __pos, _ForwardIterator __first,
1804 _GLIBCXX20_CONSTEXPR
1806 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
1808#if __cplusplus >= 201103L
1810 _GLIBCXX20_CONSTEXPR
1812 _M_default_append(size_type __n);
1814 _GLIBCXX20_CONSTEXPR
1819#if __cplusplus < 201103L
1822 _M_insert_aux(iterator __position,
const value_type& __x);
1825 _M_realloc_insert(iterator __position,
const value_type& __x);
1829 struct _Temporary_value
1831 template<
typename... _Args>
1832 _GLIBCXX20_CONSTEXPR
explicit
1833 _Temporary_value(
vector* __vec, _Args&&... __args) : _M_this(__vec)
1835 _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(),
1836 std::forward<_Args>(__args)...);
1839 _GLIBCXX20_CONSTEXPR
1841 { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); }
1843 _GLIBCXX20_CONSTEXPR value_type&
1844 _M_val() noexcept {
return _M_storage._M_val; }
1847 _GLIBCXX20_CONSTEXPR _Tp*
1852 constexpr _Storage() : _M_byte() { }
1853 _GLIBCXX20_CONSTEXPR ~_Storage() { }
1854 _Storage& operator=(
const _Storage&) =
delete;
1855 unsigned char _M_byte;
1860 _Storage _M_storage;
1865 template<
typename _Arg>
1866 _GLIBCXX20_CONSTEXPR
1868 _M_insert_aux(iterator __position, _Arg&& __arg);
1870 template<
typename... _Args>
1871 _GLIBCXX20_CONSTEXPR
1873 _M_realloc_insert(iterator __position, _Args&&... __args);
1876 _GLIBCXX20_CONSTEXPR
1878 _M_insert_rval(const_iterator __position, value_type&& __v);
1881 template<
typename... _Args>
1882 _GLIBCXX20_CONSTEXPR
1884 _M_emplace_aux(const_iterator __position, _Args&&... __args);
1887 _GLIBCXX20_CONSTEXPR
1889 _M_emplace_aux(const_iterator __position, value_type&& __v)
1890 {
return _M_insert_rval(__position,
std::move(__v)); }
1894 _GLIBCXX20_CONSTEXPR
1896 _M_check_len(size_type __n,
const char* __s)
const
1899 __throw_length_error(__N(__s));
1906 static _GLIBCXX20_CONSTEXPR size_type
1907 _S_check_init_len(size_type __n,
const allocator_type& __a)
1909 if (__n > _S_max_size(_Tp_alloc_type(__a)))
1910 __throw_length_error(
1911 __N(
"cannot create std::vector larger than max_size()"));
1915 static _GLIBCXX20_CONSTEXPR size_type
1916 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1921 const size_t __diffmax
1922 = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max /
sizeof(_Tp);
1924 return (
std::min)(__diffmax, __allocmax);
1931 _GLIBCXX20_CONSTEXPR
1933 _M_erase_at_end(pointer __pos) _GLIBCXX_NOEXCEPT
1935 if (size_type __n = this->_M_impl._M_finish - __pos)
1938 _M_get_Tp_allocator());
1939 this->_M_impl._M_finish = __pos;
1940 _GLIBCXX_ASAN_ANNOTATE_SHRINK(__n);
1944 _GLIBCXX20_CONSTEXPR
1946 _M_erase(iterator __position);
1948 _GLIBCXX20_CONSTEXPR
1950 _M_erase(iterator __first, iterator __last);
1952#if __cplusplus >= 201103L
1957 _GLIBCXX20_CONSTEXPR
1962 this->_M_impl._M_swap_data(__x._M_impl);
1963 __tmp._M_impl._M_swap_data(__x._M_impl);
1964 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
1969 _GLIBCXX20_CONSTEXPR
1973 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
1979 this->_M_assign_aux(std::make_move_iterator(__x.begin()),
1980 std::make_move_iterator(__x.end()),
1987 template<
typename _Up>
1988 _GLIBCXX20_CONSTEXPR
1990 _M_data_ptr(_Up* __ptr)
const _GLIBCXX_NOEXCEPT
1993#if __cplusplus >= 201103L
1994 template<
typename _Ptr>
1995 _GLIBCXX20_CONSTEXPR
1996 typename std::pointer_traits<_Ptr>::element_type*
1997 _M_data_ptr(_Ptr __ptr)
const
1998 {
return empty() ? nullptr : std::__to_address(__ptr); }
2000 template<
typename _Up>
2002 _M_data_ptr(_Up* __ptr) _GLIBCXX_NOEXCEPT
2005 template<
typename _Ptr>
2007 _M_data_ptr(_Ptr __ptr)
2008 {
return empty() ? (value_type*)0 : __ptr.operator->(); }
2010 template<
typename _Ptr>
2012 _M_data_ptr(_Ptr __ptr)
const
2013 {
return empty() ? (
const value_type*)0 : __ptr.operator->(); }
2017#if __cpp_deduction_guides >= 201606
2018 template<
typename _InputIterator,
typename _ValT
2019 =
typename iterator_traits<_InputIterator>::value_type,
2020 typename _Allocator = allocator<_ValT>,
2021 typename = _RequireInputIter<_InputIterator>,
2022 typename = _RequireAllocator<_Allocator>>
2023 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
2024 -> vector<_ValT, _Allocator>;
2037 template<
typename _Tp,
typename _Alloc>
2038 _GLIBCXX20_CONSTEXPR
2044#if __cpp_lib_three_way_comparison
2056 template<
typename _Tp,
typename _Alloc>
2057 _GLIBCXX20_CONSTEXPR
2058 inline __detail::__synth3way_t<_Tp>
2059 operator<=>(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2061 return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
2062 __y.begin(), __y.end(),
2063 __detail::__synth3way);
2077 template<
typename _Tp,
typename _Alloc>
2080 {
return std::lexicographical_compare(__x.
begin(), __x.
end(),
2084 template<
typename _Tp,
typename _Alloc>
2087 {
return !(__x == __y); }
2090 template<
typename _Tp,
typename _Alloc>
2093 {
return __y < __x; }
2096 template<
typename _Tp,
typename _Alloc>
2099 {
return !(__y < __x); }
2102 template<
typename _Tp,
typename _Alloc>
2105 {
return !(__x < __y); }
2109 template<
typename _Tp,
typename _Alloc>
2110 _GLIBCXX20_CONSTEXPR
2113 _GLIBCXX_NOEXCEPT_IF(
noexcept(__x.swap(__y)))
2116_GLIBCXX_END_NAMESPACE_CONTAINER
2118#if __cplusplus >= 201703L
2119 namespace __detail::__variant
2121 template<
typename>
struct _Never_valueless_alt;
2125 template<
typename _Tp,
typename _Alloc>
2126 struct _Never_valueless_alt<_GLIBCXX_STD_C::vector<_Tp, _Alloc>>
2132_GLIBCXX_END_NAMESPACE_VERSION