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>
94 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
96 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
97 std::forward<_Args>(__args)...);
98 ++this->_M_impl._M_finish;
101 _M_emplace_back_aux(std::forward<_Args>(__args)...);
105 template<
typename _Tp,
typename _Alloc>
106 typename vector<_Tp, _Alloc>::iterator
108 #if __cplusplus >= 201103L 109 insert(const_iterator __position,
const value_type& __x)
111 insert(iterator __position,
const value_type& __x)
114 const size_type __n = __position -
begin();
115 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
116 && __position ==
end())
118 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, __x);
119 ++this->_M_impl._M_finish;
123 #if __cplusplus >= 201103L 124 const auto __pos =
begin() + (__position -
cbegin());
125 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
128 _M_insert_aux(__pos, std::move(__x_copy));
131 _M_insert_aux(__pos, __x);
133 _M_insert_aux(__position, __x);
136 return iterator(this->_M_impl._M_start + __n);
139 template<
typename _Tp,
typename _Alloc>
140 typename vector<_Tp, _Alloc>::iterator
144 if (__position + 1 !=
end())
145 _GLIBCXX_MOVE3(__position + 1,
end(), __position);
146 --this->_M_impl._M_finish;
147 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
151 template<
typename _Tp,
typename _Alloc>
152 typename vector<_Tp, _Alloc>::iterator
154 _M_erase(iterator __first, iterator __last)
156 if (__first != __last)
159 _GLIBCXX_MOVE3(__last,
end(), __first);
160 _M_erase_at_end(__first.base() + (
end() - __last));
165 template<
typename _Tp,
typename _Alloc>
172 #if __cplusplus >= 201103L 173 if (_Alloc_traits::_S_propagate_on_copy_assign())
175 if (!_Alloc_traits::_S_always_equal()
176 && _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
180 _M_deallocate(this->_M_impl._M_start,
181 this->_M_impl._M_end_of_storage
182 - this->_M_impl._M_start);
183 this->_M_impl._M_start =
nullptr;
184 this->_M_impl._M_finish =
nullptr;
185 this->_M_impl._M_end_of_storage =
nullptr;
187 std::__alloc_on_copy(_M_get_Tp_allocator(),
188 __x._M_get_Tp_allocator());
191 const size_type __xlen = __x.
size();
192 if (__xlen > capacity())
194 pointer __tmp = _M_allocate_and_copy(__xlen, __x.
begin(),
196 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
197 _M_get_Tp_allocator());
198 _M_deallocate(this->_M_impl._M_start,
199 this->_M_impl._M_end_of_storage
200 - this->_M_impl._M_start);
201 this->_M_impl._M_start = __tmp;
202 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen;
204 else if (size() >= __xlen)
207 end(), _M_get_Tp_allocator());
211 std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(),
212 this->_M_impl._M_start);
213 std::__uninitialized_copy_a(__x._M_impl._M_start + size(),
214 __x._M_impl._M_finish,
215 this->_M_impl._M_finish,
216 _M_get_Tp_allocator());
218 this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
223 template<
typename _Tp,
typename _Alloc>
228 if (__n > capacity())
230 vector __tmp(__n, __val, _M_get_Tp_allocator());
231 __tmp._M_impl._M_swap_data(this->_M_impl);
233 else if (__n > size())
236 this->_M_impl._M_finish =
237 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
239 _M_get_Tp_allocator());
242 _M_erase_at_end(
std::fill_n(this->_M_impl._M_start, __n, __val));
245 template<
typename _Tp,
typename _Alloc>
246 template<
typename _InputIterator>
252 pointer __cur(this->_M_impl._M_start);
253 for (; __first != __last && __cur != this->_M_impl._M_finish;
256 if (__first == __last)
257 _M_erase_at_end(__cur);
259 insert(
end(), __first, __last);
262 template<
typename _Tp,
typename _Alloc>
263 template<
typename _ForwardIterator>
266 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
271 if (__len > capacity())
273 pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
274 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
275 _M_get_Tp_allocator());
276 _M_deallocate(this->_M_impl._M_start,
277 this->_M_impl._M_end_of_storage
278 - this->_M_impl._M_start);
279 this->_M_impl._M_start = __tmp;
280 this->_M_impl._M_finish = this->_M_impl._M_start + __len;
281 this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
283 else if (size() >= __len)
284 _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
287 _ForwardIterator __mid = __first;
289 std::copy(__first, __mid, this->_M_impl._M_start);
290 this->_M_impl._M_finish =
291 std::__uninitialized_copy_a(__mid, __last,
292 this->_M_impl._M_finish,
293 _M_get_Tp_allocator());
297 #if __cplusplus >= 201103L 298 template<
typename _Tp,
typename _Alloc>
299 template<
typename... _Args>
300 typename vector<_Tp, _Alloc>::iterator
302 emplace(const_iterator __position, _Args&&... __args)
304 const size_type __n = __position -
begin();
305 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
306 && __position ==
end())
308 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
309 std::forward<_Args>(__args)...);
310 ++this->_M_impl._M_finish;
314 std::forward<_Args>(__args)...);
315 return iterator(this->_M_impl._M_start + __n);
318 template<
typename _Tp,
typename _Alloc>
319 template<
typename... _Args>
324 template<
typename _Tp,
typename _Alloc>
330 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
332 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
333 _GLIBCXX_MOVE(*(this->_M_impl._M_finish
335 ++this->_M_impl._M_finish;
336 #if __cplusplus < 201103L 339 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
340 this->_M_impl._M_finish - 2,
341 this->_M_impl._M_finish - 1);
342 #if __cplusplus < 201103L 343 *__position = __x_copy;
345 *__position = _Tp(std::forward<_Args>(__args)...);
350 const size_type __len =
351 _M_check_len(size_type(1),
"vector::_M_insert_aux");
352 const size_type __elems_before = __position -
begin();
353 pointer __new_start(this->_M_allocate(__len));
354 pointer __new_finish(__new_start);
361 _Alloc_traits::construct(this->_M_impl,
362 __new_start + __elems_before,
363 #
if __cplusplus >= 201103L
364 std::forward<_Args>(__args)...);
368 __new_finish = pointer();
371 = std::__uninitialized_move_if_noexcept_a
372 (this->_M_impl._M_start, __position.base(),
373 __new_start, _M_get_Tp_allocator());
378 = std::__uninitialized_move_if_noexcept_a
379 (__position.base(), this->_M_impl._M_finish,
380 __new_finish, _M_get_Tp_allocator());
385 _Alloc_traits::destroy(this->_M_impl,
386 __new_start + __elems_before);
388 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
389 _M_deallocate(__new_start, __len);
390 __throw_exception_again;
392 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
393 _M_get_Tp_allocator());
394 _M_deallocate(this->_M_impl._M_start,
395 this->_M_impl._M_end_of_storage
396 - this->_M_impl._M_start);
397 this->_M_impl._M_start = __new_start;
398 this->_M_impl._M_finish = __new_finish;
399 this->_M_impl._M_end_of_storage = __new_start + __len;
403 #if __cplusplus >= 201103L 404 template<
typename _Tp,
typename _Alloc>
405 template<
typename... _Args>
410 const size_type __len =
411 _M_check_len(size_type(1),
"vector::_M_emplace_back_aux");
412 pointer __new_start(this->_M_allocate(__len));
413 pointer __new_finish(__new_start);
416 _Alloc_traits::construct(this->_M_impl, __new_start + size(),
417 std::forward<_Args>(__args)...);
418 __new_finish = pointer();
421 = std::__uninitialized_move_if_noexcept_a
422 (this->_M_impl._M_start, this->_M_impl._M_finish,
423 __new_start, _M_get_Tp_allocator());
430 _Alloc_traits::destroy(this->_M_impl, __new_start + size());
432 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
433 _M_deallocate(__new_start, __len);
434 __throw_exception_again;
436 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
437 _M_get_Tp_allocator());
438 _M_deallocate(this->_M_impl._M_start,
439 this->_M_impl._M_end_of_storage
440 - this->_M_impl._M_start);
441 this->_M_impl._M_start = __new_start;
442 this->_M_impl._M_finish = __new_finish;
443 this->_M_impl._M_end_of_storage = __new_start + __len;
447 template<
typename _Tp,
typename _Alloc>
450 _M_fill_insert(iterator __position, size_type __n,
const value_type& __x)
454 if (size_type(this->_M_impl._M_end_of_storage
455 - this->_M_impl._M_finish) >= __n)
457 value_type __x_copy = __x;
458 const size_type __elems_after =
end() - __position;
459 pointer __old_finish(this->_M_impl._M_finish);
460 if (__elems_after > __n)
462 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
463 this->_M_impl._M_finish,
464 this->_M_impl._M_finish,
465 _M_get_Tp_allocator());
466 this->_M_impl._M_finish += __n;
467 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
468 __old_finish - __n, __old_finish);
469 std::fill(__position.base(), __position.base() + __n,
474 this->_M_impl._M_finish =
475 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
478 _M_get_Tp_allocator());
479 std::__uninitialized_move_a(__position.base(), __old_finish,
480 this->_M_impl._M_finish,
481 _M_get_Tp_allocator());
482 this->_M_impl._M_finish += __elems_after;
483 std::fill(__position.base(), __old_finish, __x_copy);
488 const size_type __len =
489 _M_check_len(__n,
"vector::_M_fill_insert");
490 const size_type __elems_before = __position -
begin();
491 pointer __new_start(this->_M_allocate(__len));
492 pointer __new_finish(__new_start);
496 std::__uninitialized_fill_n_a(__new_start + __elems_before,
498 _M_get_Tp_allocator());
499 __new_finish = pointer();
502 = std::__uninitialized_move_if_noexcept_a
503 (this->_M_impl._M_start, __position.base(),
504 __new_start, _M_get_Tp_allocator());
509 = std::__uninitialized_move_if_noexcept_a
510 (__position.base(), this->_M_impl._M_finish,
511 __new_finish, _M_get_Tp_allocator());
517 __new_start + __elems_before + __n,
518 _M_get_Tp_allocator());
521 _M_get_Tp_allocator());
522 _M_deallocate(__new_start, __len);
523 __throw_exception_again;
525 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
526 _M_get_Tp_allocator());
527 _M_deallocate(this->_M_impl._M_start,
528 this->_M_impl._M_end_of_storage
529 - this->_M_impl._M_start);
530 this->_M_impl._M_start = __new_start;
531 this->_M_impl._M_finish = __new_finish;
532 this->_M_impl._M_end_of_storage = __new_start + __len;
537 #if __cplusplus >= 201103L 538 template<
typename _Tp,
typename _Alloc>
545 if (size_type(this->_M_impl._M_end_of_storage
546 - this->_M_impl._M_finish) >= __n)
548 this->_M_impl._M_finish =
549 std::__uninitialized_default_n_a(this->_M_impl._M_finish,
550 __n, _M_get_Tp_allocator());
554 const size_type __len =
555 _M_check_len(__n,
"vector::_M_default_append");
556 const size_type __old_size = this->size();
557 pointer __new_start(this->_M_allocate(__len));
558 pointer __new_finish(__new_start);
562 = std::__uninitialized_move_if_noexcept_a
563 (this->_M_impl._M_start, this->_M_impl._M_finish,
564 __new_start, _M_get_Tp_allocator());
566 std::__uninitialized_default_n_a(__new_finish, __n,
567 _M_get_Tp_allocator());
572 _M_get_Tp_allocator());
573 _M_deallocate(__new_start, __len);
574 __throw_exception_again;
576 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
577 _M_get_Tp_allocator());
578 _M_deallocate(this->_M_impl._M_start,
579 this->_M_impl._M_end_of_storage
580 - this->_M_impl._M_start);
581 this->_M_impl._M_start = __new_start;
582 this->_M_impl._M_finish = __new_finish;
583 this->_M_impl._M_end_of_storage = __new_start + __len;
588 template<
typename _Tp,
typename _Alloc>
593 if (capacity() == size())
595 return std::__shrink_to_fit_aux<vector>::_S_do_it(*
this);
599 template<
typename _Tp,
typename _Alloc>
600 template<
typename _InputIterator>
606 for (; __first != __last; ++__first)
608 __pos = insert(__pos, *__first);
613 template<
typename _Tp,
typename _Alloc>
614 template<
typename _ForwardIterator>
620 if (__first != __last)
623 if (size_type(this->_M_impl._M_end_of_storage
624 - this->_M_impl._M_finish) >= __n)
626 const size_type __elems_after =
end() - __position;
627 pointer __old_finish(this->_M_impl._M_finish);
628 if (__elems_after > __n)
630 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
631 this->_M_impl._M_finish,
632 this->_M_impl._M_finish,
633 _M_get_Tp_allocator());
634 this->_M_impl._M_finish += __n;
635 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
636 __old_finish - __n, __old_finish);
637 std::copy(__first, __last, __position);
641 _ForwardIterator __mid = __first;
643 std::__uninitialized_copy_a(__mid, __last,
644 this->_M_impl._M_finish,
645 _M_get_Tp_allocator());
646 this->_M_impl._M_finish += __n - __elems_after;
647 std::__uninitialized_move_a(__position.base(),
649 this->_M_impl._M_finish,
650 _M_get_Tp_allocator());
651 this->_M_impl._M_finish += __elems_after;
652 std::copy(__first, __mid, __position);
657 const size_type __len =
658 _M_check_len(__n,
"vector::_M_range_insert");
659 pointer __new_start(this->_M_allocate(__len));
660 pointer __new_finish(__new_start);
664 = std::__uninitialized_move_if_noexcept_a
665 (this->_M_impl._M_start, __position.base(),
666 __new_start, _M_get_Tp_allocator());
668 = std::__uninitialized_copy_a(__first, __last,
670 _M_get_Tp_allocator());
672 = std::__uninitialized_move_if_noexcept_a
673 (__position.base(), this->_M_impl._M_finish,
674 __new_finish, _M_get_Tp_allocator());
679 _M_get_Tp_allocator());
680 _M_deallocate(__new_start, __len);
681 __throw_exception_again;
683 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
684 _M_get_Tp_allocator());
685 _M_deallocate(this->_M_impl._M_start,
686 this->_M_impl._M_end_of_storage
687 - this->_M_impl._M_start);
688 this->_M_impl._M_start = __new_start;
689 this->_M_impl._M_finish = __new_finish;
690 this->_M_impl._M_end_of_storage = __new_start + __len;
697 template<
typename _Alloc>
702 _Bit_pointer __q = this->_M_allocate(__n);
704 this->_M_impl._M_finish = _M_copy_aligned(
begin(),
end(), __start);
705 this->_M_deallocate();
706 this->_M_impl._M_start = __start;
707 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
710 template<
typename _Alloc>
719 std::copy_backward(__position,
end(),
720 this->_M_impl._M_finish + difference_type(__n));
721 std::fill(__position, __position + difference_type(__n), __x);
722 this->_M_impl._M_finish += difference_type(__n);
726 const size_type __len =
727 _M_check_len(__n,
"vector<bool>::_M_fill_insert");
728 _Bit_pointer __q = this->_M_allocate(__len);
730 iterator __i = _M_copy_aligned(
begin(), __position, __start);
731 std::fill(__i, __i + difference_type(__n), __x);
732 this->_M_impl._M_finish = std::copy(__position,
end(),
733 __i + difference_type(__n));
734 this->_M_deallocate();
735 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
736 this->_M_impl._M_start = __start;
740 template<
typename _Alloc>
741 template<
typename _ForwardIterator>
747 if (__first != __last)
752 std::copy_backward(__position,
end(),
753 this->_M_impl._M_finish
754 + difference_type(__n));
755 std::copy(__first, __last, __position);
756 this->_M_impl._M_finish += difference_type(__n);
760 const size_type __len =
761 _M_check_len(__n,
"vector<bool>::_M_insert_range");
762 _Bit_pointer __q = this->_M_allocate(__len);
764 iterator __i = _M_copy_aligned(
begin(), __position, __start);
765 __i = std::copy(__first, __last, __i);
766 this->_M_impl._M_finish = std::copy(__position,
end(), __i);
767 this->_M_deallocate();
768 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
769 this->_M_impl._M_start = __start;
774 template<
typename _Alloc>
779 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
781 std::copy_backward(__position, this->_M_impl._M_finish,
782 this->_M_impl._M_finish + 1);
784 ++this->_M_impl._M_finish;
788 const size_type __len =
789 _M_check_len(size_type(1),
"vector<bool>::_M_insert_aux");
790 _Bit_pointer __q = this->_M_allocate(__len);
792 iterator __i = _M_copy_aligned(
begin(), __position, __start);
794 this->_M_impl._M_finish = std::copy(__position,
end(), __i);
795 this->_M_deallocate();
796 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
797 this->_M_impl._M_start = __start;
801 template<
typename _Alloc>
802 typename vector<bool, _Alloc>::iterator
806 if (__position + 1 !=
end())
807 std::copy(__position + 1,
end(), __position);
808 --this->_M_impl._M_finish;
812 template<
typename _Alloc>
813 typename vector<bool, _Alloc>::iterator
815 _M_erase(iterator __first, iterator __last)
817 if (__first != __last)
818 _M_erase_at_end(std::copy(__last,
end(), __first));
822 #if __cplusplus >= 201103L 823 template<
typename _Alloc>
832 _M_reallocate(
size());
840 _GLIBCXX_END_NAMESPACE_CONTAINER
843 #if __cplusplus >= 201103L 845 namespace std _GLIBCXX_VISIBILITY(default)
847 _GLIBCXX_BEGIN_NAMESPACE_VERSION
849 template<
typename _Alloc>
852 operator()(
const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b)
const noexcept
855 using _GLIBCXX_STD_C::_S_word_bit;
856 using _GLIBCXX_STD_C::_Bit_type;
858 const size_t __words = __b.size() / _S_word_bit;
861 const size_t __clength = __words *
sizeof(_Bit_type);
862 __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength);
865 const size_t __extrabits = __b.size() % _S_word_bit;
868 _Bit_type __hiword = *__b._M_impl._M_finish._M_p;
869 __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
871 const size_t __clength
872 = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
874 __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash);
876 __hash = std::_Hash_impl::hash(&__hiword, __clength);
882 _GLIBCXX_END_NAMESPACE_VERSION
void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
iterator begin() noexcept
void reserve(size_type __n)
Attempt to preallocate enough memory for specified number of elements.
vector & operator=(const vector &__x)
Vector assignment operator.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
_OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
void _Destroy(_Tp *__pointer)
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
Primary class template hash.
A standard container which offers fixed time access to individual elements in any order...
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.
size_type capacity() const noexcept
iterator emplace(const_iterator __position, _Args &&...__args)
Inserts an object in vector before specified iterator.
size_type size() const noexcept
Forward iterators support a superset of input iterator operations.
ISO C++ entities toplevel namespace is std.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...