erase method for a custom vector

I was wondering what could be the best way to create a erase methods to a custom created vector class that depends on allocate to deal with memory. The class have 3 members :

1) data : pointer points to the beginning of the container.
2) aval : pointer points to one past the last initialized memory in container.
3) limit : pointer points to one past the last uninitialized memory in container.

So how to make a :

erase(iterator f); -- iterator is a normal pointer
Well as nobody have offered help yet i wonder if the code below is a good sample or not
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
template<class T>
void Vec<T>::erase( iterator i )// iterator is of type T*
{
 // avail : points to one past the end of the last intialized object in the memory block created by allocator:allocate
// data : points to the first storage in the memory block created by allocator::allocate
	if(i < avail && i >= data)
	{
		
		for(iterator it = i; it != avail -1; ++it)
		{
			iterator after = it +1;
			*it = *after;
		}
		alloc.destroy(avail-1);
		--avail;
	}
}
Last edited on
Topic archived. No new replies allowed.