57 #define _STL_VECTOR_H 1
62 #if __cplusplus >= 201103L
65 #if __cplusplus > 201703L
71 #if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR
73 __sanitizer_annotate_contiguous_container(
const void*,
const void*,
74 const void*,
const void*);
77 namespace std _GLIBCXX_VISIBILITY(default)
79 _GLIBCXX_BEGIN_NAMESPACE_VERSION
80 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
83 template<
typename _Tp,
typename _Alloc>
87 rebind<_Tp>::other _Tp_alloc_type;
88 typedef typename __gnu_cxx::__alloc_traits<_Tp_alloc_type>::pointer
91 struct _Vector_impl_data
95 pointer _M_end_of_storage;
98 _Vector_impl_data() _GLIBCXX_NOEXCEPT
99 : _M_start(), _M_finish(), _M_end_of_storage()
102 #if __cplusplus >= 201103L
104 _Vector_impl_data(_Vector_impl_data&& __x) noexcept
105 : _M_start(__x._M_start), _M_finish(__x._M_finish),
106 _M_end_of_storage(__x._M_end_of_storage)
107 { __x._M_start = __x._M_finish = __x._M_end_of_storage = pointer(); }
112 _M_copy_data(_Vector_impl_data
const& __x) _GLIBCXX_NOEXCEPT
114 _M_start = __x._M_start;
115 _M_finish = __x._M_finish;
116 _M_end_of_storage = __x._M_end_of_storage;
121 _M_swap_data(_Vector_impl_data& __x) _GLIBCXX_NOEXCEPT
125 _Vector_impl_data __tmp;
126 __tmp._M_copy_data(*
this);
128 __x._M_copy_data(__tmp);
133 :
public _Tp_alloc_type,
public _Vector_impl_data
136 _Vector_impl() _GLIBCXX_NOEXCEPT_IF(
142 _Vector_impl(_Tp_alloc_type
const& __a) _GLIBCXX_NOEXCEPT
143 : _Tp_alloc_type(__a)
146 #if __cplusplus >= 201103L
150 _Vector_impl(_Vector_impl&& __x) noexcept
155 _Vector_impl(_Tp_alloc_type&& __a) noexcept
160 _Vector_impl(_Tp_alloc_type&& __a, _Vector_impl&& __rv) noexcept
165 #if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR
166 template<
typename = _Tp_alloc_type>
170 ::size_type size_type;
172 static _GLIBCXX20_CONSTEXPR
void
173 _S_shrink(_Vector_impl&, size_type) { }
174 static _GLIBCXX20_CONSTEXPR
void
175 _S_on_dealloc(_Vector_impl&) { }
177 typedef _Vector_impl& _Reinit;
181 _GLIBCXX20_CONSTEXPR _Grow(_Vector_impl&, size_type) { }
182 _GLIBCXX20_CONSTEXPR
void _M_grew(size_type) { }
187 template<
typename _Up>
191 ::size_type size_type;
195 static _GLIBCXX20_CONSTEXPR
void
196 _S_adjust(_Vector_impl& __impl, pointer __prev, pointer __curr)
198 #if __cpp_lib_is_constant_evaluated
202 __sanitizer_annotate_contiguous_container(__impl._M_start,
203 __impl._M_end_of_storage, __prev, __curr);
206 static _GLIBCXX20_CONSTEXPR
void
207 _S_grow(_Vector_impl& __impl, size_type __n)
208 { _S_adjust(__impl, __impl._M_finish, __impl._M_finish + __n); }
210 static _GLIBCXX20_CONSTEXPR
void
211 _S_shrink(_Vector_impl& __impl, size_type __n)
212 { _S_adjust(__impl, __impl._M_finish + __n, __impl._M_finish); }
214 static _GLIBCXX20_CONSTEXPR
void
215 _S_on_dealloc(_Vector_impl& __impl)
218 _S_adjust(__impl, __impl._M_finish, __impl._M_end_of_storage);
224 explicit _GLIBCXX20_CONSTEXPR
225 _Reinit(_Vector_impl& __impl) : _M_impl(__impl)
228 _S_on_dealloc(_M_impl);
235 if (_M_impl._M_start)
236 _S_adjust(_M_impl, _M_impl._M_end_of_storage,
240 _Vector_impl& _M_impl;
242 #if __cplusplus >= 201103L
243 _Reinit(
const _Reinit&) =
delete;
244 _Reinit& operator=(
const _Reinit&) =
delete;
252 _Grow(_Vector_impl& __impl, size_type __n)
253 : _M_impl(__impl), _M_n(__n)
254 { _S_grow(_M_impl, __n); }
257 ~_Grow() {
if (_M_n) _S_shrink(_M_impl, _M_n); }
260 void _M_grew(size_type __n) { _M_n -= __n; }
262 #if __cplusplus >= 201103L
263 _Grow(
const _Grow&) =
delete;
264 _Grow& operator=(
const _Grow&) =
delete;
267 _Vector_impl& _M_impl;
272 #define _GLIBCXX_ASAN_ANNOTATE_REINIT \
273 typename _Base::_Vector_impl::template _Asan<>::_Reinit const \
274 __attribute__((__unused__)) __reinit_guard(this->_M_impl)
275 #define _GLIBCXX_ASAN_ANNOTATE_GROW(n) \
276 typename _Base::_Vector_impl::template _Asan<>::_Grow \
277 __attribute__((__unused__)) __grow_guard(this->_M_impl, (n))
278 #define _GLIBCXX_ASAN_ANNOTATE_GREW(n) __grow_guard._M_grew(n)
279 #define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n) \
280 _Base::_Vector_impl::template _Asan<>::_S_shrink(this->_M_impl, n)
281 #define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC \
282 _Base::_Vector_impl::template _Asan<>::_S_on_dealloc(this->_M_impl)
284 #define _GLIBCXX_ASAN_ANNOTATE_REINIT
285 #define _GLIBCXX_ASAN_ANNOTATE_GROW(n)
286 #define _GLIBCXX_ASAN_ANNOTATE_GREW(n)
287 #define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n)
288 #define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC
293 typedef _Alloc allocator_type;
297 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
298 {
return this->_M_impl; }
301 const _Tp_alloc_type&
302 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
303 {
return this->_M_impl; }
307 get_allocator() const _GLIBCXX_NOEXCEPT
308 {
return allocator_type(_M_get_Tp_allocator()); }
310 #if __cplusplus >= 201103L
317 _Vector_base(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
321 #if !_GLIBCXX_INLINE_VERSION
323 _Vector_base(
size_t __n)
325 { _M_create_storage(__n); }
329 _Vector_base(
size_t __n,
const allocator_type& __a)
331 { _M_create_storage(__n); }
333 #if __cplusplus >= 201103L
334 _Vector_base(_Vector_base&&) =
default;
337 # if !_GLIBCXX_INLINE_VERSION
339 _Vector_base(_Tp_alloc_type&& __a) noexcept
343 _Vector_base(_Vector_base&& __x,
const allocator_type& __a)
346 if (__x.get_allocator() == __a)
347 this->_M_impl._M_swap_data(__x._M_impl);
350 size_t __n = __x._M_impl._M_finish - __x._M_impl._M_start;
351 _M_create_storage(__n);
357 _Vector_base(
const allocator_type& __a, _Vector_base&& __x)
358 : _M_impl(_Tp_alloc_type(__a),
std::
move(__x._M_impl))
363 ~_Vector_base() _GLIBCXX_NOEXCEPT
365 _M_deallocate(_M_impl._M_start,
366 _M_impl._M_end_of_storage - _M_impl._M_start);
370 _Vector_impl _M_impl;
374 _M_allocate(
size_t __n)
377 return __n != 0 ? _Tr::allocate(_M_impl, __n) : pointer();
382 _M_deallocate(pointer __p,
size_t __n)
386 _Tr::deallocate(_M_impl, __p, __n);
392 _M_create_storage(
size_t __n)
394 this->_M_impl._M_start = this->_M_allocate(__n);
395 this->_M_impl._M_finish = this->_M_impl._M_start;
396 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
421 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
424 #ifdef _GLIBCXX_CONCEPT_CHECKS
426 typedef typename _Alloc::value_type _Alloc_value_type;
427 # if __cplusplus < 201103L
428 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
430 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
433 #if __cplusplus >= 201103L
434 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
435 "std::vector must have a non-const, non-volatile value_type");
436 # if __cplusplus > 201703L || defined __STRICT_ANSI__
438 "std::vector must have the same value_type as its allocator");
443 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
447 typedef _Tp value_type;
448 typedef typename _Base::pointer pointer;
449 typedef typename _Alloc_traits::const_pointer const_pointer;
450 typedef typename _Alloc_traits::reference reference;
451 typedef typename _Alloc_traits::const_reference const_reference;
452 typedef __gnu_cxx::__normal_iterator<pointer, vector> iterator;
453 typedef __gnu_cxx::__normal_iterator<const_pointer, vector>
457 typedef size_t size_type;
458 typedef ptrdiff_t difference_type;
459 typedef _Alloc allocator_type;
462 #if __cplusplus >= 201103L
463 static constexpr
bool
466 return noexcept(std::__relocate_a(std::declval<pointer>(),
467 std::declval<pointer>(),
468 std::declval<pointer>(),
469 std::declval<_Tp_alloc_type&>()));
472 static constexpr
bool
476 static constexpr
bool
482 return _S_nothrow_relocate(__is_move_insertable<_Tp_alloc_type>{});
486 _S_do_relocate(pointer __first, pointer __last, pointer __result,
487 _Tp_alloc_type& __alloc,
true_type) noexcept
489 return std::__relocate_a(__first, __last, __result, __alloc);
493 _S_do_relocate(pointer, pointer, pointer __result,
497 static _GLIBCXX20_CONSTEXPR pointer
498 _S_relocate(pointer __first, pointer __last, pointer __result,
499 _Tp_alloc_type& __alloc) noexcept
501 #if __cpp_if_constexpr
503 return std::__relocate_a(__first, __last, __result, __alloc);
505 using __do_it = __bool_constant<_S_use_relocate()>;
506 return _S_do_relocate(__first, __last, __result, __alloc, __do_it{});
512 using _Base::_M_allocate;
513 using _Base::_M_deallocate;
514 using _Base::_M_impl;
515 using _Base::_M_get_Tp_allocator;
524 #if __cplusplus >= 201103L
536 vector(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
539 #if __cplusplus >= 201103L
550 vector(size_type __n,
const allocator_type& __a = allocator_type())
551 :
_Base(_S_check_init_len(__n, __a), __a)
552 { _M_default_initialize(__n); }
563 vector(size_type __n,
const value_type& __value,
564 const allocator_type& __a = allocator_type())
565 :
_Base(_S_check_init_len(__n, __a), __a)
566 { _M_fill_initialize(__n, __value); }
577 vector(size_type __n,
const value_type& __value = value_type(),
578 const allocator_type& __a = allocator_type())
579 : _Base(_S_check_init_len(__n, __a), __a)
580 { _M_fill_initialize(__n, __value); }
599 this->_M_impl._M_finish =
600 std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
601 this->_M_impl._M_start,
602 _M_get_Tp_allocator());
605 #if __cplusplus >= 201103L
618 vector(const
vector& __x, const __type_identity_t<allocator_type>& __a)
621 this->_M_impl._M_finish =
622 std::__uninitialized_copy_a(__x.begin(), __x.end(),
623 this->_M_impl._M_start,
624 _M_get_Tp_allocator());
637 if (__rv.get_allocator() == __m)
638 this->_M_impl._M_swap_data(__rv._M_impl);
639 else if (!__rv.empty())
641 this->_M_create_storage(__rv.size());
642 this->_M_impl._M_finish =
643 std::__uninitialized_move_a(__rv.begin(), __rv.end(),
644 this->_M_impl._M_start,
645 _M_get_Tp_allocator());
655 vector(std::declval<vector&&>(), std::declval<const allocator_type&>(),
656 std::declval<typename _Alloc_traits::is_always_equal>())) )
673 const allocator_type& __a = allocator_type())
676 _M_range_initialize(__l.begin(), __l.end(),
697 #if __cplusplus >= 201103L
698 template<
typename _InputIterator,
699 typename = std::_RequireInputIter<_InputIterator>>
701 vector(_InputIterator __first, _InputIterator __last,
702 const allocator_type& __a = allocator_type())
705 _M_range_initialize(__first, __last,
709 template<
typename _InputIterator>
710 vector(_InputIterator __first, _InputIterator __last,
711 const allocator_type& __a = allocator_type())
715 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
716 _M_initialize_dispatch(__first, __last, _Integral());
729 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
730 _M_get_Tp_allocator());
731 _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC;
747 #if __cplusplus >= 201103L
762 constexpr
bool __move_storage =
763 _Alloc_traits::_S_propagate_on_move_assign()
764 || _Alloc_traits::_S_always_equal();
765 _M_move_assign(
std::move(__x), __bool_constant<__move_storage>());
784 this->_M_assign_aux(__l.begin(), __l.end(),
802 assign(size_type __n,
const value_type& __val)
803 { _M_fill_assign(__n, __val); }
817 #if __cplusplus >= 201103L
818 template<
typename _InputIterator,
819 typename = std::_RequireInputIter<_InputIterator>>
822 assign(_InputIterator __first, _InputIterator __last)
823 { _M_assign_dispatch(__first, __last, __false_type()); }
825 template<
typename _InputIterator>
827 assign(_InputIterator __first, _InputIterator __last)
830 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
831 _M_assign_dispatch(__first, __last, _Integral());
835 #if __cplusplus >= 201103L
851 this->_M_assign_aux(__l.begin(), __l.end(),
857 using _Base::get_allocator;
865 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
868 {
return iterator(this->_M_impl._M_start); }
875 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
878 {
return const_iterator(this->_M_impl._M_start); }
885 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
888 {
return iterator(this->_M_impl._M_finish); }
895 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
897 end() const _GLIBCXX_NOEXCEPT
898 {
return const_iterator(this->_M_impl._M_finish); }
905 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
915 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
916 const_reverse_iterator
925 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
935 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
936 const_reverse_iterator
940 #if __cplusplus >= 201103L
946 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
949 {
return const_iterator(this->_M_impl._M_start); }
956 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
959 {
return const_iterator(this->_M_impl._M_finish); }
966 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
967 const_reverse_iterator
976 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
977 const_reverse_iterator
984 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
987 {
return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
990 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
993 {
return _S_max_size(_M_get_Tp_allocator()); }
995 #if __cplusplus >= 201103L
1005 _GLIBCXX20_CONSTEXPR
1009 if (__new_size >
size())
1010 _M_default_append(__new_size -
size());
1011 else if (__new_size <
size())
1012 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1026 _GLIBCXX20_CONSTEXPR
1028 resize(size_type __new_size,
const value_type& __x)
1030 if (__new_size >
size())
1031 _M_fill_insert(
end(), __new_size -
size(), __x);
1032 else if (__new_size <
size())
1033 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1047 _GLIBCXX20_CONSTEXPR
1049 resize(size_type __new_size, value_type __x = value_type())
1051 if (__new_size >
size())
1052 _M_fill_insert(
end(), __new_size -
size(), __x);
1053 else if (__new_size <
size())
1054 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1058 #if __cplusplus >= 201103L
1060 _GLIBCXX20_CONSTEXPR
1063 { _M_shrink_to_fit(); }
1070 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1073 {
return size_type(this->_M_impl._M_end_of_storage
1074 - this->_M_impl._M_start); }
1080 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1102 _GLIBCXX20_CONSTEXPR
1118 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1122 __glibcxx_requires_subscript(__n);
1123 return *(this->_M_impl._M_start + __n);
1137 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1141 __glibcxx_requires_subscript(__n);
1142 return *(this->_M_impl._M_start + __n);
1147 _GLIBCXX20_CONSTEXPR
1151 if (__n >= this->
size())
1152 __throw_out_of_range_fmt(__N(
"vector::_M_range_check: __n "
1153 "(which is %zu) >= this->size() "
1170 _GLIBCXX20_CONSTEXPR
1175 return (*
this)[__n];
1189 _GLIBCXX20_CONSTEXPR
1194 return (*
this)[__n];
1201 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1205 __glibcxx_requires_nonempty();
1213 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1217 __glibcxx_requires_nonempty();
1225 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1229 __glibcxx_requires_nonempty();
1230 return *(
end() - 1);
1237 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1241 __glibcxx_requires_nonempty();
1242 return *(
end() - 1);
1252 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1255 {
return _M_data_ptr(this->_M_impl._M_start); }
1257 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1259 data() const _GLIBCXX_NOEXCEPT
1260 {
return _M_data_ptr(this->_M_impl._M_start); }
1273 _GLIBCXX20_CONSTEXPR
1277 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
1279 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
1280 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
1282 ++this->_M_impl._M_finish;
1283 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
1286 _M_realloc_insert(
end(), __x);
1289 #if __cplusplus >= 201103L
1290 _GLIBCXX20_CONSTEXPR
1295 template<
typename... _Args>
1296 #if __cplusplus > 201402L
1297 _GLIBCXX20_CONSTEXPR
1302 emplace_back(_Args&&... __args);
1314 _GLIBCXX20_CONSTEXPR
1318 __glibcxx_requires_nonempty();
1319 --this->_M_impl._M_finish;
1320 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
1321 _GLIBCXX_ASAN_ANNOTATE_SHRINK(1);
1324 #if __cplusplus >= 201103L
1337 template<
typename... _Args>
1338 _GLIBCXX20_CONSTEXPR
1340 emplace(const_iterator __position, _Args&&... __args)
1341 {
return _M_emplace_aux(__position, std::forward<_Args>(__args)...); }
1354 _GLIBCXX20_CONSTEXPR
1356 insert(const_iterator __position,
const value_type& __x);
1373 #if __cplusplus >= 201103L
1385 _GLIBCXX20_CONSTEXPR
1387 insert(const_iterator __position, value_type&& __x)
1388 {
return _M_insert_rval(__position,
std::move(__x)); }
1403 _GLIBCXX20_CONSTEXPR
1407 auto __offset = __position -
cbegin();
1408 _M_range_insert(
begin() + __offset, __l.begin(), __l.end(),
1410 return begin() + __offset;
1414 #if __cplusplus >= 201103L
1429 _GLIBCXX20_CONSTEXPR
1431 insert(const_iterator __position, size_type __n,
const value_type& __x)
1433 difference_type __offset = __position -
cbegin();
1434 _M_fill_insert(
begin() + __offset, __n, __x);
1435 return begin() + __offset;
1452 insert(
iterator __position, size_type __n,
const value_type& __x)
1453 { _M_fill_insert(__position, __n, __x); }
1456 #if __cplusplus >= 201103L
1472 template<
typename _InputIterator,
1473 typename = std::_RequireInputIter<_InputIterator>>
1474 _GLIBCXX20_CONSTEXPR
1476 insert(const_iterator __position, _InputIterator __first,
1477 _InputIterator __last)
1479 difference_type __offset = __position -
cbegin();
1480 _M_insert_dispatch(
begin() + __offset,
1481 __first, __last, __false_type());
1482 return begin() + __offset;
1499 template<
typename _InputIterator>
1502 _InputIterator __last)
1505 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1506 _M_insert_dispatch(__position, __first, __last, _Integral());
1525 _GLIBCXX20_CONSTEXPR
1527 #if __cplusplus >= 201103L
1529 {
return _M_erase(
begin() + (__position -
cbegin())); }
1532 {
return _M_erase(__position); }
1553 _GLIBCXX20_CONSTEXPR
1555 #if __cplusplus >= 201103L
1556 erase(const_iterator __first, const_iterator __last)
1558 const auto __beg =
begin();
1559 const auto __cbeg =
cbegin();
1560 return _M_erase(__beg + (__first - __cbeg), __beg + (__last - __cbeg));
1564 {
return _M_erase(__first, __last); }
1578 _GLIBCXX20_CONSTEXPR
1582 #if __cplusplus >= 201103L
1583 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1584 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1586 this->_M_impl._M_swap_data(__x._M_impl);
1587 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1588 __x._M_get_Tp_allocator());
1597 _GLIBCXX20_CONSTEXPR
1600 { _M_erase_at_end(this->_M_impl._M_start); }
1607 template<
typename _ForwardIterator>
1608 _GLIBCXX20_CONSTEXPR
1611 _ForwardIterator __first, _ForwardIterator __last)
1613 pointer __result = this->_M_allocate(__n);
1616 std::__uninitialized_copy_a(__first, __last, __result,
1617 _M_get_Tp_allocator());
1622 _M_deallocate(__result, __n);
1623 __throw_exception_again;
1632 #if __cplusplus < 201103L
1635 template<
typename _Integer>
1637 _M_initialize_dispatch(_Integer __n, _Integer __value, __true_type)
1639 this->_M_impl._M_start = _M_allocate(_S_check_init_len(
1640 static_cast<size_type
>(__n), _M_get_Tp_allocator()));
1641 this->_M_impl._M_end_of_storage =
1642 this->_M_impl._M_start +
static_cast<size_type
>(__n);
1643 _M_fill_initialize(
static_cast<size_type
>(__n), __value);
1647 template<
typename _InputIterator>
1649 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1652 _M_range_initialize(__first, __last,
1658 template<
typename _InputIterator>
1659 _GLIBCXX20_CONSTEXPR
1661 _M_range_initialize(_InputIterator __first, _InputIterator __last,
1665 for (; __first != __last; ++__first)
1666 #
if __cplusplus >= 201103L
1667 emplace_back(*__first);
1673 __throw_exception_again;
1678 template<
typename _ForwardIterator>
1679 _GLIBCXX20_CONSTEXPR
1681 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
1685 this->_M_impl._M_start
1686 = this->_M_allocate(_S_check_init_len(__n, _M_get_Tp_allocator()));
1687 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
1688 this->_M_impl._M_finish =
1689 std::__uninitialized_copy_a(__first, __last,
1690 this->_M_impl._M_start,
1691 _M_get_Tp_allocator());
1696 _GLIBCXX20_CONSTEXPR
1698 _M_fill_initialize(size_type __n,
const value_type& __value)
1700 this->_M_impl._M_finish =
1701 std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value,
1702 _M_get_Tp_allocator());
1705 #if __cplusplus >= 201103L
1707 _GLIBCXX20_CONSTEXPR
1709 _M_default_initialize(size_type __n)
1711 this->_M_impl._M_finish =
1712 std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
1713 _M_get_Tp_allocator());
1724 template<
typename _Integer>
1725 _GLIBCXX20_CONSTEXPR
1727 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1728 { _M_fill_assign(__n, __val); }
1731 template<
typename _InputIterator>
1732 _GLIBCXX20_CONSTEXPR
1734 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1739 template<
typename _InputIterator>
1740 _GLIBCXX20_CONSTEXPR
1742 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1746 template<
typename _ForwardIterator>
1747 _GLIBCXX20_CONSTEXPR
1749 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1754 _GLIBCXX20_CONSTEXPR
1756 _M_fill_assign(size_type __n,
const value_type& __val);
1764 template<
typename _Integer>
1765 _GLIBCXX20_CONSTEXPR
1767 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
1769 { _M_fill_insert(__pos, __n, __val); }
1772 template<
typename _InputIterator>
1773 _GLIBCXX20_CONSTEXPR
1775 _M_insert_dispatch(iterator __pos, _InputIterator __first,
1776 _InputIterator __last, __false_type)
1778 _M_range_insert(__pos, __first, __last,
1783 template<
typename _InputIterator>
1784 _GLIBCXX20_CONSTEXPR
1786 _M_range_insert(iterator __pos, _InputIterator __first,
1790 template<
typename _ForwardIterator>
1791 _GLIBCXX20_CONSTEXPR
1793 _M_range_insert(iterator __pos, _ForwardIterator __first,
1798 _GLIBCXX20_CONSTEXPR
1800 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
1802 #if __cplusplus >= 201103L
1804 _GLIBCXX20_CONSTEXPR
1806 _M_default_append(size_type __n);
1808 _GLIBCXX20_CONSTEXPR
1813 #if __cplusplus < 201103L
1816 _M_insert_aux(iterator __position,
const value_type& __x);
1819 _M_realloc_insert(iterator __position,
const value_type& __x);
1823 struct _Temporary_value
1825 template<
typename... _Args>
1826 _GLIBCXX20_CONSTEXPR
explicit
1827 _Temporary_value(
vector* __vec, _Args&&... __args) : _M_this(__vec)
1829 _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(),
1830 std::forward<_Args>(__args)...);
1833 _GLIBCXX20_CONSTEXPR
1835 { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); }
1837 _GLIBCXX20_CONSTEXPR value_type&
1838 _M_val() noexcept {
return _M_storage._M_val; }
1841 _GLIBCXX20_CONSTEXPR _Tp*
1846 constexpr _Storage() : _M_byte() { }
1847 _GLIBCXX20_CONSTEXPR ~_Storage() { }
1848 _Storage&
operator=(
const _Storage&) =
delete;
1849 unsigned char _M_byte;
1854 _Storage _M_storage;
1859 template<
typename _Arg>
1860 _GLIBCXX20_CONSTEXPR
1862 _M_insert_aux(iterator __position, _Arg&& __arg);
1864 template<
typename... _Args>
1865 _GLIBCXX20_CONSTEXPR
1867 _M_realloc_insert(iterator __position, _Args&&... __args);
1870 _GLIBCXX20_CONSTEXPR
1872 _M_insert_rval(const_iterator __position, value_type&& __v);
1875 template<
typename... _Args>
1876 _GLIBCXX20_CONSTEXPR
1878 _M_emplace_aux(const_iterator __position, _Args&&... __args);
1881 _GLIBCXX20_CONSTEXPR
1883 _M_emplace_aux(const_iterator __position, value_type&& __v)
1884 {
return _M_insert_rval(__position,
std::move(__v)); }
1888 _GLIBCXX20_CONSTEXPR
1890 _M_check_len(size_type __n,
const char* __s)
const
1893 __throw_length_error(__N(__s));
1900 static _GLIBCXX20_CONSTEXPR size_type
1901 _S_check_init_len(size_type __n,
const allocator_type& __a)
1903 if (__n > _S_max_size(_Tp_alloc_type(__a)))
1904 __throw_length_error(
1905 __N(
"cannot create std::vector larger than max_size()"));
1909 static _GLIBCXX20_CONSTEXPR size_type
1910 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1915 const size_t __diffmax
1916 = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max /
sizeof(_Tp);
1918 return (
std::min)(__diffmax, __allocmax);
1925 _GLIBCXX20_CONSTEXPR
1927 _M_erase_at_end(pointer __pos) _GLIBCXX_NOEXCEPT
1929 if (size_type __n = this->_M_impl._M_finish - __pos)
1932 _M_get_Tp_allocator());
1933 this->_M_impl._M_finish = __pos;
1934 _GLIBCXX_ASAN_ANNOTATE_SHRINK(__n);
1938 _GLIBCXX20_CONSTEXPR
1940 _M_erase(iterator __position);
1942 _GLIBCXX20_CONSTEXPR
1944 _M_erase(iterator __first, iterator __last);
1946 #if __cplusplus >= 201103L
1951 _GLIBCXX20_CONSTEXPR
1956 this->_M_impl._M_swap_data(__x._M_impl);
1957 __tmp._M_impl._M_swap_data(__x._M_impl);
1958 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
1963 _GLIBCXX20_CONSTEXPR
1967 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
1973 this->_M_assign_aux(std::make_move_iterator(__x.begin()),
1974 std::make_move_iterator(__x.end()),
1981 template<
typename _Up>
1982 _GLIBCXX20_CONSTEXPR
1984 _M_data_ptr(_Up* __ptr)
const _GLIBCXX_NOEXCEPT
1987 #if __cplusplus >= 201103L
1988 template<
typename _Ptr>
1989 _GLIBCXX20_CONSTEXPR
1991 _M_data_ptr(_Ptr __ptr)
const
1992 {
return empty() ? nullptr : std::__to_address(__ptr); }
1994 template<
typename _Up>
1996 _M_data_ptr(_Up* __ptr) _GLIBCXX_NOEXCEPT
1999 template<
typename _Ptr>
2001 _M_data_ptr(_Ptr __ptr)
2002 {
return empty() ? (value_type*)0 : __ptr.operator->(); }
2004 template<
typename _Ptr>
2006 _M_data_ptr(_Ptr __ptr)
const
2007 {
return empty() ? (
const value_type*)0 : __ptr.operator->(); }
2011 #if __cpp_deduction_guides >= 201606
2012 template<
typename _InputIterator,
typename _ValT
2013 =
typename iterator_traits<_InputIterator>::value_type,
2014 typename _Allocator = allocator<_ValT>,
2015 typename = _RequireInputIter<_InputIterator>,
2016 typename = _RequireAllocator<_Allocator>>
2017 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
2018 -> vector<_ValT, _Allocator>;
2031 template<
typename _Tp,
typename _Alloc>
2032 _GLIBCXX20_CONSTEXPR
2038 #if __cpp_lib_three_way_comparison
2050 template<
typename _Tp,
typename _Alloc>
2051 _GLIBCXX20_CONSTEXPR
2052 inline __detail::__synth3way_t<_Tp>
2053 operator<=>(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2055 return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
2056 __y.begin(), __y.end(),
2057 __detail::__synth3way);
2071 template<
typename _Tp,
typename _Alloc>
2074 {
return std::lexicographical_compare(__x.
begin(), __x.
end(),
2078 template<
typename _Tp,
typename _Alloc>
2081 {
return !(__x == __y); }
2084 template<
typename _Tp,
typename _Alloc>
2087 {
return __y < __x; }
2090 template<
typename _Tp,
typename _Alloc>
2093 {
return !(__y < __x); }
2096 template<
typename _Tp,
typename _Alloc>
2099 {
return !(__x < __y); }
2103 template<
typename _Tp,
typename _Alloc>
2104 _GLIBCXX20_CONSTEXPR
2107 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
2110 _GLIBCXX_END_NAMESPACE_CONTAINER
2112 #if __cplusplus >= 201703L
2113 namespace __detail::__variant
2115 template<
typename>
struct _Never_valueless_alt;
2119 template<
typename _Tp,
typename _Alloc>
2120 struct _Never_valueless_alt<_GLIBCXX_STD_C::vector<_Tp, _Alloc>>
2126 _GLIBCXX_END_NAMESPACE_VERSION
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr bool is_constant_evaluated() noexcept
Returns true only when called during constant evaluation.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr void _Destroy(_ForwardIterator __first, _ForwardIterator __last, _Allocator &__alloc)
is_nothrow_default_constructible
is_nothrow_move_assignable
The standard allocator, as per C++03 [20.4.1].
Uniform interface to all pointer-like types.
Forward iterators support a superset of input iterator operations.
Random-access iterators support a superset of bidirectional iterator operations.
See bits/stl_deque.h's _Deque_base for an explanation.
A standard container which offers fixed time access to individual elements in any order.
constexpr iterator insert(const_iterator __position, const value_type &__x)
Inserts given value into vector before specified iterator.
constexpr void push_back(const value_type &__x)
Add data to the end of the vector.
constexpr void resize(size_type __new_size, const value_type &__x)
Resizes the vector to the specified number of elements.
constexpr reverse_iterator rbegin() noexcept
constexpr iterator end() noexcept
constexpr vector(const vector &__x)
Vector copy constructor.
vector()=default
Creates a vector with no elements.
constexpr iterator emplace(const_iterator __position, _Args &&... __args)
Inserts an object in vector before specified iterator.
constexpr iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into vector before specified iterator.
constexpr const_reverse_iterator rend() const noexcept
constexpr iterator begin() noexcept
constexpr size_type capacity() const noexcept
constexpr iterator insert(const_iterator __position, initializer_list< value_type > __l)
Inserts an initializer_list into the vector.
constexpr ~vector() noexcept
constexpr const_iterator begin() const noexcept
constexpr void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a vector.
constexpr void assign(size_type __n, const value_type &__val)
Assigns a given value to a vector.
constexpr iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
constexpr void swap(vector &__x) noexcept
Swaps data with another vector.
constexpr vector(vector &&__rv, const __type_identity_t< allocator_type > &__m) noexcept(noexcept(vector(std::declval< vector && >(), std::declval< const allocator_type & >(), std::declval< typename _Alloc_traits::is_always_equal >())))
Move constructor with alternative allocator.
constexpr vector(size_type __n, const allocator_type &__a=allocator_type())
Creates a vector with default constructed elements.
constexpr const_reference front() const noexcept
constexpr vector & operator=(initializer_list< value_type > __l)
Vector list assignment operator.
constexpr _Tp * data() noexcept
constexpr void pop_back() noexcept
Removes last element.
constexpr const_reference back() const noexcept
constexpr void reserve(size_type __n)
Attempt to preallocate enough memory for specified number of elements.
constexpr reference at(size_type __n)
Provides access to the data contained in the vector.
constexpr void resize(size_type __new_size)
Resizes the vector to the specified number of elements.
constexpr void _M_range_check(size_type __n) const
Safety check used only from at().
constexpr reference front() noexcept
constexpr iterator insert(const_iterator __position, size_type __n, const value_type &__x)
Inserts a number of copies of given data into the vector.
constexpr const_reference operator[](size_type __n) const noexcept
Subscript access to the data contained in the vector.
constexpr vector(const allocator_type &__a) noexcept
Creates a vector with no elements.
constexpr iterator erase(const_iterator __position)
Remove element at given position.
constexpr pointer _M_allocate_and_copy(size_type __n, _ForwardIterator __first, _ForwardIterator __last)
constexpr bool empty() const noexcept
constexpr reverse_iterator rend() noexcept
constexpr const_reverse_iterator rbegin() const noexcept
constexpr const_reverse_iterator crbegin() const noexcept
constexpr vector & operator=(vector &&__x) noexcept(_Alloc_traits::_S_nothrow_move())
Vector move assignment operator.
constexpr const_reference at(size_type __n) const
Provides access to the data contained in the vector.
constexpr const_iterator cbegin() const noexcept
constexpr vector(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a vector from a range.
constexpr vector(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a vector from an initializer list.
constexpr const_iterator end() const noexcept
vector(vector &&) noexcept=default
Vector move constructor.
constexpr iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the vector.
constexpr void clear() noexcept
constexpr void assign(initializer_list< value_type > __l)
Assigns an initializer list to a vector.
constexpr allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
constexpr size_type size() const noexcept
constexpr vector(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a vector with copies of an exemplar element.
constexpr vector & operator=(const vector &__x)
Vector assignment operator.
constexpr reference back() noexcept
constexpr const_reverse_iterator crend() const noexcept
constexpr const_iterator cend() const noexcept
constexpr reference operator[](size_type __n) noexcept
Subscript access to the data contained in the vector.
constexpr void shrink_to_fit()
constexpr size_type max_size() const noexcept
Uniform interface to C++98 and C++11 allocators.
static constexpr size_type max_size(const _Tp_alloc_type &__a) noexcept
The maximum supported allocation size.