57#define _STL_VECTOR_H 1
62#if __cplusplus >= 201103L
65#if __cplusplus >= 202002L
71#if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR
73__sanitizer_annotate_contiguous_container(
const void*,
const void*,
74 const void*,
const void*);
77namespace 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
199 if (std::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);
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;
424 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
427#ifdef _GLIBCXX_CONCEPT_CHECKS
429 typedef typename _Alloc::value_type _Alloc_value_type;
430# if __cplusplus < 201103L
431 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
433 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
436#if __cplusplus >= 201103L
438 "std::vector must have a non-const, non-volatile value_type");
439# if __cplusplus > 201703L || defined __STRICT_ANSI__
441 "std::vector must have the same value_type as its allocator");
446 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
450 typedef _Tp value_type;
451 typedef typename _Base::pointer pointer;
452 typedef typename _Alloc_traits::const_pointer const_pointer;
453 typedef typename _Alloc_traits::reference reference;
454 typedef typename _Alloc_traits::const_reference const_reference;
455 typedef __gnu_cxx::__normal_iterator<pointer, vector> iterator;
456 typedef __gnu_cxx::__normal_iterator<const_pointer, vector>
460 typedef size_t size_type;
461 typedef ptrdiff_t difference_type;
462 typedef _Alloc allocator_type;
465#if __cplusplus >= 201103L
466 static constexpr bool
469 return noexcept(std::__relocate_a(std::declval<pointer>(),
470 std::declval<pointer>(),
471 std::declval<pointer>(),
472 std::declval<_Tp_alloc_type&>()));
475 static constexpr bool
479 static constexpr bool
485 return _S_nothrow_relocate(__is_move_insertable<_Tp_alloc_type>{});
489 _S_do_relocate(pointer __first, pointer __last, pointer __result,
490 _Tp_alloc_type& __alloc,
true_type)
noexcept
492 return std::__relocate_a(__first, __last, __result, __alloc);
496 _S_do_relocate(pointer, pointer, pointer __result,
500 static _GLIBCXX20_CONSTEXPR pointer
501 _S_relocate(pointer __first, pointer __last, pointer __result,
502 _Tp_alloc_type& __alloc)
noexcept
504#if __cpp_if_constexpr
506 return std::__relocate_a(__first, __last, __result, __alloc);
508 using __do_it = __bool_constant<_S_use_relocate()>;
509 return _S_do_relocate(__first, __last, __result, __alloc, __do_it{});
515 using _Base::_M_allocate;
516 using _Base::_M_deallocate;
517 using _Base::_M_impl;
518 using _Base::_M_get_Tp_allocator;
527#if __cplusplus >= 201103L
539 vector(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
542#if __cplusplus >= 201103L
553 vector(size_type __n,
const allocator_type& __a = allocator_type())
554 :
_Base(_S_check_init_len(__n, __a), __a)
555 { _M_default_initialize(__n); }
566 vector(size_type __n,
const value_type& __value,
567 const allocator_type& __a = allocator_type())
568 :
_Base(_S_check_init_len(__n, __a), __a)
569 { _M_fill_initialize(__n, __value); }
580 vector(size_type __n,
const value_type& __value = value_type(),
581 const allocator_type& __a = allocator_type())
582 : _Base(_S_check_init_len(__n, __a), __a)
583 { _M_fill_initialize(__n, __value); }
602 this->_M_impl._M_finish =
603 std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
604 this->_M_impl._M_start,
605 _M_get_Tp_allocator());
608#if __cplusplus >= 201103L
621 vector(const
vector& __x, const __type_identity_t<allocator_type>& __a)
624 this->_M_impl._M_finish =
625 std::__uninitialized_copy_a(__x.begin(), __x.end(),
626 this->_M_impl._M_start,
627 _M_get_Tp_allocator());
640 if (__rv.get_allocator() == __m)
641 this->_M_impl._M_swap_data(__rv._M_impl);
642 else if (!__rv.empty())
644 this->_M_create_storage(__rv.size());
645 this->_M_impl._M_finish =
646 std::__uninitialized_move_a(__rv.begin(), __rv.end(),
647 this->_M_impl._M_start,
648 _M_get_Tp_allocator());
658 vector(std::declval<vector&&>(), std::declval<const allocator_type&>(),
659 std::declval<typename _Alloc_traits::is_always_equal>())) )
676 const allocator_type& __a = allocator_type())
679 _M_range_initialize(__l.begin(), __l.end(),
700#if __cplusplus >= 201103L
701 template<
typename _InputIterator,
702 typename = std::_RequireInputIter<_InputIterator>>
704 vector(_InputIterator __first, _InputIterator __last,
705 const allocator_type& __a = allocator_type())
708 _M_range_initialize(__first, __last,
712 template<
typename _InputIterator>
713 vector(_InputIterator __first, _InputIterator __last,
714 const allocator_type& __a = allocator_type())
718 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
719 _M_initialize_dispatch(__first, __last, _Integral());
732 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
733 _M_get_Tp_allocator());
734 _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC;
750#if __cplusplus >= 201103L
765 constexpr bool __move_storage =
766 _Alloc_traits::_S_propagate_on_move_assign()
767 || _Alloc_traits::_S_always_equal();
768 _M_move_assign(
std::move(__x), __bool_constant<__move_storage>());
787 this->_M_assign_aux(__l.begin(), __l.end(),
805 assign(size_type __n,
const value_type& __val)
806 { _M_fill_assign(__n, __val); }
820#if __cplusplus >= 201103L
821 template<
typename _InputIterator,
822 typename = std::_RequireInputIter<_InputIterator>>
825 assign(_InputIterator __first, _InputIterator __last)
828 template<
typename _InputIterator>
830 assign(_InputIterator __first, _InputIterator __last)
833 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
834 _M_assign_dispatch(__first, __last, _Integral());
838#if __cplusplus >= 201103L
854 this->_M_assign_aux(__l.begin(), __l.end(),
860 using _Base::get_allocator;
868 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
871 {
return iterator(this->_M_impl._M_start); }
878 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
881 {
return const_iterator(this->_M_impl._M_start); }
888 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
891 {
return iterator(this->_M_impl._M_finish); }
898 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
900 end() const _GLIBCXX_NOEXCEPT
901 {
return const_iterator(this->_M_impl._M_finish); }
908 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
918 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
919 const_reverse_iterator
928 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
938 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
939 const_reverse_iterator
943#if __cplusplus >= 201103L
949 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
952 {
return const_iterator(this->_M_impl._M_start); }
959 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
962 {
return const_iterator(this->_M_impl._M_finish); }
969 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
970 const_reverse_iterator
979 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
980 const_reverse_iterator
987 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
990 {
return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
993 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
996 {
return _S_max_size(_M_get_Tp_allocator()); }
998#if __cplusplus >= 201103L
1008 _GLIBCXX20_CONSTEXPR
1012 if (__new_size >
size())
1013 _M_default_append(__new_size -
size());
1014 else if (__new_size <
size())
1015 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1029 _GLIBCXX20_CONSTEXPR
1031 resize(size_type __new_size,
const value_type& __x)
1033 if (__new_size >
size())
1034 _M_fill_insert(
end(), __new_size -
size(), __x);
1035 else if (__new_size <
size())
1036 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1050 _GLIBCXX20_CONSTEXPR
1052 resize(size_type __new_size, value_type __x = value_type())
1054 if (__new_size >
size())
1055 _M_fill_insert(
end(), __new_size -
size(), __x);
1056 else if (__new_size <
size())
1057 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1061#if __cplusplus >= 201103L
1063 _GLIBCXX20_CONSTEXPR
1066 { _M_shrink_to_fit(); }
1073 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1077 return size_type(this->_M_impl._M_end_of_storage
1078 - this->_M_impl._M_start);
1085 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1107 _GLIBCXX20_CONSTEXPR
1123 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1127 __glibcxx_requires_subscript(__n);
1128 return *(this->_M_impl._M_start + __n);
1142 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1146 __glibcxx_requires_subscript(__n);
1147 return *(this->_M_impl._M_start + __n);
1152 _GLIBCXX20_CONSTEXPR
1156 if (__n >= this->
size())
1157 __throw_out_of_range_fmt(__N(
"vector::_M_range_check: __n "
1158 "(which is %zu) >= this->size() "
1175 _GLIBCXX20_CONSTEXPR
1180 return (*
this)[__n];
1194 _GLIBCXX20_CONSTEXPR
1199 return (*
this)[__n];
1206 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1210 __glibcxx_requires_nonempty();
1218 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1222 __glibcxx_requires_nonempty();
1230 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1234 __glibcxx_requires_nonempty();
1235 return *(
end() - 1);
1242 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1246 __glibcxx_requires_nonempty();
1247 return *(
end() - 1);
1257 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1260 {
return _M_data_ptr(this->_M_impl._M_start); }
1262 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1264 data() const _GLIBCXX_NOEXCEPT
1265 {
return _M_data_ptr(this->_M_impl._M_start); }
1278 _GLIBCXX20_CONSTEXPR
1282 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
1284 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
1285 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
1287 ++this->_M_impl._M_finish;
1288 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
1291 _M_realloc_append(__x);
1294#if __cplusplus >= 201103L
1295 _GLIBCXX20_CONSTEXPR
1300 template<
typename... _Args>
1301#if __cplusplus > 201402L
1302 _GLIBCXX20_CONSTEXPR
1307 emplace_back(_Args&&... __args);
1319 _GLIBCXX20_CONSTEXPR
1323 __glibcxx_requires_nonempty();
1324 --this->_M_impl._M_finish;
1325 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
1326 _GLIBCXX_ASAN_ANNOTATE_SHRINK(1);
1329#if __cplusplus >= 201103L
1342 template<
typename... _Args>
1343 _GLIBCXX20_CONSTEXPR
1345 emplace(const_iterator __position, _Args&&... __args)
1346 {
return _M_emplace_aux(__position, std::forward<_Args>(__args)...); }
1359 _GLIBCXX20_CONSTEXPR
1361 insert(const_iterator __position,
const value_type& __x);
1378#if __cplusplus >= 201103L
1390 _GLIBCXX20_CONSTEXPR
1392 insert(const_iterator __position, value_type&& __x)
1393 {
return _M_insert_rval(__position,
std::move(__x)); }
1408 _GLIBCXX20_CONSTEXPR
1412 auto __offset = __position -
cbegin();
1413 _M_range_insert(
begin() + __offset, __l.begin(), __l.end(),
1415 return begin() + __offset;
1419#if __cplusplus >= 201103L
1434 _GLIBCXX20_CONSTEXPR
1436 insert(const_iterator __position, size_type __n,
const value_type& __x)
1438 difference_type __offset = __position -
cbegin();
1439 _M_fill_insert(
begin() + __offset, __n, __x);
1440 return begin() + __offset;
1457 insert(
iterator __position, size_type __n,
const value_type& __x)
1458 { _M_fill_insert(__position, __n, __x); }
1461#if __cplusplus >= 201103L
1477 template<
typename _InputIterator,
1478 typename = std::_RequireInputIter<_InputIterator>>
1479 _GLIBCXX20_CONSTEXPR
1481 insert(const_iterator __position, _InputIterator __first,
1482 _InputIterator __last)
1484 difference_type __offset = __position -
cbegin();
1485 _M_range_insert(
begin() + __offset, __first, __last,
1487 return begin() + __offset;
1504 template<
typename _InputIterator>
1507 _InputIterator __last)
1510 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1511 _M_insert_dispatch(__position, __first, __last, _Integral());
1530 _GLIBCXX20_CONSTEXPR
1532#if __cplusplus >= 201103L
1534 {
return _M_erase(
begin() + (__position -
cbegin())); }
1537 {
return _M_erase(__position); }
1558 _GLIBCXX20_CONSTEXPR
1560#if __cplusplus >= 201103L
1561 erase(const_iterator __first, const_iterator __last)
1563 const auto __beg =
begin();
1564 const auto __cbeg =
cbegin();
1565 return _M_erase(__beg + (__first - __cbeg), __beg + (__last - __cbeg));
1569 {
return _M_erase(__first, __last); }
1583 _GLIBCXX20_CONSTEXPR
1587#if __cplusplus >= 201103L
1588 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1589 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1591 this->_M_impl._M_swap_data(__x._M_impl);
1592 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1593 __x._M_get_Tp_allocator());
1602 _GLIBCXX20_CONSTEXPR
1605 { _M_erase_at_end(this->_M_impl._M_start); }
1612 template<
typename _ForwardIterator>
1613 _GLIBCXX20_CONSTEXPR
1616 _ForwardIterator __first, _ForwardIterator __last)
1618 pointer __result = this->_M_allocate(__n);
1621 std::__uninitialized_copy_a(__first, __last, __result,
1622 _M_get_Tp_allocator());
1627 _M_deallocate(__result, __n);
1628 __throw_exception_again;
1637#if __cplusplus < 201103L
1640 template<
typename _Integer>
1642 _M_initialize_dispatch(_Integer __n, _Integer __value, __true_type)
1644 this->_M_impl._M_start = _M_allocate(_S_check_init_len(
1645 static_cast<size_type
>(__n), _M_get_Tp_allocator()));
1646 this->_M_impl._M_end_of_storage =
1647 this->_M_impl._M_start +
static_cast<size_type
>(__n);
1648 _M_fill_initialize(
static_cast<size_type
>(__n), __value);
1652 template<
typename _InputIterator>
1654 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1657 _M_range_initialize(__first, __last,
1663 template<
typename _InputIterator>
1664 _GLIBCXX20_CONSTEXPR
1666 _M_range_initialize(_InputIterator __first, _InputIterator __last,
1670 for (; __first != __last; ++__first)
1671#
if __cplusplus >= 201103L
1672 emplace_back(*__first);
1678 __throw_exception_again;
1683 template<
typename _ForwardIterator>
1684 _GLIBCXX20_CONSTEXPR
1686 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
1690 this->_M_impl._M_start
1691 = this->_M_allocate(_S_check_init_len(__n, _M_get_Tp_allocator()));
1692 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
1693 this->_M_impl._M_finish =
1694 std::__uninitialized_copy_a(__first, __last,
1695 this->_M_impl._M_start,
1696 _M_get_Tp_allocator());
1701 _GLIBCXX20_CONSTEXPR
1703 _M_fill_initialize(size_type __n,
const value_type& __value)
1705 this->_M_impl._M_finish =
1706 std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value,
1707 _M_get_Tp_allocator());
1710#if __cplusplus >= 201103L
1712 _GLIBCXX20_CONSTEXPR
1714 _M_default_initialize(size_type __n)
1716 this->_M_impl._M_finish =
1717 std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
1718 _M_get_Tp_allocator());
1729 template<
typename _Integer>
1730 _GLIBCXX20_CONSTEXPR
1732 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1733 { _M_fill_assign(__n, __val); }
1736 template<
typename _InputIterator>
1737 _GLIBCXX20_CONSTEXPR
1739 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1744 template<
typename _InputIterator>
1745 _GLIBCXX20_CONSTEXPR
1747 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1751 template<
typename _ForwardIterator>
1752 _GLIBCXX20_CONSTEXPR
1754 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1759 _GLIBCXX20_CONSTEXPR
1761 _M_fill_assign(size_type __n,
const value_type& __val);
1769 template<
typename _Integer>
1770 _GLIBCXX20_CONSTEXPR
1772 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
1774 { _M_fill_insert(__pos, __n, __val); }
1777 template<
typename _InputIterator>
1778 _GLIBCXX20_CONSTEXPR
1780 _M_insert_dispatch(iterator __pos, _InputIterator __first,
1781 _InputIterator __last, __false_type)
1783 _M_range_insert(__pos, __first, __last,
1788 template<
typename _InputIterator>
1789 _GLIBCXX20_CONSTEXPR
1791 _M_range_insert(iterator __pos, _InputIterator __first,
1795 template<
typename _ForwardIterator>
1796 _GLIBCXX20_CONSTEXPR
1798 _M_range_insert(iterator __pos, _ForwardIterator __first,
1803 _GLIBCXX20_CONSTEXPR
1805 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
1807#if __cplusplus >= 201103L
1809 _GLIBCXX20_CONSTEXPR
1811 _M_default_append(size_type __n);
1813 _GLIBCXX20_CONSTEXPR
1818#if __cplusplus < 201103L
1821 _M_insert_aux(iterator __position,
const value_type& __x);
1824 _M_realloc_insert(iterator __position,
const value_type& __x);
1827 _M_realloc_append(
const value_type& __x);
1831 struct _Temporary_value
1833 template<
typename... _Args>
1834 _GLIBCXX20_CONSTEXPR
explicit
1835 _Temporary_value(
vector* __vec, _Args&&... __args) : _M_this(__vec)
1837 _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(),
1838 std::forward<_Args>(__args)...);
1841 _GLIBCXX20_CONSTEXPR
1843 { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); }
1845 _GLIBCXX20_CONSTEXPR value_type&
1846 _M_val() noexcept {
return _M_storage._M_val; }
1849 _GLIBCXX20_CONSTEXPR _Tp*
1854 constexpr _Storage() : _M_byte() { }
1855 _GLIBCXX20_CONSTEXPR ~_Storage() { }
1856 _Storage&
operator=(
const _Storage&) =
delete;
1857 unsigned char _M_byte;
1862 _Storage _M_storage;
1867 template<
typename _Arg>
1868 _GLIBCXX20_CONSTEXPR
1870 _M_insert_aux(iterator __position, _Arg&& __arg);
1872 template<
typename... _Args>
1873 _GLIBCXX20_CONSTEXPR
1875 _M_realloc_insert(iterator __position, _Args&&... __args);
1877 template<
typename... _Args>
1878 _GLIBCXX20_CONSTEXPR
1880 _M_realloc_append(_Args&&... __args);
1883 _GLIBCXX20_CONSTEXPR
1885 _M_insert_rval(const_iterator __position, value_type&& __v);
1888 template<
typename... _Args>
1889 _GLIBCXX20_CONSTEXPR
1891 _M_emplace_aux(const_iterator __position, _Args&&... __args);
1894 _GLIBCXX20_CONSTEXPR
1896 _M_emplace_aux(const_iterator __position, value_type&& __v)
1897 {
return _M_insert_rval(__position,
std::move(__v)); }
1901 _GLIBCXX20_CONSTEXPR
1903 _M_check_len(size_type __n,
const char* __s)
const
1906 __throw_length_error(__N(__s));
1913 static _GLIBCXX20_CONSTEXPR size_type
1914 _S_check_init_len(size_type __n,
const allocator_type& __a)
1916 if (__n > _S_max_size(_Tp_alloc_type(__a)))
1917 __throw_length_error(
1918 __N(
"cannot create std::vector larger than max_size()"));
1922 static _GLIBCXX20_CONSTEXPR size_type
1923 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1928 const size_t __diffmax
1929 = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max /
sizeof(_Tp);
1931 return (
std::min)(__diffmax, __allocmax);
1938 _GLIBCXX20_CONSTEXPR
1940 _M_erase_at_end(pointer __pos) _GLIBCXX_NOEXCEPT
1942 if (size_type __n = this->_M_impl._M_finish - __pos)
1945 _M_get_Tp_allocator());
1946 this->_M_impl._M_finish = __pos;
1947 _GLIBCXX_ASAN_ANNOTATE_SHRINK(__n);
1951 _GLIBCXX20_CONSTEXPR
1953 _M_erase(iterator __position);
1955 _GLIBCXX20_CONSTEXPR
1957 _M_erase(iterator __first, iterator __last);
1959#if __cplusplus >= 201103L
1964 _GLIBCXX20_CONSTEXPR
1969 this->_M_impl._M_swap_data(__x._M_impl);
1970 __tmp._M_impl._M_swap_data(__x._M_impl);
1971 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
1976 _GLIBCXX20_CONSTEXPR
1980 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
1986 this->_M_assign_aux(std::make_move_iterator(__x.begin()),
1987 std::make_move_iterator(__x.end()),
1994 template<
typename _Up>
1995 _GLIBCXX20_CONSTEXPR
1997 _M_data_ptr(_Up* __ptr)
const _GLIBCXX_NOEXCEPT
2000#if __cplusplus >= 201103L
2001 template<
typename _Ptr>
2002 _GLIBCXX20_CONSTEXPR
2003 typename std::pointer_traits<_Ptr>::element_type*
2004 _M_data_ptr(_Ptr __ptr)
const
2005 {
return empty() ? nullptr : std::__to_address(__ptr); }
2007 template<
typename _Up>
2009 _M_data_ptr(_Up* __ptr) _GLIBCXX_NOEXCEPT
2012 template<
typename _Ptr>
2014 _M_data_ptr(_Ptr __ptr)
2015 {
return empty() ? (value_type*)0 : __ptr.operator->(); }
2017 template<
typename _Ptr>
2019 _M_data_ptr(_Ptr __ptr)
const
2020 {
return empty() ? (
const value_type*)0 : __ptr.operator->(); }
2024#if __cpp_deduction_guides >= 201606
2025 template<
typename _InputIterator,
typename _ValT
2026 =
typename iterator_traits<_InputIterator>::value_type,
2027 typename _Allocator = allocator<_ValT>,
2028 typename = _RequireInputIter<_InputIterator>,
2029 typename = _RequireAllocator<_Allocator>>
2030 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
2031 -> vector<_ValT, _Allocator>;
2044 template<
typename _Tp,
typename _Alloc>
2045 _GLIBCXX20_CONSTEXPR
2051#if __cpp_lib_three_way_comparison
2063 template<
typename _Tp,
typename _Alloc>
2064 _GLIBCXX20_CONSTEXPR
2065 inline __detail::__synth3way_t<_Tp>
2070 __detail::__synth3way);
2084 template<
typename _Tp,
typename _Alloc>
2086 operator<(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2087 {
return std::lexicographical_compare(__x.begin(), __x.end(),
2088 __y.begin(), __y.end()); }
2091 template<
typename _Tp,
typename _Alloc>
2093 operator!=(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2094 {
return !(__x == __y); }
2097 template<
typename _Tp,
typename _Alloc>
2099 operator>(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2100 {
return __y < __x; }
2103 template<
typename _Tp,
typename _Alloc>
2105 operator<=(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2106 {
return !(__y < __x); }
2109 template<
typename _Tp,
typename _Alloc>
2111 operator>=(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2112 {
return !(__x < __y); }
2116 template<
typename _Tp,
typename _Alloc>
2117 _GLIBCXX20_CONSTEXPR
2120 _GLIBCXX_NOEXCEPT_IF(
noexcept(__x.swap(__y)))
2123_GLIBCXX_END_NAMESPACE_CONTAINER
2125#if __cplusplus >= 201703L
2126 namespace __detail::__variant
2128 template<
typename>
struct _Never_valueless_alt;
2132 template<
typename _Tp,
typename _Alloc>
2133 struct _Never_valueless_alt<_GLIBCXX_STD_C::vector<_Tp, _Alloc>>
2139_GLIBCXX_END_NAMESPACE_VERSION
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr auto lexicographical_compare_three_way(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _Comp __comp) -> decltype(__comp(*__first1, *__first2))
Performs dictionary comparison on ranges.
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)
is_nothrow_default_constructible
is_nothrow_move_assignable
typename __detected_or_t< is_empty< _Tp_alloc_type >, __equal, _Tp_alloc_type >::type 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.