dimanche 26 juin 2016

How to iterate through a list but stop at size-1

This code:

for (std::list<point>::const_iterator it = controlPoints->begin();
    it != controlPoints->end();
    ++it) {
    ...
    }

Corresponds to:

for (int i = 0; i < controlPoints->size; i++) {
...
}

Meaning, it would iterate through all elements of the list if I got one element for each time it looped.

What would correspond to:

for (int i = 0; i < controlPoints->size-1; i++) {
    ...
    }

I mean, how can I loop size-1 times using iterators?

Aucun commentaire:

Enregistrer un commentaire