1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| void
vector<_Tp,_Alloc>::
_M_fill_insert(iterator __position, size_type __n, const value_type& __x)
{
if (__n != 0)
{
if (size_type(this->_M_impl._M_end_of_storage - this->_M_impl._M_finish) >= __n)
{
value_type __x_copy = __x;
const size_type __elems_after = end() - __position;
iterator __old_finish(this->_M_impl._M_finish);
if (__elems_after > __n)
{
std::uninitialized_copy(this->_M_impl._M_finish - __n,
this->_M_impl._M_finish,
this->_M_impl._M_finish);
this->_M_impl._M_finish += __n;
std::copy_backward(__position, __old_finish - __n, __old_finish);
std::fill(__position, __position + __n, __x_copy);
}
else
{
std::uninitialized_fill_n(this->_M_impl._M_finish,
__n - __elems_after,
__x_copy);
this->_M_impl._M_finish += __n - __elems_after;
std::uninitialized_copy(__position, __old_finish, this->_M_impl._M_finish);
this->_M_impl._M_finish += __elems_after;
std::fill(__position, __old_finish, __x_copy);
}
}
else
{
const size_type __old_size = size();
const size_type __len = __old_size + std::max(__old_size, __n);
iterator __new_start(this->_M_allocate(__len));
iterator __new_finish(__new_start);
try
{
__new_finish = std::uninitialized_copy(begin(), __position,
__new_start);
__new_finish = std::uninitialized_fill_n(__new_finish, __n, __x);
__new_finish = std::uninitialized_copy(__position, end(),
__new_finish);
}
catch(...)
{
std::_Destroy(__new_start,__new_finish);
_M_deallocate(__new_start.base(),__len);
__throw_exception_again;
}
std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish);
_M_deallocate(this->_M_impl._M_start,
this->_M_impl._M_end_of_storage - this->_M_impl._M_start);
this->_M_impl._M_start = __new_start.base();
this->_M_impl._M_finish = __new_finish.base();
this->_M_impl._M_end_of_storage = __new_start.base() + __len;
}
}
} |
Partager