The lifetime of reduce's internal seed
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Apr 22 10:31:21 PDT 2014
I opened the following bug before reading reduce's documentation carefully:
https://issues.dlang.org/show_bug.cgi?id=12610
import std.stdio;
import std.algorithm;
void main()
{
int[] arr = [ 0 ];
int[1] seed;
int[] result = reduce!((sum, _) => sum[])(seed, arr);
writefln("%s", result);
}
The output is garbage like [373728176].
Note that the original seed is a value type, which is later sliced by
the lambda.
Now I think that it can be considered a user error. Do you agree whit
that? If so, this is something else we should be careful about similar
to the internal buffer of byLine.
Ali
More information about the Digitalmars-d-learn
mailing list