I want to process elements from a vector for some time. To optimize this I don't want to remove an item when it is processed and I remove all processed items at the end.
vector<Item*>::iterator it; for(it = items.begin(); it != items.end(); ++it) { DoSomething(*it); if(TimeIsUp()) { break; } } items.erase(items.begin(), it); Is it safe to use erase when it == items.end()? In documentaion it is said that erase() will erase [first,last) and this should be safe but I want to be sure.
EDIT:
Is it safe to use std::vector.erase(begin(), begin())?
vectorof regular pointers. Either use a container specifically designed to hold pointers or use avectorof smart pointers. (A possible exception would be if the vector doesn't own the objects it points to.)end. It only incidentially containseraseandend, too.cleared, though.itmay not always be equal toitems.end()