Error: variable 'xyz' has scoped destruction, cannot build closure
Nicholas Wilson
iamthewilsonator at hotmail.com
Fri Oct 5 23:37:46 UTC 2018
On Friday, 5 October 2018 at 19:31:56 UTC, Jon Degenhardt wrote:
> On Friday, 5 October 2018 at 16:34:32 UTC, Paul Backus wrote:
>> You can thread multiple arguments through to `each` using
>> `std.range.zip`:
>>
>> tenRandomNumbers
>> .zip(repeat(output))
>> .each!(unpack!((n, output) =>
>> output.appendln(n.to!string)));
>>
>> Full code: https://run.dlang.io/is/Qe7uHt
>
> Very interesting, thanks. It's a clever way to avoid the
> delegate capture issue.
>
> (Aside: A nested function that accesses 'output' from lexical
> context has the same issue as delegates wrt to capturing the
> variable.)
Note that this solution may do a lot of output and hence running
of the destructor.
Use: `.zip(repeat(&output))` to avoid that.
More information about the Digitalmars-d-learn
mailing list