On Monday, 30 March 2015 at 19:31:54 UTC, anonymous wrote:
On Monday, 30 March 2015 at 19:03:05 UTC, matovitch wrote:
Well I have a bit of a similar problem with foreach.

If I use classic T[] range, I can do :

foreach(int i, auto t, myRange)...

But if I use an Array!T (from std.container) I get :

cannot infer argument types, expected 1 argument, not 2

Even if I add the brackets []. Any idea ? Thanks for your help ! :)

The index is the problem. Generally, foreach doesn't do automatic indices for ranges. You can use std.range.enumerate or count yourself explicitly.

foreach(i, t; myRange.enumerate) {...}

size_t i = 0;
foreach(t; myRange) {... ++i;}

Is it a compiler problem or a language restriction ? Thanks for the workaround btw, I will try it !

Reply via email to