59namespace std _GLIBCXX_VISIBILITY(default)
61_GLIBCXX_BEGIN_NAMESPACE_VERSION
62_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
64 template<
typename _Tp,
typename _Alloc>
70 if (__n > this->max_size())
71 __throw_length_error(__N(
"vector::reserve"));
72 if (this->capacity() < __n)
76#if __cplusplus >= 201103L
79 __tmp = this->_M_allocate(__n);
80 _S_relocate(this->_M_impl._M_start,
this->_M_impl._M_finish,
81 __tmp, _M_get_Tp_allocator());
86 __tmp = _M_allocate_and_copy(__n,
87 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_start),
88 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_finish));
90 _M_get_Tp_allocator());
92 _GLIBCXX_ASAN_ANNOTATE_REINIT;
93 _M_deallocate(this->_M_impl._M_start,
94 this->_M_impl._M_end_of_storage
95 -
this->_M_impl._M_start);
96 this->_M_impl._M_start =
__tmp;
98 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
102#if __cplusplus >= 201103L
103 template<
typename _Tp,
typename _Alloc>
104 template<
typename...
_Args>
105#if __cplusplus > 201402L
107 typename vector<_Tp, _Alloc>::reference
114 if (this->_M_impl._M_finish !=
this->_M_impl._M_end_of_storage)
116 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
117 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
119 ++this->_M_impl._M_finish;
120 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
124#if __cplusplus > 201402L
130 template<
typename _Tp,
typename _Alloc>
132 typename vector<_Tp, _Alloc>::iterator
134#if __cplusplus >= 201103L
135 insert(const_iterator
__position,
const value_type& __x)
137 insert(iterator
__position,
const value_type& __x)
141 if (this->_M_impl._M_finish !=
this->_M_impl._M_end_of_storage)
143 __glibcxx_assert(
__position != const_iterator());
149 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
150 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
152 ++this->_M_impl._M_finish;
153 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
157#if __cplusplus >= 201103L
161 _Temporary_value
__x_copy(
this, __x);
169#if __cplusplus >= 201103L
175 return iterator(this->_M_impl._M_start + __n);
178 template<
typename _Tp,
typename _Alloc>
180 typename vector<_Tp, _Alloc>::iterator
186 --this->_M_impl._M_finish;
187 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
188 _GLIBCXX_ASAN_ANNOTATE_SHRINK(1);
192 template<
typename _Tp,
typename _Alloc>
194 typename vector<_Tp, _Alloc>::iterator
195 vector<_Tp, _Alloc>::
196 _M_erase(iterator __first, iterator __last)
198 if (__first != __last)
201 _GLIBCXX_MOVE3(__last,
end(), __first);
202 _M_erase_at_end(__first.base() + (
end() - __last));
207 template<
typename _Tp,
typename _Alloc>
211 operator=(
const vector<_Tp, _Alloc>& __x)
215 _GLIBCXX_ASAN_ANNOTATE_REINIT;
216#if __cplusplus >= 201103L
217 if (_Alloc_traits::_S_propagate_on_copy_assign())
219 if (!_Alloc_traits::_S_always_equal()
220 && _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
224 _M_deallocate(this->_M_impl._M_start,
225 this->_M_impl._M_end_of_storage
226 - this->_M_impl._M_start);
227 this->_M_impl._M_start =
nullptr;
228 this->_M_impl._M_finish =
nullptr;
229 this->_M_impl._M_end_of_storage =
nullptr;
232 __x._M_get_Tp_allocator());
235 const size_type __xlen = __x.size();
236 if (__xlen > capacity())
238 pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(),
240 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
241 _M_get_Tp_allocator());
242 _M_deallocate(this->_M_impl._M_start,
243 this->_M_impl._M_end_of_storage
244 - this->_M_impl._M_start);
245 this->_M_impl._M_start = __tmp;
246 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen;
248 else if (
size() >= __xlen)
251 end(), _M_get_Tp_allocator());
255 std::copy(__x._M_impl._M_start, __x._M_impl._M_start +
size(),
256 this->_M_impl._M_start);
258 __x._M_impl._M_finish,
259 this->_M_impl._M_finish,
260 _M_get_Tp_allocator());
262 this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
267 template<
typename _Tp,
typename _Alloc>
270 vector<_Tp, _Alloc>::
271 _M_fill_assign(
size_t __n,
const value_type& __val)
273 const size_type __sz =
size();
274 if (__n > capacity())
277 __builtin_unreachable();
278 vector __tmp(__n, __val, _M_get_Tp_allocator());
279 __tmp._M_impl._M_swap_data(this->_M_impl);
284 const size_type __add = __n - __sz;
285 _GLIBCXX_ASAN_ANNOTATE_GROW(__add);
286 this->_M_impl._M_finish =
288 __add, __val, _M_get_Tp_allocator());
289 _GLIBCXX_ASAN_ANNOTATE_GREW(__add);
292 _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val));
295 template<
typename _Tp,
typename _Alloc>
296 template<
typename _InputIterator>
299 vector<_Tp, _Alloc>::
300 _M_assign_aux(_InputIterator __first, _InputIterator __last,
303 pointer __cur(this->_M_impl._M_start);
304 for (; __first != __last && __cur != this->_M_impl._M_finish;
305 ++__cur, (void)++__first)
307 if (__first == __last)
308 _M_erase_at_end(__cur);
310 _M_range_insert(
end(), __first, __last,
314 template<
typename _Tp,
typename _Alloc>
315 template<
typename _ForwardIterator>
318 vector<_Tp, _Alloc>::
319 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
322 const size_type __sz =
size();
325 if (__len > capacity())
328 __builtin_unreachable();
330 _S_check_init_len(__len, _M_get_Tp_allocator());
331 pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
332 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
333 _M_get_Tp_allocator());
334 _GLIBCXX_ASAN_ANNOTATE_REINIT;
335 _M_deallocate(this->_M_impl._M_start,
336 this->_M_impl._M_end_of_storage
337 - this->_M_impl._M_start);
338 this->_M_impl._M_start = __tmp;
339 this->_M_impl._M_finish = this->_M_impl._M_start + __len;
340 this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
342 else if (__sz >= __len)
343 _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
346 _ForwardIterator __mid = __first;
348 std::copy(__first, __mid, this->_M_impl._M_start);
349 const size_type __attribute__((__unused__)) __n = __len - __sz;
350 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
351 this->_M_impl._M_finish =
353 this->_M_impl._M_finish,
354 _M_get_Tp_allocator());
355 _GLIBCXX_ASAN_ANNOTATE_GREW(__n);
359#if __cplusplus >= 201103L
360 template<
typename _Tp,
typename _Alloc>
363 vector<_Tp, _Alloc>::
364 _M_insert_rval(const_iterator __position, value_type&& __v) -> iterator
366 const auto __n = __position -
cbegin();
367 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
368 if (__position ==
cend())
370 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
371 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
373 ++this->_M_impl._M_finish;
374 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
381 return iterator(this->_M_impl._M_start + __n);
384 template<
typename _Tp,
typename _Alloc>
385 template<
typename... _Args>
388 vector<_Tp, _Alloc>::
389 _M_emplace_aux(const_iterator __position, _Args&&... __args)
392 const auto __n = __position -
cbegin();
393 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
394 if (__position ==
cend())
396 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
397 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
399 ++this->_M_impl._M_finish;
400 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
413 return iterator(this->_M_impl._M_start + __n);
416 template<
typename _Tp,
typename _Alloc>
417 template<
typename _Arg>
420 vector<_Tp, _Alloc>::
421 _M_insert_aux(iterator __position, _Arg&& __arg)
423 template<
typename _Tp,
typename _Alloc>
425 vector<_Tp, _Alloc>::
426 _M_insert_aux(iterator __position,
const _Tp& __x)
429 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
430 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
431 _GLIBCXX_MOVE(*(this->_M_impl._M_finish - 1)));
432 ++this->_M_impl._M_finish;
433 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
434#if __cplusplus < 201103L
437 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
438 this->_M_impl._M_finish - 2,
439 this->_M_impl._M_finish - 1);
440#if __cplusplus < 201103L
441 *__position = __x_copy;
447#if __cplusplus >= 201103L
448 template<
typename _Tp,
typename _Alloc>
449 template<
typename... _Args>
452 vector<_Tp, _Alloc>::
453 _M_realloc_insert(iterator __position, _Args&&... __args)
455 template<
typename _Tp,
typename _Alloc>
457 vector<_Tp, _Alloc>::
458 _M_realloc_insert(iterator __position,
const _Tp& __x)
461 const size_type __len = _M_check_len(1u,
"vector::_M_realloc_insert");
463 __builtin_unreachable ();
464 pointer __old_start = this->_M_impl._M_start;
465 pointer __old_finish = this->_M_impl._M_finish;
466 const size_type __elems_before = __position -
begin();
467 pointer __new_start(this->_M_allocate(__len));
468 pointer __new_finish(__new_start);
471 _Guard_alloc __guard(__new_start, __len, *
this);
480#if __cplusplus >= 201103L
481 _Alloc_traits::construct(this->_M_impl,
485 _Alloc_traits::construct(this->_M_impl,
486 __new_start + __elems_before,
490#if __cplusplus >= 201103L
491 if _GLIBCXX17_CONSTEXPR (_S_use_relocate())
494 __new_finish = _S_relocate(__old_start, __position.base(),
495 __new_start, _M_get_Tp_allocator());
497 __new_finish = _S_relocate(__position.base(), __old_finish,
498 __new_finish, _M_get_Tp_allocator());
506 pointer _M_first, _M_last;
507 _Tp_alloc_type& _M_alloc;
510 _Guard_elts(pointer __elt, _Tp_alloc_type& __a)
511 : _M_first(__elt), _M_last(__elt + 1), _M_alloc(__a)
519 _Guard_elts(
const _Guard_elts&);
523 _Guard_elts __guard_elts(__new_start + __elems_before, _M_impl);
526 __old_start, __position.base(),
527 __new_start, _M_get_Tp_allocator());
531 __guard_elts._M_first = __new_start;
534 __position.base(), __old_finish,
535 __new_finish, _M_get_Tp_allocator());
538 __guard_elts._M_first = __old_start;
539 __guard_elts._M_last = __old_finish;
541 __guard._M_storage = __old_start;
542 __guard._M_len = this->_M_impl._M_end_of_storage - __old_start;
547 this->_M_impl._M_start = __new_start;
548 this->_M_impl._M_finish = __new_finish;
549 this->_M_impl._M_end_of_storage = __new_start + __len;
552#if __cplusplus >= 201103L
553 template<
typename _Tp,
typename _Alloc>
554 template<
typename... _Args>
557 vector<_Tp, _Alloc>::
558 _M_realloc_append(_Args&&... __args)
560 template<
typename _Tp,
typename _Alloc>
562 vector<_Tp, _Alloc>::
563 _M_realloc_append(
const _Tp& __x)
566 const size_type __len = _M_check_len(1u,
"vector::_M_realloc_append");
568 __builtin_unreachable ();
569 pointer __old_start = this->_M_impl._M_start;
570 pointer __old_finish = this->_M_impl._M_finish;
571 const size_type __elems =
end() -
begin();
572 pointer __new_start(this->_M_allocate(__len));
573 pointer __new_finish(__new_start);
576 _Guard_alloc __guard(__new_start, __len, *
this);
585#if __cplusplus >= 201103L
586 _Alloc_traits::construct(this->_M_impl,
590 _Alloc_traits::construct(this->_M_impl,
591 __new_start + __elems,
595#if __cplusplus >= 201103L
596 if _GLIBCXX17_CONSTEXPR (_S_use_relocate())
599 __new_finish = _S_relocate(__old_start, __old_finish,
600 __new_start, _M_get_Tp_allocator());
609 pointer _M_first, _M_last;
610 _Tp_alloc_type& _M_alloc;
613 _Guard_elts(pointer __elt, _Tp_alloc_type& __a)
614 : _M_first(__elt), _M_last(__elt + 1), _M_alloc(__a)
622 _Guard_elts(
const _Guard_elts&);
626 _Guard_elts __guard_elts(__new_start + __elems, _M_impl);
629 __old_start, __old_finish,
630 __new_start, _M_get_Tp_allocator());
635 __guard_elts._M_first = __old_start;
636 __guard_elts._M_last = __old_finish;
638 __guard._M_storage = __old_start;
639 __guard._M_len = this->_M_impl._M_end_of_storage - __old_start;
644 this->_M_impl._M_start = __new_start;
645 this->_M_impl._M_finish = __new_finish;
646 this->_M_impl._M_end_of_storage = __new_start + __len;
649 template<
typename _Tp,
typename _Alloc>
652 vector<_Tp, _Alloc>::
653 _M_fill_insert(iterator __position, size_type __n,
const value_type& __x)
657 if (__position.base() == this->_M_impl._M_finish)
658 _M_fill_append(__n, __x);
659 else if (size_type(this->_M_impl._M_end_of_storage
660 - this->_M_impl._M_finish) >= __n)
662#if __cplusplus < 201103L
663 value_type __x_copy = __x;
665 _Temporary_value __tmp(
this, __x);
666 value_type& __x_copy = __tmp._M_val();
668 const size_type __elems_after =
end() - __position;
669 pointer __old_finish(this->_M_impl._M_finish);
670 if (__elems_after > __n)
672 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
676 _M_get_Tp_allocator());
677 this->_M_impl._M_finish += __n;
678 _GLIBCXX_ASAN_ANNOTATE_GREW(__n);
679 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
680 __old_finish - __n, __old_finish);
681 std::fill(__position.base(), __position.base() + __n,
686 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
687 this->_M_impl._M_finish =
691 _M_get_Tp_allocator());
692 _GLIBCXX_ASAN_ANNOTATE_GREW(__n - __elems_after);
694 this->_M_impl._M_finish,
695 _M_get_Tp_allocator());
696 this->_M_impl._M_finish += __elems_after;
697 _GLIBCXX_ASAN_ANNOTATE_GREW(__elems_after);
698 std::fill(__position.base(), __old_finish, __x_copy);
705 pointer __old_start = this->_M_impl._M_start;
706 pointer __old_finish = this->_M_impl._M_finish;
707 const pointer __pos = __position.base();
709 const size_type __len =
710 _M_check_len(__n,
"vector::_M_fill_insert");
711 const size_type __elems_before = __pos - __old_start;
712 pointer __new_start(this->_M_allocate(__len));
713 pointer __new_finish(__new_start);
719 _M_get_Tp_allocator());
720 __new_finish = pointer();
724 (__old_start, __pos, __new_start, _M_get_Tp_allocator());
730 (__pos, __old_finish, __new_finish, _M_get_Tp_allocator());
736 __new_start + __elems_before + __n,
737 _M_get_Tp_allocator());
740 _M_get_Tp_allocator());
741 _M_deallocate(__new_start, __len);
742 __throw_exception_again;
744 std::_Destroy(__old_start, __old_finish, _M_get_Tp_allocator());
745 _GLIBCXX_ASAN_ANNOTATE_REINIT;
746 _M_deallocate(__old_start,
747 this->_M_impl._M_end_of_storage - __old_start);
748 this->_M_impl._M_start = __new_start;
749 this->_M_impl._M_finish = __new_finish;
750 this->_M_impl._M_end_of_storage = __new_start + __len;
755 template<
typename _Tp,
typename _Alloc>
758 vector<_Tp, _Alloc>::
759 _M_fill_append(size_type __n,
const value_type& __x)
761 if (size_type(this->_M_impl._M_end_of_storage
762 - this->_M_impl._M_finish) >= __n)
764 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
765 this->_M_impl._M_finish =
767 _M_get_Tp_allocator());
768 _GLIBCXX_ASAN_ANNOTATE_GREW(__n);
774 pointer __old_start = this->_M_impl._M_start;
775 pointer __old_finish = this->_M_impl._M_finish;
776 const size_type __old_size = __old_finish - __old_start;
778 const size_type __len =
779 _M_check_len(__n,
"vector::_M_fill_append");
780 pointer __new_start(this->_M_allocate(__len));
781 pointer __new_finish(__new_start + __old_size);
786 __new_finish, __n, __x,
787 _M_get_Tp_allocator());
789 __old_start, __old_finish, __new_start,
790 _M_get_Tp_allocator());
795 _M_get_Tp_allocator());
796 _M_deallocate(__new_start, __len);
797 __throw_exception_again;
799 std::_Destroy(__old_start, __old_finish, _M_get_Tp_allocator());
800 _GLIBCXX_ASAN_ANNOTATE_REINIT;
801 _M_deallocate(__old_start,
802 this->_M_impl._M_end_of_storage - __old_start);
803 this->_M_impl._M_start = __new_start;
804 this->_M_impl._M_finish = __new_finish;
805 this->_M_impl._M_end_of_storage = __new_start + __len;
809#if __cplusplus >= 201103L
810 template<
typename _Tp,
typename _Alloc>
813 vector<_Tp, _Alloc>::
814 _M_default_append(size_type __n)
818 const size_type __size =
size();
819 size_type __navail = size_type(this->_M_impl._M_end_of_storage
820 - this->_M_impl._M_finish);
822 if (__size > max_size() || __navail > max_size() - __size)
823 __builtin_unreachable();
827 if (!this->_M_impl._M_finish)
828 __builtin_unreachable();
830 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
831 this->_M_impl._M_finish =
833 __n, _M_get_Tp_allocator());
834 _GLIBCXX_ASAN_ANNOTATE_GREW(__n);
840 pointer __old_start = this->_M_impl._M_start;
841 pointer __old_finish = this->_M_impl._M_finish;
843 const size_type __len =
844 _M_check_len(__n,
"vector::_M_default_append");
845 pointer __new_start(this->_M_allocate(__len));
848 _Guard_alloc __guard(__new_start, __len, *
this);
851 _M_get_Tp_allocator());
853 if _GLIBCXX17_CONSTEXPR (_S_use_relocate())
855 _S_relocate(__old_start, __old_finish,
856 __new_start, _M_get_Tp_allocator());
863 pointer _M_first, _M_last;
864 _Tp_alloc_type& _M_alloc;
867 _Guard_elts(pointer __first, size_type __n,
869 : _M_first(__first), _M_last(__first + __n), _M_alloc(__a)
877 _Guard_elts(
const _Guard_elts&);
879 _Guard_elts __guard_elts(__new_start + __size, __n, _M_impl);
882 __old_start, __old_finish, __new_start,
883 _M_get_Tp_allocator());
885 __guard_elts._M_first = __old_start;
886 __guard_elts._M_last = __old_finish;
888 _GLIBCXX_ASAN_ANNOTATE_REINIT;
889 __guard._M_storage = __old_start;
890 __guard._M_len = this->_M_impl._M_end_of_storage - __old_start;
895 this->_M_impl._M_start = __new_start;
896 this->_M_impl._M_finish = __new_start + __size + __n;
897 this->_M_impl._M_end_of_storage = __new_start + __len;
902 template<
typename _Tp,
typename _Alloc>
905 vector<_Tp, _Alloc>::
908 if (capacity() ==
size())
910 _GLIBCXX_ASAN_ANNOTATE_REINIT;
915 template<
typename _Tp,
typename _Alloc>
916 template<
typename _InputIterator>
919 vector<_Tp, _Alloc>::
920 _M_range_insert(iterator __pos, _InputIterator __first,
925 for (; __first != __last; ++__first)
926 insert(
end(), *__first);
928 else if (__first != __last)
930 vector __tmp(__first, __last, _M_get_Tp_allocator());
932 _GLIBCXX_MAKE_MOVE_ITERATOR(__tmp.begin()),
933 _GLIBCXX_MAKE_MOVE_ITERATOR(__tmp.end()));
937 template<
typename _Tp,
typename _Alloc>
938 template<
typename _ForwardIterator>
941 vector<_Tp, _Alloc>::
942 _M_range_insert(iterator __position, _ForwardIterator __first,
945 if (__first != __last)
948 if (size_type(this->_M_impl._M_end_of_storage
949 - this->_M_impl._M_finish) >= __n)
951 const size_type __elems_after =
end() - __position;
952 pointer __old_finish(this->_M_impl._M_finish);
953 if (__elems_after > __n)
955 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
957 this->_M_impl._M_finish,
958 this->_M_impl._M_finish,
959 _M_get_Tp_allocator());
960 this->_M_impl._M_finish += __n;
961 _GLIBCXX_ASAN_ANNOTATE_GREW(__n);
962 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
963 __old_finish - __n, __old_finish);
964 std::copy(__first, __last, __position);
968 _ForwardIterator __mid = __first;
970 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
972 this->_M_impl._M_finish,
973 _M_get_Tp_allocator());
974 this->_M_impl._M_finish += __n - __elems_after;
975 _GLIBCXX_ASAN_ANNOTATE_GREW(__n - __elems_after);
978 this->_M_impl._M_finish,
979 _M_get_Tp_allocator());
980 this->_M_impl._M_finish += __elems_after;
981 _GLIBCXX_ASAN_ANNOTATE_GREW(__elems_after);
982 std::copy(__first, __mid, __position);
990 pointer __old_start = this->_M_impl._M_start;
991 pointer __old_finish = this->_M_impl._M_finish;
993 const size_type __len =
994 _M_check_len(__n,
"vector::_M_range_insert");
995#if __cplusplus < 201103L
996 if (__len < (__n + (__old_finish - __old_start)))
997 __builtin_unreachable();
1000 pointer __new_start(this->_M_allocate(__len));
1001 pointer __new_finish(__new_start);
1006 (__old_start, __position.base(),
1007 __new_start, _M_get_Tp_allocator());
1011 _M_get_Tp_allocator());
1014 (__position.base(), __old_finish,
1015 __new_finish, _M_get_Tp_allocator());
1020 _M_get_Tp_allocator());
1021 _M_deallocate(__new_start, __len);
1022 __throw_exception_again;
1025 _M_get_Tp_allocator());
1026 _GLIBCXX_ASAN_ANNOTATE_REINIT;
1027 _M_deallocate(__old_start,
1028 this->_M_impl._M_end_of_storage - __old_start);
1029 this->_M_impl._M_start = __new_start;
1030 this->_M_impl._M_finish = __new_finish;
1031 this->_M_impl._M_end_of_storage = __new_start + __len;
1036#if __glibcxx_containers_ranges
1037 template<
typename _Tp,
typename _Alloc>
1038 template<__detail::__container_compatible_range<_Tp> _Rg>
1040 vector<_Tp, _Alloc>::
1041 insert_range(const_iterator __pos, _Rg&& __rg)
1044 if (__pos ==
cend())
1046 const auto __ins_idx =
size();
1048 return begin() + __ins_idx;
1051 if constexpr (ranges::forward_range<_Rg>)
1053 const auto __ins_idx = __pos -
cbegin();
1055 const auto __n = size_type(ranges::distance(__rg));
1057 return begin() + __ins_idx;
1060 pointer __old_start = this->_M_impl._M_start;
1062 pointer __old_finish = this->_M_impl._M_finish;
1064 pointer __ins = __old_start + __ins_idx;
1066 const auto __cap = this->_M_impl._M_end_of_storage - __old_finish;
1070 const size_type __elems_after =
cend() - __pos;
1071 if (__elems_after > __n)
1073 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
1077 _M_get_Tp_allocator());
1078 this->_M_impl._M_finish += __n;
1079 _GLIBCXX_ASAN_ANNOTATE_GREW(__n);
1081 ranges::copy(__rg, __ins);
1085 auto __first = ranges::begin(__rg);
1086 const auto __last = ranges::end(__rg);
1087 auto __mid = ranges::next(__first, __elems_after);
1088 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
1089 _Base::_M_append_range(ranges::subrange(__mid, __last));
1090 _GLIBCXX_ASAN_ANNOTATE_GREW(__n - __elems_after);
1092 this->_M_impl._M_finish,
1093 _M_get_Tp_allocator());
1094 this->_M_impl._M_finish += __elems_after;
1095 _GLIBCXX_ASAN_ANNOTATE_GREW(__elems_after);
1096 ranges::copy(__first, __mid, __ins);
1101 const size_type __len
1102 = _M_check_len(__n,
"vector::insert_range");
1104 struct _Guard : _Guard_alloc
1107 pointer _M_finish = _Guard_alloc::_M_storage;
1109 using _Guard_alloc::_Guard_alloc;
1115 this->_M_vect._M_get_Tp_allocator());
1120 pointer __new_start(this->_M_allocate(__len));
1121 _Guard __guard(__new_start, __len, *
this);
1123 auto& __alloc = _M_get_Tp_allocator();
1132 __old_start, __ins, __new_start, __alloc);
1135 _Base::_M_append_range_to(__rg, __guard._M_finish);
1140 __ins, __old_finish, __guard._M_finish, __alloc);
1142 _GLIBCXX_ASAN_ANNOTATE_REINIT;
1146 this->_M_impl._M_start = __guard._M_storage;
1147 this->_M_impl._M_finish = __guard._M_finish;
1148 this->_M_impl._M_end_of_storage = __new_start + __len;
1149 __guard._M_storage = __old_start;
1150 __guard._M_finish = __old_finish;
1151 __guard._M_len = (__old_finish - __old_start) + __cap;
1156 return begin() + __ins_idx;
1160 _M_get_Tp_allocator()));
1165 template<
typename _Alloc>
1166 _GLIBCXX20_CONSTEXPR
1168 vector<bool, _Alloc>::
1169 _M_reallocate(size_type __n)
1171 const iterator __begin =
begin(), __end =
end();
1172 if (size_type(__end - __begin) > __n)
1173 __builtin_unreachable();
1174 _Bit_pointer __q = this->_M_allocate(__n);
1176 iterator __finish(_M_copy_aligned(__begin, __end, __start));
1177 this->_M_deallocate();
1178 this->_M_impl._M_start = __start;
1179 this->_M_impl._M_finish = __finish;
1180 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
1183 template<
typename _Alloc>
1184 _GLIBCXX20_CONSTEXPR
1186 vector<bool, _Alloc>::
1187 _M_fill_insert(iterator __position, size_type __n,
bool __x)
1191 if (capacity() -
size() >= __n)
1193 std::copy_backward(__position,
end(),
1194 this->_M_impl._M_finish + difference_type(__n));
1195 std::fill(__position, __position + difference_type(__n), __x);
1196 this->_M_impl._M_finish += difference_type(__n);
1200 const size_type __len =
1201 _M_check_len(__n,
"vector<bool>::_M_fill_insert");
1202 iterator __begin =
begin(), __end =
end();
1203 _Bit_pointer __q = this->_M_allocate(__len);
1205 iterator __i = _M_copy_aligned(__begin, __position, __start);
1206 std::fill(__i, __i + difference_type(__n), __x);
1207 iterator __finish = std::copy(__position, __end,
1208 __i + difference_type(__n));
1209 this->_M_deallocate();
1210 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
1211 this->_M_impl._M_start = __start;
1212 this->_M_impl._M_finish = __finish;
1216 template<
typename _Alloc>
1217 template<
typename _ForwardIterator>
1218 _GLIBCXX20_CONSTEXPR
1220 vector<bool, _Alloc>::
1221 _M_insert_range(iterator __position, _ForwardIterator __first,
1224 if (__first != __last)
1227 if (capacity() -
size() >= __n)
1229 std::copy_backward(__position,
end(),
1230 this->_M_impl._M_finish
1231 + difference_type(__n));
1232 std::copy(__first, __last, __position);
1233 this->_M_impl._M_finish += difference_type(__n);
1237 const size_type __len =
1238 _M_check_len(__n,
"vector<bool>::_M_insert_range");
1239 const iterator __begin =
begin(), __end =
end();
1240 _Bit_pointer __q = this->_M_allocate(__len);
1242 iterator __i = _M_copy_aligned(__begin, __position, __start);
1243 __i = std::copy(__first, __last, __i);
1244 iterator __finish = std::copy(__position, __end, __i);
1245 this->_M_deallocate();
1246 this->_M_impl._M_end_of_storage = __q + _S_nword(
__len);
1247 this->_M_impl._M_start =
__start;
1248 this->_M_impl._M_finish =
__finish;
1253 template<
typename _Alloc>
1254 _GLIBCXX20_CONSTEXPR
1256 vector<bool, _Alloc>::
1257 _M_insert_aux(iterator __position,
bool __x)
1259 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
1261 std::copy_backward(__position, this->_M_impl._M_finish,
1262 this->_M_impl._M_finish + 1);
1264 ++this->_M_impl._M_finish;
1268 const size_type __len =
1269 _M_check_len(size_type(1),
"vector<bool>::_M_insert_aux");
1270 _Bit_pointer __q = this->_M_allocate(__len);
1272 iterator __i = _M_copy_aligned(
begin(), __position, __start);
1274 iterator __finish = std::copy(__position,
end(), __i);
1275 this->_M_deallocate();
1276 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
1277 this->_M_impl._M_start = __start;
1278 this->_M_impl._M_finish = __finish;
1282 template<
typename _Alloc>
1283 _GLIBCXX20_CONSTEXPR
1284 typename vector<bool, _Alloc>::iterator
1285 vector<bool, _Alloc>::
1286 _M_erase(iterator __position)
1288 if (__position + 1 !=
end())
1289 std::copy(__position + 1,
end(), __position);
1290 --this->_M_impl._M_finish;
1294 template<
typename _Alloc>
1295 _GLIBCXX20_CONSTEXPR
1296 typename vector<bool, _Alloc>::iterator
1297 vector<bool, _Alloc>::
1298 _M_erase(iterator __first, iterator __last)
1300 if (__first != __last)
1301 _M_erase_at_end(std::copy(__last,
end(), __first));
1305#if __cplusplus >= 201103L
1306 template<
typename _Alloc>
1307 _GLIBCXX20_CONSTEXPR
1309 vector<bool, _Alloc>::
1312 if (capacity() -
size() <
int(_S_word_bit))
1316 if (size_type __n =
size())
1320 this->_M_deallocate();
1321 this->_M_impl._M_reset();
1330_GLIBCXX_END_NAMESPACE_CONTAINER
1331_GLIBCXX_END_NAMESPACE_VERSION
1334#if __cplusplus >= 201103L
1336namespace std _GLIBCXX_VISIBILITY(default)
1338_GLIBCXX_BEGIN_NAMESPACE_VERSION
1340 template<
typename _Alloc>
1342 hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>::
1343 operator()(
const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b)
const noexcept
1346 const size_t __words = __b.size() / _S_word_bit;
1349 const size_t __clength = __words *
sizeof(_Bit_type);
1350 __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength);
1353 const size_t __extrabits = __b.size() % _S_word_bit;
1356 _Bit_type __hiword = *__b._M_impl._M_finish._M_p;
1357 __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
1359 const size_t __clength
1360 = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1362 __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash);
1364 __hash = std::_Hash_impl::hash(&__hiword, __clength);
1370_GLIBCXX_END_NAMESPACE_VERSION
1375#undef _GLIBCXX_ASAN_ANNOTATE_REINIT
1376#undef _GLIBCXX_ASAN_ANNOTATE_GROW
1377#undef _GLIBCXX_ASAN_ANNOTATE_GREW
1378#undef _GLIBCXX_ASAN_ANNOTATE_SHRINK
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
constexpr _BI2 move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
Moves the range [first,last) into result.
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 auto cend(const _Container &__cont) noexcept(noexcept(std::end(__cont))) -> decltype(std::end(__cont))
Return an iterator pointing to one past the last element of the const container.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
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.
constexpr void _Destroy(_ForwardIterator __first, _ForwardIterator __last)
Forward iterators support a superset of input iterator operations.
A standard container which offers fixed time access to individual elements in any order.
constexpr vector & operator=(const vector &__x)
Vector assignment operator.
constexpr void reserve(size_type __n)
Attempt to preallocate enough memory for specified number of elements.