You should increase the iterator only if you do not delete any element in the iteration:
for(auto iter=vec.begin(); iter!=vec.end();) { if((*iter).isDead()) { std::swap(*iter, vec.back());
Or even better, replace the entire loop with remove_if :
vec.erase(std::remove_if(vec.begin(), vec.end(), std::bind(&ValueType::isDead, _1)), vec.end());
source share