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)
74 const size_type __old_size =
size();
76#if __cplusplus >= 201103L
77 if _GLIBCXX17_CONSTEXPR (_S_use_relocate())
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));
89 std::_Destroy(this->_M_impl._M_start, 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;
97 this->_M_impl._M_finish = __tmp + __old_size;
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)
140 const size_type __n = __position -
begin();
141 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
143 __glibcxx_assert(__position != const_iterator());
144 if (!(__position != const_iterator()))
145 __builtin_unreachable();
147 if (__position ==
end())
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
158 const auto __pos =
begin() + (__position -
cbegin());
161 _Temporary_value __x_copy(
this, __x);
162 _M_insert_aux(__pos,
std::move(__x_copy._M_val()));
164 _M_insert_aux(__position, __x);
169#if __cplusplus >= 201103L
170 _M_realloc_insert(
begin() + (__position -
cbegin()), __x);
172 _M_realloc_insert(__position, __x);
175 return iterator(this->_M_impl._M_start + __n);
178 template<
typename _Tp,
typename _Alloc>
180 typename vector<_Tp, _Alloc>::iterator
184 if (__position + 1 !=
end())
185 _GLIBCXX_MOVE3(__position + 1,
end(), __position);
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;
231 std::__alloc_on_copy(_M_get_Tp_allocator(),
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);
257 std::__uninitialized_copy_a(__x._M_impl._M_start +
size(),
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 =
287 std::__uninitialized_fill_n_a(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 =
352 std::__uninitialized_copy_a(__mid, __last,
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);
475 _Tp_alloc_type& _M_alloc;
478 _Guard(pointer __s, size_type __l, _Tp_alloc_type& __a)
479 : _M_storage(__s), _M_len(__l), _M_alloc(__a)
491 _Guard(
const _Guard&);
495 _Guard __guard(__new_start, __len, _M_impl);
504#if __cplusplus >= 201103L
505 _Alloc_traits::construct(this->_M_impl,
506 std::__to_address(__new_start + __elems_before),
509 _Alloc_traits::construct(this->_M_impl,
510 __new_start + __elems_before,
514#if __cplusplus >= 201103L
515 if _GLIBCXX17_CONSTEXPR (_S_use_relocate())
518 __new_finish = _S_relocate(__old_start, __position.base(),
519 __new_start, _M_get_Tp_allocator());
521 __new_finish = _S_relocate(__position.base(), __old_finish,
522 __new_finish, _M_get_Tp_allocator());
530 pointer _M_first, _M_last;
531 _Tp_alloc_type& _M_alloc;
534 _Guard_elts(pointer __elt, _Tp_alloc_type& __a)
535 : _M_first(__elt), _M_last(__elt + 1), _M_alloc(__a)
543 _Guard_elts(
const _Guard_elts&);
547 _Guard_elts __guard_elts(__new_start + __elems_before, _M_impl);
549 __new_finish = std::__uninitialized_move_if_noexcept_a(
550 __old_start, __position.base(),
551 __new_start, _M_get_Tp_allocator());
555 __guard_elts._M_first = __new_start;
557 __new_finish = std::__uninitialized_move_if_noexcept_a(
558 __position.base(), __old_finish,
559 __new_finish, _M_get_Tp_allocator());
562 __guard_elts._M_first = __old_start;
563 __guard_elts._M_last = __old_finish;
565 __guard._M_storage = __old_start;
566 __guard._M_len = this->_M_impl._M_end_of_storage - __old_start;
571 this->_M_impl._M_start = __new_start;
572 this->_M_impl._M_finish = __new_finish;
573 this->_M_impl._M_end_of_storage = __new_start + __len;
576#if __cplusplus >= 201103L
577 template<
typename _Tp,
typename _Alloc>
578 template<
typename... _Args>
581 vector<_Tp, _Alloc>::
582 _M_realloc_append(_Args&&... __args)
584 template<
typename _Tp,
typename _Alloc>
586 vector<_Tp, _Alloc>::
587 _M_realloc_append(
const _Tp& __x)
590 const size_type __len = _M_check_len(1u,
"vector::_M_realloc_append");
592 __builtin_unreachable ();
593 pointer __old_start = this->_M_impl._M_start;
594 pointer __old_finish = this->_M_impl._M_finish;
595 const size_type __elems =
end() -
begin();
596 pointer __new_start(this->_M_allocate(__len));
597 pointer __new_finish(__new_start);
604 _Tp_alloc_type& _M_alloc;
607 _Guard(pointer __s, size_type __l, _Tp_alloc_type& __a)
608 : _M_storage(__s), _M_len(__l), _M_alloc(__a)
620 _Guard(
const _Guard&);
624 _Guard __guard(__new_start, __len, _M_impl);
633#if __cplusplus >= 201103L
634 _Alloc_traits::construct(this->_M_impl,
635 std::__to_address(__new_start + __elems),
638 _Alloc_traits::construct(this->_M_impl,
639 __new_start + __elems,
643#if __cplusplus >= 201103L
644 if _GLIBCXX17_CONSTEXPR (_S_use_relocate())
647 __new_finish = _S_relocate(__old_start, __old_finish,
648 __new_start, _M_get_Tp_allocator());
657 pointer _M_first, _M_last;
658 _Tp_alloc_type& _M_alloc;
661 _Guard_elts(pointer __elt, _Tp_alloc_type& __a)
662 : _M_first(__elt), _M_last(__elt + 1), _M_alloc(__a)
670 _Guard_elts(
const _Guard_elts&);
674 _Guard_elts __guard_elts(__new_start + __elems, _M_impl);
676 __new_finish = std::__uninitialized_move_if_noexcept_a(
677 __old_start, __old_finish,
678 __new_start, _M_get_Tp_allocator());
683 __guard_elts._M_first = __old_start;
684 __guard_elts._M_last = __old_finish;
686 __guard._M_storage = __old_start;
687 __guard._M_len = this->_M_impl._M_end_of_storage - __old_start;
692 this->_M_impl._M_start = __new_start;
693 this->_M_impl._M_finish = __new_finish;
694 this->_M_impl._M_end_of_storage = __new_start + __len;
697 template<
typename _Tp,
typename _Alloc>
700 vector<_Tp, _Alloc>::
701 _M_fill_insert(iterator __position, size_type __n,
const value_type& __x)
705 if (size_type(this->_M_impl._M_end_of_storage
706 - this->_M_impl._M_finish) >= __n)
708#if __cplusplus < 201103L
709 value_type __x_copy = __x;
711 _Temporary_value __tmp(
this, __x);
712 value_type& __x_copy = __tmp._M_val();
714 const size_type __elems_after =
end() - __position;
715 pointer __old_finish(this->_M_impl._M_finish);
716 if (__elems_after > __n)
718 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
719 std::__uninitialized_move_a(__old_finish - __n,
722 _M_get_Tp_allocator());
723 this->_M_impl._M_finish += __n;
724 _GLIBCXX_ASAN_ANNOTATE_GREW(__n);
725 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
726 __old_finish - __n, __old_finish);
727 std::fill(__position.base(), __position.base() + __n,
732 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
733 this->_M_impl._M_finish =
734 std::__uninitialized_fill_n_a(__old_finish,
737 _M_get_Tp_allocator());
738 _GLIBCXX_ASAN_ANNOTATE_GREW(__n - __elems_after);
739 std::__uninitialized_move_a(__position.base(), __old_finish,
740 this->_M_impl._M_finish,
741 _M_get_Tp_allocator());
742 this->_M_impl._M_finish += __elems_after;
743 _GLIBCXX_ASAN_ANNOTATE_GREW(__elems_after);
744 std::fill(__position.base(), __old_finish, __x_copy);
751 pointer __old_start = this->_M_impl._M_start;
752 pointer __old_finish = this->_M_impl._M_finish;
753 const pointer __pos = __position.base();
755 const size_type __len =
756 _M_check_len(__n,
"vector::_M_fill_insert");
757 const size_type __elems_before = __pos - __old_start;
758 pointer __new_start(this->_M_allocate(__len));
759 pointer __new_finish(__new_start);
763 std::__uninitialized_fill_n_a(__new_start + __elems_before,
765 _M_get_Tp_allocator());
766 __new_finish = pointer();
769 = std::__uninitialized_move_if_noexcept_a
770 (__old_start, __pos, __new_start, _M_get_Tp_allocator());
775 = std::__uninitialized_move_if_noexcept_a
776 (__pos, __old_finish, __new_finish, _M_get_Tp_allocator());
782 __new_start + __elems_before + __n,
783 _M_get_Tp_allocator());
786 _M_get_Tp_allocator());
787 _M_deallocate(__new_start, __len);
788 __throw_exception_again;
790 std::_Destroy(__old_start, __old_finish, _M_get_Tp_allocator());
791 _GLIBCXX_ASAN_ANNOTATE_REINIT;
792 _M_deallocate(__old_start,
793 this->_M_impl._M_end_of_storage - __old_start);
794 this->_M_impl._M_start = __new_start;
795 this->_M_impl._M_finish = __new_finish;
796 this->_M_impl._M_end_of_storage = __new_start + __len;
801#if __cplusplus >= 201103L
802 template<
typename _Tp,
typename _Alloc>
805 vector<_Tp, _Alloc>::
806 _M_default_append(size_type __n)
810 const size_type __size =
size();
811 size_type __navail = size_type(this->_M_impl._M_end_of_storage
812 - this->_M_impl._M_finish);
814 if (__size > max_size() || __navail > max_size() - __size)
815 __builtin_unreachable();
819 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
820 this->_M_impl._M_finish =
821 std::__uninitialized_default_n_a(this->_M_impl._M_finish,
822 __n, _M_get_Tp_allocator());
823 _GLIBCXX_ASAN_ANNOTATE_GREW(__n);
829 pointer __old_start = this->_M_impl._M_start;
830 pointer __old_finish = this->_M_impl._M_finish;
832 const size_type __len =
833 _M_check_len(__n,
"vector::_M_default_append");
834 pointer __new_start(this->_M_allocate(__len));
841 _Tp_alloc_type& _M_alloc;
844 _Guard(pointer __s, size_type __l, _Tp_alloc_type& __a)
845 : _M_storage(__s), _M_len(__l), _M_alloc(__a)
857 _Guard(
const _Guard&);
861 _Guard __guard(__new_start, __len, _M_impl);
863 std::__uninitialized_default_n_a(__new_start + __size, __n,
864 _M_get_Tp_allocator());
866 if _GLIBCXX17_CONSTEXPR (_S_use_relocate())
868 _S_relocate(__old_start, __old_finish,
869 __new_start, _M_get_Tp_allocator());
876 pointer _M_first, _M_last;
877 _Tp_alloc_type& _M_alloc;
880 _Guard_elts(pointer __first, size_type __n,
882 : _M_first(__first), _M_last(__first + __n), _M_alloc(__a)
890 _Guard_elts(
const _Guard_elts&);
892 _Guard_elts __guard_elts(__new_start + __size, __n, _M_impl);
894 std::__uninitialized_move_if_noexcept_a(
895 __old_start, __old_finish, __new_start,
896 _M_get_Tp_allocator());
898 __guard_elts._M_first = __old_start;
899 __guard_elts._M_last = __old_finish;
901 _GLIBCXX_ASAN_ANNOTATE_REINIT;
902 __guard._M_storage = __old_start;
903 __guard._M_len = this->_M_impl._M_end_of_storage - __old_start;
908 this->_M_impl._M_start = __new_start;
909 this->_M_impl._M_finish = __new_start + __size + __n;
910 this->_M_impl._M_end_of_storage = __new_start + __len;
915 template<
typename _Tp,
typename _Alloc>
918 vector<_Tp, _Alloc>::
921 if (capacity() ==
size())
923 _GLIBCXX_ASAN_ANNOTATE_REINIT;
924 return std::__shrink_to_fit_aux<vector>::_S_do_it(*
this);
928 template<
typename _Tp,
typename _Alloc>
929 template<
typename _InputIterator>
932 vector<_Tp, _Alloc>::
933 _M_range_insert(iterator __pos, _InputIterator __first,
938 for (; __first != __last; ++__first)
939 insert(
end(), *__first);
941 else if (__first != __last)
943 vector __tmp(__first, __last, _M_get_Tp_allocator());
945 _GLIBCXX_MAKE_MOVE_ITERATOR(__tmp.begin()),
946 _GLIBCXX_MAKE_MOVE_ITERATOR(__tmp.end()));
950 template<
typename _Tp,
typename _Alloc>
951 template<
typename _ForwardIterator>
954 vector<_Tp, _Alloc>::
955 _M_range_insert(iterator __position, _ForwardIterator __first,
958 if (__first != __last)
961 if (size_type(this->_M_impl._M_end_of_storage
962 - this->_M_impl._M_finish) >= __n)
964 const size_type __elems_after =
end() - __position;
965 pointer __old_finish(this->_M_impl._M_finish);
966 if (__elems_after > __n)
968 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
969 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
970 this->_M_impl._M_finish,
971 this->_M_impl._M_finish,
972 _M_get_Tp_allocator());
973 this->_M_impl._M_finish += __n;
974 _GLIBCXX_ASAN_ANNOTATE_GREW(__n);
975 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
976 __old_finish - __n, __old_finish);
977 std::copy(__first, __last, __position);
981 _ForwardIterator __mid = __first;
983 _GLIBCXX_ASAN_ANNOTATE_GROW(__n);
984 std::__uninitialized_copy_a(__mid, __last,
985 this->_M_impl._M_finish,
986 _M_get_Tp_allocator());
987 this->_M_impl._M_finish += __n - __elems_after;
988 _GLIBCXX_ASAN_ANNOTATE_GREW(__n - __elems_after);
989 std::__uninitialized_move_a(__position.base(),
991 this->_M_impl._M_finish,
992 _M_get_Tp_allocator());
993 this->_M_impl._M_finish += __elems_after;
994 _GLIBCXX_ASAN_ANNOTATE_GREW(__elems_after);
995 std::copy(__first, __mid, __position);
1003 pointer __old_start = this->_M_impl._M_start;
1004 pointer __old_finish = this->_M_impl._M_finish;
1006 const size_type __len =
1007 _M_check_len(__n,
"vector::_M_range_insert");
1008#if __cplusplus < 201103LL
1009 if (__len < (__n + (__old_start - __old_finish)))
1010 __builtin_unreachable();
1013 pointer __new_start(this->_M_allocate(__len));
1014 pointer __new_finish(__new_start);
1018 = std::__uninitialized_move_if_noexcept_a
1019 (__old_start, __position.base(),
1020 __new_start, _M_get_Tp_allocator());
1022 = std::__uninitialized_copy_a(__first, __last,
1024 _M_get_Tp_allocator());
1026 = std::__uninitialized_move_if_noexcept_a
1027 (__position.base(), __old_finish,
1028 __new_finish, _M_get_Tp_allocator());
1033 _M_get_Tp_allocator());
1034 _M_deallocate(__new_start, __len);
1035 __throw_exception_again;
1038 _M_get_Tp_allocator());
1039 _GLIBCXX_ASAN_ANNOTATE_REINIT;
1040 _M_deallocate(__old_start,
1041 this->_M_impl._M_end_of_storage - __old_start);
1042 this->_M_impl._M_start = __new_start;
1043 this->_M_impl._M_finish = __new_finish;
1044 this->_M_impl._M_end_of_storage = __new_start + __len;
1051 template<
typename _Alloc>
1052 _GLIBCXX20_CONSTEXPR
1054 vector<bool, _Alloc>::
1055 _M_reallocate(size_type __n)
1057 _Bit_pointer __q = this->_M_allocate(__n);
1059 iterator __finish(_M_copy_aligned(
begin(),
end(), __start));
1060 this->_M_deallocate();
1061 this->_M_impl._M_start = __start;
1062 this->_M_impl._M_finish = __finish;
1063 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
1066 template<
typename _Alloc>
1067 _GLIBCXX20_CONSTEXPR
1069 vector<bool, _Alloc>::
1070 _M_fill_insert(iterator __position, size_type __n,
bool __x)
1074 if (capacity() -
size() >= __n)
1076 std::copy_backward(__position,
end(),
1077 this->_M_impl._M_finish + difference_type(__n));
1078 std::fill(__position, __position + difference_type(__n), __x);
1079 this->_M_impl._M_finish += difference_type(__n);
1083 const size_type __len =
1084 _M_check_len(__n,
"vector<bool>::_M_fill_insert");
1085 _Bit_pointer __q = this->_M_allocate(__len);
1087 iterator __i = _M_copy_aligned(
begin(), __position, __start);
1088 std::fill(__i, __i + difference_type(__n), __x);
1089 iterator __finish = std::copy(__position,
end(),
1090 __i + difference_type(__n));
1091 this->_M_deallocate();
1092 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
1093 this->_M_impl._M_start = __start;
1094 this->_M_impl._M_finish = __finish;
1098 template<
typename _Alloc>
1099 template<
typename _ForwardIterator>
1100 _GLIBCXX20_CONSTEXPR
1102 vector<bool, _Alloc>::
1103 _M_insert_range(iterator __position, _ForwardIterator __first,
1106 if (__first != __last)
1109 if (capacity() -
size() >= __n)
1111 std::copy_backward(__position,
end(),
1112 this->_M_impl._M_finish
1113 + difference_type(__n));
1114 std::copy(__first, __last, __position);
1115 this->_M_impl._M_finish += difference_type(__n);
1119 const size_type __len =
1120 _M_check_len(__n,
"vector<bool>::_M_insert_range");
1122 _Bit_pointer __q = this->_M_allocate(__len);
1124 iterator __i = _M_copy_aligned(__begin, __position, __start);
1125 __i = std::copy(__first, __last, __i);
1126 iterator __finish = std::copy(__position, __end, __i);
1127 this->_M_deallocate();
1128 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
1129 this->_M_impl._M_start = __start;
1130 this->_M_impl._M_finish = __finish;
1135 template<
typename _Alloc>
1136 _GLIBCXX20_CONSTEXPR
1138 vector<bool, _Alloc>::
1139 _M_insert_aux(iterator __position,
bool __x)
1141 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
1143 std::copy_backward(__position, this->_M_impl._M_finish,
1144 this->_M_impl._M_finish + 1);
1146 ++this->_M_impl._M_finish;
1150 const size_type __len =
1151 _M_check_len(size_type(1),
"vector<bool>::_M_insert_aux");
1152 _Bit_pointer __q = this->_M_allocate(__len);
1154 iterator __i = _M_copy_aligned(
begin(), __position, __start);
1156 iterator __finish = std::copy(__position,
end(), __i);
1157 this->_M_deallocate();
1158 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
1159 this->_M_impl._M_start = __start;
1160 this->_M_impl._M_finish = __finish;
1164 template<
typename _Alloc>
1165 _GLIBCXX20_CONSTEXPR
1166 typename vector<bool, _Alloc>::iterator
1167 vector<bool, _Alloc>::
1168 _M_erase(iterator __position)
1170 if (__position + 1 !=
end())
1171 std::copy(__position + 1,
end(), __position);
1172 --this->_M_impl._M_finish;
1176 template<
typename _Alloc>
1177 _GLIBCXX20_CONSTEXPR
1178 typename vector<bool, _Alloc>::iterator
1179 vector<bool, _Alloc>::
1180 _M_erase(iterator __first, iterator __last)
1182 if (__first != __last)
1183 _M_erase_at_end(std::copy(__last,
end(), __first));
1187#if __cplusplus >= 201103L
1188 template<
typename _Alloc>
1189 _GLIBCXX20_CONSTEXPR
1191 vector<bool, _Alloc>::
1194 if (capacity() -
size() <
int(_S_word_bit))
1198 if (size_type __n =
size())
1202 this->_M_deallocate();
1203 this->_M_impl._M_reset();
1212_GLIBCXX_END_NAMESPACE_CONTAINER
1213_GLIBCXX_END_NAMESPACE_VERSION
1216#if __cplusplus >= 201103L
1218namespace std _GLIBCXX_VISIBILITY(default)
1220_GLIBCXX_BEGIN_NAMESPACE_VERSION
1222 template<
typename _Alloc>
1224 hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>
::
1225 operator()(
const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b)
const noexcept
1228 const size_t __words = __b.size() / _S_word_bit;
1231 const size_t __clength = __words *
sizeof(_Bit_type);
1232 __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength);
1235 const size_t __extrabits = __b.size() % _S_word_bit;
1238 _Bit_type __hiword = *__b._M_impl._M_finish._M_p;
1239 __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
1241 const size_t __clength
1242 = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1244 __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash);
1246 __hash = std::_Hash_impl::hash(&__hiword, __clength);
1252_GLIBCXX_END_NAMESPACE_VERSION
1257#undef _GLIBCXX_ASAN_ANNOTATE_REINIT
1258#undef _GLIBCXX_ASAN_ANNOTATE_GROW
1259#undef _GLIBCXX_ASAN_ANNOTATE_GREW
1260#undef _GLIBCXX_ASAN_ANNOTATE_SHRINK
strong_ordering operator(const error_code &__lhs, const error_code &__rhs) noexcept
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.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
_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 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)
static constexpr void deallocate(_Alloc &__a, pointer __p, size_type __n)
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.