zip.map.reduce at CT?
bearophile
bearophileHUGS at lycos.com
Tue Oct 2 17:41:44 PDT 2012
Do you know if here the problem is in Phobos or if I'm asking
Phobos to do something too much hard?
import std.algorithm: map, reduce;
import std.range: zip;
struct S {}
alias bool function(S) F;
F foo(T)(T) {
return p => true;
}
F bar(F r1, F r2) {
return p => true;
}
F spam(S[] ps) {
return zip(ps, ps).map!foo().reduce!bar();
}
const r1 = spam([S(), S()]); // Error
void main() {
const r2 = spam([S(), S()]); // OK
}
Output:
...\dmd2\src\phobos\std\conv.d(3393): Error: cannot dereference
invalid pointer *result
...\dmd2\src\phobos\std\range.d(3714): called from here:
emplace(addr,front(this.ranges._field_field_0))
...\dmd2\src\phobos\std\algorithm.d(428): called from
here: this._input.front()
...\dmd2\src\phobos\std\algorithm.d(428): called from
here: foo(this._input.front())
...\dmd2\src\phobos\std\algorithm.d(697): called from
here: _param_0.front()
test.d(12): called from here: reduce(map(zip(ps,ps)))
test.d(14): called from here: spam([S(),S()])
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list