PDA

View Full Version : Iterators v.s. index based for loops



pssss
2nd February 2011, 13:30
For that reason, iterators are rarely useful in connection with QList. One place where STL-style iterators do make sense is as arguments to generic

doc.trolltech.com/4.2/qlist-iterator.html


So if I have a for loop, where the macro foreach isn't an option. Should I use iterators or indexes?



for(int i = 0; i < list.size(); i++) {
Do something with list[i]
blah blah blah
}


for(QList<type>::iterator i = list.begin(); i != list.end(); ++i) {
Do something with *i
blah blah blah
}

Lykurg
2nd February 2011, 14:27
Have a look here: http://labs.qt.nokia.com/2009/01/23/iterating-efficiently/.

pssss
2nd February 2011, 14:33
Thanks so much. The kind of answer I was looking for.