Error: variable 'xyz' has scoped destruction, cannot build closure

Jon Degenhardt jond at noreply.com
Fri Oct 5 19:31:56 UTC 2018


On Friday, 5 October 2018 at 16:34:32 UTC, Paul Backus wrote:
> On Friday, 5 October 2018 at 06:56:49 UTC, Nicholas Wilson 
> wrote:
>> On Friday, 5 October 2018 at 06:44:08 UTC, Nicholas Wilson 
>> wrote:
>>> Alas is does not because each does not accept additional 
>>> argument other than the range. Shouldn't be hard to fix 
>>> though.
>>
>> https://issues.dlang.org/show_bug.cgi?id=19287
>
> 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.)


More information about the Digitalmars-d-learn mailing list