suggested change to foreach index

Tom S h3r3tic at remove.mat.uni.torun.pl
Thu Jun 8 14:12:29 PDT 2006


Jarrett Billingsley wrote:
> Or, more consistent, make auto foreach indices require "auto"?
> 
> int i;
> 
> foreach(auto i, auto j; something)
>     writefln(i); // New local i which overrides outer i
> 
> foreach(i, auto j; something)
>     writefln(i); // Uses outer i
> 
> writefln(i); // Writes the value that i last had in the loop
> 
> This has the (wonderful) side-effect of making it bleedingly obvious that 
> the foreach indices are using type inference; the current index inference 
> form _looks_ like it's trying to use already-defined index variables. 

++votes;    // fully agreed


--
Tomasz Stachowiak  /+ a.k.a. h3r3tic +/



More information about the Digitalmars-d mailing list