Recently while I am solving a problem, I realised that increase iterator after erasing the last element of the map (the map is empty) then it would run infinitively
So I stop the loop by adding a small line to check whether it is empty or not
/// map-looping using either iterator or reverse iterator
{
/// some code upper that erase the element but possible to make the map empty
if (map.empty()) break;
}
Is there an alternative way (some other implementations) to prevent from iterator increament when the map is empty (and reverse_iterator
too if possible)