59 namespace std _GLIBCXX_VISIBILITY(default)
61 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
63 template<
typename _Tp,
typename _Alloc>
68 if (__n > this->max_size())
69 __throw_length_error(__N(
"vector::reserve"));
70 if (this->capacity() < __n)
72 const size_type __old_size = size();
73 pointer __tmp = _M_allocate_and_copy(__n,
74 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_start),
75 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_finish));
76 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
77 _M_get_Tp_allocator());
78 _M_deallocate(this->_M_impl._M_start,
79 this->_M_impl._M_end_of_storage
80 - this->_M_impl._M_start);
81 this->_M_impl._M_start = __tmp;
82 this->_M_impl._M_finish = __tmp + __old_size;
83 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
87 #if __cplusplus >= 201103L 88 template<
typename _Tp,
typename _Alloc>
89 template<
typename... _Args>
90 #if __cplusplus > 201402L 91 typename vector<_Tp, _Alloc>::reference
98 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
100 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
101 std::forward<_Args>(__args)...);
102 ++this->_M_impl._M_finish;
105 _M_realloc_insert(
end(), std::forward<_Args>(__args)...);
106 #if __cplusplus > 201402L 112 template<
typename _Tp,
typename _Alloc>
113 typename vector<_Tp, _Alloc>::iterator
115 #if __cplusplus >= 201103L 116 insert(const_iterator __position,
const value_type& __x)
118 insert(iterator __position,
const value_type& __x)
121 const size_type __n = __position -
begin();
122 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
123 if (__position ==
end())
125 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
127 ++this->_M_impl._M_finish;
131 #if __cplusplus >= 201103L 132 const auto __pos =
begin() + (__position -
cbegin());
135 _Temporary_value __x_copy(
this, __x);
136 _M_insert_aux(__pos, std::move(__x_copy._M_val()));
138 _M_insert_aux(__position, __x);
142 #if __cplusplus >= 201103L 143 _M_realloc_insert(
begin() + (__position -
cbegin()), __x);
145 _M_realloc_insert(__position, __x);
148 return iterator(this->_M_impl._M_start + __n);
151 template<
typename _Tp,
typename _Alloc>
152 typename vector<_Tp, _Alloc>::iterator
156 if (__position + 1 !=
end())
157 _GLIBCXX_MOVE3(__position + 1,
end(), __position);
158 --this->_M_impl._M_finish;
159 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
163 template<
typename _Tp,
typename _Alloc>
164 typename vector<_Tp, _Alloc>::iterator
166 _M_erase(iterator __first, iterator __last)
168 if (__first != __last)
171 _GLIBCXX_MOVE3(__last,
end(), __first);
172 _M_erase_at_end(__first.base() + (
end() - __last));
177 template<
typename _Tp,
typename _Alloc>
184 #if __cplusplus >= 201103L 185 if (_Alloc_traits::_S_propagate_on_copy_assign())
187 if (!_Alloc_traits::_S_always_equal()
188 && _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
192 _M_deallocate(this->_M_impl._M_start,
193 this->_M_impl._M_end_of_storage
194 - this->_M_impl._M_start);
195 this->_M_impl._M_start =
nullptr;
196 this->_M_impl._M_finish =
nullptr;
197 this->_M_impl._M_end_of_storage =
nullptr;
199 std::__alloc_on_copy(_M_get_Tp_allocator(),
200 __x._M_get_Tp_allocator());
203 const size_type __xlen = __x.
size();
204 if (__xlen > capacity())
206 pointer __tmp = _M_allocate_and_copy(__xlen, __x.
begin(),
208 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
209 _M_get_Tp_allocator());
210 _M_deallocate(this->_M_impl._M_start,
211 this->_M_impl._M_end_of_storage
212 - this->_M_impl._M_start);
213 this->_M_impl._M_start = __tmp;
214 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen;
216 else if (size() >= __xlen)
219 end(), _M_get_Tp_allocator());
223 std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(),
224 this->_M_impl._M_start);
225 std::__uninitialized_copy_a(__x._M_impl._M_start + size(),
226 __x._M_impl._M_finish,
227 this->_M_impl._M_finish,
228 _M_get_Tp_allocator());
230 this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
235 template<
typename _Tp,
typename _Alloc>
240 if (__n > capacity())
242 vector __tmp(__n, __val, _M_get_Tp_allocator());
243 __tmp._M_impl._M_swap_data(this->_M_impl);
245 else if (__n > size())
248 this->_M_impl._M_finish =
249 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
251 _M_get_Tp_allocator());
254 _M_erase_at_end(
std::fill_n(this->_M_impl._M_start, __n, __val));
257 template<
typename _Tp,
typename _Alloc>
258 template<
typename _InputIterator>
264 pointer __cur(this->_M_impl._M_start);
265 for (; __first != __last && __cur != this->_M_impl._M_finish;
268 if (__first == __last)
269 _M_erase_at_end(__cur);
271 _M_range_insert(
end(), __first, __last,
275 template<
typename _Tp,
typename _Alloc>
276 template<
typename _ForwardIterator>
279 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
284 if (__len > capacity())
286 pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
287 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
288 _M_get_Tp_allocator());
289 _M_deallocate(this->_M_impl._M_start,
290 this->_M_impl._M_end_of_storage
291 - this->_M_impl._M_start);
292 this->_M_impl._M_start = __tmp;
293 this->_M_impl._M_finish = this->_M_impl._M_start + __len;
294 this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
296 else if (size() >= __len)
297 _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
300 _ForwardIterator __mid = __first;
302 std::copy(__first, __mid, this->_M_impl._M_start);
303 this->_M_impl._M_finish =
304 std::__uninitialized_copy_a(__mid, __last,
305 this->_M_impl._M_finish,
306 _M_get_Tp_allocator());
310 #if __cplusplus >= 201103L 311 template<
typename _Tp,
typename _Alloc>
314 _M_insert_rval(const_iterator __position, value_type&& __v) -> iterator
316 const auto __n = __position -
cbegin();
317 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
318 if (__position ==
cend())
320 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
322 ++this->_M_impl._M_finish;
325 _M_insert_aux(
begin() + __n, std::move(__v));
327 _M_realloc_insert(
begin() + __n, std::move(__v));
329 return iterator(this->_M_impl._M_start + __n);
332 template<
typename _Tp,
typename _Alloc>
333 template<
typename... _Args>
339 const auto __n = __position -
cbegin();
340 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
341 if (__position ==
cend())
343 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
344 std::forward<_Args>(__args)...);
345 ++this->_M_impl._M_finish;
352 _Temporary_value __tmp(
this, std::forward<_Args>(__args)...);
353 _M_insert_aux(
begin() + __n, std::move(__tmp._M_val()));
356 _M_realloc_insert(
begin() + __n, std::forward<_Args>(__args)...);
358 return iterator(this->_M_impl._M_start + __n);
361 template<
typename _Tp,
typename _Alloc>
362 template<
typename _Arg>
367 template<
typename _Tp,
typename _Alloc>
373 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
374 _GLIBCXX_MOVE(*(this->_M_impl._M_finish
376 ++this->_M_impl._M_finish;
377 #if __cplusplus < 201103L 380 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
381 this->_M_impl._M_finish - 2,
382 this->_M_impl._M_finish - 1);
383 #if __cplusplus < 201103L 384 *__position = __x_copy;
386 *__position = std::forward<_Arg>(__arg);
390 #if __cplusplus >= 201103L 391 template<
typename _Tp,
typename _Alloc>
392 template<
typename... _Args>
397 template<
typename _Tp,
typename _Alloc>
403 const size_type __len =
404 _M_check_len(size_type(1),
"vector::_M_realloc_insert");
405 const size_type __elems_before = __position -
begin();
406 pointer __new_start(this->_M_allocate(__len));
407 pointer __new_finish(__new_start);
415 _Alloc_traits::construct(this->_M_impl,
416 __new_start + __elems_before,
417 #
if __cplusplus >= 201103L
418 std::forward<_Args>(__args)...);
422 __new_finish = pointer();
425 = std::__uninitialized_move_if_noexcept_a
426 (this->_M_impl._M_start, __position.base(),
427 __new_start, _M_get_Tp_allocator());
432 = std::__uninitialized_move_if_noexcept_a
433 (__position.base(), this->_M_impl._M_finish,
434 __new_finish, _M_get_Tp_allocator());
439 _Alloc_traits::destroy(this->_M_impl,
440 __new_start + __elems_before);
442 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
443 _M_deallocate(__new_start, __len);
444 __throw_exception_again;
446 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
447 _M_get_Tp_allocator());
448 _M_deallocate(this->_M_impl._M_start,
449 this->_M_impl._M_end_of_storage
450 - this->_M_impl._M_start);
451 this->_M_impl._M_start = __new_start;
452 this->_M_impl._M_finish = __new_finish;
453 this->_M_impl._M_end_of_storage = __new_start + __len;
456 template<
typename _Tp,
typename _Alloc>
459 _M_fill_insert(iterator __position, size_type __n,
const value_type& __x)
463 if (size_type(this->_M_impl._M_end_of_storage
464 - this->_M_impl._M_finish) >= __n)
466 #if __cplusplus < 201103L 467 value_type __x_copy = __x;
469 _Temporary_value __tmp(
this, __x);
470 value_type& __x_copy = __tmp._M_val();
472 const size_type __elems_after =
end() - __position;
473 pointer __old_finish(this->_M_impl._M_finish);
474 if (__elems_after > __n)
476 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
477 this->_M_impl._M_finish,
478 this->_M_impl._M_finish,
479 _M_get_Tp_allocator());
480 this->_M_impl._M_finish += __n;
481 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
482 __old_finish - __n, __old_finish);
483 std::fill(__position.base(), __position.base() + __n,
488 this->_M_impl._M_finish =
489 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
492 _M_get_Tp_allocator());
493 std::__uninitialized_move_a(__position.base(), __old_finish,
494 this->_M_impl._M_finish,
495 _M_get_Tp_allocator());
496 this->_M_impl._M_finish += __elems_after;
497 std::fill(__position.base(), __old_finish, __x_copy);
502 const size_type __len =
503 _M_check_len(__n,
"vector::_M_fill_insert");
504 const size_type __elems_before = __position -
begin();
505 pointer __new_start(this->_M_allocate(__len));
506 pointer __new_finish(__new_start);
510 std::__uninitialized_fill_n_a(__new_start + __elems_before,
512 _M_get_Tp_allocator());
513 __new_finish = pointer();
516 = std::__uninitialized_move_if_noexcept_a
517 (this->_M_impl._M_start, __position.base(),
518 __new_start, _M_get_Tp_allocator());
523 = std::__uninitialized_move_if_noexcept_a
524 (__position.base(), this->_M_impl._M_finish,
525 __new_finish, _M_get_Tp_allocator());
531 __new_start + __elems_before + __n,
532 _M_get_Tp_allocator());
535 _M_get_Tp_allocator());
536 _M_deallocate(__new_start, __len);
537 __throw_exception_again;
539 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
540 _M_get_Tp_allocator());
541 _M_deallocate(this->_M_impl._M_start,
542 this->_M_impl._M_end_of_storage
543 - this->_M_impl._M_start);
544 this->_M_impl._M_start = __new_start;
545 this->_M_impl._M_finish = __new_finish;
546 this->_M_impl._M_end_of_storage = __new_start + __len;
551 #if __cplusplus >= 201103L 552 template<
typename _Tp,
typename _Alloc>
559 if (size_type(this->_M_impl._M_end_of_storage
560 - this->_M_impl._M_finish) >= __n)
562 this->_M_impl._M_finish =
563 std::__uninitialized_default_n_a(this->_M_impl._M_finish,
564 __n, _M_get_Tp_allocator());
568 const size_type __len =
569 _M_check_len(__n,
"vector::_M_default_append");
570 const size_type __old_size = this->size();
571 pointer __new_start(this->_M_allocate(__len));
572 pointer __new_finish(__new_start);
576 = std::__uninitialized_move_if_noexcept_a
577 (this->_M_impl._M_start, this->_M_impl._M_finish,
578 __new_start, _M_get_Tp_allocator());
580 std::__uninitialized_default_n_a(__new_finish, __n,
581 _M_get_Tp_allocator());
586 _M_get_Tp_allocator());
587 _M_deallocate(__new_start, __len);
588 __throw_exception_again;
590 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
591 _M_get_Tp_allocator());
592 _M_deallocate(this->_M_impl._M_start,
593 this->_M_impl._M_end_of_storage
594 - this->_M_impl._M_start);
595 this->_M_impl._M_start = __new_start;
596 this->_M_impl._M_finish = __new_finish;
597 this->_M_impl._M_end_of_storage = __new_start + __len;
602 template<
typename _Tp,
typename _Alloc>
607 if (capacity() == size())
609 return std::__shrink_to_fit_aux<vector>::_S_do_it(*
this);
613 template<
typename _Tp,
typename _Alloc>
614 template<
typename _InputIterator>
620 for (; __first != __last; ++__first)
622 __pos = insert(__pos, *__first);
627 template<
typename _Tp,
typename _Alloc>
628 template<
typename _ForwardIterator>
634 if (__first != __last)
637 if (size_type(this->_M_impl._M_end_of_storage
638 - this->_M_impl._M_finish) >= __n)
640 const size_type __elems_after =
end() - __position;
641 pointer __old_finish(this->_M_impl._M_finish);
642 if (__elems_after > __n)
644 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
645 this->_M_impl._M_finish,
646 this->_M_impl._M_finish,
647 _M_get_Tp_allocator());
648 this->_M_impl._M_finish += __n;
649 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
650 __old_finish - __n, __old_finish);
651 std::copy(__first, __last, __position);
655 _ForwardIterator __mid = __first;
657 std::__uninitialized_copy_a(__mid, __last,
658 this->_M_impl._M_finish,
659 _M_get_Tp_allocator());
660 this->_M_impl._M_finish += __n - __elems_after;
661 std::__uninitialized_move_a(__position.base(),
663 this->_M_impl._M_finish,
664 _M_get_Tp_allocator());
665 this->_M_impl._M_finish += __elems_after;
666 std::copy(__first, __mid, __position);
671 const size_type __len =
672 _M_check_len(__n,
"vector::_M_range_insert");
673 pointer __new_start(this->_M_allocate(__len));
674 pointer __new_finish(__new_start);
678 = std::__uninitialized_move_if_noexcept_a
679 (this->_M_impl._M_start, __position.base(),
680 __new_start, _M_get_Tp_allocator());
682 = std::__uninitialized_copy_a(__first, __last,
684 _M_get_Tp_allocator());
686 = std::__uninitialized_move_if_noexcept_a
687 (__position.base(), this->_M_impl._M_finish,
688 __new_finish, _M_get_Tp_allocator());
693 _M_get_Tp_allocator());
694 _M_deallocate(__new_start, __len);
695 __throw_exception_again;
697 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
698 _M_get_Tp_allocator());
699 _M_deallocate(this->_M_impl._M_start,
700 this->_M_impl._M_end_of_storage
701 - this->_M_impl._M_start);
702 this->_M_impl._M_start = __new_start;
703 this->_M_impl._M_finish = __new_finish;
704 this->_M_impl._M_end_of_storage = __new_start + __len;
711 template<
typename _Alloc>
716 _Bit_pointer __q = this->_M_allocate(__n);
718 iterator __finish(_M_copy_aligned(
begin(),
end(), __start));
719 this->_M_deallocate();
720 this->_M_impl._M_start = __start;
721 this->_M_impl._M_finish = __finish;
722 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
725 template<
typename _Alloc>
734 std::copy_backward(__position,
end(),
735 this->_M_impl._M_finish + difference_type(__n));
736 std::fill(__position, __position + difference_type(__n), __x);
737 this->_M_impl._M_finish += difference_type(__n);
741 const size_type __len =
742 _M_check_len(__n,
"vector<bool>::_M_fill_insert");
743 _Bit_pointer __q = this->_M_allocate(__len);
745 iterator __i = _M_copy_aligned(
begin(), __position, __start);
746 std::fill(__i, __i + difference_type(__n), __x);
747 iterator __finish = std::copy(__position,
end(),
748 __i + difference_type(__n));
749 this->_M_deallocate();
750 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
751 this->_M_impl._M_start = __start;
752 this->_M_impl._M_finish = __finish;
756 template<
typename _Alloc>
757 template<
typename _ForwardIterator>
763 if (__first != __last)
768 std::copy_backward(__position,
end(),
769 this->_M_impl._M_finish
770 + difference_type(__n));
771 std::copy(__first, __last, __position);
772 this->_M_impl._M_finish += difference_type(__n);
776 const size_type __len =
777 _M_check_len(__n,
"vector<bool>::_M_insert_range");
778 _Bit_pointer __q = this->_M_allocate(__len);
780 iterator __i = _M_copy_aligned(
begin(), __position, __start);
781 __i = std::copy(__first, __last, __i);
782 iterator __finish = std::copy(__position,
end(), __i);
783 this->_M_deallocate();
784 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
785 this->_M_impl._M_start = __start;
786 this->_M_impl._M_finish = __finish;
791 template<
typename _Alloc>
796 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
798 std::copy_backward(__position, this->_M_impl._M_finish,
799 this->_M_impl._M_finish + 1);
801 ++this->_M_impl._M_finish;
805 const size_type __len =
806 _M_check_len(size_type(1),
"vector<bool>::_M_insert_aux");
807 _Bit_pointer __q = this->_M_allocate(__len);
809 iterator __i = _M_copy_aligned(
begin(), __position, __start);
811 iterator __finish = std::copy(__position,
end(), __i);
812 this->_M_deallocate();
813 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
814 this->_M_impl._M_start = __start;
815 this->_M_impl._M_finish = __finish;
819 template<
typename _Alloc>
820 typename vector<bool, _Alloc>::iterator
824 if (__position + 1 !=
end())
825 std::copy(__position + 1,
end(), __position);
826 --this->_M_impl._M_finish;
830 template<
typename _Alloc>
831 typename vector<bool, _Alloc>::iterator
833 _M_erase(iterator __first, iterator __last)
835 if (__first != __last)
836 _M_erase_at_end(std::copy(__last,
end(), __first));
840 #if __cplusplus >= 201103L 841 template<
typename _Alloc>
850 _M_reallocate(
size());
858 _GLIBCXX_END_NAMESPACE_CONTAINER
861 #if __cplusplus >= 201103L 863 namespace std _GLIBCXX_VISIBILITY(default)
865 _GLIBCXX_BEGIN_NAMESPACE_VERSION
867 template<
typename _Alloc>
870 operator()(
const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b)
const noexcept
873 using _GLIBCXX_STD_C::_S_word_bit;
874 using _GLIBCXX_STD_C::_Bit_type;
876 const size_t __words = __b.size() / _S_word_bit;
879 const size_t __clength = __words *
sizeof(_Bit_type);
880 __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength);
883 const size_t __extrabits = __b.size() % _S_word_bit;
886 _Bit_type __hiword = *__b._M_impl._M_finish._M_p;
887 __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
889 const size_t __clength
890 = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
892 __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash);
894 __hash = std::_Hash_impl::hash(&__hiword, __clength);
900 _GLIBCXX_END_NAMESPACE_VERSION
iterator begin() noexcept
void reserve(size_type __n)
Attempt to preallocate enough memory for specified number of elements.
_OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
size_type capacity() const noexcept
size_type size() const noexcept
iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
A standard container which offers fixed time access to individual elements in any order...
vector & operator=(const vector &__x)
Vector assignment operator.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
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.
ISO C++ entities toplevel namespace is std.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
Forward iterators support a superset of input iterator operations.
Primary class template hash.
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.
void _Destroy(_Tp *__pointer)