News and problems about foreach loops

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Nov 3 07:39:23 PDT 2012


On 11/3/12, bearophile <bearophileHUGS at lycos.com> wrote:
> Now you can omit the type, this is very handy:
>
> struct Foo { int x; }
> void main() {
>      auto data = [Foo(10), Foo(20), Foo(30)];
>      foreach (const f; data) {}
> }

That's really cool that we have this now. But this error message needs
to improve:

    foreach (const f; data)
    {
        f.x++;
    }

test.d(9): Error: can only initialize const member x inside constructor

It should be something like "cannot modify const member x".


More information about the Digitalmars-d mailing list