for (auto it = m.cbegin(), next_it = it; it != m.cend(); it = next_it) { ++next_it; if (must_delete) { m.erase(it); } }