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

Jon Degenhardt jond at noreply.com
Fri Oct 5 06:55:58 UTC 2018


On Friday, 5 October 2018 at 06:44:08 UTC, Nicholas Wilson wrote:
> On Friday, 5 October 2018 at 06:22:57 UTC, Nicholas Wilson 
> wrote:
>> tenRandomNumbers.each!((n,o) => 
>> o.appendln(n.to!string))(output);
>>
>> or
>>
>> tenRandomNumbers.each!((n, ref o) => 
>> o.appendln(n.to!string))(output);
>>
>> should hopefully do the trick (run.dlang.io seems to be down 
>> atm).
>>
>
> Alas is does not because each does not accept additional 
> argument other than the range. Shouldn't be hard to fix though.

Yeah, that's what I was seeing also. Thanks for taking a look. Is 
there perhaps a way to limit the scope of the delegate to the 
local function? Something that would tell the compiler the 
delegate has a lifetime shorter than the struct.

One specific it points out is that this a place where the 
BufferedOutputRange I wrote cannot be used interchangeably with 
other output ranges. It's minor, but the intent was to be able to 
pass this anyplace an output range could be used.


More information about the Digitalmars-d-learn mailing list