vector::erase invalidates iterators. It's not safe for erase_if to cache the end iterator nor increment, then erase.