mardi 2 août 2016

How to stop a for loop by advancing the std::map iterator?

I'm iterating through a std::map twice through using an outer for loop and a nested for loop. I want stop the inner loop when the condition is met. I know that if I call break, it will stop both the loops. I don't want that. I only want to stop the inner for loop.

My code snippet is as below:

    for(auto markerCounter = ellipsePropertiesMap.begin(); markerCounter != ellipsePropertiesMap.end(); markerCounter++)
    {                                    
        for(auto markerCounter2 = ellipsePropertiesMap.begin(); markerCounter2 != ellipsePropertiesMap.end(); markerCounter2++)
        {
            if(conditionMet)
            std::advance(markerCounter2, ellipsePropertiesMap.size());
            //I also tried the following:
            //markerCounter2 = ellipsePropertiesMap.end();
            //markerCounter2++;
        }
    }

I'm trying to stop the inner for loop by advancing the iterator by the size of the std::map, but it's not working. I also tried to get the ending iterator and advance it to end the loop. Apparently that isn't working either.

So, how can I actually stop the inner loop?

Thanks.

Aucun commentaire:

Enregistrer un commentaire