The correct usage of erasing an element in the map is
for (pos = coll.begin(); pos != coll.end(); ) {
if (pos->second == value) {
coll.erase(pos++);
}
else {
++pos;
}
}
So erase will invalide the current interator pos, but not the begin and
end of the map.