gcc doesn't like foreach with const-ref containers
Andreas Pakulat
apaku at gmx.de
Wed Sep 5 22:23:34 CEST 2007
On 05.09.07 21:24:31, Thiago Macieira wrote:
> Christian Ehrlicher wrote:
> >I wonder why this works on linux. A quick solution would be to remove
> >the reference. It's implicit shared so it doesn't matter if you pass a
> >reference or a copy here. And if this breaks BC, just use an internal
> > copy:
> >
> >void foo(const QList<MyClass>& l_)
> >{
> > const QList<MyClass> l(l_);
> > foreach(const MyClass& c, l)
> > ...
> >}
>
> Yes, it's a GCC bug. It doesn't like const-refs as the second argument to
> foreach.
Recently saw that there's a gcc 4.x prerelease available from mingw
project, hopefully that will fix some things...
> Don't change the function signature, but create a local (cheap) copy of
> it.
I won't do either of these. I'm using a plain old for() with
const_iterator, simply because that doesn't need an additional comment
why a local copy is created.
Andreas
--
You will soon meet a person who will play an important role in your life.
More information about the Kde-windows
mailing list