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_ITERATOR(this->_M_impl._M_start),
76 _GLIBCXX_MAKE_MOVE_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 this->_M_impl.construct(this->_M_impl._M_finish,
98 std::forward<_Args>(__args)...);
99 ++this->_M_impl._M_finish;
102 _M_insert_aux(
end(), 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 this->_M_impl.construct(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 this->_M_impl.destroy(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 const size_type __xlen = __x.
size();
167 if (__xlen > capacity())
169 pointer __tmp = _M_allocate_and_copy(__xlen, __x.
begin(),
171 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
172 _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);
176 this->_M_impl._M_start = __tmp;
177 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen;
179 else if (
size() >= __xlen)
182 end(), _M_get_Tp_allocator());
186 std::copy(__x._M_impl._M_start, __x._M_impl._M_start +
size(),
187 this->_M_impl._M_start);
188 std::__uninitialized_copy_a(__x._M_impl._M_start +
size(),
189 __x._M_impl._M_finish,
190 this->_M_impl._M_finish,
191 _M_get_Tp_allocator());
193 this->_M_impl._M_finish = this->_M_impl._M_start + __xlen;
198 template<
typename _Tp,
typename _Alloc>
203 if (__n > capacity())
205 vector __tmp(__n, __val, _M_get_Tp_allocator());
208 else if (__n >
size())
211 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
213 _M_get_Tp_allocator());
214 this->_M_impl._M_finish += __n -
size();
217 _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val));
220 template<
typename _Tp,
typename _Alloc>
221 template<
typename _InputIterator>
223 vector<_Tp, _Alloc>::
224 _M_assign_aux(_InputIterator __first, _InputIterator __last,
227 pointer __cur(this->_M_impl._M_start);
228 for (; __first != __last && __cur != this->_M_impl._M_finish;
231 if (__first == __last)
232 _M_erase_at_end(__cur);
234 insert(
end(), __first, __last);
237 template<
typename _Tp,
typename _Alloc>
238 template<
typename _ForwardIterator>
240 vector<_Tp, _Alloc>::
241 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
246 if (__len > capacity())
248 pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
249 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
250 _M_get_Tp_allocator());
251 _M_deallocate(this->_M_impl._M_start,
252 this->_M_impl._M_end_of_storage
253 - this->_M_impl._M_start);
254 this->_M_impl._M_start = __tmp;
255 this->_M_impl._M_finish = this->_M_impl._M_start + __len;
256 this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
258 else if (
size() >= __len)
259 _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
262 _ForwardIterator __mid = __first;
264 std::copy(__first, __mid, this->_M_impl._M_start);
265 this->_M_impl._M_finish =
266 std::__uninitialized_copy_a(__mid, __last,
267 this->_M_impl._M_finish,
268 _M_get_Tp_allocator());
272 #ifdef __GXX_EXPERIMENTAL_CXX0X__
273 template<
typename _Tp,
typename _Alloc>
274 template<
typename... _Args>
275 typename vector<_Tp, _Alloc>::iterator
277 emplace(iterator __position, _Args&&... __args)
279 const size_type __n = __position -
begin();
280 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
281 && __position ==
end())
283 this->_M_impl.construct(this->_M_impl._M_finish,
284 std::forward<_Args>(__args)...);
285 ++this->_M_impl._M_finish;
288 _M_insert_aux(__position, std::forward<_Args>(__args)...);
289 return iterator(this->_M_impl._M_start + __n);
292 template<
typename _Tp,
typename _Alloc>
293 template<
typename... _Args>
295 vector<_Tp, _Alloc>::
296 _M_insert_aux(iterator __position, _Args&&... __args)
298 template<
typename _Tp,
typename _Alloc>
300 vector<_Tp, _Alloc>::
301 _M_insert_aux(iterator __position,
const _Tp& __x)
304 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
306 this->_M_impl.construct(this->_M_impl._M_finish,
307 _GLIBCXX_MOVE(*(this->_M_impl._M_finish
309 ++this->_M_impl._M_finish;
310 #ifndef __GXX_EXPERIMENTAL_CXX0X__
313 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
314 this->_M_impl._M_finish - 2,
315 this->_M_impl._M_finish - 1);
316 #ifndef __GXX_EXPERIMENTAL_CXX0X__
317 *__position = __x_copy;
319 *__position = _Tp(std::forward<_Args>(__args)...);
324 const size_type __len =
325 _M_check_len(size_type(1),
"vector::_M_insert_aux");
326 const size_type __elems_before = __position -
begin();
327 pointer __new_start(this->_M_allocate(__len));
328 pointer __new_finish(__new_start);
335 this->_M_impl.construct(__new_start + __elems_before,
336 #ifdef __GXX_EXPERIMENTAL_CXX0X__
337 std::forward<_Args>(__args)...);
344 std::__uninitialized_move_a(this->_M_impl._M_start,
345 __position.base(), __new_start,
346 _M_get_Tp_allocator());
350 std::__uninitialized_move_a(__position.base(),
351 this->_M_impl._M_finish,
353 _M_get_Tp_allocator());
358 this->_M_impl.destroy(__new_start + __elems_before);
360 std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator());
361 _M_deallocate(__new_start, __len);
362 __throw_exception_again;
364 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
365 _M_get_Tp_allocator());
366 _M_deallocate(this->_M_impl._M_start,
367 this->_M_impl._M_end_of_storage
368 - this->_M_impl._M_start);
369 this->_M_impl._M_start = __new_start;
370 this->_M_impl._M_finish = __new_finish;
371 this->_M_impl._M_end_of_storage = __new_start + __len;
375 template<
typename _Tp,
typename _Alloc>
377 vector<_Tp, _Alloc>::
378 _M_fill_insert(iterator __position, size_type __n,
const value_type& __x)
382 if (size_type(this->_M_impl._M_end_of_storage
383 - this->_M_impl._M_finish) >= __n)
385 value_type __x_copy = __x;
386 const size_type __elems_after =
end() - __position;
387 pointer __old_finish(this->_M_impl._M_finish);
388 if (__elems_after > __n)
390 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
391 this->_M_impl._M_finish,
392 this->_M_impl._M_finish,
393 _M_get_Tp_allocator());
394 this->_M_impl._M_finish += __n;
395 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
396 __old_finish - __n, __old_finish);
397 std::fill(__position.base(), __position.base() + __n,
402 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
405 _M_get_Tp_allocator());
406 this->_M_impl._M_finish += __n - __elems_after;
407 std::__uninitialized_move_a(__position.base(), __old_finish,
408 this->_M_impl._M_finish,
409 _M_get_Tp_allocator());
410 this->_M_impl._M_finish += __elems_after;
411 std::fill(__position.base(), __old_finish, __x_copy);
416 const size_type __len =
417 _M_check_len(__n,
"vector::_M_fill_insert");
418 const size_type __elems_before = __position -
begin();
419 pointer __new_start(this->_M_allocate(__len));
420 pointer __new_finish(__new_start);
424 std::__uninitialized_fill_n_a(__new_start + __elems_before,
426 _M_get_Tp_allocator());
430 std::__uninitialized_move_a(this->_M_impl._M_start,
433 _M_get_Tp_allocator());
437 std::__uninitialized_move_a(__position.base(),
438 this->_M_impl._M_finish,
440 _M_get_Tp_allocator());
446 __new_start + __elems_before + __n,
447 _M_get_Tp_allocator());
450 _M_get_Tp_allocator());
451 _M_deallocate(__new_start, __len);
452 __throw_exception_again;
454 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
455 _M_get_Tp_allocator());
456 _M_deallocate(this->_M_impl._M_start,
457 this->_M_impl._M_end_of_storage
458 - this->_M_impl._M_start);
459 this->_M_impl._M_start = __new_start;
460 this->_M_impl._M_finish = __new_finish;
461 this->_M_impl._M_end_of_storage = __new_start + __len;
466 #ifdef __GXX_EXPERIMENTAL_CXX0X__
467 template<
typename _Tp,
typename _Alloc>
469 vector<_Tp, _Alloc>::
470 _M_default_append(size_type __n)
474 if (size_type(this->_M_impl._M_end_of_storage
475 - this->_M_impl._M_finish) >= __n)
477 std::__uninitialized_default_n_a(this->_M_impl._M_finish,
478 __n, _M_get_Tp_allocator());
479 this->_M_impl._M_finish += __n;
483 const size_type __len =
484 _M_check_len(__n,
"vector::_M_default_append");
485 const size_type __old_size = this->
size();
486 pointer __new_start(this->_M_allocate(__len));
487 pointer __new_finish(__new_start);
491 std::__uninitialized_move_a(this->_M_impl._M_start,
492 this->_M_impl._M_finish,
494 _M_get_Tp_allocator());
495 std::__uninitialized_default_n_a(__new_finish, __n,
496 _M_get_Tp_allocator());
502 _M_get_Tp_allocator());
503 _M_deallocate(__new_start, __len);
504 __throw_exception_again;
506 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
507 _M_get_Tp_allocator());
508 _M_deallocate(this->_M_impl._M_start,
509 this->_M_impl._M_end_of_storage
510 - this->_M_impl._M_start);
511 this->_M_impl._M_start = __new_start;
512 this->_M_impl._M_finish = __new_finish;
513 this->_M_impl._M_end_of_storage = __new_start + __len;
519 template<
typename _Tp,
typename _Alloc>
520 template<
typename _InputIterator>
522 vector<_Tp, _Alloc>::
523 _M_range_insert(iterator __pos, _InputIterator __first,
526 for (; __first != __last; ++__first)
528 __pos = insert(__pos, *__first);
533 template<
typename _Tp,
typename _Alloc>
534 template<
typename _ForwardIterator>
536 vector<_Tp, _Alloc>::
537 _M_range_insert(iterator __position, _ForwardIterator __first,
540 if (__first != __last)
543 if (size_type(this->_M_impl._M_end_of_storage
544 - this->_M_impl._M_finish) >= __n)
546 const size_type __elems_after =
end() - __position;
547 pointer __old_finish(this->_M_impl._M_finish);
548 if (__elems_after > __n)
550 std::__uninitialized_move_a(this->_M_impl._M_finish - __n,
551 this->_M_impl._M_finish,
552 this->_M_impl._M_finish,
553 _M_get_Tp_allocator());
554 this->_M_impl._M_finish += __n;
555 _GLIBCXX_MOVE_BACKWARD3(__position.base(),
556 __old_finish - __n, __old_finish);
557 std::copy(__first, __last, __position);
561 _ForwardIterator __mid = __first;
563 std::__uninitialized_copy_a(__mid, __last,
564 this->_M_impl._M_finish,
565 _M_get_Tp_allocator());
566 this->_M_impl._M_finish += __n - __elems_after;
567 std::__uninitialized_move_a(__position.base(),
569 this->_M_impl._M_finish,
570 _M_get_Tp_allocator());
571 this->_M_impl._M_finish += __elems_after;
572 std::copy(__first, __mid, __position);
577 const size_type __len =
578 _M_check_len(__n,
"vector::_M_range_insert");
579 pointer __new_start(this->_M_allocate(__len));
580 pointer __new_finish(__new_start);
584 std::__uninitialized_move_a(this->_M_impl._M_start,
587 _M_get_Tp_allocator());
589 std::__uninitialized_copy_a(__first, __last,
591 _M_get_Tp_allocator());
593 std::__uninitialized_move_a(__position.base(),
594 this->_M_impl._M_finish,
596 _M_get_Tp_allocator());
601 _M_get_Tp_allocator());
602 _M_deallocate(__new_start, __len);
603 __throw_exception_again;
605 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
606 _M_get_Tp_allocator());
607 _M_deallocate(this->_M_impl._M_start,
608 this->_M_impl._M_end_of_storage
609 - this->_M_impl._M_start);
610 this->_M_impl._M_start = __new_start;
611 this->_M_impl._M_finish = __new_finish;
612 this->_M_impl._M_end_of_storage = __new_start + __len;
620 template<
typename _Alloc>
626 __throw_length_error(__N(
"vector::reserve"));
629 _Bit_type* __q = this->_M_allocate(__n);
630 this->_M_impl._M_finish = _M_copy_aligned(
begin(),
end(),
632 this->_M_deallocate();
633 this->_M_impl._M_start = iterator(__q, 0);
634 this->_M_impl._M_end_of_storage = (__q + (__n + int(_S_word_bit) - 1)
639 template<
typename _Alloc>
641 vector<bool, _Alloc>::
642 _M_fill_insert(iterator __position, size_type __n,
bool __x)
648 std::copy_backward(__position,
end(),
649 this->_M_impl._M_finish + difference_type(__n));
650 std::fill(__position, __position + difference_type(__n), __x);
651 this->_M_impl._M_finish += difference_type(__n);
655 const size_type __len =
656 _M_check_len(__n,
"vector<bool>::_M_fill_insert");
657 _Bit_type * __q = this->_M_allocate(__len);
658 iterator __i = _M_copy_aligned(
begin(), __position,
660 std::fill(__i, __i + difference_type(__n), __x);
661 this->_M_impl._M_finish = std::copy(__position,
end(),
662 __i + difference_type(__n));
663 this->_M_deallocate();
664 this->_M_impl._M_end_of_storage = (__q + ((__len
665 + int(_S_word_bit) - 1)
666 /
int(_S_word_bit)));
667 this->_M_impl._M_start = iterator(__q, 0);
671 template<
typename _Alloc>
672 template<
typename _ForwardIterator>
674 vector<bool, _Alloc>::
675 _M_insert_range(iterator __position, _ForwardIterator __first,
678 if (__first != __last)
683 std::copy_backward(__position,
end(),
684 this->_M_impl._M_finish
685 + difference_type(__n));
686 std::copy(__first, __last, __position);
687 this->_M_impl._M_finish += difference_type(__n);
691 const size_type __len =
692 _M_check_len(__n,
"vector<bool>::_M_insert_range");
693 _Bit_type * __q = this->_M_allocate(__len);
694 iterator __i = _M_copy_aligned(
begin(), __position,
696 __i = std::copy(__first, __last, __i);
697 this->_M_impl._M_finish = std::copy(__position,
end(), __i);
698 this->_M_deallocate();
699 this->_M_impl._M_end_of_storage = (__q
701 + int(_S_word_bit) - 1)
702 /
int(_S_word_bit)));
703 this->_M_impl._M_start = iterator(__q, 0);
708 template<
typename _Alloc>
710 vector<bool, _Alloc>::
711 _M_insert_aux(iterator __position,
bool __x)
713 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
715 std::copy_backward(__position, this->_M_impl._M_finish,
716 this->_M_impl._M_finish + 1);
718 ++this->_M_impl._M_finish;
722 const size_type __len =
723 _M_check_len(size_type(1),
"vector<bool>::_M_insert_aux");
724 _Bit_type * __q = this->_M_allocate(__len);
725 iterator __i = _M_copy_aligned(
begin(), __position,
728 this->_M_impl._M_finish = std::copy(__position,
end(), __i);
729 this->_M_deallocate();
730 this->_M_impl._M_end_of_storage = (__q + ((__len
731 + int(_S_word_bit) - 1)
732 /
int(_S_word_bit)));
733 this->_M_impl._M_start = iterator(__q, 0);
737 _GLIBCXX_END_NAMESPACE_CONTAINER
740 #ifdef __GXX_EXPERIMENTAL_CXX0X__
742 namespace std _GLIBCXX_VISIBILITY(default)
744 _GLIBCXX_BEGIN_NAMESPACE_VERSION
746 template<
typename _Alloc>
748 hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>::
749 operator()(
const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b)
const
752 using _GLIBCXX_STD_C::_S_word_bit;
753 using _GLIBCXX_STD_C::_Bit_type;
755 const size_t __words = __b.size() / _S_word_bit;
758 const size_t __clength = __words *
sizeof(_Bit_type);
759 __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength);
762 const size_t __extrabits = __b.size() % _S_word_bit;
765 _Bit_type __hiword = *__b._M_impl._M_finish._M_p;
766 __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
768 const size_t __clength
769 = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
771 __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash);
773 __hash = std::_Hash_impl::hash(&__hiword, __clength);
779 _GLIBCXX_END_NAMESPACE_VERSION
782 #endif // __GXX_EXPERIMENTAL_CXX0X__
constexpr const _Tp * begin(initializer_list< _Tp > __ils)
Return an iterator pointing to the first element of the initilizer_list.
void _Destroy(_Tp *__pointer)
vector & operator=(const vector &__x)
Vector assignment operator.
iterator insert(iterator __position, const value_type &__x)
Inserts given value into vector before specified iterator.
Forward iterators support a superset of input iterator operations.
iterator erase(iterator __position)
Remove element at given position.
constexpr size_t size() const
Returns the total number of bits.
void reserve(size_type __n)
Attempt to preallocate enough memory for specified number of elements.
size_type max_size() const
constexpr const _Tp * end(initializer_list< _Tp > __ils)
Return an iterator pointing to one past the last element of the initilizer_list.
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
A standard container which offers fixed time access to individual elements in any order...
iterator emplace(iterator __position, _Args &&...__args)
Inserts an object in vector before specified iterator.
void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
size_type capacity() const