57 #define _STL_VECTOR_H 1 62 #if __cplusplus >= 201103L 68 #if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR 70 __sanitizer_annotate_contiguous_container(
const void*,
const void*,
71 const void*,
const void*);
74 namespace std _GLIBCXX_VISIBILITY(default)
76 _GLIBCXX_BEGIN_NAMESPACE_VERSION
77 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
80 template<
typename _Tp,
typename _Alloc>
84 rebind<_Tp>::other _Tp_alloc_type;
85 typedef typename __gnu_cxx::__alloc_traits<_Tp_alloc_type>::pointer
88 struct _Vector_impl_data
92 pointer _M_end_of_storage;
94 _Vector_impl_data() _GLIBCXX_NOEXCEPT
95 : _M_start(), _M_finish(), _M_end_of_storage()
98 #if __cplusplus >= 201103L 99 _Vector_impl_data(_Vector_impl_data&& __x) noexcept
100 : _M_start(__x._M_start), _M_finish(__x._M_finish),
101 _M_end_of_storage(__x._M_end_of_storage)
102 { __x._M_start = __x._M_finish = __x._M_end_of_storage = pointer(); }
106 _M_copy_data(_Vector_impl_data
const& __x) _GLIBCXX_NOEXCEPT
108 _M_start = __x._M_start;
109 _M_finish = __x._M_finish;
110 _M_end_of_storage = __x._M_end_of_storage;
114 _M_swap_data(_Vector_impl_data& __x) _GLIBCXX_NOEXCEPT
118 _Vector_impl_data __tmp;
119 __tmp._M_copy_data(*
this);
121 __x._M_copy_data(__tmp);
126 :
public _Tp_alloc_type,
public _Vector_impl_data
128 _Vector_impl() _GLIBCXX_NOEXCEPT_IF(
133 _Vector_impl(_Tp_alloc_type
const& __a) _GLIBCXX_NOEXCEPT
134 : _Tp_alloc_type(__a)
137 #if __cplusplus >= 201103L 140 _Vector_impl(_Vector_impl&& __x) noexcept
141 : _Tp_alloc_type(std::move(__x)), _Vector_impl_data(std::move(__x))
144 _Vector_impl(_Tp_alloc_type&& __a) noexcept
145 : _Tp_alloc_type(std::move(__a))
148 _Vector_impl(_Tp_alloc_type&& __a, _Vector_impl&& __rv) noexcept
149 : _Tp_alloc_type(std::move(__a)), _Vector_impl_data(std::move(__rv))
153 #if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR 154 template<
typename = _Tp_alloc_type>
158 ::size_type size_type;
160 static void _S_shrink(_Vector_impl&, size_type) { }
161 static void _S_on_dealloc(_Vector_impl&) { }
163 typedef _Vector_impl& _Reinit;
167 _Grow(_Vector_impl&, size_type) { }
168 void _M_grew(size_type) { }
173 template<
typename _Up>
174 struct _Asan<allocator<_Up> >
177 ::size_type size_type;
182 _S_adjust(_Vector_impl& __impl, pointer __prev, pointer __curr)
184 __sanitizer_annotate_contiguous_container(__impl._M_start,
185 __impl._M_end_of_storage, __prev, __curr);
189 _S_grow(_Vector_impl& __impl, size_type __n)
190 { _S_adjust(__impl, __impl._M_finish, __impl._M_finish + __n); }
193 _S_shrink(_Vector_impl& __impl, size_type __n)
194 { _S_adjust(__impl, __impl._M_finish + __n, __impl._M_finish); }
197 _S_on_dealloc(_Vector_impl& __impl)
200 _S_adjust(__impl, __impl._M_finish, __impl._M_end_of_storage);
206 explicit _Reinit(_Vector_impl& __impl) : _M_impl(__impl)
209 _S_on_dealloc(_M_impl);
215 if (_M_impl._M_start)
216 _S_adjust(_M_impl, _M_impl._M_end_of_storage,
220 _Vector_impl& _M_impl;
222 #if __cplusplus >= 201103L 223 _Reinit(
const _Reinit&) =
delete;
224 _Reinit& operator=(
const _Reinit&) =
delete;
231 _Grow(_Vector_impl& __impl, size_type __n)
232 : _M_impl(__impl), _M_n(__n)
233 { _S_grow(_M_impl, __n); }
235 ~_Grow() {
if (_M_n) _S_shrink(_M_impl, _M_n); }
237 void _M_grew(size_type __n) { _M_n -= __n; }
239 #if __cplusplus >= 201103L 240 _Grow(
const _Grow&) =
delete;
241 _Grow& operator=(
const _Grow&) =
delete;
244 _Vector_impl& _M_impl;
249 #define _GLIBCXX_ASAN_ANNOTATE_REINIT \ 250 typename _Base::_Vector_impl::template _Asan<>::_Reinit const \ 251 __attribute__((__unused__)) __reinit_guard(this->_M_impl) 252 #define _GLIBCXX_ASAN_ANNOTATE_GROW(n) \ 253 typename _Base::_Vector_impl::template _Asan<>::_Grow \ 254 __attribute__((__unused__)) __grow_guard(this->_M_impl, (n)) 255 #define _GLIBCXX_ASAN_ANNOTATE_GREW(n) __grow_guard._M_grew(n) 256 #define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n) \ 257 _Base::_Vector_impl::template _Asan<>::_S_shrink(this->_M_impl, n) 258 #define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC \ 259 _Base::_Vector_impl::template _Asan<>::_S_on_dealloc(this->_M_impl) 260 #else // ! (_GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR) 261 #define _GLIBCXX_ASAN_ANNOTATE_REINIT 262 #define _GLIBCXX_ASAN_ANNOTATE_GROW(n) 263 #define _GLIBCXX_ASAN_ANNOTATE_GREW(n) 264 #define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n) 265 #define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC 266 #endif // _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR 270 typedef _Alloc allocator_type;
273 _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
274 {
return this->_M_impl; }
276 const _Tp_alloc_type&
277 _M_get_Tp_allocator()
const _GLIBCXX_NOEXCEPT
278 {
return this->_M_impl; }
281 get_allocator()
const _GLIBCXX_NOEXCEPT
282 {
return allocator_type(_M_get_Tp_allocator()); }
284 #if __cplusplus >= 201103L 290 _Vector_base(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
294 #if !_GLIBCXX_INLINE_VERSION 297 { _M_create_storage(__n); }
302 { _M_create_storage(__n); }
304 #if __cplusplus >= 201103L 308 # if !_GLIBCXX_INLINE_VERSION 310 : _M_impl(std::move(__a)) { }
315 if (__x.get_allocator() == __a)
316 this->_M_impl._M_swap_data(__x._M_impl);
319 size_t __n = __x._M_impl._M_finish - __x._M_impl._M_start;
320 _M_create_storage(__n);
326 : _M_impl(_Tp_alloc_type(__a), std::move(__x._M_impl))
332 _M_deallocate(_M_impl._M_start,
333 _M_impl._M_end_of_storage - _M_impl._M_start);
337 _Vector_impl _M_impl;
340 _M_allocate(
size_t __n)
343 return __n != 0 ? _Tr::allocate(_M_impl, __n) : pointer();
347 _M_deallocate(pointer __p,
size_t __n)
351 _Tr::deallocate(_M_impl, __p, __n);
356 _M_create_storage(
size_t __n)
358 this->_M_impl._M_start = this->_M_allocate(__n);
359 this->_M_impl._M_finish = this->_M_impl._M_start;
360 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
385 template<
typename _Tp,
typename _Alloc = std::allocator<_Tp> >
388 #ifdef _GLIBCXX_CONCEPT_CHECKS 390 typedef typename _Alloc::value_type _Alloc_value_type;
391 # if __cplusplus < 201103L 392 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
394 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
397 #if __cplusplus >= 201103L 398 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
399 "std::vector must have a non-const, non-volatile value_type");
400 # ifdef __STRICT_ANSI__ 402 "std::vector must have the same value_type as its allocator");
407 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
411 typedef _Tp value_type;
412 typedef typename _Base::pointer pointer;
413 typedef typename _Alloc_traits::const_pointer const_pointer;
414 typedef typename _Alloc_traits::reference reference;
415 typedef typename _Alloc_traits::const_reference const_reference;
416 typedef __gnu_cxx::__normal_iterator<pointer, vector> iterator;
417 typedef __gnu_cxx::__normal_iterator<const_pointer, vector>
421 typedef size_t size_type;
422 typedef ptrdiff_t difference_type;
423 typedef _Alloc allocator_type;
426 #if __cplusplus >= 201103L 427 static constexpr
bool 430 return noexcept(std::__relocate_a(std::declval<pointer>(),
431 std::declval<pointer>(),
432 std::declval<pointer>(),
433 std::declval<_Tp_alloc_type&>()));
438 using _Base::_M_allocate;
439 using _Base::_M_deallocate;
440 using _Base::_M_impl;
441 using _Base::_M_get_Tp_allocator;
450 #if __cplusplus >= 201103L 461 vector(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
464 #if __cplusplus >= 201103L 474 vector(size_type __n,
const allocator_type& __a = allocator_type())
475 : _Base(_S_check_init_len(__n, __a), __a)
476 { _M_default_initialize(__n); }
486 vector(size_type __n,
const value_type& __value,
487 const allocator_type& __a = allocator_type())
488 : _Base(_S_check_init_len(__n, __a), __a)
489 { _M_fill_initialize(__n, __value); }
500 vector(size_type __n,
const value_type& __value = value_type(),
501 const allocator_type& __a = allocator_type())
502 : _Base(_S_check_init_len(__n, __a), __a)
503 { _M_fill_initialize(__n, __value); }
519 _Alloc_traits::_S_select_on_copy(__x._M_get_Tp_allocator()))
521 this->_M_impl._M_finish =
522 std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
523 this->_M_impl._M_start,
524 _M_get_Tp_allocator());
527 #if __cplusplus >= 201103L 540 : _Base(__x.size(), __a)
542 this->_M_impl._M_finish =
543 std::__uninitialized_copy_a(__x.
begin(), __x.
end(),
544 this->_M_impl._M_start,
545 _M_get_Tp_allocator());
550 : _Base(__m, std::move(__rv))
556 if (__rv.get_allocator() == __m)
557 this->_M_impl._M_swap_data(__rv._M_impl);
558 else if (!__rv.empty())
560 this->_M_create_storage(__rv.size());
561 this->_M_impl._M_finish =
562 std::__uninitialized_move_a(__rv.begin(), __rv.end(),
563 this->_M_impl._M_start,
564 _M_get_Tp_allocator());
573 vector(std::declval<vector&&>(), std::declval<const allocator_type&>(),
574 std::declval<typename _Alloc_traits::is_always_equal>())) )
575 :
vector(
std::move(__rv), __m, typename _Alloc_traits::is_always_equal{})
590 const allocator_type& __a = allocator_type())
593 _M_range_initialize(__l.begin(), __l.end(),
614 #if __cplusplus >= 201103L 615 template<
typename _InputIterator,
616 typename = std::_RequireInputIter<_InputIterator>>
617 vector(_InputIterator __first, _InputIterator __last,
618 const allocator_type& __a = allocator_type())
621 _M_range_initialize(__first, __last,
625 template<
typename _InputIterator>
626 vector(_InputIterator __first, _InputIterator __last,
627 const allocator_type& __a = allocator_type())
631 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
632 _M_initialize_dispatch(__first, __last, _Integral());
644 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
645 _M_get_Tp_allocator());
646 _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC;
659 operator=(
const vector& __x);
661 #if __cplusplus >= 201103L 675 constexpr
bool __move_storage =
676 _Alloc_traits::_S_propagate_on_move_assign()
677 || _Alloc_traits::_S_always_equal();
696 this->_M_assign_aux(__l.begin(), __l.end(),
713 assign(size_type __n,
const value_type& __val)
714 { _M_fill_assign(__n, __val); }
728 #if __cplusplus >= 201103L 729 template<
typename _InputIterator,
730 typename = std::_RequireInputIter<_InputIterator>>
732 assign(_InputIterator __first, _InputIterator __last)
733 { _M_assign_dispatch(__first, __last, __false_type()); }
735 template<
typename _InputIterator>
737 assign(_InputIterator __first, _InputIterator __last)
740 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
741 _M_assign_dispatch(__first, __last, _Integral());
745 #if __cplusplus >= 201103L 760 this->_M_assign_aux(__l.begin(), __l.end(),
766 using _Base::get_allocator;
776 {
return iterator(this->_M_impl._M_start); }
785 {
return const_iterator(this->_M_impl._M_start); }
794 {
return iterator(this->_M_impl._M_finish); }
802 end() const _GLIBCXX_NOEXCEPT
803 {
return const_iterator(this->_M_impl._M_finish); }
812 {
return reverse_iterator(
end()); }
819 const_reverse_iterator
821 {
return const_reverse_iterator(
end()); }
830 {
return reverse_iterator(
begin()); }
837 const_reverse_iterator
839 {
return const_reverse_iterator(
begin()); }
841 #if __cplusplus >= 201103L 849 {
return const_iterator(this->_M_impl._M_start); }
858 {
return const_iterator(this->_M_impl._M_finish); }
865 const_reverse_iterator
867 {
return const_reverse_iterator(
end()); }
874 const_reverse_iterator
876 {
return const_reverse_iterator(
begin()); }
883 {
return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
888 {
return _S_max_size(_M_get_Tp_allocator()); }
890 #if __cplusplus >= 201103L 903 if (__new_size > size())
904 _M_default_append(__new_size - size());
905 else if (__new_size < size())
906 _M_erase_at_end(this->_M_impl._M_start + __new_size);
921 resize(size_type __new_size,
const value_type& __x)
923 if (__new_size > size())
924 _M_fill_insert(
end(), __new_size - size(), __x);
925 else if (__new_size < size())
926 _M_erase_at_end(this->_M_impl._M_start + __new_size);
941 resize(size_type __new_size, value_type __x = value_type())
943 if (__new_size > size())
944 _M_fill_insert(
end(), __new_size - size(), __x);
945 else if (__new_size < size())
946 _M_erase_at_end(this->_M_impl._M_start + __new_size);
950 #if __cplusplus >= 201103L 954 { _M_shrink_to_fit(); }
963 {
return size_type(this->_M_impl._M_end_of_storage
964 - this->_M_impl._M_start); }
970 _GLIBCXX_NODISCARD
bool 992 reserve(size_type __n);
1009 __glibcxx_requires_subscript(__n);
1010 return *(this->_M_impl._M_start + __n);
1027 __glibcxx_requires_subscript(__n);
1028 return *(this->_M_impl._M_start + __n);
1036 if (__n >= this->size())
1037 __throw_out_of_range_fmt(__N(
"vector::_M_range_check: __n " 1038 "(which is %zu) >= this->size() " 1058 _M_range_check(__n);
1059 return (*
this)[__n];
1076 _M_range_check(__n);
1077 return (*
this)[__n];
1087 __glibcxx_requires_nonempty();
1098 __glibcxx_requires_nonempty();
1109 __glibcxx_requires_nonempty();
1110 return *(
end() - 1);
1120 __glibcxx_requires_nonempty();
1121 return *(
end() - 1);
1133 {
return _M_data_ptr(this->_M_impl._M_start); }
1136 data()
const _GLIBCXX_NOEXCEPT
1137 {
return _M_data_ptr(this->_M_impl._M_start); }
1153 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
1155 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
1156 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
1158 ++this->_M_impl._M_finish;
1159 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
1162 _M_realloc_insert(
end(), __x);
1165 #if __cplusplus >= 201103L 1167 push_back(value_type&& __x)
1168 { emplace_back(std::move(__x)); }
1170 template<
typename... _Args>
1171 #if __cplusplus > 201402L 1176 emplace_back(_Args&&... __args);
1191 __glibcxx_requires_nonempty();
1192 --this->_M_impl._M_finish;
1193 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
1194 _GLIBCXX_ASAN_ANNOTATE_SHRINK(1);
1197 #if __cplusplus >= 201103L 1210 template<
typename... _Args>
1212 emplace(const_iterator __position, _Args&&... __args)
1213 {
return _M_emplace_aux(__position, std::forward<_Args>(__args)...); }
1227 insert(const_iterator __position,
const value_type& __x);
1241 insert(iterator __position,
const value_type& __x);
1244 #if __cplusplus >= 201103L 1257 insert(const_iterator __position, value_type&& __x)
1258 {
return _M_insert_rval(__position, std::move(__x)); }
1276 auto __offset = __position -
cbegin();
1277 _M_range_insert(
begin() + __offset, __l.begin(), __l.end(),
1279 return begin() + __offset;
1283 #if __cplusplus >= 201103L 1299 insert(const_iterator __position, size_type __n,
const value_type& __x)
1301 difference_type __offset = __position -
cbegin();
1302 _M_fill_insert(
begin() + __offset, __n, __x);
1303 return begin() + __offset;
1320 insert(iterator __position, size_type __n,
const value_type& __x)
1321 { _M_fill_insert(__position, __n, __x); }
1324 #if __cplusplus >= 201103L 1340 template<
typename _InputIterator,
1341 typename = std::_RequireInputIter<_InputIterator>>
1343 insert(const_iterator __position, _InputIterator __first,
1344 _InputIterator __last)
1346 difference_type __offset = __position -
cbegin();
1347 _M_insert_dispatch(
begin() + __offset,
1348 __first, __last, __false_type());
1349 return begin() + __offset;
1366 template<
typename _InputIterator>
1368 insert(iterator __position, _InputIterator __first,
1369 _InputIterator __last)
1372 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1373 _M_insert_dispatch(__position, __first, __last, _Integral());
1393 #if __cplusplus >= 201103L 1395 {
return _M_erase(
begin() + (__position -
cbegin())); }
1397 erase(iterator __position)
1398 {
return _M_erase(__position); }
1420 #if __cplusplus >= 201103L 1421 erase(const_iterator __first, const_iterator __last)
1423 const auto __beg =
begin();
1424 const auto __cbeg =
cbegin();
1425 return _M_erase(__beg + (__first - __cbeg), __beg + (__last - __cbeg));
1428 erase(iterator __first, iterator __last)
1429 {
return _M_erase(__first, __last); }
1446 #if __cplusplus >= 201103L 1447 __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value
1448 || _M_get_Tp_allocator() == __x._M_get_Tp_allocator());
1450 this->_M_impl._M_swap_data(__x._M_impl);
1451 _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(),
1452 __x._M_get_Tp_allocator());
1463 { _M_erase_at_end(this->_M_impl._M_start); }
1470 template<
typename _ForwardIterator>
1473 _ForwardIterator __first, _ForwardIterator __last)
1475 pointer __result = this->_M_allocate(__n);
1478 std::__uninitialized_copy_a(__first, __last, __result,
1479 _M_get_Tp_allocator());
1484 _M_deallocate(__result, __n);
1485 __throw_exception_again;
1494 #if __cplusplus < 201103L 1497 template<
typename _Integer>
1499 _M_initialize_dispatch(_Integer __n, _Integer __value, __true_type)
1501 this->_M_impl._M_start = _M_allocate(_S_check_init_len(
1502 static_cast<size_type>(__n), _M_get_Tp_allocator()));
1503 this->_M_impl._M_end_of_storage =
1504 this->_M_impl._M_start +
static_cast<size_type
>(__n);
1505 _M_fill_initialize(static_cast<size_type>(__n), __value);
1509 template<
typename _InputIterator>
1511 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1514 _M_range_initialize(__first, __last,
1520 template<
typename _InputIterator>
1522 _M_range_initialize(_InputIterator __first, _InputIterator __last,
1526 for (; __first != __last; ++__first)
1527 #
if __cplusplus >= 201103L
1528 emplace_back(*__first);
1530 push_back(*__first);
1534 __throw_exception_again;
1539 template<
typename _ForwardIterator>
1541 _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
1545 this->_M_impl._M_start
1546 = this->_M_allocate(_S_check_init_len(__n, _M_get_Tp_allocator()));
1547 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
1548 this->_M_impl._M_finish =
1549 std::__uninitialized_copy_a(__first, __last,
1550 this->_M_impl._M_start,
1551 _M_get_Tp_allocator());
1557 _M_fill_initialize(size_type __n,
const value_type& __value)
1559 this->_M_impl._M_finish =
1560 std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value,
1561 _M_get_Tp_allocator());
1564 #if __cplusplus >= 201103L 1567 _M_default_initialize(size_type __n)
1569 this->_M_impl._M_finish =
1570 std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
1571 _M_get_Tp_allocator());
1582 template<
typename _Integer>
1584 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1585 { _M_fill_assign(__n, __val); }
1588 template<
typename _InputIterator>
1590 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1595 template<
typename _InputIterator>
1597 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1601 template<
typename _ForwardIterator>
1603 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1609 _M_fill_assign(size_type __n,
const value_type& __val);
1617 template<
typename _Integer>
1619 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
1621 { _M_fill_insert(__pos, __n, __val); }
1624 template<
typename _InputIterator>
1626 _M_insert_dispatch(iterator __pos, _InputIterator __first,
1627 _InputIterator __last, __false_type)
1629 _M_range_insert(__pos, __first, __last,
1634 template<
typename _InputIterator>
1636 _M_range_insert(iterator __pos, _InputIterator __first,
1640 template<
typename _ForwardIterator>
1642 _M_range_insert(iterator __pos, _ForwardIterator __first,
1648 _M_fill_insert(iterator __pos, size_type __n,
const value_type& __x);
1650 #if __cplusplus >= 201103L 1653 _M_default_append(size_type __n);
1659 #if __cplusplus < 201103L 1662 _M_insert_aux(iterator __position,
const value_type& __x);
1665 _M_realloc_insert(iterator __position,
const value_type& __x);
1669 struct _Temporary_value
1671 template<
typename... _Args>
1673 _Temporary_value(
vector* __vec, _Args&&... __args) : _M_this(__vec)
1675 _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(),
1676 std::forward<_Args>(__args)...);
1680 { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); }
1683 _M_val() {
return *_M_ptr(); }
1687 _M_ptr() {
return reinterpret_cast<_Tp*
>(&__buf); }
1695 template<
typename _Arg>
1697 _M_insert_aux(iterator __position, _Arg&& __arg);
1699 template<
typename... _Args>
1701 _M_realloc_insert(iterator __position, _Args&&... __args);
1705 _M_insert_rval(const_iterator __position, value_type&& __v);
1708 template<
typename... _Args>
1710 _M_emplace_aux(const_iterator __position, _Args&&... __args);
1714 _M_emplace_aux(const_iterator __position, value_type&& __v)
1715 {
return _M_insert_rval(__position, std::move(__v)); }
1720 _M_check_len(size_type __n,
const char* __s)
const 1722 if (max_size() - size() < __n)
1723 __throw_length_error(__N(__s));
1725 const size_type __len = size() + (
std::max)(size(), __n);
1726 return (__len < size() || __len > max_size()) ? max_size() : __len;
1731 _S_check_init_len(size_type __n,
const allocator_type& __a)
1733 if (__n > _S_max_size(_Tp_alloc_type(__a)))
1734 __throw_length_error(
1735 __N(
"cannot create std::vector larger than max_size()"));
1740 _S_max_size(
const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT
1745 const size_t __diffmax
1746 = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max /
sizeof(_Tp);
1747 const size_t __allocmax = _Alloc_traits::max_size(__a);
1748 return (
std::min)(__diffmax, __allocmax);
1756 _M_erase_at_end(pointer __pos) _GLIBCXX_NOEXCEPT
1758 if (size_type __n = this->_M_impl._M_finish - __pos)
1761 _M_get_Tp_allocator());
1762 this->_M_impl._M_finish = __pos;
1763 _GLIBCXX_ASAN_ANNOTATE_SHRINK(__n);
1768 _M_erase(iterator __position);
1771 _M_erase(iterator __first, iterator __last);
1773 #if __cplusplus >= 201103L 1781 vector __tmp(get_allocator());
1782 this->_M_impl._M_swap_data(__x._M_impl);
1783 __tmp._M_impl._M_swap_data(__x._M_impl);
1784 std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator());
1792 if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
1793 _M_move_assign(std::move(__x),
true_type());
1798 this->assign(std::__make_move_if_noexcept_iterator(__x.begin()),
1799 std::__make_move_if_noexcept_iterator(__x.end()));
1805 template<
typename _Up>
1807 _M_data_ptr(_Up* __ptr)
const _GLIBCXX_NOEXCEPT
1810 #if __cplusplus >= 201103L 1811 template<
typename _Ptr>
1813 _M_data_ptr(_Ptr __ptr)
const 1814 {
return empty() ? nullptr : std::__to_address(__ptr); }
1816 template<
typename _Up>
1818 _M_data_ptr(_Up* __ptr) _GLIBCXX_NOEXCEPT
1821 template<
typename _Ptr>
1823 _M_data_ptr(_Ptr __ptr)
1824 {
return empty() ? (value_type*)0 : __ptr.operator->(); }
1826 template<
typename _Ptr>
1828 _M_data_ptr(_Ptr __ptr)
const 1829 {
return empty() ? (
const value_type*)0 : __ptr.operator->(); }
1833 #if __cpp_deduction_guides >= 201606 1834 template<
typename _InputIterator,
typename _ValT
1835 =
typename iterator_traits<_InputIterator>::value_type,
1837 typename = _RequireInputIter<_InputIterator>,
1838 typename = _RequireAllocator<_Allocator>>
1839 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
1853 template<
typename _Tp,
typename _Alloc>
1870 template<
typename _Tp,
typename _Alloc>
1874 __y.begin(), __y.end()); }
1877 template<
typename _Tp,
typename _Alloc>
1880 {
return !(__x == __y); }
1883 template<
typename _Tp,
typename _Alloc>
1886 {
return __y < __x; }
1889 template<
typename _Tp,
typename _Alloc>
1892 {
return !(__y < __x); }
1895 template<
typename _Tp,
typename _Alloc>
1898 {
return !(__x < __y); }
1901 template<
typename _Tp,
typename _Alloc>
1904 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1907 _GLIBCXX_END_NAMESPACE_CONTAINER
1908 _GLIBCXX_END_NAMESPACE_VERSION
const_reverse_iterator crbegin() const noexcept
const_reverse_iterator rbegin() const noexcept
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
reverse_iterator rend() noexcept
vector(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a vector from an initializer list.
Random-access iterators support a superset of bidirectional iterator operations.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
iterator begin() noexcept
vector(const vector &__x)
Vector copy constructor.
void assign(initializer_list< value_type > __l)
Assigns an initializer list to a vector.
vector(const vector &__x, const allocator_type &__a)
Copy constructor with alternative allocator.
reference back() noexcept
const_iterator begin() const noexcept
const_reference back() const noexcept
const_reference at(size_type __n) const
Provides access to the data contained in the vector.
const_iterator end() const noexcept
void resize(size_type __new_size)
Resizes the vector to the specified number of elements.
reference operator[](size_type __n) noexcept
Subscript access to the data contained in the vector.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
ISO C++ entities toplevel namespace is std.
size_type max_size() const noexcept
void pop_back() noexcept
Removes last element.
The standard allocator, as per [20.4].
vector & operator=(vector &&__x) noexcept(_Alloc_traits::_S_nothrow_move())
Vector move assignment operator.
__detected_or_t< __get_first_arg_t< _Ptr >, __element_type, _Ptr > element_type
The type pointed to.
vector(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a vector from a range.
void _Destroy(_Tp *__pointer)
void _M_range_check(size_type __n) const
Safety check used only from at().
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
reference at(size_type __n)
Provides access to the data contained in the vector.
void assign(size_type __n, const value_type &__val)
Assigns a given value to a vector.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
const_reference front() const noexcept
void push_back(const value_type &__x)
Add data to the end of the vector.
iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into vector before specified iterator.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
iterator emplace(const_iterator __position, _Args &&... __args)
Inserts an object in vector before specified iterator.
is_nothrow_default_constructible
reference front() noexcept
iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the vector.
vector(size_type __n, const allocator_type &__a=allocator_type())
Creates a vector with default constructed elements.
const_iterator cend() const noexcept
vector(const allocator_type &__a) noexcept
Creates a vector with no elements.
const_reference operator[](size_type __n) const noexcept
Subscript access to the data contained in the vector.
vector(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a vector with copies of an exemplar element.
size_type size() const noexcept
const_iterator cbegin() const noexcept
vector(vector &&__rv, const 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.
Uniform interface to C++98 and C++11 allocators.
iterator erase(const_iterator __position)
Remove element at given position.
vector & operator=(initializer_list< value_type > __l)
Vector list assignment operator.
iterator insert(const_iterator __position, initializer_list< value_type > __l)
Inserts an initializer_list into the vector.
void resize(size_type __new_size, const value_type &__x)
Resizes the vector to the specified number of elements.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a vector.
iterator insert(const_iterator __position, size_type __n, const value_type &__x)
Inserts a number of copies of given data into the vector.
void swap(vector &__x) noexcept
Swaps data with another vector.
pointer _M_allocate_and_copy(size_type __n, _ForwardIterator __first, _ForwardIterator __last)
size_type capacity() const noexcept
_GLIBCXX_NODISCARD bool empty() const noexcept
const_reverse_iterator rend() const noexcept
const_reverse_iterator crend() const noexcept
Forward iterators support a superset of input iterator operations.
iterator erase(const_iterator __first, const_iterator __last)
Remove a range of elements.
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.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
A standard container which offers fixed time access to individual elements in any order...
See bits/stl_deque.h's _Deque_base for an explanation.
bool equal(_IIter1 __first1, _IIter1 __last1, _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
Tests a range for element-wise equality.
reverse_iterator rbegin() noexcept