int i = 0; while (i != MyVector.size()) { if(CONDITION) MyVector.erase(&MyVector[i]); else // we only move i forward if we did not erase a cell because erasing a cell shifts the entire vector backwards i++; }
What's wrong with my vector?
Here''s the standard algorithm for iterating through a vector and checking a condition for erasing the cell we''re currently looking at:
quote:Original post by Enokh
Here''s the standard algorithm for iterating through a vector and checking a condition for erasing the cell we''re currently looking at:
"The standard" algorithm for iterating through a vector doesn''t involve iterators? Ok...
quote:Original post by EnokhThat won''t even compile under the compiler I use. &MyVector[i] is not necessarily an iterator and should not be passed to erase.
Here''s the standard algorithm for iterating through a vector and checking a condition for erasing the cell we''re currently looking at:
int i = 0; while (i != MyVector.size()) { if(CONDITION) MyVector.erase(&MyVector[i]); else // we only move i forward if we did not erase a cell because erasing a cell shifts the entire vector backwards i++; }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement