It really depends on the container type. For
std::deque and especially
std::vector, using the return value of
erase() in a loop is very inefficient. You should prefer the STL algorithms
std::remove() or
std::remove_if(), combined with the
erase() overload for an iterator range.
WDR, keep variable declarations local and use
for instead of
while. Your code is very difficult to read, because your iterators are declared all over the place and have a far too wide scope. A typical iterator loop looks as follows,
with the iterator declared inside the loop head:
for (auto itr = container.begin(); itr != container.end(); ++itr)
And I agree with Ixrec's second point: Your code will become much cleaner, safer and more efficient, if you simply set a flag in the objects that should be removed. If your objects have attributes like hitpoints, this can be implicitly achieved by a condition like "hitpoints <= 0". Then, all you need to do is a
std::remove_if() or
std::list::remove_if() at the end of each frame.