57 #define _STL_VECTOR_H 1 62 #if __cplusplus >= 201103L 65 #if __cplusplus >= 202002L 68 #if __glibcxx_concepts // C++ >= C++20 74 #if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR 76 __sanitizer_annotate_contiguous_container(
const void*,
const void*,
77 const void*,
const void*);
80 namespace std _GLIBCXX_VISIBILITY(default)
82 _GLIBCXX_BEGIN_NAMESPACE_VERSION
83 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
86 template<
typename _Tp,
typename _Alloc>
90 rebind<_Tp>::other _Tp_alloc_type;
91 typedef typename __gnu_cxx::__alloc_traits<_Tp_alloc_type>::pointer
94 struct _Vector_impl_data
98 pointer _M_end_of_storage;
101 _Vector_impl_data() _GLIBCXX_NOEXCEPT
102 : _M_start(), _M_finish(), _M_end_of_storage()
105 #if __cplusplus >= 201103L 107 _Vector_impl_data(_Vector_impl_data&& __x) noexcept
108 : _M_start(__x._M_start), _M_finish(__x._M_finish),
109 _M_end_of_storage(__x._M_end_of_storage)
110 { __x._M_start = __x._M_finish = __x._M_end_of_storage = pointer(); }
115 _M_copy_data(_Vector_impl_data
const& __x) _GLIBCXX_NOEXCEPT
117 _M_start = __x._M_start;
118 _M_finish = __x._M_finish;
119 _M_end_of_storage = __x._M_end_of_storage;
124 _M_swap_data(_Vector_impl_data& __x) _GLIBCXX_NOEXCEPT
128 _Vector_impl_data __tmp;
129 __tmp._M_copy_data(*
this);
131 __x._M_copy_data(__tmp);
136 :
public _Tp_alloc_type,
public _Vector_impl_data
139 _Vector_impl() _GLIBCXX_NOEXCEPT_IF(
141 #if __cpp_lib_concepts 142 requires is_default_constructible_v<_Tp_alloc_type>
148 _Vector_impl(_Tp_alloc_type
const& __a) _GLIBCXX_NOEXCEPT
149 : _Tp_alloc_type(__a)
152 #if __cplusplus >= 201103L 156 _Vector_impl(_Vector_impl&& __x) noexcept
161 _Vector_impl(_Tp_alloc_type&& __a) noexcept
166 _Vector_impl(_Tp_alloc_type&& __a, _Vector_impl&& __rv) noexcept
171 #if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR 172 template<
typename = _Tp_alloc_type>
176 ::size_type size_type;
178 static _GLIBCXX20_CONSTEXPR
void 179 _S_shrink(_Vector_impl&, size_type) { }
180 static _GLIBCXX20_CONSTEXPR
void 181 _S_on_dealloc(_Vector_impl&) { }
183 typedef _Vector_impl& _Reinit;
187 _GLIBCXX20_CONSTEXPR _Grow(_Vector_impl&, size_type) { }
188 _GLIBCXX20_CONSTEXPR
void _M_grew(size_type) { }
193 template<
typename _Up>
194 struct _Asan<allocator<_Up> >
197 ::size_type size_type;
201 static _GLIBCXX20_CONSTEXPR
void 202 _S_adjust(_Vector_impl& __impl, pointer __prev, pointer __curr)
204 #if __cpp_lib_is_constant_evaluated 205 if (std::is_constant_evaluated())
208 __sanitizer_annotate_contiguous_container(__impl._M_start,
209 __impl._M_end_of_storage, __prev, __curr);
212 static _GLIBCXX20_CONSTEXPR
void 213 _S_grow(_Vector_impl& __impl, size_type __n)
214 { _S_adjust(__impl, __impl._M_finish, __impl._M_finish + __n); }
216 static _GLIBCXX20_CONSTEXPR
void 217 _S_shrink(_Vector_impl& __impl, size_type __n)
218 { _S_adjust(__impl, __impl._M_finish + __n, __impl._M_finish); }
220 static _GLIBCXX20_CONSTEXPR
void 221 _S_on_dealloc(_Vector_impl& __impl)
224 _S_adjust(__impl, __impl._M_finish, __impl._M_end_of_storage);
230 explicit _GLIBCXX20_CONSTEXPR
231 _Reinit(_Vector_impl& __impl) : _M_impl(__impl)
234 _S_on_dealloc(_M_impl);
241 if (_M_impl._M_start)
242 _S_adjust(_M_impl, _M_impl._M_end_of_storage,
246 _Vector_impl& _M_impl;
248 #if __cplusplus >= 201103L 249 _Reinit(
const _Reinit&) =
delete;
250 _Reinit& operator=(
const _Reinit&) =
delete;
258 _Grow(_Vector_impl& __impl, size_type __n)
259 : _M_impl(__impl), _M_n(__n)
260 { _S_grow(_M_impl, __n); }
263 ~_Grow() {
if (_M_n) _S_shrink(_M_impl, _M_n); }
266 void _M_grew(size_type __n) { _M_n -= __n; }
268 #if __cplusplus >= 201103L 269 _Grow(
const _Grow&) =
delete;
270 _Grow& operator=(
const _Grow&) =
delete;
273 _Vector_impl& _M_impl;
278 #define _GLIBCXX_ASAN_ANNOTATE_REINIT \ 279 typename _Base::_Vector_impl::template _Asan<>::_Reinit const \ 280 __attribute__((__unused__)) __reinit_guard(this->_M_impl) 281 #define _GLIBCXX_ASAN_ANNOTATE_GROW(n) \ 282 typename _Base::_Vector_impl::template _Asan<>::_Grow \ 283 __attribute__((__unused__)) __grow_guard(this->_M_impl, (n)) 284 #define _GLIBCXX_ASAN_ANNOTATE_GREW(n) __grow_guard._M_grew(n) 285 #define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n) \ 286 _Base::_Vector_impl::template _Asan<>::_S_shrink(this->_M_impl, n) 287 #define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC \ 288 _Base::_Vector_impl::template _Asan<>::_S_on_dealloc(this->_M_impl) 289 #else // ! (_GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR) 290 #define _GLIBCXX_ASAN_ANNOTATE_REINIT 291 #define _GLIBCXX_ASAN_ANNOTATE_GROW(n) 292 #define _GLIBCXX_ASAN_ANNOTATE_GREW(n) 293 #define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n) 294 #define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC 295 #endif // _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR 299 typedef _Alloc allocator_type;
303 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
304 {
return this->_M_impl; }
307 const _Tp_alloc_type&
308 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
309 {
return this->_M_impl; }
313 get_allocator()
const _GLIBCXX_NOEXCEPT
314 {
return allocator_type(_M_get_Tp_allocator()); }
316 #if __cplusplus >= 201103L 323 _Vector_base(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
327 #if !_GLIBCXX_INLINE_VERSION 331 { _M_create_storage(__n); }
335 _Vector_base(
size_t __n,
const allocator_type& __a)
337 { _M_create_storage(__n); }
339 #if __cplusplus >= 201103L 340 _Vector_base(_Vector_base&&) =
default;
343 # if !_GLIBCXX_INLINE_VERSION 345 _Vector_base(_Tp_alloc_type&& __a) noexcept
349 _Vector_base(_Vector_base&& __x,
const allocator_type& __a)
352 if (__x.get_allocator() == __a)
353 this->_M_impl._M_swap_data(__x._M_impl);
356 size_t __n = __x._M_impl._M_finish - __x._M_impl._M_start;
357 _M_create_storage(__n);
363 _Vector_base(
const allocator_type& __a, _Vector_base&& __x)
364 : _M_impl(_Tp_alloc_type(__a),
std::move(__x._M_impl))
369 ~_Vector_base() _GLIBCXX_NOEXCEPT
371 _M_deallocate(_M_impl._M_start,
372 _M_impl._M_end_of_storage - _M_impl._M_start);
376 _Vector_impl _M_impl;
380 _M_allocate(
size_t __n)
383 return __n != 0 ? _Tr::allocate(_M_impl, __n) : pointer();
388 _M_deallocate(pointer __p,
size_t __n)
392 _Tr::deallocate(_M_impl, __p, __n);
399 _M_create_storage(
size_t __n)
401 this->_M_impl._M_start = this->_M_allocate(__n);
402 this->_M_impl._M_finish = this->_M_impl._M_start;
403 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
430 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
433 #ifdef _GLIBCXX_CONCEPT_CHECKS 435 typedef typename _Alloc::value_type _Alloc_value_type;
436 # if __cplusplus < 201103L 437 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
439 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
442 #if __cplusplus >= 201103L 443 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
444 "std::vector must have a non-const, non-volatile value_type");
445 # if __cplusplus > 201703L || defined __STRICT_ANSI__ 447 "std::vector must have the same value_type as its allocator");
452 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
456 typedef _Tp value_type;
457 typedef typename _Base::pointer pointer;
458 typedef typename _Alloc_traits::const_pointer const_pointer;
459 typedef typename _Alloc_traits::reference reference;
460 typedef typename _Alloc_traits::const_reference const_reference;
461 typedef __gnu_cxx::__normal_iterator<pointer, vector> iterator;
462 typedef __gnu_cxx::__normal_iterator<const_pointer, vector>
466 typedef size_t size_type;
467 typedef ptrdiff_t difference_type;
468 typedef _Alloc allocator_type;
471 #if __cplusplus >= 201103L 472 static constexpr
bool 475 return noexcept(std::__relocate_a(std::declval<pointer>(),
476 std::declval<pointer>(),
477 std::declval<pointer>(),
478 std::declval<_Tp_alloc_type&>()));
481 static constexpr
bool 485 static constexpr
bool 491 return _S_nothrow_relocate(__is_move_insertable<_Tp_alloc_type>{});
495 _S_do_relocate(pointer __first, pointer __last, pointer __result,
496 _Tp_alloc_type& __alloc,
true_type) noexcept
498 return std::__relocate_a(__first, __last, __result, __alloc);
502 _S_do_relocate(pointer, pointer, pointer __result,
506 static _GLIBCXX20_CONSTEXPR pointer
507 _S_relocate(pointer __first, pointer __last, pointer __result,
508 _Tp_alloc_type& __alloc) noexcept
510 #if __cpp_if_constexpr 512 return std::__relocate_a(__first, __last, __result, __alloc);
514 using __do_it = __bool_constant<_S_use_relocate()>;
515 return _S_do_relocate(__first, __last, __result, __alloc, __do_it{});
521 using _Base::_M_allocate;
522 using _Base::_M_deallocate;
523 using _Base::_M_impl;
524 using _Base::_M_get_Tp_allocator;
533 #if __cplusplus >= 201103L 545 vector(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
548 #if __cplusplus >= 201103L 559 vector(size_type __n,
const allocator_type& __a = allocator_type())
560 : _Base(_S_check_init_len(__n, __a), __a)
561 { _M_default_initialize(__n); }
572 vector(size_type __n,
const value_type& __value,
573 const allocator_type& __a = allocator_type())
574 : _Base(_S_check_init_len(__n, __a), __a)
575 { _M_fill_initialize(__n, __value); }
586 vector(size_type __n,
const value_type& __value = value_type(),
587 const allocator_type& __a = allocator_type())
588 : _Base(_S_check_init_len(__n, __a), __a)
589 { _M_fill_initialize(__n, __value); }
606 _Alloc_traits::_S_select_on_copy(__x._M_get_Tp_allocator()))
608 this->_M_impl._M_finish =
609 std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
610 this->_M_impl._M_start,
611 _M_get_Tp_allocator());
614 #if __cplusplus >= 201103L 627 vector(
const vector& __x,
const __type_identity_t<allocator_type>& __a)
628 : _Base(__x.
size(), __a)
630 this->_M_impl._M_finish =
631 std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
632 this->_M_impl._M_start,
633 _M_get_Tp_allocator());
646 if (__rv.get_allocator() == __m)
647 this->_M_impl._M_swap_data(__rv._M_impl);
648 else if (!__rv.empty())
650 this->_M_create_storage(__rv.size());
651 this->_M_impl._M_finish =
652 std::__uninitialized_move_a(__rv.begin(), __rv.end(),
653 this->_M_impl._M_start,
654 _M_get_Tp_allocator());
662 vector(vector&& __rv,
const __type_identity_t<allocator_type>& __m)
664 vector(std::declval<vector&&>(), std::declval<const allocator_type&>(),
665 std::declval<typename _Alloc_traits::is_always_equal>())) )
666 : vector(
std::
move(__rv), __m, typename _Alloc_traits::is_always_equal{})
682 const allocator_type& __a = allocator_type())
685 _M_range_initialize_n(__l.begin(), __l.end(), __l.size());
705 #if __cplusplus >= 201103L 706 template<
typename _InputIterator,
707 typename = std::_RequireInputIter<_InputIterator>>
709 vector(_InputIterator __first, _InputIterator __last,
710 const allocator_type& __a = allocator_type())
713 #if __glibcxx_concepts // C++ >= C++20 714 if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>
715 || forward_iterator<_InputIterator>)
719 _M_range_initialize_n(__first, __last, __n);
724 _M_range_initialize(__first, __last,
728 template<
typename _InputIterator>
729 vector(_InputIterator __first, _InputIterator __last,
730 const allocator_type& __a = allocator_type())
734 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
735 _M_initialize_dispatch(__first, __last, _Integral());
748 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
749 _M_get_Tp_allocator());
750 _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC;
764 operator=(
const vector& __x);
766 #if __cplusplus >= 201103L 779 operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
781 constexpr
bool __move_storage =
782 _Alloc_traits::_S_propagate_on_move_assign()
783 || _Alloc_traits::_S_always_equal();
784 _M_move_assign(
std::move(__x), __bool_constant<__move_storage>());
803 this->_M_assign_aux(__l.begin(), __l.end(),
821 assign(size_type __n,
const value_type& __val)
822 { _M_fill_assign(__n, __val); }
836 #if __cplusplus >= 201103L 837 template<
typename _InputIterator,
838 typename = std::_RequireInputIter<_InputIterator>>
841 assign(_InputIterator __first, _InputIterator __last)
844 template<
typename _InputIterator>
846 assign(_InputIterator __first, _InputIterator __last)
849 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
850 _M_assign_dispatch(__first, __last, _Integral());
854 #if __cplusplus >= 201103L 870 this->_M_assign_aux(__l.begin(), __l.end(),
876 using _Base::get_allocator;
884 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
887 {
return iterator(this->_M_impl._M_start); }
894 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
897 {
return const_iterator(this->_M_impl._M_start); }
904 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
907 {
return iterator(this->_M_impl._M_finish); }
914 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
916 end() const _GLIBCXX_NOEXCEPT
917 {
return const_iterator(this->_M_impl._M_finish); }
924 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
927 {
return reverse_iterator(
end()); }
934 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
935 const_reverse_iterator
937 {
return const_reverse_iterator(
end()); }
944 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
947 {
return reverse_iterator(
begin()); }
954 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
955 const_reverse_iterator
957 {
return const_reverse_iterator(
begin()); }
959 #if __cplusplus >= 201103L 965 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
968 {
return const_iterator(this->_M_impl._M_start); }
975 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
978 {
return const_iterator(this->_M_impl._M_finish); }
985 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
986 const_reverse_iterator
988 {
return const_reverse_iterator(
end()); }
995 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
996 const_reverse_iterator
998 {
return const_reverse_iterator(
begin()); }
1003 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1006 {
return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
1009 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1012 {
return _S_max_size(_M_get_Tp_allocator()); }
1014 #if __cplusplus >= 201103L 1024 _GLIBCXX20_CONSTEXPR
1028 if (__new_size >
size())
1029 _M_default_append(__new_size -
size());
1030 else if (__new_size <
size())
1031 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1045 _GLIBCXX20_CONSTEXPR
1047 resize(size_type __new_size,
const value_type& __x)
1049 if (__new_size >
size())
1050 _M_fill_append(__new_size -
size(), __x);
1051 else if (__new_size <
size())
1052 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1066 _GLIBCXX20_CONSTEXPR
1068 resize(size_type __new_size, value_type __x = value_type())
1070 if (__new_size >
size())
1071 _M_fill_append(__new_size -
size(), __x);
1072 else if (__new_size <
size())
1073 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1077 #if __cplusplus >= 201103L 1079 _GLIBCXX20_CONSTEXPR
1082 { _M_shrink_to_fit(); }
1089 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1093 return size_type(this->_M_impl._M_end_of_storage
1094 - this->_M_impl._M_start);
1101 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1123 _GLIBCXX20_CONSTEXPR
1125 reserve(size_type __n);
1139 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1143 __glibcxx_requires_subscript(__n);
1144 return *(this->_M_impl._M_start + __n);
1158 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1162 __glibcxx_requires_subscript(__n);
1163 return *(this->_M_impl._M_start + __n);
1168 _GLIBCXX20_CONSTEXPR
1172 if (__n >= this->
size())
1173 __throw_out_of_range_fmt(__N(
"vector::_M_range_check: __n " 1174 "(which is %zu) >= this->size() " 1191 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1195 _M_range_check(__n);
1196 return (*
this)[__n];
1210 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1214 _M_range_check(__n);
1215 return (*
this)[__n];
1222 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1226 __glibcxx_requires_nonempty();
1234 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1238 __glibcxx_requires_nonempty();
1246 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1250 __glibcxx_requires_nonempty();
1251 return *(
end() - 1);
1258 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1262 __glibcxx_requires_nonempty();
1263 return *(
end() - 1);
1273 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1276 {
return _M_data_ptr(this->_M_impl._M_start); }
1278 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1280 data()
const _GLIBCXX_NOEXCEPT
1281 {
return _M_data_ptr(this->_M_impl._M_start); }
1294 _GLIBCXX20_CONSTEXPR
1298 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
1300 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
1301 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
1303 ++this->_M_impl._M_finish;
1304 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
1307 _M_realloc_append(__x);
1310 #if __cplusplus >= 201103L 1311 _GLIBCXX20_CONSTEXPR
1313 push_back(value_type&& __x)
1316 template<
typename... _Args>
1317 #if __cplusplus > 201402L 1318 _GLIBCXX20_CONSTEXPR
1323 emplace_back(_Args&&... __args);
1335 _GLIBCXX20_CONSTEXPR
1339 __glibcxx_requires_nonempty();
1340 --this->_M_impl._M_finish;
1341 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
1342 _GLIBCXX_ASAN_ANNOTATE_SHRINK(1);
1345 #if __cplusplus >= 201103L 1358 template<
typename... _Args>
1359 _GLIBCXX20_CONSTEXPR
1361 emplace(const_iterator __position, _Args&&... __args)
1362 {
return _M_emplace_aux(__position, std::forward<_Args>(__args)...); }
1375 _GLIBCXX20_CONSTEXPR
1377 insert(const_iterator __position,
const value_type& __x);
1391 insert(iterator __position,
const value_type& __x);
1394 #if __cplusplus >= 201103L 1406 _GLIBCXX20_CONSTEXPR
1408 insert(const_iterator __position, value_type&& __x)
1409 {
return _M_insert_rval(__position,
std::move(__x)); }
1424 _GLIBCXX20_CONSTEXPR
1428 auto __offset = __position -
cbegin();
1429 _M_range_insert(
begin() + __offset, __l.begin(), __l.end(),
1431 return begin() + __offset;
1435 #if __cplusplus >= 201103L 1450 _GLIBCXX20_CONSTEXPR
1452 insert(const_iterator __position, size_type __n,
const value_type& __x)
1454 difference_type __offset = __position -
cbegin();
1455 _M_fill_insert(
begin() + __offset, __n, __x);
1456 return begin() + __offset;
1473 insert(iterator __position, size_type __n,
const value_type& __x)
1474 { _M_fill_insert(__position, __n, __x); }
1477 #if __cplusplus >= 201103L 1493 template<
typename _InputIterator,
1494 typename = std::_RequireInputIter<_InputIterator>>
1495 _GLIBCXX20_CONSTEXPR
1497 insert(const_iterator __position, _InputIterator __first,
1498 _InputIterator __last)
1500 difference_type __offset = __position -
cbegin();
1501 _M_range_insert(
begin() + __offset, __first, __last,
1503 return begin() + __offset;
1520 template<
typename _InputIterator>
1522 insert(iterator __position, _InputIterator __first,
1523 _InputIterator __last)
1526 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1527 _M_insert_dispatch(__position, __first, __last, _Integral());
1546 _GLIBCXX20_CONSTEXPR
1548 #if __cplusplus >= 201103L 1550 {
return _M_erase(
begin() + (__position -
cbegin())); }
1552 erase(iterator __position)
1553 {
return _M_erase(__position); }
1574 _GLIBCXX20_CONSTEXPR
1576 #if __cplusplus >= 201103L 1577 erase(const_iterator __first, const_iterator __last)
1579 const auto __beg =
begin();
1580 const auto __cbeg =
cbegin();
1581 return _M_erase(__beg + (__first - __cbeg), __beg + (__last - __cbeg));
1584 erase(iterator __first, iterator __last)
1585 {
return _M_erase(__first, __last); }
1599 _GLIBCXX20_CONSTEXPR
1601 swap(vector& __x) _GLIBCXX_NOEXCEPT
1603 #if __cplusplus >= 201103L 1604 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1605 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1607 this->_M_impl._M_swap_data(__x._M_impl);
1608 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1609 __x._M_get_Tp_allocator());
1618 _GLIBCXX20_CONSTEXPR
1621 { _M_erase_at_end(this->_M_impl._M_start); }
1628 template<
typename _ForwardIterator>
1629 _GLIBCXX20_CONSTEXPR
1632 _ForwardIterator __first, _ForwardIterator __last)
1634 pointer __result = this->_M_allocate(__n);
1637 std::__uninitialized_copy_a(__first, __last, __result,
1638 _M_get_Tp_allocator());
1643 _M_deallocate(__result, __n);
1644 __throw_exception_again;
1653 #if __cplusplus < 201103L 1656 template<
typename _Integer>
1658 _M_initialize_dispatch(_Integer __n, _Integer __value, __true_type)
1660 this->_M_impl._M_start = _M_allocate(_S_check_init_len(
1661 static_cast<size_type>(__n), _M_get_Tp_allocator()));
1662 this->_M_impl._M_end_of_storage =
1663 this->_M_impl._M_start +
static_cast<size_type
>(__n);
1664 _M_fill_initialize(static_cast<size_type>(__n), __value);
1668 template<
typename _InputIterator>
1670 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1673 _M_range_initialize(__first, __last,
1679 template<
typename _InputIterator>
1680 _GLIBCXX20_CONSTEXPR
1682 _M_range_initialize(_InputIterator __first, _InputIterator __last,
1686 for (; __first != __last; ++__first)
1687 #
if __cplusplus >= 201103L
1688 emplace_back(*__first);
1690 push_back(*__first);
1694 __throw_exception_again;
1699 template<
typename _ForwardIterator>
1700 _GLIBCXX20_CONSTEXPR
1702 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
1705 _M_range_initialize_n(__first, __last,
1709 template<
typename _Iterator>
1710 _GLIBCXX20_CONSTEXPR
1712 _M_range_initialize_n(_Iterator __first, _Iterator __last,
1715 pointer __start = this->_M_impl._M_start =
1716 this->_M_allocate(_S_check_init_len(__n, _M_get_Tp_allocator()));
1717 this->_M_impl._M_end_of_storage = __start + __n;
1718 this->_M_impl._M_finish
1719 = std::__uninitialized_copy_a(_GLIBCXX_MOVE(__first), __last,
1720 __start, _M_get_Tp_allocator());
1725 _GLIBCXX20_CONSTEXPR
1727 _M_fill_initialize(size_type __n,
const value_type& __value)
1729 this->_M_impl._M_finish =
1730 std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value,
1731 _M_get_Tp_allocator());
1734 #if __cplusplus >= 201103L 1736 _GLIBCXX20_CONSTEXPR
1738 _M_default_initialize(size_type __n)
1740 this->_M_impl._M_finish =
1741 std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
1742 _M_get_Tp_allocator());
1753 template<
typename _Integer>
1754 _GLIBCXX20_CONSTEXPR
1756 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1757 { _M_fill_assign(__n, __val); }
1760 template<
typename _InputIterator>
1761 _GLIBCXX20_CONSTEXPR
1763 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1768 template<
typename _InputIterator>
1769 _GLIBCXX20_CONSTEXPR
1771 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1775 template<
typename _ForwardIterator>
1776 _GLIBCXX20_CONSTEXPR
1778 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1783 _GLIBCXX20_CONSTEXPR
1785 _M_fill_assign(size_type __n,
const value_type& __val);
1793 template<
typename _Integer>
1794 _GLIBCXX20_CONSTEXPR
1796 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
1798 { _M_fill_insert(__pos, __n, __val); }
1801 template<
typename _InputIterator>
1802 _GLIBCXX20_CONSTEXPR
1804 _M_insert_dispatch(iterator __pos, _InputIterator __first,
1805 _InputIterator __last, __false_type)
1807 _M_range_insert(__pos, __first, __last,
1812 template<
typename _InputIterator>
1813 _GLIBCXX20_CONSTEXPR
1815 _M_range_insert(iterator __pos, _InputIterator __first,
1819 template<
typename _ForwardIterator>
1820 _GLIBCXX20_CONSTEXPR
1822 _M_range_insert(iterator __pos, _ForwardIterator __first,
1827 _GLIBCXX20_CONSTEXPR
1829 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
1832 _GLIBCXX20_CONSTEXPR
1834 _M_fill_append(size_type __n,
const value_type& __x);
1836 #if __cplusplus >= 201103L 1838 _GLIBCXX20_CONSTEXPR
1840 _M_default_append(size_type __n);
1842 _GLIBCXX20_CONSTEXPR
1847 #if __cplusplus < 201103L 1850 _M_insert_aux(iterator __position,
const value_type& __x);
1853 _M_realloc_insert(iterator __position,
const value_type& __x);
1856 _M_realloc_append(
const value_type& __x);
1860 struct _Temporary_value
1862 template<
typename... _Args>
1863 _GLIBCXX20_CONSTEXPR
explicit 1864 _Temporary_value(vector* __vec, _Args&&... __args) : _M_this(__vec)
1866 _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(),
1867 std::forward<_Args>(__args)...);
1870 _GLIBCXX20_CONSTEXPR
1872 { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); }
1874 _GLIBCXX20_CONSTEXPR value_type&
1875 _M_val() noexcept {
return _M_storage._M_val; }
1878 _GLIBCXX20_CONSTEXPR _Tp*
1883 constexpr _Storage() : _M_byte() { }
1884 _GLIBCXX20_CONSTEXPR ~_Storage() { }
1885 _Storage& operator=(
const _Storage&) =
delete;
1886 unsigned char _M_byte;
1891 _Storage _M_storage;
1896 template<
typename _Arg>
1897 _GLIBCXX20_CONSTEXPR
1899 _M_insert_aux(iterator __position, _Arg&& __arg);
1901 template<
typename... _Args>
1902 _GLIBCXX20_CONSTEXPR
1904 _M_realloc_insert(iterator __position, _Args&&... __args);
1906 template<
typename... _Args>
1907 _GLIBCXX20_CONSTEXPR
1909 _M_realloc_append(_Args&&... __args);
1912 _GLIBCXX20_CONSTEXPR
1914 _M_insert_rval(const_iterator __position, value_type&& __v);
1917 template<
typename... _Args>
1918 _GLIBCXX20_CONSTEXPR
1920 _M_emplace_aux(const_iterator __position, _Args&&... __args);
1923 _GLIBCXX20_CONSTEXPR
1925 _M_emplace_aux(const_iterator __position, value_type&& __v)
1926 {
return _M_insert_rval(__position,
std::move(__v)); }
1930 _GLIBCXX20_CONSTEXPR
1932 _M_check_len(size_type __n,
const char* __s)
const 1934 if (max_size() -
size() < __n)
1935 __throw_length_error(__N(__s));
1938 return (__len <
size() || __len > max_size()) ? max_size() : __len;
1942 static _GLIBCXX20_CONSTEXPR size_type
1943 _S_check_init_len(size_type __n,
const allocator_type& __a)
1945 if (__n > _S_max_size(_Tp_alloc_type(__a)))
1946 __throw_length_error(
1947 __N(
"cannot create std::vector larger than max_size()"));
1951 static _GLIBCXX20_CONSTEXPR size_type
1952 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1957 const size_t __diffmax
1958 = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max /
sizeof(_Tp);
1959 const size_t __allocmax = _Alloc_traits::max_size(__a);
1960 return (
std::min)(__diffmax, __allocmax);
1967 _GLIBCXX20_CONSTEXPR
1969 _M_erase_at_end(pointer __pos) _GLIBCXX_NOEXCEPT
1971 if (size_type __n = this->_M_impl._M_finish - __pos)
1974 _M_get_Tp_allocator());
1975 this->_M_impl._M_finish = __pos;
1976 _GLIBCXX_ASAN_ANNOTATE_SHRINK(__n);
1980 _GLIBCXX20_CONSTEXPR
1982 _M_erase(iterator __position);
1984 _GLIBCXX20_CONSTEXPR
1986 _M_erase(iterator __first, iterator __last);
1988 #if __cplusplus >= 201103L 1993 _GLIBCXX20_CONSTEXPR
1995 _M_move_assign(vector&& __x,
true_type) noexcept
1997 vector __tmp(get_allocator());
1998 this->_M_impl._M_swap_data(__x._M_impl);
1999 __tmp._M_impl._M_swap_data(__x._M_impl);
2000 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
2005 _GLIBCXX20_CONSTEXPR
2009 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
2015 this->_M_assign_aux(std::make_move_iterator(__x.begin()),
2016 std::make_move_iterator(__x.end()),
2023 template<
typename _Up>
2024 _GLIBCXX20_CONSTEXPR
2026 _M_data_ptr(_Up* __ptr)
const _GLIBCXX_NOEXCEPT
2029 #if __cplusplus >= 201103L 2030 template<
typename _Ptr>
2031 _GLIBCXX20_CONSTEXPR
2032 typename std::pointer_traits<_Ptr>::element_type*
2033 _M_data_ptr(_Ptr __ptr)
const 2034 {
return empty() ? nullptr : std::__to_address(__ptr); }
2036 template<
typename _Up>
2038 _M_data_ptr(_Up* __ptr) _GLIBCXX_NOEXCEPT
2041 template<
typename _Ptr>
2043 _M_data_ptr(_Ptr __ptr)
2044 {
return empty() ? (value_type*)0 : __ptr.operator->(); }
2046 template<
typename _Ptr>
2048 _M_data_ptr(_Ptr __ptr)
const 2049 {
return empty() ? (
const value_type*)0 : __ptr.operator->(); }
2053 #if __cpp_deduction_guides >= 201606 2054 template<
typename _InputIterator,
typename _ValT
2057 typename = _RequireInputIter<_InputIterator>,
2058 typename = _RequireAllocator<_Allocator>>
2059 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
2073 template<
typename _Tp,
typename _Alloc>
2074 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2080 #if __cpp_lib_three_way_comparison // >= C++20 2092 template<
typename _Tp,
typename _Alloc>
2094 constexpr __detail::__synth3way_t<_Tp>
2099 __detail::__synth3way);
2113 template<
typename _Tp,
typename _Alloc>
2114 _GLIBCXX_NODISCARD
inline bool 2117 __y.begin(), __y.end()); }
2120 template<
typename _Tp,
typename _Alloc>
2121 _GLIBCXX_NODISCARD
inline bool 2123 {
return !(__x == __y); }
2126 template<
typename _Tp,
typename _Alloc>
2127 _GLIBCXX_NODISCARD
inline bool 2129 {
return __y < __x; }
2132 template<
typename _Tp,
typename _Alloc>
2133 _GLIBCXX_NODISCARD
inline bool 2135 {
return !(__y < __x); }
2138 template<
typename _Tp,
typename _Alloc>
2139 _GLIBCXX_NODISCARD
inline bool 2141 {
return !(__x < __y); }
2142 #endif // three-way comparison 2145 template<
typename _Tp,
typename _Alloc>
2146 _GLIBCXX20_CONSTEXPR
2149 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.
swap(__y)))
2152 _GLIBCXX_END_NAMESPACE_CONTAINER
2154 #if __cplusplus >= 201703L 2155 namespace __detail::__variant
2157 template<
typename>
struct _Never_valueless_alt;
2161 template<
typename _Tp,
typename _Alloc>
2162 struct _Never_valueless_alt<_GLIBCXX_STD_C::vector<_Tp, _Alloc>>
2168 _GLIBCXX_END_NAMESPACE_VERSION
Forward iterators support a superset of input iterator operations.
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_reverse_iterator crbegin() const noexcept
constexpr void assign(size_type __n, const value_type &__val)
Assigns a given value to a vector.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
constexpr iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into vector before specified iterator.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
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 void resize(size_type __new_size)
Resizes the vector to the specified number of elements.
constexpr reference back() noexcept
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
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 front() const noexcept
constexpr const_reverse_iterator rbegin() const noexcept
constexpr auto cbegin(const _Container &__cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont))
Return an iterator pointing to the first element of the const container.
is_nothrow_move_assignable
The standard allocator, as per C++03 [20.4.1].
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
constexpr const_reference operator[](size_type __n) const noexcept
Subscript access to the data contained in the vector.
A standard container which offers fixed time access to individual elements in any order...
constexpr ~vector() noexcept
constexpr vector(const vector &__x)
Vector copy constructor.
is_nothrow_default_constructible
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 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 const_iterator begin() const noexcept
ISO C++ entities toplevel namespace is std.
constexpr void _M_range_check(size_type __n) const
Safety check used only from at().
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr vector(size_type __n, const allocator_type &__a=allocator_type())
Creates a vector with default constructed elements.
constexpr vector & operator=(vector &&__x) noexcept(_Alloc_traits::_S_nothrow_move())
Vector move assignment operator.
Traits class for iterators.
constexpr const_iterator cbegin() const noexcept
constexpr const_reverse_iterator crend() const noexcept
constexpr iterator begin() noexcept
constexpr iterator emplace(const_iterator __position, _Args &&... __args)
Inserts an object in vector before specified iterator.
constexpr const_reference at(size_type __n) const
Provides access to the data contained in the vector.
constexpr pointer _M_allocate_and_copy(size_type __n, _ForwardIterator __first, _ForwardIterator __last)
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
constexpr vector(const vector &__x, const __type_identity_t< allocator_type > &__a)
Copy constructor with alternative allocator.
constexpr reference at(size_type __n)
Provides access to the data contained in the vector.
constexpr void clear() noexcept
constexpr void pop_back() noexcept
Removes last element.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
constexpr const_iterator cend() const noexcept
constexpr bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
constexpr reference front() noexcept
constexpr bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
constexpr const_reverse_iterator rend() const noexcept
constexpr void swap(vector &__x) noexcept
Swaps data with another vector.
Random-access iterators support a superset of bidirectional iterator operations.
constexpr iterator erase(const_iterator __position)
Remove element at given position.
constexpr void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a vector.
constexpr size_type max_size() const noexcept
constexpr const_reference back() const noexcept
See bits/stl_deque.h's _Deque_base for an explanation.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr vector(const allocator_type &__a) noexcept
Creates a vector with no elements.
constexpr size_type capacity() const noexcept
constexpr auto data(_Container &__cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data())
Return the data pointer of a container.
constexpr iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
constexpr iterator end() noexcept
constexpr void assign(initializer_list< value_type > __l)
Assigns an initializer list to a vector.
constexpr reverse_iterator rend() 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 const_iterator end() const noexcept
constexpr size_type size() const noexcept
constexpr _Tp * data() noexcept
constexpr bool empty() const noexcept
constexpr void push_back(const value_type &__x)
Add data to the end of the vector.
constexpr iterator insert(const_iterator __position, initializer_list< value_type > __l)
Inserts an initializer_list into the vector.
constexpr iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the vector.
constexpr void shrink_to_fit()
constexpr reference operator[](size_type __n) noexcept
Subscript access to the data contained in the vector.
constexpr void _Destroy(_ForwardIterator __first, _ForwardIterator __last)
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
constexpr reverse_iterator rbegin() noexcept
Uniform interface to C++98 and C++11 allocators.