On Friday, 2 March 2018 at 10:21:39 UTC, Arredondo wrote:
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
try
https://dlang.org/phobos/std_range.html#enumerate
foreach (i, el; enumerate(range)) {
writeln(i, ": ", el);
}