[Development] QStringLiteral vs QLatin1String , foreach vs for range

Thiago Macieira thiago.macieira at intel.com
Wed Jan 20 08:47:16 CET 2016

On Wednesday 20 January 2016 08:37:45 André Somers wrote:
> Op 20/01/2016 om 08:18 schreef Knoll Lars:
> >> Where is this qAsConst coming from? When was it introduced? Where is it
> >> documented?
> >> 
> >> I can't find it in my Qt documentation.
> > 
> > It just got added some weeks ago, after we realised that range-for would
> > lead to our containers detaching. So it'll be in 5.7.
> > 
> > In general, I'm very much in favour of getting rid of foreach in favour of
> > range-for.
> Perhaps in the meantime the foreach macro could just be changed to
> actually expand to a range-for?

It can't. I tried a few years ago and it's not compatible.

Ranged for requires that the first part (before the colon) be a declaration. 
Foreach allows an existing variable.

Foreach also requires creating a copy and that causes the dangling reference 
issue we discussed before.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Development mailing list