Mapping with partial

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 30 12:31:53 PDT 2015


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;}


More information about the Digitalmars-d-learn mailing list