It should be for (auto it = a.begin(); it != a.end(); ){ //If elem must be deleted it = a erase(it); else ++it; continue; } The erase method returns the next valid iterator into the map. An easier way to do this would be std::erase_if(a, /*function obj to check condition for erasing*/); //C++20