On 2015-12-05 06:08, Julien Blanc wrote: > Am I the only one to think that this example is inherently broken ? I > mean, why wouldn’t any sane person write : > > for(auto const& element : list) > foo(element)
If you don't actually *need* the index, then yes. "Broken" might be strong, but yes, the example is somewhat lacking. A better example would be: foo(i, list[i]); (And yes, if you don't need the index, *please do* iterate over the elements directly!) > On 2015-12-03 13:49, Marc Mutz wrote: >> - all loop variables (both index and iterators) >> the reason being that spelling out the name is usually wrong: >> size_t i = stdVector.size() // wrong, should be >> std::vector::size_type... >> also helps when porting from Qt containers to STL ones > > That looks perfectly fine for me. Index based loops should be avoided > whenever it is possible, and for iterator based loops auto makes no harm > (seriously, who wants to write > std::vector<my_very_long_type>::const_iterator instead of auto ?). Agreed. But the above started with objections to using 'auto' for indexed iteration :-). -- Matthew _______________________________________________ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development