next up previous
Next: System Macro Up: C++/C Previous: Enforcing Compile-time Constraints

Usage of erase of std::map

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.


Wei Lu 2007-11-06