So I am trying to implement a vector template class and I am trying to write an erase function. The erase function takes two iterators, start
and end
. It then erases every element from position start
to end
including start
, but not end
. After it erases the range of elements it shifts the elements left so that there are no empty elements in the middle of the array (I can try and explain better if this is not clear enough).
The private member data for the class is an integer called Size
, which stores the current number of elements in the array, an integer called Capacity
which stores the current space allocated for the array, and an array called Arr
. I'm not great with iterators yet, can someone explain to me how I can do this better or how to fix it?
template <typename T>
typename Vector<T>::iterator Vector<T>::erase(iterator start, iterator end)
{
iterator x = start;
for(; x != end; x++)
{
Arr[x].~T();
}
for(iterator x = start; x < theSize - (start - end); x++)
{
Arr[x] = Arr[x + (start - end)];
}
Size -= end - start;
}