In the case, std::mapiterators and references to erased elements are invalid [23.1.2 / 8]. Your code uses an iterator after it is invalidated, this leads to Undefined Behavior . To avoid this Undefined behavior, the iterator needs to increment it before it becomes invalid in the call erase().
:
for(it = m.begin(); it != m.end(); ) {
if( condition )
m.erase(it++);
else
++it;
}
, it++ it , , . , it , erase().