@nogc closures

Alex sascha.orlov at gmail.com
Sun Aug 5 10:17:38 UTC 2018


On Sunday, 5 August 2018 at 09:20:21 UTC, vit wrote:
> It's possible create something like this without errors?
>
> void main()@nogc{   //Error: function `app.main` is `@nogc`
>                     //  yet allocates closures with the GC
>     import std.experimental.all;
>
>     const int j = 2;
>     int i = 0;
>     const int[3] tmp = [1, 2, 3];
>
>     tmp[]
>         .filter!((x)scope => x == j)    ///main.__lambda1 
> closes over variable j
>         .each!((x)scope => i = x);
> }

No, at least as I understand it.
https://issues.dlang.org/show_bug.cgi?id=17841

But you can define a struct, with the needed j and i are stored, 
and some functions within, which performs map reduce logic you 
need.


More information about the Digitalmars-d-learn mailing list