44template <
class _TypeT,
class _Allocator>
45vector<_TypeT, _Allocator>&
46vector<_TypeT, _Allocator>::
47operator= (
const vector &__rhs)
49#ifndef _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
51 if (capacity () < __rhs.size ())
52 vector (__rhs).swap (*
this);
53 else if (&__rhs !=
this)
54 assign (__rhs.begin (), __rhs.end ());
58 vector (__rhs).swap (*
this);
66template <
class _TypeT,
class _Allocator>
68vector<_TypeT, _Allocator>::
69_C_realloc (size_type __n)
71 const size_type __max_size = max_size ();
78 if (__max_size < __cap)
82 vector __tmp (get_allocator ());
85 __tmp._C_alloc._C_begin = _C_alloc.allocate (__cap,
this);
88 __tmp._C_alloc._C_end = __tmp._C_alloc._C_begin;
89 __tmp._C_alloc._C_bufend = __tmp._C_alloc._C_begin + __cap;
96 for (pointer __ptr = _C_alloc._C_begin; !(__ptr == _C_alloc._C_end);
98 __tmp._C_push_back (*__ptr);
106template <
class _TypeT,
class _Allocator>
107void vector<_TypeT, _Allocator>::
108_C_destroy (iterator __first)
112 for (size_type __n =
end () - __first; !(0 == __n); --__n)
113 _C_alloc.destroy (--_C_alloc._C_end);
117template <
class _TypeT,
class _Allocator>
118void vector<_TypeT, _Allocator>::
119_C_unsafe_swap (vector &__other)
122 _RWSTD_ASSERT (!(get_allocator () == __other.get_allocator ()));
128 vector __tmp (__other.get_allocator ());
133 _RWSTD_ASSERT (__tmp.get_allocator () == __other.get_allocator ());
135 __tmp.assign (begin (),
end ());
136 assign (__other.begin (), __other.end ());
137 __other.swap (__tmp);
141template <
class _TypeT,
class _Allocator>
142void vector<_TypeT, _Allocator>::
143_C_assign_n (size_type __n, const_reference __x)
145#ifndef _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
150 insert (begin (), __n, __x);
155 insert (begin (), __n, __x);
161template <
class _TypeT,
class _Allocator>
162void vector<_TypeT, _Allocator>::
163_C_insert_1 (
const iterator &__it, const_reference __x)
167 if (
size () < capacity ()) {
171 const pointer __end = _C_alloc._C_end;
176 _C_push_back (*(_C_alloc._C_end - difference_type (1)));
180 _STD::copy_backward (__it,
end () - 2, __end);
192 _C_insert_n (__it, size_type (1), __x);
197template <
class _TypeT,
class _Allocator>
198void vector<_TypeT, _Allocator>::
199_C_insert_n (
const iterator &__it, size_type __n, const_reference __x)
210 const size_type __size1 =
_DISTANCE (begin (), __it, size_type);
211 const size_type __size2 =
size () + __n;
213 if (capacity () < __size2) {
216 vector __tmp (get_allocator ());
217 __tmp.reserve (__size2);
225 for (__i = begin (); !(__i == __it); ++__i) {
228 == __tmp._C_alloc._C_bufend));
230 __tmp._C_push_back (*__i);
236 for ( ; __n; --__n) {
239 == __tmp._C_alloc._C_bufend));
241 __tmp._C_push_back (__x);
249 for (__i = __it; !(__i ==
end ()); ++__i) {
252 == __tmp._C_alloc._C_bufend));
254 __tmp._C_push_back (*__i);
267 const pointer __movbeg = _C_alloc._C_begin + __size1;
268 const pointer __movend = __movbeg + __n;
272 if (__movend <= _C_alloc._C_end) {
280 const pointer __ucpbeg = _C_alloc._C_end - __n;
281 const pointer __ucpend = _C_alloc._C_end;
285 _STD::uninitialized_copy (__ucpbeg, _C_alloc._C_end,
286 _C_alloc._C_end, _C_alloc);
289 _C_alloc._C_end += __n;
293 _STD::copy_backward (__movbeg, __ucpbeg, __ucpend);
300 const size_type __n1 =
size () - __size1;
301 const size_type __n2 = __n - __n1;
303 _STD::uninitialized_fill_n (_C_alloc._C_end, __n2, __x, _C_alloc);
305 const pointer __end = _C_alloc._C_end;
307 _C_alloc._C_end += __n2;
311 _STD::uninitialized_copy (__movbeg, __end, _C_alloc._C_end, _C_alloc);
313 _C_alloc._C_end += __end - __movbeg;
318 _STD::fill_n (__movbeg, __n, __x);
322template<
class _TypeT,
class _Allocator>
323template<
class _InputIter>
324void vector<_TypeT, _Allocator>::
325_C_assign_range (_InputIter __first, _InputIter __last, input_iterator_tag)
329#ifndef _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
345 const iterator __end = this->
end ();
347 for (iterator __it = this->begin (); __it != __end; ++__it, ++__first) {
348 if (__first == __last) {
349 this->erase (__it, __end);
355 this->insert (__end, __first, __last);
366 this->insert (this->begin (), __first, __last);
373template <
class _TypeT,
class _Allocator>
374template <
class _FwdIter>
375void vector<_TypeT, _Allocator>::
376_C_assign_range (_FwdIter __first, _FwdIter __last, forward_iterator_tag)
380#ifndef _RWSTD_NO_EXT_VECTOR_ASSIGN_IN_PLACE
392 const size_type __size1 =
_DISTANCE (__first, __last, size_type);
393 const size_type __size2 = this->
size () + __size1;
395 if (this->capacity () < __size2) {
399 vector<value_type, allocator_type> __tmp (this->get_allocator ());
400 __tmp.reserve (__size2);
408 for ( ; !(__first == __last); ++__first)
409 __tmp._C_push_back (*__first);
417 const iterator __end = this->
end ();
419 for (iterator __i = this->begin (); __i != __end; ++__i, ++__first) {
420 if (__first == __last) {
421 this->erase (__i, __end);
427 this->insert (__end, __first, __last);
438 this->insert (this->begin (), __first, __last);
445template <
class _TypeT,
class _Allocator>
446template <
class _InputIter>
447void vector<_TypeT, _Allocator>::
448_C_insert_range (iterator __it, _InputIter __first, _InputIter __last,
454#ifndef _RWSTD_NO_EXT_VECTOR_INSERT_IN_PLACE
465 const size_type __size = this->
size ();
466 const size_type __inx =
_DISTANCE (this->begin (), __it, size_type);
470 for (; !(__first == __last); ++__first)
471 this->push_back (*__first);
473 if (__inx < __size) {
477 const pointer __beg = this->_C_alloc._C_begin + __inx;
478 const pointer __mid = this->_C_alloc._C_begin + __size;
481 for (pointer __p0 = __beg, __p1 = __mid; __p0 < --__p1; ++__p0)
482 _STD::iter_swap (__p0, __p1);
485 if (__mid < this->_C_alloc._C_end) {
486 for (pointer __p0 = __mid, __p1 = this->_C_alloc._C_end;
487 __p0 < --__p1; ++__p0)
488 _STD::iter_swap (__p0, __p1);
491 if (__beg < this->_C_alloc._C_end) {
492 for (pointer __p0 = __beg, __p1 = this->_C_alloc._C_end;
493 __p0 < --__p1; ++__p0)
494 _STD::iter_swap (__p0, __p1);
513 vector<value_type, allocator_type> __tmp (this->get_allocator ());
515 for ( ; !(__first == __last); ++__first)
516 __tmp.push_back (*__first);
520 this->insert (__it, __tmp.begin (), __tmp.end ());
527template <
class _TypeT,
class _Allocator>
528template <
class _FwdIter>
529void vector<_TypeT, _Allocator>::
530_C_insert_range (iterator __it, _FwdIter __first, _FwdIter __last,
531 forward_iterator_tag)
540 const size_type __size1 =
_DISTANCE (this->begin (), __it, size_type);
541 const size_type __size2 =
_DISTANCE (__first, __last, size_type);
546#ifndef _RWSTD_NO_EXT_VECTOR_INSERT_IN_PLACE
547 const bool __insert_in_place =
548 this->
size () + __size2 <= this->capacity ();
550 const bool __insert_in_place =
false;
553 if (__insert_in_place) {
559 const pointer __movbeg = this->_C_alloc._C_begin + __size1;
560 const pointer __movend = __movbeg + __size2;
564 const pointer __end = this->_C_alloc._C_end;
566 if (__movend <= __end) {
570 const pointer __ucpbeg = __end - __size2;
574 for (pointer __p = __ucpbeg; !(__p == __end); ++__p)
575 this->_C_push_back (*__p);
578 for (pointer __q = __end; __movend < __q; ) {
580 *__q = *(__q - __size2);
587 const size_type __size2a = this->
size () - __size1;
588 _FwdIter __mid = __first;
589 _STD::advance (__mid, __size2a);
595 for (_FwdIter __m = __mid ; !(__m == __last); ++__m)
596 this->_C_push_back (*__m);
603 for (pointer __p = __movbeg; !(__p == __end); ++__p)
604 this->_C_push_back (*__p);
609 _STD::copy (__first, __last, __movbeg);
616 vector<value_type, allocator_type> __tmp (this->get_allocator ());
618 __tmp.reserve (this->
size () + __size2);
631 for (__ix = this->begin (); __ix != __it; ++__ix) {
632 __tmp._C_push_back (*__ix);
638 for (; !(__first == __last); ++__first) {
639 __tmp._C_push_back (*__first);
643 for ( ; __ix != this->
end (); ++__ix) {
644 __tmp._C_push_back (*__ix);
654#ifndef _RWSTD_NO_VECTOR_BOOL
656#ifndef _RWSTD_NO_BOOL
660#if !defined (_RWSTD_NO_CLASS_PARTIAL_SPEC)
661 template <
class _Allocator>
662 template<
class _InputIter>
663 void vector<bool, _Allocator >::insert
665 template<
class _InputIter>
666 void vector<bool, allocator<bool> >::insert
668 (iterator __it, _InputIter __first, _InputIter __last)
671 if (__first == __last)
return;
672 size_type __n =
_DISTANCE (__first, __last, size_type);
673 if (capacity() -
size() >= __n)
675 copy_backward(__it,
end(), _C_end + __n);
676 copy(__first, __last, __it);
683 unsigned int* __q = _C_bit_alloc(__len);
684 iterator __i = copy(begin(), __it, iterator(__q, 0));
685 __i = copy(__first, __last, __i);
686 _C_end = copy(__it,
end(), __i);
687 _C_value_alloc_type (*this).
688 deallocate((pointer)_C_begin._C_p,_C_bufend - _C_begin._C_p);
689 _C_bufend = __q + (__len + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
690 _C_begin = iterator(__q, 0);
694#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
699 template <
class _Allocator>
700 void vector<bool,_Allocator >::flip ()
702 for (iterator __i = begin(); !(__i ==
end()); __i++)
706 template <
class _Allocator>
707 void vector<bool,_Allocator >::swap (reference __x, reference __y)
709 bool __tmp = __x; __x = __y; __y = __tmp;
713template <
class _Allocator>
714void vector<bool,_Allocator >::
715_C_insert (iterator __it,
bool __x)
719 if (
size () < capacity ()) {
721 const iterator __end = _C_end;
728 _STD::copy_backward (__it, __end, ++_C_end);
735 size_type __len =
size() ? 2 *
size() : _RWSTD_WORD_BIT;
736 unsigned int* __q = _C_bit_alloc(__len);
737 iterator __i = _C_copy(begin(), __it, iterator(__q, 0));
739 _C_end = _C_copy(__it,
end(), __i);
740 _C_value_alloc_type (*this).
741 deallocate((pointer)_C_begin._C_p,_C_bufend - _C_begin._C_p);
742 _C_bufend = __q + (__len + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
743 _C_begin = iterator(__q, 0);
748 template <
class _Allocator>
749 void vector<bool,_Allocator >::insert (iterator __it, size_type __n,
752 if (__n == 0)
return;
753 if (capacity() -
size() >= __n)
755 _C_copy_backward(__it,
end(), _C_end + __n);
756 _C_fill(__it, __it + __n, __x);
762 unsigned int* __q = _C_bit_alloc(__len);
763 iterator __i = _C_copy(begin(), __it, iterator(__q, 0));
764 _C_fill_n(__i, __n, __x);
765 _C_end = _C_copy(__it,
end(), __i + __n);
766 _C_value_alloc_type (*this).
767 deallocate((pointer)_C_begin._C_p,_C_bufend - _C_begin._C_p);
768 _C_bufend = __q + (__len + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
769 _C_begin = iterator(__q, 0);
774 template <
class _Allocator>
775 void vector<bool,_Allocator >::resize (size_type __new_size,
bool __c)
777 if (__new_size >
size())
778 insert(
end(), __new_size -
size(), __c);
779 else if (__new_size <
size())
780 erase(begin() + __new_size,
end());
#define _RWSTD_NAMESPACE(name)
#define _RWSTD_NEW_CAPACITY(ignore, what, from)
#define _RWSTD_ASSERT(ignore)
#define _DISTANCE(first, last, ignore)
#define _RWSTD_ASSERT_RANGE(ign1, ign2)