Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
November 18, 2015 Unable to call each on a lockstep range containing 2 or more ranges | ||||
---|---|---|---|---|
| ||||
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. |
November 18, 2015 Re: Unable to call each on a lockstep range containing 2 or more ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to maik klein | 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));
|
November 18, 2015 Re: Unable to call each on a lockstep range containing 2 or more ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Wednesday, 18 November 2015 at 13:51:59 UTC, John Colvin wrote:
> On Wednesday, 18 November 2015 at 12:20:42 UTC, maik klein wrote:
>> [...]
>
> 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));
Thanks, but the problem I have with zip is that it doesn't work with "ref".
for example
auto arange3 = zip(ai[],ai1[],ai2[]);
foreach(ref a; arange3){
a[0] = 42;
}
Won't change anything. Is this another bug?
|
November 18, 2015 Re: Unable to call each on a lockstep range containing 2 or more ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to maik klein | On Wednesday, 18 November 2015 at 14:11:45 UTC, maik klein wrote: > On Wednesday, 18 November 2015 at 13:51:59 UTC, John Colvin wrote: >> On Wednesday, 18 November 2015 at 12:20:42 UTC, maik klein wrote: >>> [...] >> >> 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)); > > Thanks, but the problem I have with zip is that it doesn't work with "ref". > > > for example > > auto arange3 = zip(ai[],ai1[],ai2[]); > foreach(ref a; arange3){ > a[0] = 42; > } > Won't change anything. Is this another bug? Unfortunately, yes: https://issues.dlang.org/show_bug.cgi?id=10541 Note that while(!arange3.empty) { arange3.front[0] = 42; arange3.popFront(); } should work as expected. |
November 18, 2015 Re: Unable to call each on a lockstep range containing 2 or more ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to maik klein | 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.
Which version of the compiler are you using?
|
November 18, 2015 Re: Unable to call each on a lockstep range containing 2 or more ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Wednesday, 18 November 2015 at 17:22:52 UTC, Meta wrote:
> On Wednesday, 18 November 2015 at 12:20:42 UTC, maik klein wrote:
>> [...]
>
> Which version of the compiler are you using?
Linux - DMD64 D Compiler v2.069.0
|
November 18, 2015 Re: Unable to call each on a lockstep range containing 2 or more ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to maik klein | On Wednesday, 18 November 2015 at 17:40:21 UTC, maik klein wrote: > On Wednesday, 18 November 2015 at 17:22:52 UTC, Meta wrote: >> >> Which version of the compiler are you using? > Linux - DMD64 D Compiler v2.069.0 https://issues.dlang.org/show_bug.cgi?id=15357 https://issues.dlang.org/show_bug.cgi?id=15358 |
Copyright © 1999-2021 by the D Language Foundation