Wow! ;) You guys are intense.
I don't really have anything at this point to add, I just need to read all
those posts a couple more times.
What it boils down to is that I'm parsing a file's contents into a vector
of logical chunks from the file.
When I add the wonderful reserve line, I get about a 200% speed increase in
read time. So I like reserve for that reason.
later, when I am allowing the user to copy, move, delete and rename these
logical chunks from one vector to another, I wanted to use iterators to
manipulate the data. Here is a situation where it is apparent how clean it
would be to use an iterator;
(this is a plugin DLL, I'm using the API's UI stuff)
I have a List control which has an Items() collection that makes up the
"list", each item in this collection has a char* for the name and a unsigned
long member to stick a ptr in there.
Then later, if the user has selected the 3rd item in the list and hits the
delete button, I can retrieve that pointer(iterator from the original
vector) from the list collection and pass it to the erase() call. Otherwise
I'm working with indexes and it's just so much sloppier!
but, as you all know.. when a vector is modified, the iterators can be
invalidated or WILL be invalidated. So once I delete or move an item in the
vector, the pointers in the list control are pointing to garbage or the
hope that makes sense.
Another example... let's say the user has selected 10 items from the
list(ui) and then they hit the delete button. Using the index to access the
vector's items will be buggy, cause I'm using indexes from the list control
that will be mismatched after the first call to erase on the vector as all
it's indexes shift. To handle this, I hacked my way through it with an
offset index, each item that is removed, I subtract one from the list
control index so that it will line up w/ the vector's index.
As you can see, iterators would be MUCH cleaner.