57#define _STL_VECTOR_H 1
62#if __cplusplus >= 201103L
65#if __cplusplus >= 202002L
67#define __cpp_lib_constexpr_vector 201907L
72#if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR
74__sanitizer_annotate_contiguous_container(
const void*,
const void*,
75 const void*,
const void*);
78namespace std _GLIBCXX_VISIBILITY(default)
80_GLIBCXX_BEGIN_NAMESPACE_VERSION
81_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
84 template<
typename _Tp,
typename _Alloc>
88 rebind<_Tp>::other _Tp_alloc_type;
89 typedef typename __gnu_cxx::__alloc_traits<_Tp_alloc_type>::pointer
92 struct _Vector_impl_data
96 pointer _M_end_of_storage;
99 _Vector_impl_data() _GLIBCXX_NOEXCEPT
100 : _M_start(), _M_finish(), _M_end_of_storage()
103#if __cplusplus >= 201103L
105 _Vector_impl_data(_Vector_impl_data&& __x) noexcept
106 : _M_start(__x._M_start), _M_finish(__x._M_finish),
107 _M_end_of_storage(__x._M_end_of_storage)
108 { __x._M_start = __x._M_finish = __x._M_end_of_storage = pointer(); }
113 _M_copy_data(_Vector_impl_data
const& __x) _GLIBCXX_NOEXCEPT
115 _M_start = __x._M_start;
116 _M_finish = __x._M_finish;
117 _M_end_of_storage = __x._M_end_of_storage;
122 _M_swap_data(_Vector_impl_data& __x) _GLIBCXX_NOEXCEPT
126 _Vector_impl_data __tmp;
127 __tmp._M_copy_data(*
this);
129 __x._M_copy_data(__tmp);
134 :
public _Tp_alloc_type,
public _Vector_impl_data
137 _Vector_impl() _GLIBCXX_NOEXCEPT_IF(
143 _Vector_impl(_Tp_alloc_type
const& __a) _GLIBCXX_NOEXCEPT
144 : _Tp_alloc_type(__a)
147#if __cplusplus >= 201103L
151 _Vector_impl(_Vector_impl&& __x) noexcept
156 _Vector_impl(_Tp_alloc_type&& __a) noexcept
161 _Vector_impl(_Tp_alloc_type&& __a, _Vector_impl&& __rv) noexcept
166#if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR
167 template<
typename = _Tp_alloc_type>
171 ::size_type size_type;
173 static _GLIBCXX20_CONSTEXPR
void
174 _S_shrink(_Vector_impl&, size_type) { }
175 static _GLIBCXX20_CONSTEXPR
void
176 _S_on_dealloc(_Vector_impl&) { }
178 typedef _Vector_impl& _Reinit;
182 _GLIBCXX20_CONSTEXPR _Grow(_Vector_impl&, size_type) { }
183 _GLIBCXX20_CONSTEXPR
void _M_grew(size_type) { }
188 template<
typename _Up>
192 ::size_type size_type;
196 static _GLIBCXX20_CONSTEXPR
void
197 _S_adjust(_Vector_impl& __impl, pointer __prev, pointer __curr)
199#if __cpp_lib_is_constant_evaluated
203 __sanitizer_annotate_contiguous_container(__impl._M_start,
204 __impl._M_end_of_storage, __prev, __curr);
207 static _GLIBCXX20_CONSTEXPR
void
208 _S_grow(_Vector_impl& __impl, size_type __n)
209 { _S_adjust(__impl, __impl._M_finish, __impl._M_finish + __n); }
211 static _GLIBCXX20_CONSTEXPR
void
212 _S_shrink(_Vector_impl& __impl, size_type __n)
213 { _S_adjust(__impl, __impl._M_finish + __n, __impl._M_finish); }
215 static _GLIBCXX20_CONSTEXPR
void
216 _S_on_dealloc(_Vector_impl& __impl)
219 _S_adjust(__impl, __impl._M_finish, __impl._M_end_of_storage);
225 explicit _GLIBCXX20_CONSTEXPR
226 _Reinit(_Vector_impl& __impl) : _M_impl(__impl)
229 _S_on_dealloc(_M_impl);
236 if (_M_impl._M_start)
237 _S_adjust(_M_impl, _M_impl._M_end_of_storage,
241 _Vector_impl& _M_impl;
243#if __cplusplus >= 201103L
244 _Reinit(
const _Reinit&) =
delete;
245 _Reinit& operator=(
const _Reinit&) =
delete;
253 _Grow(_Vector_impl& __impl, size_type __n)
254 : _M_impl(__impl), _M_n(__n)
255 { _S_grow(_M_impl, __n); }
258 ~_Grow() {
if (_M_n) _S_shrink(_M_impl, _M_n); }
261 void _M_grew(size_type __n) { _M_n -= __n; }
263#if __cplusplus >= 201103L
264 _Grow(
const _Grow&) =
delete;
265 _Grow& operator=(
const _Grow&) =
delete;
268 _Vector_impl& _M_impl;
273#define _GLIBCXX_ASAN_ANNOTATE_REINIT \
274 typename _Base::_Vector_impl::template _Asan<>::_Reinit const \
275 __attribute__((__unused__)) __reinit_guard(this->_M_impl)
276#define _GLIBCXX_ASAN_ANNOTATE_GROW(n) \
277 typename _Base::_Vector_impl::template _Asan<>::_Grow \
278 __attribute__((__unused__)) __grow_guard(this->_M_impl, (n))
279#define _GLIBCXX_ASAN_ANNOTATE_GREW(n) __grow_guard._M_grew(n)
280#define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n) \
281 _Base::_Vector_impl::template _Asan<>::_S_shrink(this->_M_impl, n)
282#define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC \
283 _Base::_Vector_impl::template _Asan<>::_S_on_dealloc(this->_M_impl)
285#define _GLIBCXX_ASAN_ANNOTATE_REINIT
286#define _GLIBCXX_ASAN_ANNOTATE_GROW(n)
287#define _GLIBCXX_ASAN_ANNOTATE_GREW(n)
288#define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n)
289#define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC
294 typedef _Alloc allocator_type;
298 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
299 {
return this->_M_impl; }
302 const _Tp_alloc_type&
303 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
304 {
return this->_M_impl; }
308 get_allocator() const _GLIBCXX_NOEXCEPT
309 {
return allocator_type(_M_get_Tp_allocator()); }
311#if __cplusplus >= 201103L
318 _Vector_base(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
322#if !_GLIBCXX_INLINE_VERSION
324 _Vector_base(
size_t __n)
326 { _M_create_storage(__n); }
330 _Vector_base(
size_t __n,
const allocator_type& __a)
332 { _M_create_storage(__n); }
334#if __cplusplus >= 201103L
335 _Vector_base(_Vector_base&&) =
default;
338# if !_GLIBCXX_INLINE_VERSION
340 _Vector_base(_Tp_alloc_type&& __a) noexcept
344 _Vector_base(_Vector_base&& __x,
const allocator_type& __a)
347 if (__x.get_allocator() == __a)
348 this->_M_impl._M_swap_data(__x._M_impl);
351 size_t __n = __x._M_impl._M_finish - __x._M_impl._M_start;
352 _M_create_storage(__n);
358 _Vector_base(
const allocator_type& __a, _Vector_base&& __x)
359 : _M_impl(_Tp_alloc_type(__a),
std::
move(__x._M_impl))
364 ~_Vector_base() _GLIBCXX_NOEXCEPT
366 _M_deallocate(_M_impl._M_start,
367 _M_impl._M_end_of_storage - _M_impl._M_start);
371 _Vector_impl _M_impl;
375 _M_allocate(
size_t __n)
378 return __n != 0 ? _Tr::allocate(_M_impl, __n) : pointer();
383 _M_deallocate(pointer __p,
size_t __n)
387 _Tr::deallocate(_M_impl, __p, __n);
393 _M_create_storage(
size_t __n)
395 this->_M_impl._M_start = this->_M_allocate(__n);
396 this->_M_impl._M_finish = this->_M_impl._M_start;
397 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
422 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
425#ifdef _GLIBCXX_CONCEPT_CHECKS
427 typedef typename _Alloc::value_type _Alloc_value_type;
428# if __cplusplus < 201103L
429 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
431 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
434#if __cplusplus >= 201103L
436 "std::vector must have a non-const, non-volatile value_type");
437# if __cplusplus > 201703L || defined __STRICT_ANSI__
439 "std::vector must have the same value_type as its allocator");
444 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
448 typedef _Tp value_type;
449 typedef typename _Base::pointer pointer;
450 typedef typename _Alloc_traits::const_pointer const_pointer;
451 typedef typename _Alloc_traits::reference reference;
452 typedef typename _Alloc_traits::const_reference const_reference;
453 typedef __gnu_cxx::__normal_iterator<pointer, vector> iterator;
454 typedef __gnu_cxx::__normal_iterator<const_pointer, vector>
458 typedef size_t size_type;
459 typedef ptrdiff_t difference_type;
460 typedef _Alloc allocator_type;
463#if __cplusplus >= 201103L
464 static constexpr bool
467 return noexcept(std::__relocate_a(std::declval<pointer>(),
468 std::declval<pointer>(),
469 std::declval<pointer>(),
470 std::declval<_Tp_alloc_type&>()));
473 static constexpr bool
477 static constexpr bool
483 return _S_nothrow_relocate(__is_move_insertable<_Tp_alloc_type>{});
487 _S_do_relocate(pointer __first, pointer __last, pointer __result,
488 _Tp_alloc_type& __alloc,
true_type)
noexcept
490 return std::__relocate_a(__first, __last, __result, __alloc);
494 _S_do_relocate(pointer, pointer, pointer __result,
498 static _GLIBCXX20_CONSTEXPR pointer
499 _S_relocate(pointer __first, pointer __last, pointer __result,
500 _Tp_alloc_type& __alloc)
noexcept
502#if __cpp_if_constexpr
504 return std::__relocate_a(__first, __last, __result, __alloc);
506 using __do_it = __bool_constant<_S_use_relocate()>;
507 return _S_do_relocate(__first, __last, __result, __alloc, __do_it{});
513 using _Base::_M_allocate;
514 using _Base::_M_deallocate;
515 using _Base::_M_impl;
516 using _Base::_M_get_Tp_allocator;
525#if __cplusplus >= 201103L
537 vector(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
540#if __cplusplus >= 201103L
551 vector(size_type __n,
const allocator_type& __a = allocator_type())
552 :
_Base(_S_check_init_len(__n, __a), __a)
553 { _M_default_initialize(__n); }
564 vector(size_type __n,
const value_type& __value,
565 const allocator_type& __a = allocator_type())
566 :
_Base(_S_check_init_len(__n, __a), __a)
567 { _M_fill_initialize(__n, __value); }
578 vector(size_type __n,
const value_type& __value = value_type(),
579 const allocator_type& __a = allocator_type())
580 : _Base(_S_check_init_len(__n, __a), __a)
581 { _M_fill_initialize(__n, __value); }
600 this->_M_impl._M_finish =
601 std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
602 this->_M_impl._M_start,
603 _M_get_Tp_allocator());
606#if __cplusplus >= 201103L
619 vector(const
vector& __x, const __type_identity_t<allocator_type>& __a)
622 this->_M_impl._M_finish =
623 std::__uninitialized_copy_a(__x.begin(), __x.end(),
624 this->_M_impl._M_start,
625 _M_get_Tp_allocator());
638 if (__rv.get_allocator() == __m)
639 this->_M_impl._M_swap_data(__rv._M_impl);
640 else if (!__rv.empty())
642 this->_M_create_storage(__rv.size());
643 this->_M_impl._M_finish =
644 std::__uninitialized_move_a(__rv.begin(), __rv.end(),
645 this->_M_impl._M_start,
646 _M_get_Tp_allocator());
656 vector(std::declval<vector&&>(), std::declval<const allocator_type&>(),
657 std::declval<typename _Alloc_traits::is_always_equal>())) )
674 const allocator_type& __a = allocator_type())
677 _M_range_initialize(__l.begin(), __l.end(),
698#if __cplusplus >= 201103L
699 template<
typename _InputIterator,
700 typename = std::_RequireInputIter<_InputIterator>>
702 vector(_InputIterator __first, _InputIterator __last,
703 const allocator_type& __a = allocator_type())
706 _M_range_initialize(__first, __last,
710 template<
typename _InputIterator>
711 vector(_InputIterator __first, _InputIterator __last,
712 const allocator_type& __a = allocator_type())
716 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
717 _M_initialize_dispatch(__first, __last, _Integral());
730 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
731 _M_get_Tp_allocator());
732 _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC;
748#if __cplusplus >= 201103L
763 constexpr bool __move_storage =
764 _Alloc_traits::_S_propagate_on_move_assign()
765 || _Alloc_traits::_S_always_equal();
766 _M_move_assign(
std::move(__x), __bool_constant<__move_storage>());
785 this->_M_assign_aux(__l.begin(), __l.end(),
803 assign(size_type __n,
const value_type& __val)
804 { _M_fill_assign(__n, __val); }
818#if __cplusplus >= 201103L
819 template<
typename _InputIterator,
820 typename = std::_RequireInputIter<_InputIterator>>
823 assign(_InputIterator __first, _InputIterator __last)
824 { _M_assign_dispatch(__first, __last, __false_type()); }
826 template<
typename _InputIterator>
828 assign(_InputIterator __first, _InputIterator __last)
831 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
832 _M_assign_dispatch(__first, __last, _Integral());
836#if __cplusplus >= 201103L
852 this->_M_assign_aux(__l.begin(), __l.end(),
858 using _Base::get_allocator;
866 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
869 {
return iterator(this->_M_impl._M_start); }
876 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
879 {
return const_iterator(this->_M_impl._M_start); }
886 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
889 {
return iterator(this->_M_impl._M_finish); }
896 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
898 end() const _GLIBCXX_NOEXCEPT
899 {
return const_iterator(this->_M_impl._M_finish); }
906 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
916 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
917 const_reverse_iterator
926 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
936 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
937 const_reverse_iterator
941#if __cplusplus >= 201103L
947 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
950 {
return const_iterator(this->_M_impl._M_start); }
957 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
960 {
return const_iterator(this->_M_impl._M_finish); }
967 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
968 const_reverse_iterator
977 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
978 const_reverse_iterator
985 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
988 {
return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
991 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
994 {
return _S_max_size(_M_get_Tp_allocator()); }
996#if __cplusplus >= 201103L
1006 _GLIBCXX20_CONSTEXPR
1010 if (__new_size >
size())
1011 _M_default_append(__new_size -
size());
1012 else if (__new_size <
size())
1013 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1027 _GLIBCXX20_CONSTEXPR
1029 resize(size_type __new_size,
const value_type& __x)
1031 if (__new_size >
size())
1032 _M_fill_insert(
end(), __new_size -
size(), __x);
1033 else if (__new_size <
size())
1034 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1048 _GLIBCXX20_CONSTEXPR
1050 resize(size_type __new_size, value_type __x = value_type())
1052 if (__new_size >
size())
1053 _M_fill_insert(
end(), __new_size -
size(), __x);
1054 else if (__new_size <
size())
1055 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1059#if __cplusplus >= 201103L
1061 _GLIBCXX20_CONSTEXPR
1064 { _M_shrink_to_fit(); }
1071 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1074 {
return size_type(this->_M_impl._M_end_of_storage
1075 - this->_M_impl._M_start); }
1081 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1103 _GLIBCXX20_CONSTEXPR
1119 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1123 __glibcxx_requires_subscript(__n);
1124 return *(this->_M_impl._M_start + __n);
1138 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1142 __glibcxx_requires_subscript(__n);
1143 return *(this->_M_impl._M_start + __n);
1148 _GLIBCXX20_CONSTEXPR
1152 if (__n >= this->
size())
1153 __throw_out_of_range_fmt(__N(
"vector::_M_range_check: __n "
1154 "(which is %zu) >= this->size() "
1171 _GLIBCXX20_CONSTEXPR
1176 return (*
this)[__n];
1190 _GLIBCXX20_CONSTEXPR
1195 return (*
this)[__n];
1202 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1206 __glibcxx_requires_nonempty();
1214 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1218 __glibcxx_requires_nonempty();
1226 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1230 __glibcxx_requires_nonempty();
1231 return *(
end() - 1);
1238 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1242 __glibcxx_requires_nonempty();
1243 return *(
end() - 1);
1253 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1256 {
return _M_data_ptr(this->_M_impl._M_start); }
1258 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1260 data() const _GLIBCXX_NOEXCEPT
1261 {
return _M_data_ptr(this->_M_impl._M_start); }
1274 _GLIBCXX20_CONSTEXPR
1278 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
1280 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
1281 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
1283 ++this->_M_impl._M_finish;
1284 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
1287 _M_realloc_insert(
end(), __x);
1290#if __cplusplus >= 201103L
1291 _GLIBCXX20_CONSTEXPR
1296 template<
typename... _Args>
1297#if __cplusplus > 201402L
1298 _GLIBCXX20_CONSTEXPR
1303 emplace_back(_Args&&... __args);
1315 _GLIBCXX20_CONSTEXPR
1319 __glibcxx_requires_nonempty();
1320 --this->_M_impl._M_finish;
1321 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
1322 _GLIBCXX_ASAN_ANNOTATE_SHRINK(1);
1325#if __cplusplus >= 201103L
1338 template<
typename... _Args>
1339 _GLIBCXX20_CONSTEXPR
1341 emplace(const_iterator __position, _Args&&... __args)
1342 {
return _M_emplace_aux(__position, std::forward<_Args>(__args)...); }
1355 _GLIBCXX20_CONSTEXPR
1357 insert(const_iterator __position,
const value_type& __x);
1374#if __cplusplus >= 201103L
1386 _GLIBCXX20_CONSTEXPR
1388 insert(const_iterator __position, value_type&& __x)
1389 {
return _M_insert_rval(__position,
std::move(__x)); }
1404 _GLIBCXX20_CONSTEXPR
1408 auto __offset = __position -
cbegin();
1409 _M_range_insert(
begin() + __offset, __l.begin(), __l.end(),
1411 return begin() + __offset;
1415#if __cplusplus >= 201103L
1430 _GLIBCXX20_CONSTEXPR
1432 insert(const_iterator __position, size_type __n,
const value_type& __x)
1434 difference_type __offset = __position -
cbegin();
1435 _M_fill_insert(
begin() + __offset, __n, __x);
1436 return begin() + __offset;
1453 insert(
iterator __position, size_type __n,
const value_type& __x)
1454 { _M_fill_insert(__position, __n, __x); }
1457#if __cplusplus >= 201103L
1473 template<
typename _InputIterator,
1474 typename = std::_RequireInputIter<_InputIterator>>
1475 _GLIBCXX20_CONSTEXPR
1477 insert(const_iterator __position, _InputIterator __first,
1478 _InputIterator __last)
1480 difference_type __offset = __position -
cbegin();
1481 _M_insert_dispatch(
begin() + __offset,
1482 __first, __last, __false_type());
1483 return begin() + __offset;
1500 template<
typename _InputIterator>
1503 _InputIterator __last)
1506 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1507 _M_insert_dispatch(__position, __first, __last, _Integral());
1526 _GLIBCXX20_CONSTEXPR
1528#if __cplusplus >= 201103L
1530 {
return _M_erase(
begin() + (__position -
cbegin())); }
1533 {
return _M_erase(__position); }
1554 _GLIBCXX20_CONSTEXPR
1556#if __cplusplus >= 201103L
1557 erase(const_iterator __first, const_iterator __last)
1559 const auto __beg =
begin();
1560 const auto __cbeg =
cbegin();
1561 return _M_erase(__beg + (__first - __cbeg), __beg + (__last - __cbeg));
1565 {
return _M_erase(__first, __last); }
1579 _GLIBCXX20_CONSTEXPR
1583#if __cplusplus >= 201103L
1584 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1585 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1587 this->_M_impl._M_swap_data(__x._M_impl);
1588 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1589 __x._M_get_Tp_allocator());
1598 _GLIBCXX20_CONSTEXPR
1601 { _M_erase_at_end(this->_M_impl._M_start); }
1608 template<
typename _ForwardIterator>
1609 _GLIBCXX20_CONSTEXPR
1612 _ForwardIterator __first, _ForwardIterator __last)
1614 pointer __result = this->_M_allocate(__n);
1617 std::__uninitialized_copy_a(__first, __last, __result,
1618 _M_get_Tp_allocator());
1623 _M_deallocate(__result, __n);
1624 __throw_exception_again;
1633#if __cplusplus < 201103L
1636 template<
typename _Integer>
1638 _M_initialize_dispatch(_Integer __n, _Integer __value, __true_type)
1640 this->_M_impl._M_start = _M_allocate(_S_check_init_len(
1641 static_cast<size_type
>(__n), _M_get_Tp_allocator()));
1642 this->_M_impl._M_end_of_storage =
1643 this->_M_impl._M_start +
static_cast<size_type
>(__n);
1644 _M_fill_initialize(
static_cast<size_type
>(__n), __value);
1648 template<
typename _InputIterator>
1650 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1653 _M_range_initialize(__first, __last,
1659 template<
typename _InputIterator>
1660 _GLIBCXX20_CONSTEXPR
1662 _M_range_initialize(_InputIterator __first, _InputIterator __last,
1666 for (; __first != __last; ++__first)
1667#
if __cplusplus >= 201103L
1668 emplace_back(*__first);
1674 __throw_exception_again;
1679 template<
typename _ForwardIterator>
1680 _GLIBCXX20_CONSTEXPR
1682 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
1686 this->_M_impl._M_start
1687 = this->_M_allocate(_S_check_init_len(__n, _M_get_Tp_allocator()));
1688 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
1689 this->_M_impl._M_finish =
1690 std::__uninitialized_copy_a(__first, __last,
1691 this->_M_impl._M_start,
1692 _M_get_Tp_allocator());
1697 _GLIBCXX20_CONSTEXPR
1699 _M_fill_initialize(size_type __n,
const value_type& __value)
1701 this->_M_impl._M_finish =
1702 std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value,
1703 _M_get_Tp_allocator());
1706#if __cplusplus >= 201103L
1708 _GLIBCXX20_CONSTEXPR
1710 _M_default_initialize(size_type __n)
1712 this->_M_impl._M_finish =
1713 std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
1714 _M_get_Tp_allocator());
1725 template<
typename _Integer>
1726 _GLIBCXX20_CONSTEXPR
1728 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1729 { _M_fill_assign(__n, __val); }
1732 template<
typename _InputIterator>
1733 _GLIBCXX20_CONSTEXPR
1735 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1740 template<
typename _InputIterator>
1741 _GLIBCXX20_CONSTEXPR
1743 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1747 template<
typename _ForwardIterator>
1748 _GLIBCXX20_CONSTEXPR
1750 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1755 _GLIBCXX20_CONSTEXPR
1757 _M_fill_assign(size_type __n,
const value_type& __val);
1765 template<
typename _Integer>
1766 _GLIBCXX20_CONSTEXPR
1768 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
1770 { _M_fill_insert(__pos, __n, __val); }
1773 template<
typename _InputIterator>
1774 _GLIBCXX20_CONSTEXPR
1776 _M_insert_dispatch(iterator __pos, _InputIterator __first,
1777 _InputIterator __last, __false_type)
1779 _M_range_insert(__pos, __first, __last,
1784 template<
typename _InputIterator>
1785 _GLIBCXX20_CONSTEXPR
1787 _M_range_insert(iterator __pos, _InputIterator __first,
1791 template<
typename _ForwardIterator>
1792 _GLIBCXX20_CONSTEXPR
1794 _M_range_insert(iterator __pos, _ForwardIterator __first,
1799 _GLIBCXX20_CONSTEXPR
1801 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
1803#if __cplusplus >= 201103L
1805 _GLIBCXX20_CONSTEXPR
1807 _M_default_append(size_type __n);
1809 _GLIBCXX20_CONSTEXPR
1814#if __cplusplus < 201103L
1817 _M_insert_aux(iterator __position,
const value_type& __x);
1820 _M_realloc_insert(iterator __position,
const value_type& __x);
1824 struct _Temporary_value
1826 template<
typename... _Args>
1827 _GLIBCXX20_CONSTEXPR
explicit
1828 _Temporary_value(
vector* __vec, _Args&&... __args) : _M_this(__vec)
1830 _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(),
1831 std::forward<_Args>(__args)...);
1834 _GLIBCXX20_CONSTEXPR
1836 { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); }
1838 _GLIBCXX20_CONSTEXPR value_type&
1839 _M_val() noexcept {
return _M_storage._M_val; }
1842 _GLIBCXX20_CONSTEXPR _Tp*
1847 constexpr _Storage() : _M_byte() { }
1848 _GLIBCXX20_CONSTEXPR ~_Storage() { }
1849 _Storage& operator=(
const _Storage&) =
delete;
1850 unsigned char _M_byte;
1855 _Storage _M_storage;
1860 template<
typename _Arg>
1861 _GLIBCXX20_CONSTEXPR
1863 _M_insert_aux(iterator __position, _Arg&& __arg);
1865 template<
typename... _Args>
1866 _GLIBCXX20_CONSTEXPR
1868 _M_realloc_insert(iterator __position, _Args&&... __args);
1871 _GLIBCXX20_CONSTEXPR
1873 _M_insert_rval(const_iterator __position, value_type&& __v);
1876 template<
typename... _Args>
1877 _GLIBCXX20_CONSTEXPR
1879 _M_emplace_aux(const_iterator __position, _Args&&... __args);
1882 _GLIBCXX20_CONSTEXPR
1884 _M_emplace_aux(const_iterator __position, value_type&& __v)
1885 {
return _M_insert_rval(__position,
std::move(__v)); }
1889 _GLIBCXX20_CONSTEXPR
1891 _M_check_len(size_type __n,
const char* __s)
const
1894 __throw_length_error(__N(__s));
1901 static _GLIBCXX20_CONSTEXPR size_type
1902 _S_check_init_len(size_type __n,
const allocator_type& __a)
1904 if (__n > _S_max_size(_Tp_alloc_type(__a)))
1905 __throw_length_error(
1906 __N(
"cannot create std::vector larger than max_size()"));
1910 static _GLIBCXX20_CONSTEXPR size_type
1911 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1916 const size_t __diffmax
1917 = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max /
sizeof(_Tp);
1919 return (
std::min)(__diffmax, __allocmax);
1926 _GLIBCXX20_CONSTEXPR
1928 _M_erase_at_end(pointer __pos) _GLIBCXX_NOEXCEPT
1930 if (size_type __n = this->_M_impl._M_finish - __pos)
1933 _M_get_Tp_allocator());
1934 this->_M_impl._M_finish = __pos;
1935 _GLIBCXX_ASAN_ANNOTATE_SHRINK(__n);
1939 _GLIBCXX20_CONSTEXPR
1941 _M_erase(iterator __position);
1943 _GLIBCXX20_CONSTEXPR
1945 _M_erase(iterator __first, iterator __last);
1947#if __cplusplus >= 201103L
1952 _GLIBCXX20_CONSTEXPR
1957 this->_M_impl._M_swap_data(__x._M_impl);
1958 __tmp._M_impl._M_swap_data(__x._M_impl);
1959 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
1964 _GLIBCXX20_CONSTEXPR
1968 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
1974 this->_M_assign_aux(std::make_move_iterator(__x.begin()),
1975 std::make_move_iterator(__x.end()),
1982 template<
typename _Up>
1983 _GLIBCXX20_CONSTEXPR
1985 _M_data_ptr(_Up* __ptr)
const _GLIBCXX_NOEXCEPT
1988#if __cplusplus >= 201103L
1989 template<
typename _Ptr>
1990 _GLIBCXX20_CONSTEXPR
1991 typename std::pointer_traits<_Ptr>::element_type*
1992 _M_data_ptr(_Ptr __ptr)
const
1993 {
return empty() ? nullptr : std::__to_address(__ptr); }
1995 template<
typename _Up>
1997 _M_data_ptr(_Up* __ptr) _GLIBCXX_NOEXCEPT
2000 template<
typename _Ptr>
2002 _M_data_ptr(_Ptr __ptr)
2003 {
return empty() ? (value_type*)0 : __ptr.operator->(); }
2005 template<
typename _Ptr>
2007 _M_data_ptr(_Ptr __ptr)
const
2008 {
return empty() ? (
const value_type*)0 : __ptr.operator->(); }
2012#if __cpp_deduction_guides >= 201606
2013 template<
typename _InputIterator,
typename _ValT
2014 =
typename iterator_traits<_InputIterator>::value_type,
2015 typename _Allocator = allocator<_ValT>,
2016 typename = _RequireInputIter<_InputIterator>,
2017 typename = _RequireAllocator<_Allocator>>
2018 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
2019 -> vector<_ValT, _Allocator>;
2032 template<
typename _Tp,
typename _Alloc>
2033 _GLIBCXX20_CONSTEXPR
2039#if __cpp_lib_three_way_comparison
2051 template<
typename _Tp,
typename _Alloc>
2052 _GLIBCXX20_CONSTEXPR
2053 inline __detail::__synth3way_t<_Tp>
2054 operator<=>(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2056 return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
2057 __y.begin(), __y.end(),
2058 __detail::__synth3way);
2072 template<
typename _Tp,
typename _Alloc>
2075 {
return std::lexicographical_compare(__x.
begin(), __x.
end(),
2079 template<
typename _Tp,
typename _Alloc>
2082 {
return !(__x == __y); }
2085 template<
typename _Tp,
typename _Alloc>
2088 {
return __y < __x; }
2091 template<
typename _Tp,
typename _Alloc>
2094 {
return !(__y < __x); }
2097 template<
typename _Tp,
typename _Alloc>
2100 {
return !(__x < __y); }
2104 template<
typename _Tp,
typename _Alloc>
2105 _GLIBCXX20_CONSTEXPR
2108 _GLIBCXX_NOEXCEPT_IF(
noexcept(__x.swap(__y)))
2111_GLIBCXX_END_NAMESPACE_CONTAINER
2113#if __cplusplus >= 201703L
2114 namespace __detail::__variant
2116 template<
typename>
struct _Never_valueless_alt;
2120 template<
typename _Tp,
typename _Alloc>
2121 struct _Never_valueless_alt<_GLIBCXX_STD_C::vector<_Tp, _Alloc>>
2127_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 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 _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
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
__detected_or_t< typename is_empty< _Alloc >::type, __equal, _Alloc > is_always_equal
Whether all instances of the allocator type compare equal.
The standard allocator, as per C++03 [20.4.1].
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 vector & operator=(initializer_list< value_type > __l)
Vector list assignment operator.
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 _Tp * data() noexcept
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 void pop_back() noexcept
Removes last element.
constexpr vector & operator=(vector &&__x) noexcept(_Alloc_traits::_S_nothrow_move())
Vector move assignment operator.
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 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.