static foreach considered

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 8 15:16:49 PDT 2015


On 06/09/2015 12:12 AM, Idan Arye wrote:
> On Monday, 8 June 2015 at 21:32:52 UTC, Timon Gehr wrote:
>> I think the body should have access to a scope that is hidden from the
>> outside which contains the loop variable, but declarations should be
>> inserted into the enclosing scope like for static if.
>
> This would require some syntax to mark the declarations we want to
> expose. Maybe `out`?
>
> This is far better than the mixin template approach, since it'll alert
> us early about conflicts:
>
>      static foreach (ident; ["a", "b", "a"])
>      {
>          int mixin(ident ~ "1");
>          out int mixin(ident ~ "2");
>      }
>
> `a1` is created twice, but that's OK since it isn't marked with `out`.
> `a2` is declared twice and raises a compilation error because it's
> marked with `out`. This will ensure these kind of errors are detected
> early and the compilation error points to the exact place of declaration.

I actually intended all declarations in the body to be inserted into the 
enclosing scope, at least by default.


More information about the Digitalmars-d mailing list