why foreach() don't use 'auto'?

Timon Gehr timon.gehr at gmx.ch
Fri Mar 28 15:42:48 PDT 2014


On 03/28/2014 01:58 PM, w0rp wrote:
> On Thursday, 27 March 2014 at 10:30:59 UTC, ketmar wrote:
>>> You can use `auto` in foreach, as well as any explicit type. It can
>>> be omitted because it is unambiguous.
>> no, i can't. at least in current GDC.
>>
>> import std.stdio, std.string;
>>
>> void main () {
>>     foreach (auto val; [0,1,2,3]) writeln(val);
>> }
>>
>> error: basic type expected, not auto
>
> I reckon that is a bug, and it should be legal. Perhaps someone else
> will know more.

It is documented that code like the above is illegal:

http://dlang.org/statement.html#ForeachType


More information about the Digitalmars-d mailing list