Implement Vector::insert( it, begin, end ).

This commit is contained in:
Bartosz Taudul 2017-10-19 23:26:02 +02:00
parent 82476a310c
commit cc1715ae98

View File

@ -103,6 +103,17 @@ public:
return m_ptr + dist; return m_ptr + dist;
} }
void insert( T* it, T* begin, T* end )
{
assert( it >= m_ptr && it <= m_ptr + m_size );
const auto sz = end - begin;
const auto dist = it - m_ptr;
while( m_size + sz > m_capacity ) AllocMore();
if( dist != m_size ) memmove( m_ptr + dist + sz, m_ptr + dist, ( m_size - dist ) * sizeof( T ) );
m_size += sz;
memcpy( m_ptr + dist, begin, sz * sizeof( T ) );
}
T* erase( T* begin, T* end ) T* erase( T* begin, T* end )
{ {
assert( begin >= m_ptr && begin <= m_ptr + m_size ); assert( begin >= m_ptr && begin <= m_ptr + m_size );