Oh, thanks for the hint! I wasn't aware that this loop allows access to the key. It does not solve the removal-problem, however. When I remove the client while in the loop the behavior of the rest of the loop will be undefined.
I could add a local std::set and store the to-be-removed ids in there, removing them when the loop is done. Do you prefer this to the iterator?
std::set to_remove;
for (auto& client: clients_) {
...
if (error) { to_remove.add(client.first); continue;
}
...
}
for (auto id: to_remove)
close(id);
Oh, thanks for the hint! I wasn't aware that this loop allows access to the key. It does not solve the removal-problem, however. When I remove the client while in the loop the behavior of the rest of the loop will be undefined.
I could add a local std::set and store the to-be-removed ids in there, removing them when the loop is done. Do you prefer this to the iterator?
std::set to_remove;
to_ remove. add(client. first);
continue;
for (auto& client: clients_) {
...
if (error) {
}
...
}
for (auto id: to_remove)
close(id);