ranges reading garbage

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 15 14:38:16 PST 2015


On Sunday, 15 February 2015 at 19:54:45 UTC, anonymous wrote:
> Reduced some more:
>
> import std.algorithm, std.stdio;
> void main()
> {
>     int ys_length = 4;
>     auto indices = [0]
>         .map!(xBase => [0].map!(y => ys_length))
>         .joiner();
>     writeln(indices);
> }

And more:

import std.stdio;
struct MapResult(alias fun)
{
     @property int front() {return fun();}
     @property auto save() {return typeof(this)();}
}
void main()
{
     int ys_length = 4;
     auto dg = {return MapResult!({return ys_length;})();};
     writeln(dg().front); /* 4, correct */
     writeln(dg().save.front); /* garbage */
}


More information about the Digitalmars-d-learn mailing list