to auto or not to auto ( in foreach )

pineapple via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 16 18:57:21 PDT 2016


On Saturday, 16 July 2016 at 22:05:49 UTC, ketmar wrote:
> actually, `foreach (v; rng)` looks like `foreach` is *reusing* 
> *existing* *variable*. most of the time you can put `immutable` 
> or something like that there to note that it is not reusing 
> (purely cosmetical thing), but sometimes you cannot, and then 
> `auto` is perfect candidate... but it is not allowed. (sigh)

Chipping in my agreement. foreach(x; y) makes as much syntactic 
sense as for(x = 0; x < y; x++) where x was not previously 
defined. One does not expect something that does not look like 
every other variable definition in the language to be defining a 
new variable.


More information about the Digitalmars-d-learn mailing list