Original Post
Is it safe to ++ a map iterator when its equal to the end()? Or -- when its equal to begin()?
map::erase returns an iterator to the next valid element, or end() if the last element was erased, so if we have this code
for( itMap = myMap.begin() ; itMap != myMap.end() ; ++itMap )
{
if( /* some condition */ )
{
itNext = myMap.erase( itMap ) ;
// make sure next iteration is correct
itMap = --itNext;
}
}
is it safe, or do I have to put checks for itNext == end() and begin() in as well?
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley