Lambda capture by value

Elronnd elronnd at elronnd.net
Mon Feb 24 20:33:19 UTC 2020


>>         printers[i] = () { write(i); };
>
> I know it looks silly but if you make that:
>
>          printers[i] = (int i) { return () { write(i); }; }(i);
>
> it will do what you want.

Or, the slightly prettier (imo)

           printers[i] = ((i) => () => write(i))(i);

Or, if you need to force it to return void:

           printers[i] = ((i) => {write(i);})(i);


More information about the Digitalmars-d-learn mailing list