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*);
77 namespace std _GLIBCXX_VISIBILITY(default)
79 _GLIBCXX_BEGIN_NAMESPACE_VERSION
80 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
83 template<
typename _Tp,
typename _Alloc>
87 rebind<_Tp>::other _Tp_alloc_type;
88 typedef typename __gnu_cxx::__alloc_traits<_Tp_alloc_type>::pointer
91 struct _Vector_impl_data
95 pointer _M_end_of_storage;
98 _Vector_impl_data() _GLIBCXX_NOEXCEPT
99 : _M_start(), _M_finish(), _M_end_of_storage()
102 #if __cplusplus >= 201103L
104 _Vector_impl_data(_Vector_impl_data&& __x) noexcept
105 : _M_start(__x._M_start), _M_finish(__x._M_finish),
106 _M_end_of_storage(__x._M_end_of_storage)
107 { __x._M_start = __x._M_finish = __x._M_end_of_storage = pointer(); }
112 _M_copy_data(_Vector_impl_data
const& __x) _GLIBCXX_NOEXCEPT
114 _M_start = __x._M_start;
115 _M_finish = __x._M_finish;
116 _M_end_of_storage = __x._M_end_of_storage;
121 _M_swap_data(_Vector_impl_data& __x) _GLIBCXX_NOEXCEPT
125 _Vector_impl_data __tmp;
126 __tmp._M_copy_data(*
this);
128 __x._M_copy_data(__tmp);
133 :
public _Tp_alloc_type,
public _Vector_impl_data
136 _Vector_impl() _GLIBCXX_NOEXCEPT_IF(
138 #if __cpp_lib_concepts
139 requires is_default_constructible_v<_Tp_alloc_type>
145 _Vector_impl(_Tp_alloc_type
const& __a) _GLIBCXX_NOEXCEPT
146 : _Tp_alloc_type(__a)
149 #if __cplusplus >= 201103L
153 _Vector_impl(_Vector_impl&& __x) noexcept
158 _Vector_impl(_Tp_alloc_type&& __a) noexcept
163 _Vector_impl(_Tp_alloc_type&& __a, _Vector_impl&& __rv) noexcept
168 #if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR
169 template<
typename = _Tp_alloc_type>
173 ::size_type size_type;
175 static _GLIBCXX20_CONSTEXPR
void
176 _S_shrink(_Vector_impl&, size_type) { }
177 static _GLIBCXX20_CONSTEXPR
void
178 _S_on_dealloc(_Vector_impl&) { }
180 typedef _Vector_impl& _Reinit;
184 _GLIBCXX20_CONSTEXPR _Grow(_Vector_impl&, size_type) { }
185 _GLIBCXX20_CONSTEXPR
void _M_grew(size_type) { }
190 template<
typename _Up>
194 ::size_type size_type;
198 static _GLIBCXX20_CONSTEXPR
void
199 _S_adjust(_Vector_impl& __impl, pointer __prev, pointer __curr)
201 #if __cpp_lib_is_constant_evaluated
202 if (std::is_constant_evaluated())
205 __sanitizer_annotate_contiguous_container(__impl._M_start,
206 __impl._M_end_of_storage, __prev, __curr);
209 static _GLIBCXX20_CONSTEXPR
void
210 _S_grow(_Vector_impl& __impl, size_type __n)
211 { _S_adjust(__impl, __impl._M_finish, __impl._M_finish + __n); }
213 static _GLIBCXX20_CONSTEXPR
void
214 _S_shrink(_Vector_impl& __impl, size_type __n)
215 { _S_adjust(__impl, __impl._M_finish + __n, __impl._M_finish); }
217 static _GLIBCXX20_CONSTEXPR
void
218 _S_on_dealloc(_Vector_impl& __impl)
221 _S_adjust(__impl, __impl._M_finish, __impl._M_end_of_storage);
227 explicit _GLIBCXX20_CONSTEXPR
228 _Reinit(_Vector_impl& __impl) : _M_impl(__impl)
231 _S_on_dealloc(_M_impl);
238 if (_M_impl._M_start)
239 _S_adjust(_M_impl, _M_impl._M_end_of_storage,
243 _Vector_impl& _M_impl;
245 #if __cplusplus >= 201103L
246 _Reinit(
const _Reinit&) =
delete;
247 _Reinit& operator=(
const _Reinit&) =
delete;
255 _Grow(_Vector_impl& __impl, size_type __n)
256 : _M_impl(__impl), _M_n(__n)
257 { _S_grow(_M_impl, __n); }
260 ~_Grow() {
if (_M_n) _S_shrink(_M_impl, _M_n); }
263 void _M_grew(size_type __n) { _M_n -= __n; }
265 #if __cplusplus >= 201103L
266 _Grow(
const _Grow&) =
delete;
267 _Grow& operator=(
const _Grow&) =
delete;
270 _Vector_impl& _M_impl;
275 #define _GLIBCXX_ASAN_ANNOTATE_REINIT \
276 typename _Base::_Vector_impl::template _Asan<>::_Reinit const \
277 __attribute__((__unused__)) __reinit_guard(this->_M_impl)
278 #define _GLIBCXX_ASAN_ANNOTATE_GROW(n) \
279 typename _Base::_Vector_impl::template _Asan<>::_Grow \
280 __attribute__((__unused__)) __grow_guard(this->_M_impl, (n))
281 #define _GLIBCXX_ASAN_ANNOTATE_GREW(n) __grow_guard._M_grew(n)
282 #define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n) \
283 _Base::_Vector_impl::template _Asan<>::_S_shrink(this->_M_impl, n)
284 #define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC \
285 _Base::_Vector_impl::template _Asan<>::_S_on_dealloc(this->_M_impl)
287 #define _GLIBCXX_ASAN_ANNOTATE_REINIT
288 #define _GLIBCXX_ASAN_ANNOTATE_GROW(n)
289 #define _GLIBCXX_ASAN_ANNOTATE_GREW(n)
290 #define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n)
291 #define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC
296 typedef _Alloc allocator_type;
300 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
301 {
return this->_M_impl; }
304 const _Tp_alloc_type&
305 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
306 {
return this->_M_impl; }
310 get_allocator() const _GLIBCXX_NOEXCEPT
311 {
return allocator_type(_M_get_Tp_allocator()); }
313 #if __cplusplus >= 201103L
320 _Vector_base(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
324 #if !_GLIBCXX_INLINE_VERSION
326 _Vector_base(
size_t __n)
328 { _M_create_storage(__n); }
332 _Vector_base(
size_t __n,
const allocator_type& __a)
334 { _M_create_storage(__n); }
336 #if __cplusplus >= 201103L
337 _Vector_base(_Vector_base&&) =
default;
340 # if !_GLIBCXX_INLINE_VERSION
342 _Vector_base(_Tp_alloc_type&& __a) noexcept
346 _Vector_base(_Vector_base&& __x,
const allocator_type& __a)
349 if (__x.get_allocator() == __a)
350 this->_M_impl._M_swap_data(__x._M_impl);
353 size_t __n = __x._M_impl._M_finish - __x._M_impl._M_start;
354 _M_create_storage(__n);
360 _Vector_base(
const allocator_type& __a, _Vector_base&& __x)
361 : _M_impl(_Tp_alloc_type(__a),
std::
move(__x._M_impl))
366 ~_Vector_base() _GLIBCXX_NOEXCEPT
368 _M_deallocate(_M_impl._M_start,
369 _M_impl._M_end_of_storage - _M_impl._M_start);
373 _Vector_impl _M_impl;
377 _M_allocate(
size_t __n)
380 return __n != 0 ? _Tr::allocate(_M_impl, __n) : pointer();
385 _M_deallocate(pointer __p,
size_t __n)
389 _Tr::deallocate(_M_impl, __p, __n);
396 _M_create_storage(
size_t __n)
398 this->_M_impl._M_start = this->_M_allocate(__n);
399 this->_M_impl._M_finish = this->_M_impl._M_start;
400 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
427 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
430 #ifdef _GLIBCXX_CONCEPT_CHECKS
432 typedef typename _Alloc::value_type _Alloc_value_type;
433 # if __cplusplus < 201103L
434 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
436 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
439 #if __cplusplus >= 201103L
440 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
441 "std::vector must have a non-const, non-volatile value_type");
442 # if __cplusplus > 201703L || defined __STRICT_ANSI__
444 "std::vector must have the same value_type as its allocator");
449 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
453 typedef _Tp value_type;
454 typedef typename _Base::pointer pointer;
455 typedef typename _Alloc_traits::const_pointer const_pointer;
456 typedef typename _Alloc_traits::reference reference;
457 typedef typename _Alloc_traits::const_reference const_reference;
458 typedef __gnu_cxx::__normal_iterator<pointer, vector> iterator;
459 typedef __gnu_cxx::__normal_iterator<const_pointer, vector>
463 typedef size_t size_type;
464 typedef ptrdiff_t difference_type;
465 typedef _Alloc allocator_type;
468 #if __cplusplus >= 201103L
469 static constexpr
bool
472 return noexcept(std::__relocate_a(std::declval<pointer>(),
473 std::declval<pointer>(),
474 std::declval<pointer>(),
475 std::declval<_Tp_alloc_type&>()));
478 static constexpr
bool
482 static constexpr
bool
488 return _S_nothrow_relocate(__is_move_insertable<_Tp_alloc_type>{});
492 _S_do_relocate(pointer __first, pointer __last, pointer __result,
493 _Tp_alloc_type& __alloc,
true_type) noexcept
495 return std::__relocate_a(__first, __last, __result, __alloc);
499 _S_do_relocate(pointer, pointer, pointer __result,
503 static _GLIBCXX20_CONSTEXPR pointer
504 _S_relocate(pointer __first, pointer __last, pointer __result,
505 _Tp_alloc_type& __alloc) noexcept
507 #if __cpp_if_constexpr
509 return std::__relocate_a(__first, __last, __result, __alloc);
511 using __do_it = __bool_constant<_S_use_relocate()>;
512 return _S_do_relocate(__first, __last, __result, __alloc, __do_it{});
518 using _Base::_M_allocate;
519 using _Base::_M_deallocate;
520 using _Base::_M_impl;
521 using _Base::_M_get_Tp_allocator;
530 #if __cplusplus >= 201103L
542 vector(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
545 #if __cplusplus >= 201103L
556 vector(size_type __n,
const allocator_type& __a = allocator_type())
557 :
_Base(_S_check_init_len(__n, __a), __a)
558 { _M_default_initialize(__n); }
569 vector(size_type __n,
const value_type& __value,
570 const allocator_type& __a = allocator_type())
571 :
_Base(_S_check_init_len(__n, __a), __a)
572 { _M_fill_initialize(__n, __value); }
583 vector(size_type __n,
const value_type& __value = value_type(),
584 const allocator_type& __a = allocator_type())
585 : _Base(_S_check_init_len(__n, __a), __a)
586 { _M_fill_initialize(__n, __value); }
605 this->_M_impl._M_finish =
606 std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
607 this->_M_impl._M_start,
608 _M_get_Tp_allocator());
611 #if __cplusplus >= 201103L
624 vector(const
vector& __x, const __type_identity_t<allocator_type>& __a)
627 this->_M_impl._M_finish =
628 std::__uninitialized_copy_a(__x.begin(), __x.end(),
629 this->_M_impl._M_start,
630 _M_get_Tp_allocator());
643 if (__rv.get_allocator() == __m)
644 this->_M_impl._M_swap_data(__rv._M_impl);
645 else if (!__rv.empty())
647 this->_M_create_storage(__rv.size());
648 this->_M_impl._M_finish =
649 std::__uninitialized_move_a(__rv.begin(), __rv.end(),
650 this->_M_impl._M_start,
651 _M_get_Tp_allocator());
661 vector(std::declval<vector&&>(), std::declval<const allocator_type&>(),
662 std::declval<typename _Alloc_traits::is_always_equal>())) )
679 const allocator_type& __a = allocator_type())
682 _M_range_initialize(__l.begin(), __l.end(),
703 #if __cplusplus >= 201103L
704 template<
typename _InputIterator,
705 typename = std::_RequireInputIter<_InputIterator>>
707 vector(_InputIterator __first, _InputIterator __last,
708 const allocator_type& __a = allocator_type())
711 _M_range_initialize(__first, __last,
715 template<
typename _InputIterator>
716 vector(_InputIterator __first, _InputIterator __last,
717 const allocator_type& __a = allocator_type())
721 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
722 _M_initialize_dispatch(__first, __last, _Integral());
735 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
736 _M_get_Tp_allocator());
737 _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC;
753 #if __cplusplus >= 201103L
768 constexpr
bool __move_storage =
769 _Alloc_traits::_S_propagate_on_move_assign()
770 || _Alloc_traits::_S_always_equal();
771 _M_move_assign(
std::move(__x), __bool_constant<__move_storage>());
790 this->_M_assign_aux(__l.begin(), __l.end(),
808 assign(size_type __n,
const value_type& __val)
809 { _M_fill_assign(__n, __val); }
823 #if __cplusplus >= 201103L
824 template<
typename _InputIterator,
825 typename = std::_RequireInputIter<_InputIterator>>
828 assign(_InputIterator __first, _InputIterator __last)
831 template<
typename _InputIterator>
833 assign(_InputIterator __first, _InputIterator __last)
836 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
837 _M_assign_dispatch(__first, __last, _Integral());
841 #if __cplusplus >= 201103L
857 this->_M_assign_aux(__l.begin(), __l.end(),
863 using _Base::get_allocator;
871 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
874 {
return iterator(this->_M_impl._M_start); }
881 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
884 {
return const_iterator(this->_M_impl._M_start); }
891 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
894 {
return iterator(this->_M_impl._M_finish); }
901 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
903 end() const _GLIBCXX_NOEXCEPT
904 {
return const_iterator(this->_M_impl._M_finish); }
911 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
921 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
922 const_reverse_iterator
931 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
941 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
942 const_reverse_iterator
946 #if __cplusplus >= 201103L
952 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
955 {
return const_iterator(this->_M_impl._M_start); }
962 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
965 {
return const_iterator(this->_M_impl._M_finish); }
972 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
973 const_reverse_iterator
982 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
983 const_reverse_iterator
990 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
993 {
return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
996 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
999 {
return _S_max_size(_M_get_Tp_allocator()); }
1001 #if __cplusplus >= 201103L
1011 _GLIBCXX20_CONSTEXPR
1015 if (__new_size >
size())
1016 _M_default_append(__new_size -
size());
1017 else if (__new_size <
size())
1018 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1032 _GLIBCXX20_CONSTEXPR
1034 resize(size_type __new_size,
const value_type& __x)
1036 if (__new_size >
size())
1037 _M_fill_insert(
end(), __new_size -
size(), __x);
1038 else if (__new_size <
size())
1039 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1053 _GLIBCXX20_CONSTEXPR
1055 resize(size_type __new_size, value_type __x = value_type())
1057 if (__new_size >
size())
1058 _M_fill_insert(
end(), __new_size -
size(), __x);
1059 else if (__new_size <
size())
1060 _M_erase_at_end(this->_M_impl._M_start + __new_size);
1064 #if __cplusplus >= 201103L
1066 _GLIBCXX20_CONSTEXPR
1069 { _M_shrink_to_fit(); }
1076 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1080 return size_type(this->_M_impl._M_end_of_storage
1081 - this->_M_impl._M_start);
1088 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1110 _GLIBCXX20_CONSTEXPR
1126 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1130 __glibcxx_requires_subscript(__n);
1131 return *(this->_M_impl._M_start + __n);
1145 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1149 __glibcxx_requires_subscript(__n);
1150 return *(this->_M_impl._M_start + __n);
1155 _GLIBCXX20_CONSTEXPR
1159 if (__n >= this->
size())
1160 __throw_out_of_range_fmt(__N(
"vector::_M_range_check: __n "
1161 "(which is %zu) >= this->size() "
1178 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1183 return (*
this)[__n];
1197 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1202 return (*
this)[__n];
1209 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1213 __glibcxx_requires_nonempty();
1221 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1225 __glibcxx_requires_nonempty();
1233 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1237 __glibcxx_requires_nonempty();
1238 return *(
end() - 1);
1245 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1249 __glibcxx_requires_nonempty();
1250 return *(
end() - 1);
1260 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1263 {
return _M_data_ptr(this->_M_impl._M_start); }
1265 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1267 data() const _GLIBCXX_NOEXCEPT
1268 {
return _M_data_ptr(this->_M_impl._M_start); }
1281 _GLIBCXX20_CONSTEXPR
1285 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
1287 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
1288 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
1290 ++this->_M_impl._M_finish;
1291 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
1294 _M_realloc_append(__x);
1297 #if __cplusplus >= 201103L
1298 _GLIBCXX20_CONSTEXPR
1303 template<
typename... _Args>
1304 #if __cplusplus > 201402L
1305 _GLIBCXX20_CONSTEXPR
1310 emplace_back(_Args&&... __args);
1322 _GLIBCXX20_CONSTEXPR
1326 __glibcxx_requires_nonempty();
1327 --this->_M_impl._M_finish;
1328 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
1329 _GLIBCXX_ASAN_ANNOTATE_SHRINK(1);
1332 #if __cplusplus >= 201103L
1345 template<
typename... _Args>
1346 _GLIBCXX20_CONSTEXPR
1348 emplace(const_iterator __position, _Args&&... __args)
1349 {
return _M_emplace_aux(__position, std::forward<_Args>(__args)...); }
1362 _GLIBCXX20_CONSTEXPR
1364 insert(const_iterator __position,
const value_type& __x);
1381 #if __cplusplus >= 201103L
1393 _GLIBCXX20_CONSTEXPR
1395 insert(const_iterator __position, value_type&& __x)
1396 {
return _M_insert_rval(__position,
std::move(__x)); }
1411 _GLIBCXX20_CONSTEXPR
1415 auto __offset = __position -
cbegin();
1416 _M_range_insert(
begin() + __offset, __l.begin(), __l.end(),
1418 return begin() + __offset;
1422 #if __cplusplus >= 201103L
1437 _GLIBCXX20_CONSTEXPR
1439 insert(const_iterator __position, size_type __n,
const value_type& __x)
1441 difference_type __offset = __position -
cbegin();
1442 _M_fill_insert(
begin() + __offset, __n, __x);
1443 return begin() + __offset;
1460 insert(
iterator __position, size_type __n,
const value_type& __x)
1461 { _M_fill_insert(__position, __n, __x); }
1464 #if __cplusplus >= 201103L
1480 template<
typename _InputIterator,
1481 typename = std::_RequireInputIter<_InputIterator>>
1482 _GLIBCXX20_CONSTEXPR
1484 insert(const_iterator __position, _InputIterator __first,
1485 _InputIterator __last)
1487 difference_type __offset = __position -
cbegin();
1488 _M_range_insert(
begin() + __offset, __first, __last,
1490 return begin() + __offset;
1507 template<
typename _InputIterator>
1510 _InputIterator __last)
1513 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1514 _M_insert_dispatch(__position, __first, __last, _Integral());
1533 _GLIBCXX20_CONSTEXPR
1535 #if __cplusplus >= 201103L
1537 {
return _M_erase(
begin() + (__position -
cbegin())); }
1540 {
return _M_erase(__position); }
1561 _GLIBCXX20_CONSTEXPR
1563 #if __cplusplus >= 201103L
1564 erase(const_iterator __first, const_iterator __last)
1566 const auto __beg =
begin();
1567 const auto __cbeg =
cbegin();
1568 return _M_erase(__beg + (__first - __cbeg), __beg + (__last - __cbeg));
1572 {
return _M_erase(__first, __last); }
1586 _GLIBCXX20_CONSTEXPR
1590 #if __cplusplus >= 201103L
1591 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1592 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1594 this->_M_impl._M_swap_data(__x._M_impl);
1595 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1596 __x._M_get_Tp_allocator());
1605 _GLIBCXX20_CONSTEXPR
1608 { _M_erase_at_end(this->_M_impl._M_start); }
1615 template<
typename _ForwardIterator>
1616 _GLIBCXX20_CONSTEXPR
1619 _ForwardIterator __first, _ForwardIterator __last)
1621 pointer __result = this->_M_allocate(__n);
1624 std::__uninitialized_copy_a(__first, __last, __result,
1625 _M_get_Tp_allocator());
1630 _M_deallocate(__result, __n);
1631 __throw_exception_again;
1640 #if __cplusplus < 201103L
1643 template<
typename _Integer>
1645 _M_initialize_dispatch(_Integer __n, _Integer __value, __true_type)
1647 this->_M_impl._M_start = _M_allocate(_S_check_init_len(
1648 static_cast<size_type
>(__n), _M_get_Tp_allocator()));
1649 this->_M_impl._M_end_of_storage =
1650 this->_M_impl._M_start +
static_cast<size_type
>(__n);
1651 _M_fill_initialize(
static_cast<size_type
>(__n), __value);
1655 template<
typename _InputIterator>
1657 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1660 _M_range_initialize(__first, __last,
1666 template<
typename _InputIterator>
1667 _GLIBCXX20_CONSTEXPR
1669 _M_range_initialize(_InputIterator __first, _InputIterator __last,
1673 for (; __first != __last; ++__first)
1674 #
if __cplusplus >= 201103L
1675 emplace_back(*__first);
1681 __throw_exception_again;
1686 template<
typename _ForwardIterator>
1687 _GLIBCXX20_CONSTEXPR
1689 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
1693 this->_M_impl._M_start
1694 = this->_M_allocate(_S_check_init_len(__n, _M_get_Tp_allocator()));
1695 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
1696 this->_M_impl._M_finish =
1697 std::__uninitialized_copy_a(__first, __last,
1698 this->_M_impl._M_start,
1699 _M_get_Tp_allocator());
1704 _GLIBCXX20_CONSTEXPR
1706 _M_fill_initialize(size_type __n,
const value_type& __value)
1708 this->_M_impl._M_finish =
1709 std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value,
1710 _M_get_Tp_allocator());
1713 #if __cplusplus >= 201103L
1715 _GLIBCXX20_CONSTEXPR
1717 _M_default_initialize(size_type __n)
1719 this->_M_impl._M_finish =
1720 std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
1721 _M_get_Tp_allocator());
1732 template<
typename _Integer>
1733 _GLIBCXX20_CONSTEXPR
1735 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1736 { _M_fill_assign(__n, __val); }
1739 template<
typename _InputIterator>
1740 _GLIBCXX20_CONSTEXPR
1742 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1747 template<
typename _InputIterator>
1748 _GLIBCXX20_CONSTEXPR
1750 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1754 template<
typename _ForwardIterator>
1755 _GLIBCXX20_CONSTEXPR
1757 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1762 _GLIBCXX20_CONSTEXPR
1764 _M_fill_assign(size_type __n,
const value_type& __val);
1772 template<
typename _Integer>
1773 _GLIBCXX20_CONSTEXPR
1775 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
1777 { _M_fill_insert(__pos, __n, __val); }
1780 template<
typename _InputIterator>
1781 _GLIBCXX20_CONSTEXPR
1783 _M_insert_dispatch(iterator __pos, _InputIterator __first,
1784 _InputIterator __last, __false_type)
1786 _M_range_insert(__pos, __first, __last,
1791 template<
typename _InputIterator>
1792 _GLIBCXX20_CONSTEXPR
1794 _M_range_insert(iterator __pos, _InputIterator __first,
1798 template<
typename _ForwardIterator>
1799 _GLIBCXX20_CONSTEXPR
1801 _M_range_insert(iterator __pos, _ForwardIterator __first,
1806 _GLIBCXX20_CONSTEXPR
1808 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
1810 #if __cplusplus >= 201103L
1812 _GLIBCXX20_CONSTEXPR
1814 _M_default_append(size_type __n);
1816 _GLIBCXX20_CONSTEXPR
1821 #if __cplusplus < 201103L
1824 _M_insert_aux(iterator __position,
const value_type& __x);
1827 _M_realloc_insert(iterator __position,
const value_type& __x);
1830 _M_realloc_append(
const value_type& __x);
1834 struct _Temporary_value
1836 template<
typename... _Args>
1837 _GLIBCXX20_CONSTEXPR
explicit
1838 _Temporary_value(
vector* __vec, _Args&&... __args) : _M_this(__vec)
1840 _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(),
1841 std::forward<_Args>(__args)...);
1844 _GLIBCXX20_CONSTEXPR
1846 { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); }
1848 _GLIBCXX20_CONSTEXPR value_type&
1849 _M_val() noexcept {
return _M_storage._M_val; }
1852 _GLIBCXX20_CONSTEXPR _Tp*
1857 constexpr _Storage() : _M_byte() { }
1858 _GLIBCXX20_CONSTEXPR ~_Storage() { }
1859 _Storage&
operator=(
const _Storage&) =
delete;
1860 unsigned char _M_byte;
1865 _Storage _M_storage;
1870 template<
typename _Arg>
1871 _GLIBCXX20_CONSTEXPR
1873 _M_insert_aux(iterator __position, _Arg&& __arg);
1875 template<
typename... _Args>
1876 _GLIBCXX20_CONSTEXPR
1878 _M_realloc_insert(iterator __position, _Args&&... __args);
1880 template<
typename... _Args>
1881 _GLIBCXX20_CONSTEXPR
1883 _M_realloc_append(_Args&&... __args);
1886 _GLIBCXX20_CONSTEXPR
1888 _M_insert_rval(const_iterator __position, value_type&& __v);
1891 template<
typename... _Args>
1892 _GLIBCXX20_CONSTEXPR
1894 _M_emplace_aux(const_iterator __position, _Args&&... __args);
1897 _GLIBCXX20_CONSTEXPR
1899 _M_emplace_aux(const_iterator __position, value_type&& __v)
1900 {
return _M_insert_rval(__position,
std::move(__v)); }
1904 _GLIBCXX20_CONSTEXPR
1906 _M_check_len(size_type __n,
const char* __s)
const
1909 __throw_length_error(__N(__s));
1916 static _GLIBCXX20_CONSTEXPR size_type
1917 _S_check_init_len(size_type __n,
const allocator_type& __a)
1919 if (__n > _S_max_size(_Tp_alloc_type(__a)))
1920 __throw_length_error(
1921 __N(
"cannot create std::vector larger than max_size()"));
1925 static _GLIBCXX20_CONSTEXPR size_type
1926 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1931 const size_t __diffmax
1932 = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max /
sizeof(_Tp);
1934 return (
std::min)(__diffmax, __allocmax);
1941 _GLIBCXX20_CONSTEXPR
1943 _M_erase_at_end(pointer __pos) _GLIBCXX_NOEXCEPT
1945 if (size_type __n = this->_M_impl._M_finish - __pos)
1948 _M_get_Tp_allocator());
1949 this->_M_impl._M_finish = __pos;
1950 _GLIBCXX_ASAN_ANNOTATE_SHRINK(__n);
1954 _GLIBCXX20_CONSTEXPR
1956 _M_erase(iterator __position);
1958 _GLIBCXX20_CONSTEXPR
1960 _M_erase(iterator __first, iterator __last);
1962 #if __cplusplus >= 201103L
1967 _GLIBCXX20_CONSTEXPR
1972 this->_M_impl._M_swap_data(__x._M_impl);
1973 __tmp._M_impl._M_swap_data(__x._M_impl);
1974 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
1979 _GLIBCXX20_CONSTEXPR
1983 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
1989 this->_M_assign_aux(std::make_move_iterator(__x.begin()),
1990 std::make_move_iterator(__x.end()),
1997 template<
typename _Up>
1998 _GLIBCXX20_CONSTEXPR
2000 _M_data_ptr(_Up* __ptr)
const _GLIBCXX_NOEXCEPT
2003 #if __cplusplus >= 201103L
2004 template<
typename _Ptr>
2005 _GLIBCXX20_CONSTEXPR
2006 typename std::pointer_traits<_Ptr>::element_type*
2007 _M_data_ptr(_Ptr __ptr)
const
2008 {
return empty() ? nullptr : std::__to_address(__ptr); }
2010 template<
typename _Up>
2012 _M_data_ptr(_Up* __ptr) _GLIBCXX_NOEXCEPT
2015 template<
typename _Ptr>
2017 _M_data_ptr(_Ptr __ptr)
2018 {
return empty() ? (value_type*)0 : __ptr.operator->(); }
2020 template<
typename _Ptr>
2022 _M_data_ptr(_Ptr __ptr)
const
2023 {
return empty() ? (
const value_type*)0 : __ptr.operator->(); }
2027 #if __cpp_deduction_guides >= 201606
2028 template<
typename _InputIterator,
typename _ValT
2029 =
typename iterator_traits<_InputIterator>::value_type,
2030 typename _Allocator = allocator<_ValT>,
2031 typename = _RequireInputIter<_InputIterator>,
2032 typename = _RequireAllocator<_Allocator>>
2033 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
2034 -> vector<_ValT, _Allocator>;
2047 template<
typename _Tp,
typename _Alloc>
2048 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
2054 #if __cpp_lib_three_way_comparison
2066 template<
typename _Tp,
typename _Alloc>
2068 constexpr __detail::__synth3way_t<_Tp>
2069 operator<=>(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2072 __y.begin(), __y.end(),
2073 __detail::__synth3way);
2087 template<
typename _Tp,
typename _Alloc>
2088 _GLIBCXX_NODISCARD
inline bool
2089 operator<(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2090 {
return std::lexicographical_compare(__x.begin(), __x.end(),
2091 __y.begin(), __y.end()); }
2094 template<
typename _Tp,
typename _Alloc>
2095 _GLIBCXX_NODISCARD
inline bool
2096 operator!=(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2097 {
return !(__x == __y); }
2100 template<
typename _Tp,
typename _Alloc>
2101 _GLIBCXX_NODISCARD
inline bool
2102 operator>(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2103 {
return __y < __x; }
2106 template<
typename _Tp,
typename _Alloc>
2107 _GLIBCXX_NODISCARD
inline bool
2108 operator<=(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2109 {
return !(__y < __x); }
2112 template<
typename _Tp,
typename _Alloc>
2113 _GLIBCXX_NODISCARD
inline bool
2114 operator>=(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
2115 {
return !(__x < __y); }
2119 template<
typename _Tp,
typename _Alloc>
2120 _GLIBCXX20_CONSTEXPR
2123 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
2126 _GLIBCXX_END_NAMESPACE_CONTAINER
2128 #if __cplusplus >= 201703L
2129 namespace __detail::__variant
2131 template<
typename>
struct _Never_valueless_alt;
2135 template<
typename _Tp,
typename _Alloc>
2136 struct _Never_valueless_alt<_GLIBCXX_STD_C::vector<_Tp, _Alloc>>
2142 _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)
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 _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
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
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 reverse_iterator rbegin() noexcept
constexpr iterator end() noexcept
constexpr vector(const vector &__x)
Vector copy constructor.
vector()=default
Creates a vector with no elements.
constexpr iterator emplace(const_iterator __position, _Args &&... __args)
Inserts an object in vector before specified iterator.
constexpr iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into vector before specified iterator.
constexpr const_reverse_iterator rend() const noexcept
constexpr iterator begin() noexcept
constexpr size_type capacity() const noexcept
constexpr iterator insert(const_iterator __position, initializer_list< value_type > __l)
Inserts an initializer_list into the vector.
constexpr ~vector() noexcept
constexpr const_iterator begin() const noexcept
constexpr void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a vector.
constexpr void assign(size_type __n, const value_type &__val)
Assigns a given value to a vector.
constexpr iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
constexpr void swap(vector &__x) noexcept
Swaps data with another vector.
constexpr vector(vector &&__rv, const __type_identity_t< allocator_type > &__m) noexcept(noexcept(vector(std::declval< vector && >(), std::declval< const allocator_type & >(), std::declval< typename _Alloc_traits::is_always_equal >())))
Move constructor with alternative allocator.
constexpr vector(size_type __n, const allocator_type &__a=allocator_type())
Creates a vector with default constructed elements.
constexpr const_reference front() const noexcept
constexpr vector & operator=(initializer_list< value_type > __l)
Vector list assignment operator.
constexpr _Tp * data() noexcept
constexpr void pop_back() noexcept
Removes last element.
constexpr const_reference back() const noexcept
constexpr void reserve(size_type __n)
Attempt to preallocate enough memory for specified number of elements.
constexpr reference at(size_type __n)
Provides access to the data contained in the vector.
constexpr void resize(size_type __new_size)
Resizes the vector to the specified number of elements.
constexpr void _M_range_check(size_type __n) const
Safety check used only from at().
constexpr reference front() noexcept
constexpr iterator insert(const_iterator __position, size_type __n, const value_type &__x)
Inserts a number of copies of given data into the vector.
constexpr const_reference operator[](size_type __n) const noexcept
Subscript access to the data contained in the vector.
constexpr vector(const allocator_type &__a) noexcept
Creates a vector with no elements.
constexpr iterator erase(const_iterator __position)
Remove element at given position.
constexpr pointer _M_allocate_and_copy(size_type __n, _ForwardIterator __first, _ForwardIterator __last)
constexpr bool empty() const noexcept
constexpr reverse_iterator rend() noexcept
constexpr const_reverse_iterator rbegin() const noexcept
constexpr const_reverse_iterator crbegin() const noexcept
constexpr vector & operator=(vector &&__x) noexcept(_Alloc_traits::_S_nothrow_move())
Vector move assignment operator.
constexpr const_reference at(size_type __n) const
Provides access to the data contained in the vector.
constexpr const_iterator cbegin() const noexcept
constexpr vector(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a vector from a range.
constexpr vector(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a vector from an initializer list.
constexpr const_iterator end() const noexcept
vector(vector &&) noexcept=default
Vector move constructor.
constexpr iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the vector.
constexpr void clear() noexcept
constexpr void assign(initializer_list< value_type > __l)
Assigns an initializer list to a vector.
constexpr allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
constexpr size_type size() const noexcept
constexpr vector(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a vector with copies of an exemplar element.
constexpr vector & operator=(const vector &__x)
Vector assignment operator.
constexpr reference back() noexcept
constexpr const_reverse_iterator crend() const noexcept
constexpr const_iterator cend() const noexcept
constexpr reference operator[](size_type __n) noexcept
Subscript access to the data contained in the vector.
constexpr void shrink_to_fit()
constexpr size_type max_size() const noexcept
Uniform interface to C++98 and C++11 allocators.
static constexpr size_type max_size(const _Tp_alloc_type &__a) noexcept
The maximum supported allocation size.