94 rebind<_Tp>::other _Tp_alloc_type;
95 typedef typename __gnu_cxx::__alloc_traits<_Tp_alloc_type>::pointer
98 struct _Vector_impl_data
102 pointer _M_end_of_storage;
105 _Vector_impl_data() _GLIBCXX_NOEXCEPT
106 : _M_start(), _M_finish(), _M_end_of_storage()
109#if __cplusplus >= 201103L
111 _Vector_impl_data(_Vector_impl_data&& __x) noexcept
112 : _M_start(__x._M_start), _M_finish(__x._M_finish),
113 _M_end_of_storage(__x._M_end_of_storage)
114 { __x._M_start = __x._M_finish = __x._M_end_of_storage = pointer(); }
119 _M_copy_data(_Vector_impl_data
const& __x) _GLIBCXX_NOEXCEPT
121 _M_start = __x._M_start;
122 _M_finish = __x._M_finish;
123 _M_end_of_storage = __x._M_end_of_storage;
128 _M_swap_data(_Vector_impl_data& __x) _GLIBCXX_NOEXCEPT
132 _Vector_impl_data __tmp;
133 __tmp._M_copy_data(*
this);
135 __x._M_copy_data(__tmp);
140 :
public _Tp_alloc_type,
public _Vector_impl_data
143 _Vector_impl() _GLIBCXX_NOEXCEPT_IF(
145#if __cpp_lib_concepts
146 requires is_default_constructible_v<_Tp_alloc_type>
152 _Vector_impl(_Tp_alloc_type
const& __a) _GLIBCXX_NOEXCEPT
153 : _Tp_alloc_type(__a)
156#if __cplusplus >= 201103L
160 _Vector_impl(_Vector_impl&& __x) noexcept
165 _Vector_impl(_Tp_alloc_type&& __a) noexcept
170 _Vector_impl(_Tp_alloc_type&& __a, _Vector_impl&& __rv) noexcept
175#if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR
176 template<
typename = _Tp_alloc_type>
182 static _GLIBCXX20_CONSTEXPR
void
184 static _GLIBCXX20_CONSTEXPR
void
185 _S_on_dealloc(_Vector_impl&) { }
187 typedef _Vector_impl& _Reinit;
191 _GLIBCXX20_CONSTEXPR _Grow(_Vector_impl&,
size_type) { }
192 _GLIBCXX20_CONSTEXPR
void _M_grew(
size_type) { }
197 template<
typename _Up>
205 static _GLIBCXX20_CONSTEXPR
void
206 _S_adjust(_Vector_impl& __impl, pointer __prev, pointer __curr)
208#if __cpp_lib_is_constant_evaluated
209 if (std::is_constant_evaluated())
212 __sanitizer_annotate_contiguous_container(__impl._M_start,
213 __impl._M_end_of_storage, __prev, __curr);
216 static _GLIBCXX20_CONSTEXPR
void
217 _S_grow(_Vector_impl& __impl,
size_type __n)
218 { _S_adjust(__impl, __impl._M_finish, __impl._M_finish + __n); }
220 static _GLIBCXX20_CONSTEXPR
void
221 _S_shrink(_Vector_impl& __impl,
size_type __n)
222 { _S_adjust(__impl, __impl._M_finish + __n, __impl._M_finish); }
224 static _GLIBCXX20_CONSTEXPR
void
225 _S_on_dealloc(_Vector_impl& __impl)
228 _S_adjust(__impl, __impl._M_finish, __impl._M_end_of_storage);
234 explicit _GLIBCXX20_CONSTEXPR
235 _Reinit(_Vector_impl& __impl) : _M_impl(__impl)
238 _S_on_dealloc(_M_impl);
245 if (_M_impl._M_start)
246 _S_adjust(_M_impl, _M_impl._M_end_of_storage,
250 _Vector_impl& _M_impl;
252#if __cplusplus >= 201103L
253 _Reinit(
const _Reinit&) =
delete;
254 _Reinit& operator=(
const _Reinit&) =
delete;
262 _Grow(_Vector_impl& __impl,
size_type __n)
263 : _M_impl(__impl), _M_n(__n)
264 { _S_grow(_M_impl, __n); }
267 ~_Grow() {
if (_M_n) _S_shrink(_M_impl, _M_n); }
270 void _M_grew(
size_type __n) { _M_n -= __n; }
272#if __cplusplus >= 201103L
273 _Grow(
const _Grow&) =
delete;
274 _Grow& operator=(
const _Grow&) =
delete;
277 _Vector_impl& _M_impl;
282#define _GLIBCXX_ASAN_ANNOTATE_REINIT \
283 typename _Base::_Vector_impl::template _Asan<>::_Reinit const \
284 __attribute__((__unused__)) __reinit_guard(this->_M_impl)
285#define _GLIBCXX_ASAN_ANNOTATE_GROW(n) \
286 typename _Base::_Vector_impl::template _Asan<>::_Grow \
287 __attribute__((__unused__)) __grow_guard(this->_M_impl, (n))
288#define _GLIBCXX_ASAN_ANNOTATE_GREW(n) __grow_guard._M_grew(n)
289#define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n) \
290 _Base::_Vector_impl::template _Asan<>::_S_shrink(this->_M_impl, n)
291#define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC \
292 _Base::_Vector_impl::template _Asan<>::_S_on_dealloc(this->_M_impl)
294#define _GLIBCXX_ASAN_ANNOTATE_REINIT
295#define _GLIBCXX_ASAN_ANNOTATE_GROW(n)
296#define _GLIBCXX_ASAN_ANNOTATE_GREW(n)
297#define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n)
298#define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC
303 typedef _Alloc allocator_type;
307 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
308 {
return this->_M_impl; }
311 const _Tp_alloc_type&
312 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
313 {
return this->_M_impl; }
318 {
return allocator_type(_M_get_Tp_allocator()); }
320 static _GLIBCXX20_CONSTEXPR
size_t
321 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
326 const size_t __diffmax =
327 __gnu_cxx::__numeric_traits<ptrdiff_t>::__max /
sizeof(_Tp);
328 const size_t __allocmax =
330 return (
std::min)(__diffmax, __allocmax);
333#if __cplusplus >= 201103L
334 _Vector_base() =
default;
340 _Vector_base(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
344#if !_GLIBCXX_INLINE_VERSION
346 _Vector_base(
size_t __n)
348 { _M_create_storage(__n); }
352 _Vector_base(
size_t __n,
const allocator_type& __a)
354 { _M_create_storage(__n); }
356#if __cplusplus >= 201103L
357 _Vector_base(_Vector_base&&) =
default;
360# if !_GLIBCXX_INLINE_VERSION
362 _Vector_base(_Tp_alloc_type&& __a) noexcept
366 _Vector_base(_Vector_base&& __x,
const allocator_type& __a)
369 if (__x.get_allocator() == __a)
370 this->_M_impl._M_swap_data(__x._M_impl);
373 size_t __n = __x._M_impl._M_finish - __x._M_impl._M_start;
374 _M_create_storage(__n);
380 _Vector_base(
const allocator_type& __a, _Vector_base&& __x)
381 : _M_impl(_Tp_alloc_type(__a), std::
move(__x._M_impl))
386 ~_Vector_base() _GLIBCXX_NOEXCEPT
388 ptrdiff_t __n = _M_impl._M_end_of_storage - _M_impl._M_start;
390 __builtin_unreachable();
391 _M_deallocate(_M_impl._M_start,
size_t(__n));
395 _Vector_impl _M_impl;
399 _M_allocate(
size_t __n)
401 typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr;
402 return __n != 0 ? _Tr::allocate(_M_impl, __n) : pointer();
405 struct _Alloc_result { pointer __ptr;
size_t __count; };
409 _M_allocate_at_least(
size_t __n)
411 typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr;
413 if (__builtin_expect(__n != 0,
true))
415#ifdef __glibcxx_allocate_at_least
416 if constexpr (
requires { _Tr::allocate_at_least(_M_impl, __n); })
418 auto [__ptr, __count] = _Tr::allocate_at_least(_M_impl, __n);
421 size_t __max = _S_max_size(_M_get_Tp_allocator());
422 if (__builtin_expect(__count > __max,
false))
425 __r = { __ptr, __count };
430 __r.__ptr = _Tr::allocate(_M_impl, __n);
436 __r.__ptr = pointer();
444 _M_deallocate(pointer __p,
size_t __n)
446 typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr;
448 _Tr::deallocate(_M_impl, __p, __n);
455 _M_create_storage(
size_t __n)
457 _Alloc_result __r = this->_M_allocate_at_least(__n);
458 this->_M_impl._M_finish = this->_M_impl._M_start = __r.__ptr;
459 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __r.__count;
462#if __glibcxx_containers_ranges
468 template<ranges::input_range _Rg>
470 _M_append_range_to(_Rg&& __rg, pointer& __ptr)
472 __ptr = std::__uninitialized_copy_a(ranges::begin(__rg),
474 __ptr, _M_get_Tp_allocator());
479 template<ranges::input_range _Rg>
481 _M_append_range(_Rg&& __rg)
510 class vector :
protected _Vector_base<_Tp, _Alloc>
512#ifdef _GLIBCXX_CONCEPT_CHECKS
514 typedef typename _Alloc::value_type _Alloc_value_type;
515# if __cplusplus < 201103L
516 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
518 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
521#if __cplusplus >= 201103L
523 "std::vector must have a non-const, non-volatile value_type");
524# if __cplusplus > 201703L || defined __STRICT_ANSI__
526 "std::vector must have the same value_type as its allocator");
530 typedef _Vector_base<_Tp, _Alloc> _Base;
531 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
533 typedef typename _Base::_Alloc_result _Alloc_result;
536 typedef _Tp value_type;
537 typedef typename _Base::pointer pointer;
538 typedef typename _Alloc_traits::const_pointer const_pointer;
539 typedef typename _Alloc_traits::reference reference;
540 typedef typename _Alloc_traits::const_reference const_reference;
541 typedef __gnu_cxx::__normal_iterator<pointer, vector> iterator;
542 typedef __gnu_cxx::__normal_iterator<const_pointer, vector>
546 typedef size_t size_type;
547 typedef ptrdiff_t difference_type;
548 typedef _Alloc allocator_type;
551#if __cplusplus >= 201103L
552 static constexpr bool
561 static constexpr bool
565 static constexpr bool
571 return _S_nothrow_relocate(__is_move_insertable<_Tp_alloc_type>{});
574 static _GLIBCXX20_CONSTEXPR pointer
575 _S_relocate(pointer __first, pointer __last, pointer __result,
576 _Tp_alloc_type& __alloc)
noexcept
578#pragma GCC diagnostic push
579#pragma GCC diagnostic ignored "-Wc++17-extensions"
580 if constexpr (_S_use_relocate())
581 return std::__relocate_a(__first, __last, __result, __alloc);
584#pragma GCC diagnostic pop
589 using _Base::_M_allocate;
590 using _Base::_M_allocate_at_least;
591 using _Base::_M_deallocate;
592 using _Base::_M_impl;
593 using _Base::_M_get_Tp_allocator;
602#if __cplusplus >= 201103L
614 vector(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
617#if __cplusplus >= 201103L
628 vector(size_type __n,
const allocator_type& __a = allocator_type())
629 : _Base(_S_check_init_len(__n, __a), __a)
630 { _M_default_initialize(__n); }
641 vector(size_type __n,
const value_type& __value,
642 const allocator_type& __a = allocator_type())
643 : _Base(_S_check_init_len(__n, __a), __a)
644 { _M_fill_initialize(__n, __value); }
656 const allocator_type& __a = allocator_type())
657 : _Base(_S_check_init_len(__n, __a), __a)
658 { _M_fill_initialize(__n, __value); }
675 _Alloc_traits::_S_select_on_copy(__x._M_get_Tp_allocator()))
677 this->_M_impl._M_finish =
678 std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
679 this->_M_impl._M_start,
680 _M_get_Tp_allocator());
683#if __cplusplus >= 201103L
696 vector(const
vector& __x, const __type_identity_t<allocator_type>& __a)
697 : _Base(__x.
size(), __a)
699 this->_M_impl._M_finish =
700 std::__uninitialized_copy_a(__x.begin(), __x.end(),
701 this->_M_impl._M_start,
702 _M_get_Tp_allocator());
712 vector(vector&& __rv,
const allocator_type& __m, false_type)
715 if (__rv.get_allocator() == __m)
716 this->_M_impl._M_swap_data(__rv._M_impl);
717 else if (!__rv.empty())
719 this->_M_create_storage(__rv.size());
720 this->_M_impl._M_finish =
721 std::__uninitialized_move_a(__rv.begin(), __rv.end(),
722 this->_M_impl._M_start,
723 _M_get_Tp_allocator());
735 :
vector(
std::
move(__rv), __m, typename _Alloc_traits::is_always_equal{})
751 const allocator_type& __a = allocator_type())
754 _M_range_initialize_n(__l.begin(), __l.end(), __l.size());
774#if __cplusplus >= 201103L
775 template<
typename _InputIterator,
776 typename = std::_RequireInputIter<_InputIterator>>
778 vector(_InputIterator __first, _InputIterator __last,
779 const allocator_type& __a = allocator_type())
782#if __glibcxx_concepts
783 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>
784 || forward_iterator<_InputIterator>)
787 =
static_cast<size_type
>(ranges::distance(__first, __last));
788 _M_range_initialize_n(__first, __last, __n);
793 _M_range_initialize(__first, __last,
794 std::__iterator_category(__first));
797 template<
typename _InputIterator>
798 vector(_InputIterator __first, _InputIterator __last,
799 const allocator_type& __a = allocator_type())
803 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
804 _M_initialize_dispatch(__first, __last, _Integral());
808#if __glibcxx_containers_ranges
814 template<__detail::__container_compatible_range<_Tp> _Rg>
816 vector(from_range_t, _Rg&& __rg,
const _Alloc& __a = _Alloc())
819 if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>)
821 const auto __n =
static_cast<size_type
>(ranges::distance(__rg));
822 _M_range_initialize_n(ranges::begin(__rg), ranges::end(__rg),
827 auto __first = ranges::begin(__rg);
828 const auto __last = ranges::end(__rg);
829 for (; __first != __last; ++__first)
830 emplace_back(*__first);
844 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
845 _M_get_Tp_allocator());
846 _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC;
862#if __cplusplus >= 201103L
877 constexpr bool __move_storage =
878 _Alloc_traits::_S_propagate_on_move_assign()
879 || _Alloc_traits::_S_always_equal();
880 _M_move_assign(
std::move(__x), __bool_constant<__move_storage>());
899 this->_M_assign_aux(__l.begin(), __l.end(),
917 assign(size_type __n,
const value_type& __val)
918 { _M_fill_assign(__n, __val); }
932#if __cplusplus >= 201103L
933 template<
typename _InputIterator,
934 typename = std::_RequireInputIter<_InputIterator>>
937 assign(_InputIterator __first, _InputIterator __last)
938 { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
940 template<
typename _InputIterator>
942 assign(_InputIterator __first, _InputIterator __last)
945 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
946 _M_assign_dispatch(__first, __last, _Integral());
950#if __cplusplus >= 201103L
966 this->_M_assign_aux(__l.begin(), __l.end(),
971#if __glibcxx_containers_ranges
978 template<__detail::__container_compatible_range<_Tp> _Rg>
980 assign_range(_Rg&& __rg)
986 const auto __n =
size_type(ranges::distance(__rg));
989 auto __res = ranges::copy(__rg, this->_M_impl._M_start);
990 _M_erase_at_end(__res.out);
995 auto __first = ranges::copy_n(ranges::begin(__rg),
size(),
996 this->_M_impl._M_start).in;
997 [[maybe_unused]]
const auto __diff = __n -
size();
998 _GLIBCXX_ASAN_ANNOTATE_GROW(__diff);
999 _Base::_M_append_range(ranges::subrange(
std::move(__first),
1000 ranges::end(__rg)));
1001 _GLIBCXX_ASAN_ANNOTATE_GREW(__diff);
1005 auto __first = ranges::begin(__rg);
1006 const auto __last = ranges::end(__rg);
1007 pointer __ptr = this->_M_impl._M_start;
1008 pointer
const __end = this->_M_impl._M_finish;
1010 while (__ptr < __end && __first != __last)
1017 if (__first == __last)
1018 _M_erase_at_end(__ptr);
1022 emplace_back(*__first);
1023 while (++__first != __last);
1030 using _Base::get_allocator;
1038 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1041 {
return iterator(this->_M_impl._M_start); }
1048 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1051 {
return const_iterator(this->_M_impl._M_start); }
1058 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1061 {
return iterator(this->_M_impl._M_finish); }
1068 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1071 {
return const_iterator(this->_M_impl._M_finish); }
1078 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1081 {
return reverse_iterator(
end()); }
1088 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1089 const_reverse_iterator
1091 {
return const_reverse_iterator(
end()); }
1098 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1101 {
return reverse_iterator(
begin()); }
1108 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1109 const_reverse_iterator
1111 {
return const_reverse_iterator(
begin()); }
1113#if __cplusplus >= 201103L
1119 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1122 {
return const_iterator(this->_M_impl._M_start); }
1129 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1132 {
return const_iterator(this->_M_impl._M_finish); }
1139 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1140 const_reverse_iterator
1142 {
return const_reverse_iterator(
end()); }
1149 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1150 const_reverse_iterator
1152 {
return const_reverse_iterator(
begin()); }
1157 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1161 ptrdiff_t __dif = this->_M_impl._M_finish - this->_M_impl._M_start;
1163 __builtin_unreachable();
1164 return size_type(__dif);
1168 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1171 {
return _Base::_S_max_size(_M_get_Tp_allocator()); }
1173#if __cplusplus >= 201103L
1183 _GLIBCXX20_CONSTEXPR
1187 if (__new_size >
size())
1188 _M_default_append(__new_size -
size());
1189 else if (__new_size <
size())
1190 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1204 _GLIBCXX20_CONSTEXPR
1206 resize(size_type __new_size,
const value_type& __x)
1208 if (__new_size >
size())
1209 _M_fill_append(__new_size -
size(), __x);
1210 else if (__new_size <
size())
1211 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1225 _GLIBCXX20_CONSTEXPR
1229 if (__new_size >
size())
1230 _M_fill_append(__new_size -
size(), __x);
1231 else if (__new_size <
size())
1232 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1236#if __cplusplus >= 201103L
1238 _GLIBCXX20_CONSTEXPR
1241 { _M_shrink_to_fit(); }
1248 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1252 ptrdiff_t __dif = this->_M_impl._M_end_of_storage
1253 - this->_M_impl._M_start;
1255 __builtin_unreachable();
1256 return size_type(__dif);
1263 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1285 _GLIBCXX20_CONSTEXPR
1301 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1305 __glibcxx_requires_subscript(__n);
1306 return *(this->_M_impl._M_start + __n);
1320 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1324 __glibcxx_requires_subscript(__n);
1325 return *(this->_M_impl._M_start + __n);
1330 _GLIBCXX20_CONSTEXPR
1334 if (__n >= this->
size())
1335 __throw_out_of_range_fmt(__N(
"vector::_M_range_check: __n "
1336 "(which is %zu) >= this->size() "
1353 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1358 return (*
this)[__n];
1372 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1377 return (*
this)[__n];
1384 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1388 __glibcxx_requires_nonempty();
1396 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1400 __glibcxx_requires_nonempty();
1408 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1412 __glibcxx_requires_nonempty();
1413 return *(
end() - 1);
1420 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1424 __glibcxx_requires_nonempty();
1425 return *(
end() - 1);
1435 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1438 {
return _M_data_ptr(this->_M_impl._M_start); }
1440 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1442 data() const _GLIBCXX_NOEXCEPT
1443 {
return _M_data_ptr(this->_M_impl._M_start); }
1456 _GLIBCXX20_CONSTEXPR
1460 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
1462 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
1463 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
1465 ++this->_M_impl._M_finish;
1466 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
1469 _M_realloc_append(__x);
1472#if __cplusplus >= 201103L
1473 _GLIBCXX20_CONSTEXPR
1478 template<
typename... _Args>
1479#if __cplusplus > 201402L
1480 _GLIBCXX20_CONSTEXPR
1485 emplace_back(_Args&&... __args);
1497 _GLIBCXX20_CONSTEXPR
1501 __glibcxx_requires_nonempty();
1502 --this->_M_impl._M_finish;
1503 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
1504 _GLIBCXX_ASAN_ANNOTATE_SHRINK(1);
1507#if __cplusplus >= 201103L
1520 template<
typename... _Args>
1521 _GLIBCXX20_CONSTEXPR
1523 emplace(const_iterator __position, _Args&&... __args)
1537 _GLIBCXX20_CONSTEXPR
1539 insert(const_iterator __position,
const value_type& __x);
1553 insert(iterator __position,
const value_type& __x);
1556#if __cplusplus >= 201103L
1568 _GLIBCXX20_CONSTEXPR
1570 insert(const_iterator __position, value_type&& __x)
1571 {
return _M_insert_rval(__position,
std::move(__x)); }
1586 _GLIBCXX20_CONSTEXPR
1590 auto __offset = __position -
cbegin();
1591 _M_range_insert(
begin() + __offset, __l.begin(), __l.end(),
1593 return begin() + __offset;
1597#if __cplusplus >= 201103L
1612 _GLIBCXX20_CONSTEXPR
1614 insert(const_iterator __position, size_type __n,
const value_type& __x)
1616 difference_type __offset = __position -
cbegin();
1617 _M_fill_insert(
begin() + __offset, __n, __x);
1618 return begin() + __offset;
1636 { _M_fill_insert(__position, __n, __x); }
1639#if __cplusplus >= 201103L
1655 template<
typename _InputIterator,
1656 typename = std::_RequireInputIter<_InputIterator>>
1657 _GLIBCXX20_CONSTEXPR
1659 insert(const_iterator __position, _InputIterator __first,
1660 _InputIterator __last)
1662 difference_type __offset = __position -
cbegin();
1663 _M_range_insert(
begin() + __offset, __first, __last,
1664 std::__iterator_category(__first));
1665 return begin() + __offset;
1682 template<
typename _InputIterator>
1685 _InputIterator __last)
1688 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1689 _M_insert_dispatch(__position, __first, __last, _Integral());
1693#if __glibcxx_containers_ranges
1702 template<__detail::__container_compatible_range<_Tp> _Rg>
1704 insert_range(const_iterator __pos, _Rg&& __rg);
1711 template<__detail::__container_compatible_range<_Tp> _Rg>
1713 append_range(_Rg&& __rg)
1718 if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>)
1720 const auto __n = size_type(ranges::distance(__rg));
1727 const auto __sz =
size();
1728 const auto __capacity =
capacity();
1729 if ((__capacity - __sz) >= __n)
1731 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
1732 _Base::_M_append_range(__rg);
1733 _GLIBCXX_ASAN_ANNOTATE_GREW(__n);
1737 const size_type __ask = _M_check_len(__n,
"vector::append_range");
1739 pointer __old_start = this->_M_impl._M_start;
1740 pointer __old_finish = this->_M_impl._M_finish;
1742 auto [__ptr, __got] = this->_M_allocate_at_least(__ask);
1743 const pointer __start = __ptr;
1744 const pointer __mid = __start + __sz;
1745 const pointer __back = __mid + __n;
1746 _Guard_alloc __guard(__start, __got, *
this);
1747 allocator_type& __a = _M_get_Tp_allocator();
1748 std::__uninitialized_copy_a(ranges::begin(__rg),
1752 if constexpr (_S_use_relocate())
1753 _S_relocate(__old_start, __old_finish, __start, __a);
1759 pointer _M_first, _M_last;
1760 _Tp_alloc_type& _M_alloc;
1763 _Guard_elts(pointer __f, pointer __l, _Tp_alloc_type& __a)
1764 : _M_first(__f), _M_last(__l), _M_alloc(__a)
1771 _Guard_elts(_Guard_elts&&) =
delete;
1773 _Guard_elts __guard_elts{__mid, __back, __a};
1775 std::__uninitialized_move_a(__old_start, __old_finish,
1779 __guard_elts._M_first = __old_start;
1780 __guard_elts._M_last = __old_finish;
1784 __guard._M_storage = __old_start;
1785 __guard._M_len = __capacity;
1787 this->_M_impl._M_start = __start;
1788 this->_M_impl._M_finish = __back;
1789 this->_M_impl._M_end_of_storage = __start + __got;
1793 auto __first = ranges::begin(__rg);
1794 const auto __last = ranges::end(__rg);
1798 __first != __last && __free > 0;
1799 ++__first, (void) --__free)
1800 emplace_back(*__first);
1802 if (__first == __last)
1806 vector __tmp(_M_get_Tp_allocator());
1807 for (; __first != __last; ++__first)
1808 __tmp.emplace_back(*__first);
1809 reserve(_M_check_len(__tmp.size(),
"vector::append_range"));
1810 ranges::subrange __r(std::make_move_iterator(__tmp.begin()),
1811 std::make_move_iterator(__tmp.end()));
1832 _GLIBCXX20_CONSTEXPR
1834#if __cplusplus >= 201103L
1836 {
return _M_erase(
begin() + (__position -
cbegin())); }
1839 {
return _M_erase(__position); }
1860 _GLIBCXX20_CONSTEXPR
1862#if __cplusplus >= 201103L
1863 erase(const_iterator __first, const_iterator __last)
1865 const auto __beg =
begin();
1866 const auto __cbeg =
cbegin();
1867 return _M_erase(__beg + (__first - __cbeg), __beg + (__last - __cbeg));
1871 {
return _M_erase(__first, __last); }
1885 _GLIBCXX20_CONSTEXPR
1889#if __cplusplus >= 201103L
1890 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1891 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1893 this->_M_impl._M_swap_data(__x._M_impl);
1894 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1895 __x._M_get_Tp_allocator());
1904 _GLIBCXX20_CONSTEXPR
1907 { _M_erase_at_end(this->_M_impl._M_start); }
1917 _GLIBCXX20_CONSTEXPR
1918 _Guard_alloc(pointer __s,
size_type __l, _Base& __vect)
1919 : _M_storage(__s), _M_len(__l), _M_vect(__vect)
1922 _GLIBCXX20_CONSTEXPR
1926 _M_vect._M_deallocate(_M_storage, _M_len);
1929 _GLIBCXX20_CONSTEXPR
1933 pointer __res = _M_storage;
1934 _M_storage = pointer();
1939 _Guard_alloc(
const _Guard_alloc&);
1948 template<
typename _ForwardIterator>
1949 _GLIBCXX20_CONSTEXPR
1952 _ForwardIterator __first, _ForwardIterator __last)
1954 _Alloc_result __r = this->_M_allocate_at_least(__n);
1955 _Guard_alloc __guard(__r.__ptr, __r.__count, *
this);
1956 std::__uninitialized_copy_a
1957 (__first, __last, __guard._M_storage, _M_get_Tp_allocator());
1958 (void) __guard._M_release();
1962 _GLIBCXX20_CONSTEXPR
void
1963 _M_replace_storage(pointer __start, pointer __end,
size_type __cap)
1965 _GLIBCXX_ASAN_ANNOTATE_REINIT;
1966 _M_deallocate(this->_M_impl._M_start,
1967 this->_M_impl._M_end_of_storage - this->_M_impl._M_start);
1968 this->_M_impl._M_start = __start;
1969 this->_M_impl._M_finish = __end;
1970 this->_M_impl._M_end_of_storage = __start + __cap;
1973 template<
typename _ForwardIterator>
1974 _GLIBCXX20_CONSTEXPR
1976 _M_replace_with(size_type __n,
1977 _ForwardIterator __first, _ForwardIterator __last)
1981 this->_M_impl._M_finish, _M_get_Tp_allocator());
1982 _M_replace_storage(__r.__ptr, __r.__ptr + __n, __r.__count);
1989#if __cplusplus < 201103L
1992 template<
typename _Integer>
1994 _M_initialize_dispatch(_Integer __int_n, _Integer __value, __true_type)
1996 const size_type __n =
static_cast<size_type
>(__int_n);
1999 _M_allocate(_S_check_init_len(__n, _M_get_Tp_allocator()));
2000 this->_M_impl._M_start = __start;
2001 this->_M_impl._M_end_of_storage = __start + __n;
2002 _M_fill_initialize(__n, __value);
2006 template<
typename _InputIterator>
2008 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
2011 _M_range_initialize(__first, __last,
2012 std::__iterator_category(__first));
2017 template<
typename _InputIterator>
2018 _GLIBCXX20_CONSTEXPR
2020 _M_range_initialize(_InputIterator __first, _InputIterator __last,
2021 std::input_iterator_tag)
2024 for (; __first != __last; ++__first)
2025#
if __cplusplus >= 201103L
2026 emplace_back(*__first);
2032 __throw_exception_again;
2037 template<
typename _ForwardIterator>
2038 _GLIBCXX20_CONSTEXPR
2040 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
2041 std::forward_iterator_tag)
2043 _M_range_initialize_n(__first, __last,
2047 template<
typename _Iterator,
typename _Sentinel>
2048 _GLIBCXX20_CONSTEXPR
2050 _M_range_initialize_n(_Iterator __first, _Sentinel __last,
2053 _Alloc_result __r = this->_M_allocate_at_least(
2054 _S_check_init_len(__n, _M_get_Tp_allocator()));
2055 pointer __start = __r.__ptr;
2056 this->_M_impl._M_start = this->_M_impl._M_finish = __start;
2057 this->_M_impl._M_end_of_storage = __start + __r.__count;
2058 this->_M_impl._M_finish
2059 = std::__uninitialized_copy_a(_GLIBCXX_MOVE(__first), __last,
2060 __start, _M_get_Tp_allocator());
2065 _GLIBCXX20_CONSTEXPR
2067 _M_fill_initialize(size_type __n,
const value_type& __value)
2069 this->_M_impl._M_finish =
2070 std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value,
2071 _M_get_Tp_allocator());
2074#if __cplusplus >= 201103L
2076 _GLIBCXX20_CONSTEXPR
2078 _M_default_initialize(size_type __n)
2080 this->_M_impl._M_finish =
2081 std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
2082 _M_get_Tp_allocator());
2093 template<
typename _Integer>
2094 _GLIBCXX20_CONSTEXPR
2096 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
2097 { _M_fill_assign(__n, __val); }
2100 template<
typename _InputIterator>
2101 _GLIBCXX20_CONSTEXPR
2103 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
2105 { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
2108 template<
typename _InputIterator>
2109 _GLIBCXX20_CONSTEXPR
2111 _M_assign_aux(_InputIterator __first, _InputIterator __last,
2112 std::input_iterator_tag);
2115 template<
typename _ForwardIterator>
2116 _GLIBCXX20_CONSTEXPR
2118 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
2119 std::forward_iterator_tag);
2123 _GLIBCXX20_CONSTEXPR
2125 _M_fill_assign(size_type __n,
const value_type& __val);
2133 template<
typename _Integer>
2134 _GLIBCXX20_CONSTEXPR
2136 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
2138 { _M_fill_insert(__pos, __n, __val); }
2141 template<
typename _InputIterator>
2142 _GLIBCXX20_CONSTEXPR
2144 _M_insert_dispatch(iterator __pos, _InputIterator __first,
2145 _InputIterator __last, __false_type)
2147 _M_range_insert(__pos, __first, __last,
2148 std::__iterator_category(__first));
2152 template<
typename _InputIterator>
2153 _GLIBCXX20_CONSTEXPR
2155 _M_range_insert(iterator __pos, _InputIterator __first,
2156 _InputIterator __last, std::input_iterator_tag);
2159 template<
typename _ForwardIterator>
2160 _GLIBCXX20_CONSTEXPR
2162 _M_range_insert(iterator __pos, _ForwardIterator __first,
2163 _ForwardIterator __last, std::forward_iterator_tag);
2167 _GLIBCXX20_CONSTEXPR
2169 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
2172 _GLIBCXX20_CONSTEXPR
2174 _M_fill_append(size_type __n,
const value_type& __x);
2176#if __cplusplus >= 201103L
2178 _GLIBCXX20_CONSTEXPR
2180 _M_default_append(size_type __n);
2182 _GLIBCXX20_CONSTEXPR
2187#if __cplusplus < 201103L
2190 _M_insert_aux(iterator __position,
const value_type& __x);
2193 _M_realloc_insert(iterator __position,
const value_type& __x);
2196 _M_realloc_append(
const value_type& __x);
2200 struct _Temporary_value
2202 template<
typename... _Args>
2203 _GLIBCXX20_CONSTEXPR
explicit
2204 _Temporary_value(
vector* __vec, _Args&&... __args) : _M_this(__vec)
2206 _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(),
2210 _GLIBCXX20_CONSTEXPR
2212 { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); }
2214 _GLIBCXX20_CONSTEXPR value_type&
2215 _M_val() noexcept {
return _M_storage._M_val; }
2218 _GLIBCXX20_CONSTEXPR _Tp*
2223 constexpr _Storage() : _M_byte() { }
2224 _GLIBCXX20_CONSTEXPR ~_Storage() { }
2225 _Storage& operator=(
const _Storage&) =
delete;
2226 unsigned char _M_byte;
2231 _Storage _M_storage;
2236 template<
typename _Arg>
2237 _GLIBCXX20_CONSTEXPR
2239 _M_insert_aux(iterator __position, _Arg&& __arg);
2241 template<
typename... _Args>
2242 _GLIBCXX20_CONSTEXPR
2244 _M_realloc_insert(iterator __position, _Args&&... __args);
2246 template<
typename... _Args>
2247 _GLIBCXX20_CONSTEXPR
2249 _M_realloc_append(_Args&&... __args);
2252 _GLIBCXX20_CONSTEXPR
2254 _M_insert_rval(const_iterator __position, value_type&& __v);
2257 template<
typename... _Args>
2258 _GLIBCXX20_CONSTEXPR
2260 _M_emplace_aux(const_iterator __position, _Args&&... __args);
2263 _GLIBCXX20_CONSTEXPR
2265 _M_emplace_aux(const_iterator __position, value_type&& __v)
2266 {
return _M_insert_rval(__position,
std::move(__v)); }
2270 _GLIBCXX20_CONSTEXPR
2272 _M_check_len(size_type __n,
const char* __s)
const
2276 __throw_length_error(__N(__s));
2282 return size() + __n;
2286 static _GLIBCXX20_CONSTEXPR size_type
2287 _S_check_init_len(size_type __n,
const allocator_type& __a)
2289 if (__n > _Base::_S_max_size(_Tp_alloc_type(__a)))
2290 __throw_length_error(
2291 __N(
"cannot create std::vector larger than max_size()"));
2299 _GLIBCXX20_CONSTEXPR
2301 _M_erase_at_end(pointer __pos) _GLIBCXX_NOEXCEPT
2303 if (size_type __n = this->_M_impl._M_finish - __pos)
2306 _M_get_Tp_allocator());
2307 this->_M_impl._M_finish = __pos;
2308 _GLIBCXX_ASAN_ANNOTATE_SHRINK(__n);
2312 _GLIBCXX20_CONSTEXPR
2314 _M_erase(iterator __position);
2316 _GLIBCXX20_CONSTEXPR
2318 _M_erase(iterator __first, iterator __last);
2320#if __cplusplus >= 201103L
2325 _GLIBCXX20_CONSTEXPR
2330 this->_M_impl._M_swap_data(__x._M_impl);
2331 __tmp._M_impl._M_swap_data(__x._M_impl);
2332 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2337 _GLIBCXX20_CONSTEXPR
2341 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2347 this->_M_assign_aux(std::make_move_iterator(__x.begin()),
2348 std::make_move_iterator(__x.end()),
2349 std::random_access_iterator_tag());
2355 template<
typename _Up>
2356 _GLIBCXX20_CONSTEXPR
2358 _M_data_ptr(_Up* __ptr)
const _GLIBCXX_NOEXCEPT
2361#if __cplusplus >= 201103L
2362 template<
typename _Ptr>
2363 _GLIBCXX20_CONSTEXPR
2364 typename std::pointer_traits<_Ptr>::element_type*
2365 _M_data_ptr(_Ptr __ptr)
const
2366 {
return empty() ? nullptr : std::__to_address(__ptr); }
2368 template<
typename _Ptr>
2370 _M_data_ptr(_Ptr __ptr)
const
2371 {
return empty() ? (value_type*)0 : __ptr.operator->(); }