Unexpected behaviour of foreach statement

Arredondo arm.plus at gmail.com
Fri Mar 2 10:21:39 UTC 2018


Hi,

The following works as expected:

auto range = [1, 2, 3, 4, 5];
foreach (i, el; range) {
	writeln(i, ": ", el);
}

but this slight modification doesn't:

auto range = iota(5);
foreach (i, el; range) {
	writeln(i, ": ", el);
}

DMD 2.078.3 says:
Error: cannot infer argument types, expected 1 argument, not 2

The error message is not helpful either, because indicating the 
types, as in:

foreach (int i, int el; range) { ... }

throws the same error.
What's going on here?

Arredondo


More information about the Digitalmars-d-learn mailing list