jeudi 13 juillet 2017

Moving an iterator while in a stl algorithm

Is there a way to move forward (or backwards) while in a loop

For example

vector<int> s{1,2,3,4,5,6,7,8};
for_each(begin(s), end(s), []() {
    if(....) // Some logic that moves the iterator forward 2 spaces
    {
        next(s); 
    }
    else {
         // Normal processing
    }
});

of course the regular for loops does the same thing but I want to avoid it if I can.

for(auto i = 0UL; i < size();) {
    i+=2; 
}

Aucun commentaire:

Enregistrer un commentaire