A possible suggestion for the Foreach loop

Timon Gehr timon.gehr at gmx.ch
Thu Aug 22 06:02:55 PDT 2013


On 08/21/2013 10:53 PM, Dylan Knutson wrote:
>>
>
> I do like the idea of it being called 'static foreach' instead of
> 'foreach', to keep in step with how the rest of the language handles
> other compile time constructs (static assert). Plus, as you said in your
> bugreport, visual disambiguation between that and a runtime foreach is
> nice feedback for the programmer to pick up instantly.

It's important to keep them separate regardless. static foreach is close 
to useless if it introduces a new scope for its body.

I.e.:

int main(){
     foreach(_;Seq!int){
         int x;
     }
     return x; // error
}

int main(){
     static foreach(_;Seq!int){
         int x;
     }
     return x; // ok
}


More information about the Digitalmars-d mailing list