to auto or not to auto ( in foreach )
Dennis Ritchie via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jul 16 07:10:45 PDT 2016
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote:
> foreach(auto v; msg)
> writeln(v);
>
> gives an error that a basic type is expected
>
> foreach(v; msg)
> writeln(v);
>
> works
>
> .. but why?
`Note: The ForeachTypeAttribute is implicit, and when a type is
not specified, it is inferred. In that case, auto is implied, and
it is not necessary (and actually forbidden) to use it.`
http://dlang.org/spec/statement.html#ForeachStatement
More information about the Digitalmars-d-learn
mailing list