Unable to call each on a lockstep range containing 2 or more ranges
John Colvin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Nov 18 05:51:56 PST 2015
On Wednesday, 18 November 2015 at 12:20:42 UTC, maik klein wrote:
> https://stackoverflow.com/questions/33779822/unable-to-call-each-on-a-lockstep-range-containing-2-or-more-ranges
>
> http://dpaste.dzfl.pl/76c79f1f12ab
>
> void main(){
> import std.container;
> import std.stdio;
> import std.algorithm.iteration;
> import std.range;
> Array!int ai = [1,2,3,4];
> Array!int ai1 = [1,2,3,4];
> Array!int ai2 = [1,2,3,4];
>
> auto arange = lockstep(ai[],ai1[]);
> arange.each!((a,b) => writeln(a, b));
>
> auto arange2 = lockstep(ai[],ai1[],ai2[]);
> arange2.each!((a,b,c) => writeln(a, b, c));
> }
>
> Error: template std.algorithm.iteration.each cannot deduce
> function from argument types !((a, b, c) => writeln(a, b,
> c))(Lockstep!(RangeT!(Array!int), RangeT!(Array!int),
> RangeT!(Array!int))), candidates are:
> /opt/compilers/dmd2/include/std/algorithm/iteration.d(820):
> std.algorithm.iteration.each(alias pred = "a")
>
>
> "arange" works but "arange2" doesn't because the compiler is
> unable to deduce the the function. The error even appears if I
> explicitly add the argument types.
I think this is a bug, please report it at issues.dlang.org and
perhaps there will be an explanation or it will be fixed.
In the mean time, something like this should work:
auto arange2 = zip(ai[],ai1[],ai2[]);
arange2.each!((t) => writeln(t[0], t[1], t[2]));
// or if you really must have the names:
arange2.each!((t) => (a,b,c){ writeln(a, b, c); }(t.expand));
More information about the Digitalmars-d-learn
mailing list