__iterator__ _VECTOR_IMPL<_Tp, _Alloc>::insert(iterator __pos, const _Tp& __x) { size_type __n = __pos - begin(); if (this->_M_finish != this->_M_end_of_storage._M_data) { if (__pos == end()) { _Copy_Construct(this->_M_finish, __x); ++this->_M_finish; } else { if (&__x >= this->_M_start && &__x < this->_M_finish) { _Tp __x_copy = __x; insert(__pos, __x_copy); } else { _Copy_Construct(this->_M_finish, *(this->_M_finish - 1)); ++this->_M_finish; __copy_backward_ptrs(__pos, this->_M_finish - 2, this->_M_finish - 1, _TrivialAss()); *__pos = __x; } } } else _M_insert_overflow(__pos, __x, _TrivialCpy(), 1UL); return begin() + __n; }
void _VECTOR_IMPL<_Tp, _Alloc>::_M_insert_overflow_aux(pointer __pos, const _Tp& __x, const __false_type& /*NOT TO USE!!*/, size_type __fill_len, bool __atend ) { const size_type __old_size = size(); const size_type __len = __old_size + (max)(__old_size, __fill_len); pointer __new_start = this->_M_end_of_storage.allocate(__len); pointer __new_finish = __new_start; _STLP_TRY { __new_finish = __uninitialized_move(this->_M_start, __pos, __new_start, _TrivialUCpy(), _Movable()); // handle insertion if (__fill_len == 1) { _Copy_Construct(__new_finish, __x); ++__new_finish; } else __new_finish = __uninitialized_fill_n(__new_finish, __fill_len, __x, __false_type()); if (!__atend) __new_finish = __uninitialized_move(__pos, this->_M_finish, __new_finish, _TrivialUCpy(), _Movable()); // copy remainder } _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish), this->_M_end_of_storage.deallocate(__new_start,__len))) _M_clear_after_move(); _M_set(__new_start, __new_finish, __new_start + __len); }