Diff between function and delegate
Meta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 29 10:36:46 PDT 2016
On Monday, 27 June 2016 at 19:59:05 UTC, Mathias Lang wrote:
> - You use `scope myDG = (Params) { body... }`
It looks like i is still moved to the heap but marking `test`
with @nogc compiles successfully. Then when I run the code the
assertion is triggered. What exactly is going on here?
auto test() @nogc //Compiles
{
int i = 10;
scope dg = { assert(i == 10); }; //AssertFailure
i = 11;
return dg;
}
void main()
{
auto dg = test();
dg();
}
More information about the Digitalmars-d-learn
mailing list