[Development] How to port from Q_FOREACH to range-based for

André Pönitz apoenitz at t-online.de
Thu Jun 20 20:24:59 CEST 2019


On Thu, Jun 20, 2019 at 08:44:40AM +0000, Frederik Gladhorn wrote:
> On tirsdag 11. juni 2019 09:48:00 CEST Lars Knoll wrote:
> > > On 11 Jun 2019, at 09:35, Olivier Goffart <olivier at woboq.com> wrote:
> > > 
> > > On 11.06.19 09:17, Lars Knoll wrote:
> > > 
> > >> So, is removing it worth all the hassle to us and our users? Q_FOREACH is
> > >> a macro and it doesn’t really cost us anything to keep it around. Yes,
> > >> it has issues with non Qt containers and I wouldn’t recommend it for any
> > >> new code. But maybe we could simply fix that part, but making Q_FOREACH
> > >> emit a compiler warning if used on a container that’s not implicitly
> > >> shared?
> > 
> > > 
> > > +1
> > > Although we should probably still discourage its usage in the
> > > documentation.
>  
> > > Regarding the compiler warning:
> > > 
> > >  https://codereview.qt-project.org/c/qt/qtbase/+/244010
> > > 
> > > 
> > 
> > 
> > Nice. So doesn’t this solve most of the issues we have with Q_FOREACH (maybe
> > with the exception that some people find macros ugly)?
> 
> Yes, I'd also be happy about changes to the docs,

Yes,

> let's really not encourage new uses of foreach. But I think we'd do
> ourselves and especially our users a disfavor by deprecating it.

Yes, and yes.
 
> I have seen enough bugs introduced by people fixing deprecation warnings 
> blindly,

Yes.

> and there seem to be so many issues when it comes to foreach that I 
> think it's simply not worth it.

And yes.

> Frederik
> 
> (I hope q_foreach continues its long career in the shade, relaxing and slowly 
> fading from public memory...)

And yes.

And now something feels odd. But I think I can get used to that.

Andre'


More information about the Development mailing list