When iterating through a QList<T>
with a foreach
loop, in the tests I conducted the items are returned in the same order as they are with a standard for
loop.
My question is, will the foreach
always return items in numerical order by index like this, for containers that have natural ordering (like QList
and QVector
)? For example, are the following always equivalent?
QList<T> list;
for( int i=0; i<list.count(); ++i )
{
// process items in numerical order by index
// do something with "list[i]";
}
foreach( T item, list )
{
// will items always be processed in numerical order by index?
// do something with "item";
}