[Development] foreach (was: RFC: more liberal 'auto' rules?)
Matthew Woehlke
mwoehlke.floss at gmail.com
Tue Dec 22 17:10:08 CET 2015
On 2015-12-22 11:08, Marc Mutz wrote:
> Try to port all your Q_FOREACH to range-for loops. You will be surprised how
> much digging is required if you don't always want to take the hit of taking a
> copy.
Okay, thanks for the info. (One reason I ask is because qtExtensions¹
actually replaces 'foreach' with either a real range-based for, or - for
pre-C++11 compilers - a clever construct that is very nearly equivalent²³.)
(¹ https://github.com/kitware/qtextensions, although the public version
doesn't have the relevant changes yet.)
(² See
https://github.com/Kitware/vital/blob/master/vital/vital_foreach.h...
qtExtensions QTE_FOREACH omits the BOOST_FOREACH flavor but is otherwise
identical. We do require that the compiler supports at least partial
C++11, including auto.)
(³ I believe the only significant difference from how range-based for is
specified is that our version currently requires begin and end to be
methods on the container. That's mostly laziness; if it ever becomes an
issue, we could try to improve this.)
--
Matthew
More information about the Development
mailing list