is std.algorithm.joiner lazy?
Edwin van Leeuwen via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Apr 7 03:57:25 PDT 2016
On Thursday, 7 April 2016 at 09:55:56 UTC, Puming wrote:
> When compiled, I get the error:
>
> Error: open path skips field __caches_field_0
> source/app.d(19, 36): Error: template instance
> std.algorithm.iteration.cache!(MapResult!(__lambda1, int[]))
> error instantiating
That seems like a bug to me and you might want to submit it to
the bug tracker. Even converting it to an array first does not
seem to work:
import std.stdio : writeln;
import std.algorithm : map, cache, joiner;
import std.array : array;
auto read(int a) {
return [0, a]; // second level
}
auto mkarray(int a) {
return [-a, a].map!(x=>read(x)).cache.joiner; // to avoid
calling read twice
}
void main() {
auto xs = [1,2 ,3, 4];
auto r = xs.map!(x=>mkarray(x)).array;
// Both lines below should be equal, but second does not compile
[[0, -1, 0, 1], [0, -2, 0, 2], [0, -3, 0, 3], [0, -4, 0,
4]].cache.joiner.writeln;
r.cache.joiner.writeln;
}
Above results in following error:
/opt/compilers/dmd2/include/std/algorithm/iteration.d(326):
Error: one path skips field __caches_field_0
/d617/f62.d(19): Error: template instance
std.algorithm.iteration.cache!(Result[]) error instantiating
More information about the Digitalmars-d-learn
mailing list