static foreach considered

Idan Arye via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 8 13:16:51 PDT 2015


On Monday, 8 June 2015 at 20:02:11 UTC, Andrei Alexandrescu wrote:
> Walter and I are looking at ways to implement it. Here's a 
> baseline without static foreach - a "trace" function that 
> prints function calls before they are made:
>
> http://dpaste.dzfl.pl/762c83c7fe30
>
> If the function is overloaded, that won't work. In such cases, 
> static foreach might be helpful. Here's code from the cycle "I 
> have a dream":
>
> http://dpaste.dzfl.pl/82a70c809210
>
> I'm trying to collect together motivating examples and to 
> figure out the semantics of the feature.
>
>
> Andrei

How will scoping work? Similar to mixin templates?

It would be nice together with this feature to be able to mixin 
identifiers:

     static foreach (ident; ["foo", "bar"])
     {
         auto mixin(ident)()
         {
             // code for foo/bar
         }
     }

Otherwise, other than overloads and template instantiations this 
won't be much better then generating code strings with CTFE...


More information about the Digitalmars-d mailing list