It certainly looks like you know what you are doing. In fact, I'd say you've picked-up C++ better than a lot of people...
Just a couple comments. ;-)
I'd be a little wary of simply doubling the space available (limit) every time you grow. The space potentially wasted grows exponentially the larger the vector gets.
If you want to be really careful, you can add an adaptive difference based upon usage patterns, but to be simple just pick some constant number of elements and add that amount every time...
In your erase(), you calculate 'size'. Why not just use the method you already created to do just that?
new_data = new_avail = alloc.allocate( size() );
Chances are that it is inline anyway...
If you are really concerned about forcing stupid compilers to be as absolutely efficient as possible:
register size_type size = size();
The point is that you should try to calculate specific values in only one place. Then, if you change one, you don't have to scratch your head figuring out why the code breaks.
Speed improvements based on adding extra conditions are temperamental at best. The greatest speed improvement would be just to have two loops:
1 2
|
for (k=data; k<i; k++) alloc.construct(new_avail++, *k);
for (k=j+1; k<avail; k++) alloc.construct(new_avail++, *k);
|
This might produce a few bytes worth more code...
The other option would be not to allocate a new array at all. Just move elements j+1, j+2, j+3, ... to i, i+1, i+2, ... using a simple bit-copy and then fill the (now unused) parts with the uninitialized value.
Finally, you could conceivably reduce the array size if enough elements are erased.
Just some thoughts for the terminally bit-minded. :-P
Good job! (It is better than I would have done...)
Hope this helps.