60 namespace std _GLIBCXX_VISIBILITY(default)
62 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
64 template<
typename _Tp,
typename _Alloc>
69 if (__n > this->max_size())
70 __throw_length_error(__N(
"vector::reserve"));
71 if (this->capacity() < __n)
73 const size_type __old_size =
size();
74 pointer __tmp = _M_allocate_and_copy(__n,
75 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_start),
76 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_finish));
77 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
78 _M_get_Tp_allocator());
79 _M_deallocate(this->_M_impl._M_start,
80 this->_M_impl._M_end_of_storage
81 - this->_M_impl._M_start);
82 this->_M_impl._M_start = __tmp;
83 this->_M_impl._M_finish = __tmp + __old_size;
84 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
88 #ifdef __GXX_EXPERIMENTAL_CXX0X__
89 template<
typename _Tp,
typename _Alloc>
90 template<
typename... _Args>
95 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
97 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
98 std::forward<_Args>(__args)...);
99 ++this->_M_impl._M_finish;
102 _M_emplace_back_aux(std::forward<_Args>(__args)...);
106 template<
typename _Tp,
typename _Alloc>
107 typename vector<_Tp, _Alloc>::iterator
109 insert(iterator __position,
const value_type& __x)
111 const size_type __n = __position -
begin();
112 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
113 && __position ==
end())
115 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, __x);
116 ++this->_M_impl._M_finish;
120 #ifdef __GXX_EXPERIMENTAL_CXX0X__
121 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
124 _M_insert_aux(__position, std::move(__x_copy));
128 _M_insert_aux(__position, __x);
130 return iterator(this->_M_impl._M_start + __n);
133 template<
typename _Tp,
typename _Alloc>
134 typename vector<_Tp, _Alloc>::iterator
138 if (__position + 1 !=
end())
139 _GLIBCXX_MOVE3(__position + 1,
end(), __position);
140 --this->_M_impl._M_finish;
141 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
145 template<
typename _Tp,
typename _Alloc>
146 typename vector<_Tp, _Alloc>::iterator
148 erase(iterator __first, iterator __last)
150 if (__first != __last)
153 _GLIBCXX_MOVE3(__last,
end(), __first);
154 _M_erase_at_end(__first.base() + (
end() - __last));
159 template<
typename _Tp,
typename _Alloc>
166 #ifdef __GXX_EXPERIMENTAL_CXX0X__
167 if (_Alloc_traits::_S_propagate_on_copy_assign())
169 if (!_Alloc_traits::_S_always_equal()
170 && _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
174 _M_deallocate(this->_M_impl._M_start,
175 this->_M_impl._M_end_of_storage
176 - this->_M_impl._M_start);
178 std::__alloc_on_copy(_M_get_Tp_allocator(),
179 __x._M_get_Tp_allocator());
182 const size_type __xlen = __x.
size();
183 if (__xlen > capacity())
185 pointer __tmp = _M_allocate_and_copy(__xlen, __x.
begin(),
187 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
188 _M_get_Tp_allocator());
189 _M_deallocate(this->_M_impl._M_start,
190 this->_M_impl._M_end_of_storage
191 - this->_M_impl._M_start);
192 this->_M_impl._M_start = __tmp;
193 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen;
195 else if (
size() >= __xlen)
198 end(), _M_get_Tp_allocator());
202 std::copy(__x._M_impl._M_start, __x._M_impl._M_start +
size(),
203 this->_M_impl._M_start);
204 std::__uninitialized_copy_a(__x._M_impl._M_start +
size(),
205 __x._M_impl._M_finish,
206 this->_M_impl._M_finish,
207 _M_get_Tp_allocator());
209 this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
214 template<
typename _Tp,
typename _Alloc>
219 if (__n > capacity())
221 vector __tmp(__n, __val, _M_get_Tp_allocator());
224 else if (__n >
size())
227 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
229 _M_get_Tp_allocator());
230 this->_M_impl._M_finish += __n -
size();
233 _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val));
236 template<
typename _Tp,
typename _Alloc>
237 template<
typename _InputIterator>
239 vector<_Tp, _Alloc>::
240 _M_assign_aux(_InputIterator __first, _InputIterator __last,
243 pointer __cur(this->_M_impl._M_start);
244 for (; __first != __last && __cur != this->_M_impl._M_finish;
247 if (__first == __last)
248 _M_erase_at_end(__cur);
250 insert(
end(), __first, __last);
253 template<
typename _Tp,
typename _Alloc>
254 template<
typename _ForwardIterator>
256 vector<_Tp, _Alloc>::
257 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
262 if (__len > capacity())
264 pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
265 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
266 _M_get_Tp_allocator());
267 _M_deallocate(this->_M_impl._M_start,
268 this->_M_impl._M_end_of_storage
269 - this->_M_impl._M_start);
270 this->_M_impl._M_start = __tmp;
271 this->_M_impl._M_finish = this->_M_impl._M_start + __len;
272 this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
274 else if (
size() >= __len)
275 _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
278 _ForwardIterator __mid = __first;
280 std::copy(__first, __mid, this->_M_impl._M_start);
281 this->_M_impl._M_finish =
282 std::__uninitialized_copy_a(__mid, __last,
283 this->_M_impl._M_finish,
284 _M_get_Tp_allocator());
288 #ifdef __GXX_EXPERIMENTAL_CXX0X__
289 template<
typename _Tp,
typename _Alloc>
290 template<
typename... _Args>
291 typename vector<_Tp, _Alloc>::iterator
293 emplace(iterator __position, _Args&&... __args)
295 const size_type __n = __position -
begin();
296 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
297 && __position ==
end())
299 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
300 std::forward<_Args>(__args)...);
301 ++this->_M_impl._M_finish;
304 _M_insert_aux(__position, std::forward<_Args>(__args)...);
305 return iterator(this->_M_impl._M_start + __n);
308 template<
typename _Tp,
typename _Alloc>
309 template<
typename... _Args>
314 template<
typename _Tp,
typename _Alloc>
320 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
322 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
323 _GLIBCXX_MOVE(*(this->_M_impl._M_finish
325 ++this->_M_impl._M_finish;
326 #ifndef __GXX_EXPERIMENTAL_CXX0X__
329 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
330 this->_M_impl._M_finish - 2,
331 this->_M_impl._M_finish - 1);
332 #ifndef __GXX_EXPERIMENTAL_CXX0X__
333 *__position = __x_copy;
335 *__position = _Tp(std::forward<_Args>(__args)...);
340 const size_type __len =
341 _M_check_len(size_type(1),
"vector::_M_insert_aux");
342 const size_type __elems_before = __position -
begin();
343 pointer __new_start(this->_M_allocate(__len));
344 pointer __new_finish(__new_start);
351 _Alloc_traits::construct(this->_M_impl,
352 __new_start + __elems_before,
353 #ifdef __GXX_EXPERIMENTAL_CXX0X__
354 std::forward<_Args>(__args)...);
361 = std::__uninitialized_move_if_noexcept_a
362 (this->_M_impl._M_start, __position.base(),
363 __new_start, _M_get_Tp_allocator());
368 = std::__uninitialized_move_if_noexcept_a
369 (__position.base(), this->_M_impl._M_finish,
370 __new_finish, _M_get_Tp_allocator());
375 _Alloc_traits::destroy(this->_M_impl,
376 __new_start + __elems_before);
378 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
379 _M_deallocate(__new_start, __len);
380 __throw_exception_again;
382 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
383 _M_get_Tp_allocator());
384 _M_deallocate(this->_M_impl._M_start,
385 this->_M_impl._M_end_of_storage
386 - this->_M_impl._M_start);
387 this->_M_impl._M_start = __new_start;
388 this->_M_impl._M_finish = __new_finish;
389 this->_M_impl._M_end_of_storage = __new_start + __len;
393 #ifdef __GXX_EXPERIMENTAL_CXX0X__
394 template<
typename _Tp,
typename _Alloc>
395 template<
typename... _Args>
397 vector<_Tp, _Alloc>::
398 _M_emplace_back_aux(_Args&&... __args)
400 const size_type __len =
401 _M_check_len(size_type(1),
"vector::_M_emplace_back_aux");
402 pointer __new_start(this->_M_allocate(__len));
403 pointer __new_finish(__new_start);
406 _Alloc_traits::construct(this->_M_impl, __new_start +
size(),
407 std::forward<_Args>(__args)...);
411 = std::__uninitialized_move_if_noexcept_a
412 (this->_M_impl._M_start, this->_M_impl._M_finish,
413 __new_start, _M_get_Tp_allocator());
420 _Alloc_traits::destroy(this->_M_impl, __new_start +
size());
422 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
423 _M_deallocate(__new_start, __len);
424 __throw_exception_again;
426 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
427 _M_get_Tp_allocator());
428 _M_deallocate(this->_M_impl._M_start,
429 this->_M_impl._M_end_of_storage
430 - this->_M_impl._M_start);
431 this->_M_impl._M_start = __new_start;
432 this->_M_impl._M_finish = __new_finish;
433 this->_M_impl._M_end_of_storage = __new_start + __len;
437 template<
typename _Tp,
typename _Alloc>
439 vector<_Tp, _Alloc>::
440 _M_fill_insert(iterator __position, size_type __n,
const value_type& __x)
444 if (size_type(this->_M_impl._M_end_of_storage
445 - this->_M_impl._M_finish) >= __n)
447 value_type __x_copy = __x;
448 const size_type __elems_after =
end() - __position;
449 pointer __old_finish(this->_M_impl._M_finish);
450 if (__elems_after > __n)
452 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
453 this->_M_impl._M_finish,
454 this->_M_impl._M_finish,
455 _M_get_Tp_allocator());
456 this->_M_impl._M_finish += __n;
457 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
458 __old_finish - __n, __old_finish);
459 std::fill(__position.base(), __position.base() + __n,
464 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
467 _M_get_Tp_allocator());
468 this->_M_impl._M_finish += __n - __elems_after;
469 std::__uninitialized_move_a(__position.base(), __old_finish,
470 this->_M_impl._M_finish,
471 _M_get_Tp_allocator());
472 this->_M_impl._M_finish += __elems_after;
473 std::fill(__position.base(), __old_finish, __x_copy);
478 const size_type __len =
479 _M_check_len(__n,
"vector::_M_fill_insert");
480 const size_type __elems_before = __position -
begin();
481 pointer __new_start(this->_M_allocate(__len));
482 pointer __new_finish(__new_start);
486 std::__uninitialized_fill_n_a(__new_start + __elems_before,
488 _M_get_Tp_allocator());
492 = std::__uninitialized_move_if_noexcept_a
493 (this->_M_impl._M_start, __position.base(),
494 __new_start, _M_get_Tp_allocator());
499 = std::__uninitialized_move_if_noexcept_a
500 (__position.base(), this->_M_impl._M_finish,
501 __new_finish, _M_get_Tp_allocator());
507 __new_start + __elems_before + __n,
508 _M_get_Tp_allocator());
511 _M_get_Tp_allocator());
512 _M_deallocate(__new_start, __len);
513 __throw_exception_again;
515 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
516 _M_get_Tp_allocator());
517 _M_deallocate(this->_M_impl._M_start,
518 this->_M_impl._M_end_of_storage
519 - this->_M_impl._M_start);
520 this->_M_impl._M_start = __new_start;
521 this->_M_impl._M_finish = __new_finish;
522 this->_M_impl._M_end_of_storage = __new_start + __len;
527 #ifdef __GXX_EXPERIMENTAL_CXX0X__
528 template<
typename _Tp,
typename _Alloc>
530 vector<_Tp, _Alloc>::
531 _M_default_append(size_type __n)
535 if (size_type(this->_M_impl._M_end_of_storage
536 - this->_M_impl._M_finish) >= __n)
538 std::__uninitialized_default_n_a(this->_M_impl._M_finish,
539 __n, _M_get_Tp_allocator());
540 this->_M_impl._M_finish += __n;
544 const size_type __len =
545 _M_check_len(__n,
"vector::_M_default_append");
546 const size_type __old_size = this->
size();
547 pointer __new_start(this->_M_allocate(__len));
548 pointer __new_finish(__new_start);
552 = std::__uninitialized_move_if_noexcept_a
553 (this->_M_impl._M_start, this->_M_impl._M_finish,
554 __new_start, _M_get_Tp_allocator());
555 std::__uninitialized_default_n_a(__new_finish, __n,
556 _M_get_Tp_allocator());
562 _M_get_Tp_allocator());
563 _M_deallocate(__new_start, __len);
564 __throw_exception_again;
566 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
567 _M_get_Tp_allocator());
568 _M_deallocate(this->_M_impl._M_start,
569 this->_M_impl._M_end_of_storage
570 - this->_M_impl._M_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;
578 template<
typename _Tp,
typename _Alloc>
580 vector<_Tp, _Alloc>::
583 if (capacity() ==
size())
585 return std::__shrink_to_fit_aux<vector>::_S_do_it(*
this);
589 template<
typename _Tp,
typename _Alloc>
590 template<
typename _InputIterator>
592 vector<_Tp, _Alloc>::
593 _M_range_insert(iterator __pos, _InputIterator __first,
596 for (; __first != __last; ++__first)
598 __pos = insert(__pos, *__first);
603 template<
typename _Tp,
typename _Alloc>
604 template<
typename _ForwardIterator>
606 vector<_Tp, _Alloc>::
607 _M_range_insert(iterator __position, _ForwardIterator __first,
610 if (__first != __last)
613 if (size_type(this->_M_impl._M_end_of_storage
614 - this->_M_impl._M_finish) >= __n)
616 const size_type __elems_after =
end() - __position;
617 pointer __old_finish(this->_M_impl._M_finish);
618 if (__elems_after > __n)
620 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
621 this->_M_impl._M_finish,
622 this->_M_impl._M_finish,
623 _M_get_Tp_allocator());
624 this->_M_impl._M_finish += __n;
625 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
626 __old_finish - __n, __old_finish);
627 std::copy(__first, __last, __position);
631 _ForwardIterator __mid = __first;
633 std::__uninitialized_copy_a(__mid, __last,
634 this->_M_impl._M_finish,
635 _M_get_Tp_allocator());
636 this->_M_impl._M_finish += __n - __elems_after;
637 std::__uninitialized_move_a(__position.base(),
639 this->_M_impl._M_finish,
640 _M_get_Tp_allocator());
641 this->_M_impl._M_finish += __elems_after;
642 std::copy(__first, __mid, __position);
647 const size_type __len =
648 _M_check_len(__n,
"vector::_M_range_insert");
649 pointer __new_start(this->_M_allocate(__len));
650 pointer __new_finish(__new_start);
654 = std::__uninitialized_move_if_noexcept_a
655 (this->_M_impl._M_start, __position.base(),
656 __new_start, _M_get_Tp_allocator());
658 = std::__uninitialized_copy_a(__first, __last,
660 _M_get_Tp_allocator());
662 = std::__uninitialized_move_if_noexcept_a
663 (__position.base(), this->_M_impl._M_finish,
664 __new_finish, _M_get_Tp_allocator());
669 _M_get_Tp_allocator());
670 _M_deallocate(__new_start, __len);
671 __throw_exception_again;
673 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
674 _M_get_Tp_allocator());
675 _M_deallocate(this->_M_impl._M_start,
676 this->_M_impl._M_end_of_storage
677 - this->_M_impl._M_start);
678 this->_M_impl._M_start = __new_start;
679 this->_M_impl._M_finish = __new_finish;
680 this->_M_impl._M_end_of_storage = __new_start + __len;
687 template<
typename _Alloc>
689 vector<bool, _Alloc>::
690 _M_reallocate(size_type __n)
692 _Bit_type* __q = this->_M_allocate(__n);
693 this->_M_impl._M_finish = _M_copy_aligned(
begin(),
end(),
695 this->_M_deallocate();
696 this->_M_impl._M_start = iterator(__q, 0);
697 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
700 template<
typename _Alloc>
702 vector<bool, _Alloc>::
703 _M_fill_insert(iterator __position, size_type __n,
bool __x)
709 std::copy_backward(__position,
end(),
710 this->_M_impl._M_finish + difference_type(__n));
711 std::fill(__position, __position + difference_type(__n), __x);
712 this->_M_impl._M_finish += difference_type(__n);
716 const size_type __len =
717 _M_check_len(__n,
"vector<bool>::_M_fill_insert");
718 _Bit_type * __q = this->_M_allocate(__len);
719 iterator __i = _M_copy_aligned(
begin(), __position,
721 std::fill(__i, __i + difference_type(__n), __x);
722 this->_M_impl._M_finish = std::copy(__position,
end(),
723 __i + difference_type(__n));
724 this->_M_deallocate();
725 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
726 this->_M_impl._M_start = iterator(__q, 0);
730 template<
typename _Alloc>
731 template<
typename _ForwardIterator>
733 vector<bool, _Alloc>::
734 _M_insert_range(iterator __position, _ForwardIterator __first,
737 if (__first != __last)
742 std::copy_backward(__position,
end(),
743 this->_M_impl._M_finish
744 + difference_type(__n));
745 std::copy(__first, __last, __position);
746 this->_M_impl._M_finish += difference_type(__n);
750 const size_type __len =
751 _M_check_len(__n,
"vector<bool>::_M_insert_range");
752 _Bit_type * __q = this->_M_allocate(__len);
753 iterator __i = _M_copy_aligned(
begin(), __position,
755 __i = std::copy(__first, __last, __i);
756 this->_M_impl._M_finish = std::copy(__position,
end(), __i);
757 this->_M_deallocate();
758 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
759 this->_M_impl._M_start = iterator(__q, 0);
764 template<
typename _Alloc>
766 vector<bool, _Alloc>::
767 _M_insert_aux(iterator __position,
bool __x)
769 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
771 std::copy_backward(__position, this->_M_impl._M_finish,
772 this->_M_impl._M_finish + 1);
774 ++this->_M_impl._M_finish;
778 const size_type __len =
779 _M_check_len(size_type(1),
"vector<bool>::_M_insert_aux");
780 _Bit_type * __q = this->_M_allocate(__len);
781 iterator __i = _M_copy_aligned(
begin(), __position,
784 this->_M_impl._M_finish = std::copy(__position,
end(), __i);
785 this->_M_deallocate();
786 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
787 this->_M_impl._M_start = iterator(__q, 0);
791 #ifdef __GXX_EXPERIMENTAL_CXX0X__
792 template<
typename _Alloc>
794 vector<bool, _Alloc>::
801 _M_reallocate(
size());
809 _GLIBCXX_END_NAMESPACE_CONTAINER
812 #ifdef __GXX_EXPERIMENTAL_CXX0X__
814 namespace std _GLIBCXX_VISIBILITY(default)
816 _GLIBCXX_BEGIN_NAMESPACE_VERSION
818 template<
typename _Alloc>
820 hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>::
821 operator()(
const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b)
const noexcept
824 using _GLIBCXX_STD_C::_S_word_bit;
825 using _GLIBCXX_STD_C::_Bit_type;
827 const size_t __words = __b.size() / _S_word_bit;
830 const size_t __clength = __words *
sizeof(_Bit_type);
831 __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength);
834 const size_t __extrabits = __b.size() % _S_word_bit;
837 _Bit_type __hiword = *__b._M_impl._M_finish._M_p;
838 __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
840 const size_t __clength
841 = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
843 __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash);
845 __hash = std::_Hash_impl::hash(&__hiword, __clength);
851 _GLIBCXX_END_NAMESPACE_VERSION
854 #endif // __GXX_EXPERIMENTAL_CXX0X__