to auto or not to auto ( in foreach )

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 16 15:05:49 PDT 2016


On Saturday, 16 July 2016 at 21:39:42 UTC, cym13 wrote:
> However auto should be allowed here. You are defining a 
> variable and the fact that it's in a foreach shouldn't be of 
> any importance. The language should enforce orthogonality of 
> orthogonal things, not break it. A variable definition in a 
> foreach should be allowed not because I like to be pedantic but 
> because it's allowed everywhere else. That also stands for the 
> principle of least surprise.

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)


More information about the Digitalmars-d-learn mailing list