Qt foreach loop ordering vs. for loop for QList
The foreach
macro (aka. Q_FOREACH
) uses the begin()
and end()
iterator request methods of the container.
So if your container is a QList
or QVector
then your examples will always be equivalent. You can view the foreach
source code here.
The foreach
macro isn't great though, it makes a copy of the container - so only use on containers that support implicit-sharing. Use C++11 for( : ) {}
loops if available, otherwise Boost has an equivalent that is superior.
Based on the information found here, foreach
is much slower than the first, suggesting that it is not equivalent.