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 insert(iterator __position,
const value_type& __x)
110 const size_type __n = __position -
begin();
111 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
112 && __position ==
end())
114 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, __x);
115 ++this->_M_impl._M_finish;
119 #if __cplusplus >= 201103L
120 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
123 _M_insert_aux(__position, std::move(__x_copy));
127 _M_insert_aux(__position, __x);
129 return iterator(this->_M_impl._M_start + __n);
132 template<
typename _Tp,
typename _Alloc>
133 typename vector<_Tp, _Alloc>::iterator
137 if (__position + 1 !=
end())
138 _GLIBCXX_MOVE3(__position + 1,
end(), __position);
139 --this->_M_impl._M_finish;
140 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
144 template<
typename _Tp,
typename _Alloc>
145 typename vector<_Tp, _Alloc>::iterator
147 erase(iterator __first, iterator __last)
149 if (__first != __last)
152 _GLIBCXX_MOVE3(__last,
end(), __first);
153 _M_erase_at_end(__first.base() + (
end() - __last));
158 template<
typename _Tp,
typename _Alloc>
165 #if __cplusplus >= 201103L
166 if (_Alloc_traits::_S_propagate_on_copy_assign())
168 if (!_Alloc_traits::_S_always_equal()
169 && _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
173 _M_deallocate(this->_M_impl._M_start,
174 this->_M_impl._M_end_of_storage
175 - this->_M_impl._M_start);
177 std::__alloc_on_copy(_M_get_Tp_allocator(),
178 __x._M_get_Tp_allocator());
181 const size_type __xlen = __x.
size();
182 if (__xlen > capacity())
184 pointer __tmp = _M_allocate_and_copy(__xlen, __x.
begin(),
186 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
187 _M_get_Tp_allocator());
188 _M_deallocate(this->_M_impl._M_start,
189 this->_M_impl._M_end_of_storage
190 - this->_M_impl._M_start);
191 this->_M_impl._M_start = __tmp;
192 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen;
194 else if (
size() >= __xlen)
197 end(), _M_get_Tp_allocator());
201 std::copy(__x._M_impl._M_start, __x._M_impl._M_start +
size(),
202 this->_M_impl._M_start);
203 std::__uninitialized_copy_a(__x._M_impl._M_start +
size(),
204 __x._M_impl._M_finish,
205 this->_M_impl._M_finish,
206 _M_get_Tp_allocator());
208 this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
213 template<
typename _Tp,
typename _Alloc>
218 if (__n > capacity())
220 vector __tmp(__n, __val, _M_get_Tp_allocator());
223 else if (__n >
size())
226 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
228 _M_get_Tp_allocator());
229 this->_M_impl._M_finish += __n -
size();
232 _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val));
235 template<
typename _Tp,
typename _Alloc>
236 template<
typename _InputIterator>
238 vector<_Tp, _Alloc>::
239 _M_assign_aux(_InputIterator __first, _InputIterator __last,
242 pointer __cur(this->_M_impl._M_start);
243 for (; __first != __last && __cur != this->_M_impl._M_finish;
246 if (__first == __last)
247 _M_erase_at_end(__cur);
249 insert(
end(), __first, __last);
252 template<
typename _Tp,
typename _Alloc>
253 template<
typename _ForwardIterator>
255 vector<_Tp, _Alloc>::
256 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
261 if (__len > capacity())
263 pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
264 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
265 _M_get_Tp_allocator());
266 _M_deallocate(this->_M_impl._M_start,
267 this->_M_impl._M_end_of_storage
268 - this->_M_impl._M_start);
269 this->_M_impl._M_start = __tmp;
270 this->_M_impl._M_finish = this->_M_impl._M_start + __len;
271 this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
273 else if (
size() >= __len)
274 _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
277 _ForwardIterator __mid = __first;
279 std::copy(__first, __mid, this->_M_impl._M_start);
280 this->_M_impl._M_finish =
281 std::__uninitialized_copy_a(__mid, __last,
282 this->_M_impl._M_finish,
283 _M_get_Tp_allocator());
287 #if __cplusplus >= 201103L
288 template<
typename _Tp,
typename _Alloc>
289 template<
typename... _Args>
290 typename vector<_Tp, _Alloc>::iterator
292 emplace(iterator __position, _Args&&... __args)
294 const size_type __n = __position -
begin();
295 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
296 && __position ==
end())
298 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
299 std::forward<_Args>(__args)...);
300 ++this->_M_impl._M_finish;
303 _M_insert_aux(__position, std::forward<_Args>(__args)...);
304 return iterator(this->_M_impl._M_start + __n);
307 template<
typename _Tp,
typename _Alloc>
308 template<
typename... _Args>
310 vector<_Tp, _Alloc>::
311 _M_insert_aux(iterator __position, _Args&&... __args)
313 template<
typename _Tp,
typename _Alloc>
315 vector<_Tp, _Alloc>::
316 _M_insert_aux(iterator __position,
const _Tp& __x)
319 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
321 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
322 _GLIBCXX_MOVE(*(this->_M_impl._M_finish
324 ++this->_M_impl._M_finish;
325 #if __cplusplus < 201103L
328 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
329 this->_M_impl._M_finish - 2,
330 this->_M_impl._M_finish - 1);
331 #if __cplusplus < 201103L
332 *__position = __x_copy;
334 *__position = _Tp(std::forward<_Args>(__args)...);
339 const size_type __len =
340 _M_check_len(size_type(1),
"vector::_M_insert_aux");
341 const size_type __elems_before = __position -
begin();
342 pointer __new_start(this->_M_allocate(__len));
343 pointer __new_finish(__new_start);
350 _Alloc_traits::construct(this->_M_impl,
351 __new_start + __elems_before,
352 #
if __cplusplus >= 201103L
353 std::forward<_Args>(__args)...);
360 = std::__uninitialized_move_if_noexcept_a
361 (this->_M_impl._M_start, __position.base(),
362 __new_start, _M_get_Tp_allocator());
367 = std::__uninitialized_move_if_noexcept_a
368 (__position.base(), this->_M_impl._M_finish,
369 __new_finish, _M_get_Tp_allocator());
374 _Alloc_traits::destroy(this->_M_impl,
375 __new_start + __elems_before);
377 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
378 _M_deallocate(__new_start, __len);
379 __throw_exception_again;
381 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
382 _M_get_Tp_allocator());
383 _M_deallocate(this->_M_impl._M_start,
384 this->_M_impl._M_end_of_storage
385 - this->_M_impl._M_start);
386 this->_M_impl._M_start = __new_start;
387 this->_M_impl._M_finish = __new_finish;
388 this->_M_impl._M_end_of_storage = __new_start + __len;
392 #if __cplusplus >= 201103L
393 template<
typename _Tp,
typename _Alloc>
394 template<
typename... _Args>
396 vector<_Tp, _Alloc>::
397 _M_emplace_back_aux(_Args&&... __args)
399 const size_type __len =
400 _M_check_len(size_type(1),
"vector::_M_emplace_back_aux");
401 pointer __new_start(this->_M_allocate(__len));
402 pointer __new_finish(__new_start);
405 _Alloc_traits::construct(this->_M_impl, __new_start +
size(),
406 std::forward<_Args>(__args)...);
410 = std::__uninitialized_move_if_noexcept_a
411 (this->_M_impl._M_start, this->_M_impl._M_finish,
412 __new_start, _M_get_Tp_allocator());
419 _Alloc_traits::destroy(this->_M_impl, __new_start +
size());
421 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
422 _M_deallocate(__new_start, __len);
423 __throw_exception_again;
425 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
426 _M_get_Tp_allocator());
427 _M_deallocate(this->_M_impl._M_start,
428 this->_M_impl._M_end_of_storage
429 - this->_M_impl._M_start);
430 this->_M_impl._M_start = __new_start;
431 this->_M_impl._M_finish = __new_finish;
432 this->_M_impl._M_end_of_storage = __new_start + __len;
436 template<
typename _Tp,
typename _Alloc>
438 vector<_Tp, _Alloc>::
439 _M_fill_insert(iterator __position, size_type __n,
const value_type& __x)
443 if (size_type(this->_M_impl._M_end_of_storage
444 - this->_M_impl._M_finish) >= __n)
446 value_type __x_copy = __x;
447 const size_type __elems_after =
end() - __position;
448 pointer __old_finish(this->_M_impl._M_finish);
449 if (__elems_after > __n)
451 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
452 this->_M_impl._M_finish,
453 this->_M_impl._M_finish,
454 _M_get_Tp_allocator());
455 this->_M_impl._M_finish += __n;
456 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
457 __old_finish - __n, __old_finish);
458 std::fill(__position.base(), __position.base() + __n,
463 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
466 _M_get_Tp_allocator());
467 this->_M_impl._M_finish += __n - __elems_after;
468 std::__uninitialized_move_a(__position.base(), __old_finish,
469 this->_M_impl._M_finish,
470 _M_get_Tp_allocator());
471 this->_M_impl._M_finish += __elems_after;
472 std::fill(__position.base(), __old_finish, __x_copy);
477 const size_type __len =
478 _M_check_len(__n,
"vector::_M_fill_insert");
479 const size_type __elems_before = __position -
begin();
480 pointer __new_start(this->_M_allocate(__len));
481 pointer __new_finish(__new_start);
485 std::__uninitialized_fill_n_a(__new_start + __elems_before,
487 _M_get_Tp_allocator());
491 = std::__uninitialized_move_if_noexcept_a
492 (this->_M_impl._M_start, __position.base(),
493 __new_start, _M_get_Tp_allocator());
498 = std::__uninitialized_move_if_noexcept_a
499 (__position.base(), this->_M_impl._M_finish,
500 __new_finish, _M_get_Tp_allocator());
506 __new_start + __elems_before + __n,
507 _M_get_Tp_allocator());
510 _M_get_Tp_allocator());
511 _M_deallocate(__new_start, __len);
512 __throw_exception_again;
514 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
515 _M_get_Tp_allocator());
516 _M_deallocate(this->_M_impl._M_start,
517 this->_M_impl._M_end_of_storage
518 - this->_M_impl._M_start);
519 this->_M_impl._M_start = __new_start;
520 this->_M_impl._M_finish = __new_finish;
521 this->_M_impl._M_end_of_storage = __new_start + __len;
526 #if __cplusplus >= 201103L
527 template<
typename _Tp,
typename _Alloc>
529 vector<_Tp, _Alloc>::
530 _M_default_append(size_type __n)
534 if (size_type(this->_M_impl._M_end_of_storage
535 - this->_M_impl._M_finish) >= __n)
537 std::__uninitialized_default_n_a(this->_M_impl._M_finish,
538 __n, _M_get_Tp_allocator());
539 this->_M_impl._M_finish += __n;
543 const size_type __len =
544 _M_check_len(__n,
"vector::_M_default_append");
545 const size_type __old_size = this->
size();
546 pointer __new_start(this->_M_allocate(__len));
547 pointer __new_finish(__new_start);
551 = std::__uninitialized_move_if_noexcept_a
552 (this->_M_impl._M_start, this->_M_impl._M_finish,
553 __new_start, _M_get_Tp_allocator());
554 std::__uninitialized_default_n_a(__new_finish, __n,
555 _M_get_Tp_allocator());
561 _M_get_Tp_allocator());
562 _M_deallocate(__new_start, __len);
563 __throw_exception_again;
565 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
566 _M_get_Tp_allocator());
567 _M_deallocate(this->_M_impl._M_start,
568 this->_M_impl._M_end_of_storage
569 - this->_M_impl._M_start);
570 this->_M_impl._M_start = __new_start;
571 this->_M_impl._M_finish = __new_finish;
572 this->_M_impl._M_end_of_storage = __new_start + __len;
577 template<
typename _Tp,
typename _Alloc>
579 vector<_Tp, _Alloc>::
582 if (capacity() ==
size())
584 return std::__shrink_to_fit_aux<vector>::_S_do_it(*
this);
588 template<
typename _Tp,
typename _Alloc>
589 template<
typename _InputIterator>
591 vector<_Tp, _Alloc>::
592 _M_range_insert(iterator __pos, _InputIterator __first,
595 for (; __first != __last; ++__first)
597 __pos = insert(__pos, *__first);
602 template<
typename _Tp,
typename _Alloc>
603 template<
typename _ForwardIterator>
605 vector<_Tp, _Alloc>::
606 _M_range_insert(iterator __position, _ForwardIterator __first,
609 if (__first != __last)
612 if (size_type(this->_M_impl._M_end_of_storage
613 - this->_M_impl._M_finish) >= __n)
615 const size_type __elems_after =
end() - __position;
616 pointer __old_finish(this->_M_impl._M_finish);
617 if (__elems_after > __n)
619 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
620 this->_M_impl._M_finish,
621 this->_M_impl._M_finish,
622 _M_get_Tp_allocator());
623 this->_M_impl._M_finish += __n;
624 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
625 __old_finish - __n, __old_finish);
626 std::copy(__first, __last, __position);
630 _ForwardIterator __mid = __first;
632 std::__uninitialized_copy_a(__mid, __last,
633 this->_M_impl._M_finish,
634 _M_get_Tp_allocator());
635 this->_M_impl._M_finish += __n - __elems_after;
636 std::__uninitialized_move_a(__position.base(),
638 this->_M_impl._M_finish,
639 _M_get_Tp_allocator());
640 this->_M_impl._M_finish += __elems_after;
641 std::copy(__first, __mid, __position);
646 const size_type __len =
647 _M_check_len(__n,
"vector::_M_range_insert");
648 pointer __new_start(this->_M_allocate(__len));
649 pointer __new_finish(__new_start);
653 = std::__uninitialized_move_if_noexcept_a
654 (this->_M_impl._M_start, __position.base(),
655 __new_start, _M_get_Tp_allocator());
657 = std::__uninitialized_copy_a(__first, __last,
659 _M_get_Tp_allocator());
661 = std::__uninitialized_move_if_noexcept_a
662 (__position.base(), this->_M_impl._M_finish,
663 __new_finish, _M_get_Tp_allocator());
668 _M_get_Tp_allocator());
669 _M_deallocate(__new_start, __len);
670 __throw_exception_again;
672 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
673 _M_get_Tp_allocator());
674 _M_deallocate(this->_M_impl._M_start,
675 this->_M_impl._M_end_of_storage
676 - this->_M_impl._M_start);
677 this->_M_impl._M_start = __new_start;
678 this->_M_impl._M_finish = __new_finish;
679 this->_M_impl._M_end_of_storage = __new_start + __len;
686 template<
typename _Alloc>
688 vector<bool, _Alloc>::
689 _M_reallocate(size_type __n)
691 _Bit_type* __q = this->_M_allocate(__n);
692 this->_M_impl._M_finish = _M_copy_aligned(
begin(),
end(),
694 this->_M_deallocate();
695 this->_M_impl._M_start = iterator(__q, 0);
696 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
699 template<
typename _Alloc>
701 vector<bool, _Alloc>::
702 _M_fill_insert(iterator __position, size_type __n,
bool __x)
708 std::copy_backward(__position,
end(),
709 this->_M_impl._M_finish + difference_type(__n));
710 std::fill(__position, __position + difference_type(__n), __x);
711 this->_M_impl._M_finish += difference_type(__n);
715 const size_type __len =
716 _M_check_len(__n,
"vector<bool>::_M_fill_insert");
717 _Bit_type * __q = this->_M_allocate(__len);
718 iterator __i = _M_copy_aligned(
begin(), __position,
720 std::fill(__i, __i + difference_type(__n), __x);
721 this->_M_impl._M_finish = std::copy(__position,
end(),
722 __i + difference_type(__n));
723 this->_M_deallocate();
724 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
725 this->_M_impl._M_start = iterator(__q, 0);
729 template<
typename _Alloc>
730 template<
typename _ForwardIterator>
732 vector<bool, _Alloc>::
733 _M_insert_range(iterator __position, _ForwardIterator __first,
736 if (__first != __last)
741 std::copy_backward(__position,
end(),
742 this->_M_impl._M_finish
743 + difference_type(__n));
744 std::copy(__first, __last, __position);
745 this->_M_impl._M_finish += difference_type(__n);
749 const size_type __len =
750 _M_check_len(__n,
"vector<bool>::_M_insert_range");
751 _Bit_type * __q = this->_M_allocate(__len);
752 iterator __i = _M_copy_aligned(
begin(), __position,
754 __i = std::copy(__first, __last, __i);
755 this->_M_impl._M_finish = std::copy(__position,
end(), __i);
756 this->_M_deallocate();
757 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
758 this->_M_impl._M_start = iterator(__q, 0);
763 template<
typename _Alloc>
765 vector<bool, _Alloc>::
766 _M_insert_aux(iterator __position,
bool __x)
768 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
770 std::copy_backward(__position, this->_M_impl._M_finish,
771 this->_M_impl._M_finish + 1);
773 ++this->_M_impl._M_finish;
777 const size_type __len =
778 _M_check_len(size_type(1),
"vector<bool>::_M_insert_aux");
779 _Bit_type * __q = this->_M_allocate(__len);
780 iterator __i = _M_copy_aligned(
begin(), __position,
783 this->_M_impl._M_finish = std::copy(__position,
end(), __i);
784 this->_M_deallocate();
785 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
786 this->_M_impl._M_start = iterator(__q, 0);
790 #if __cplusplus >= 201103L
791 template<
typename _Alloc>
793 vector<bool, _Alloc>::
800 _M_reallocate(
size());
808 _GLIBCXX_END_NAMESPACE_CONTAINER
811 #if __cplusplus >= 201103L
813 namespace std _GLIBCXX_VISIBILITY(default)
815 _GLIBCXX_BEGIN_NAMESPACE_VERSION
817 template<
typename _Alloc>
819 hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>::
820 operator()(
const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b)
const noexcept
823 using _GLIBCXX_STD_C::_S_word_bit;
824 using _GLIBCXX_STD_C::_Bit_type;
826 const size_t __words = __b.size() / _S_word_bit;
829 const size_t __clength = __words *
sizeof(_Bit_type);
830 __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength);
833 const size_t __extrabits = __b.size() % _S_word_bit;
836 _Bit_type __hiword = *__b._M_impl._M_finish._M_p;
837 __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
839 const size_t __clength
840 = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
842 __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash);
844 __hash = std::_Hash_impl::hash(&__hiword, __clength);
850 _GLIBCXX_END_NAMESPACE_VERSION