Re: Variables with scoped destruction in closures

2016-10-16 Thread ketmar via Digitalmars-d-learn
On Saturday, 15 October 2016 at 07:55:30 UTC, ketmar wrote: p.s. compiler doesn't complain each time, only in some circumstances. i don't remember the exact code now, but some of it has nothing to do with closures at all -- no std.algo, no templates with lambda args, etc.

Re: Variables with scoped destruction in closures

2016-10-16 Thread ketmar via Digitalmars-d-learn
On Saturday, 15 October 2016 at 05:41:05 UTC, Walter Bright wrote: The problem is the closure is generated when it is expected that the delegate will survive past the end of the scope (it's the whole point of a closure). But with a destructor that runs at the end of the scope, it cannot

Re: Variables with scoped destruction in closures

2016-10-16 Thread Walter Bright via Digitalmars-d-learn
On 10/14/2016 3:18 AM, Nordlöw wrote: t_scope.d(23,6): Error: variable t_scope.below.s has scoped destruction, cannot build closure https://github.com/dlang/dmd/blob/master/src/toir.d#L820 The problem is the closure is generated when it is expected that the delegate will survive past the

Re: Variables with scoped destruction in closures

2016-10-14 Thread Nordlöw via Digitalmars-d-learn
On Friday, 14 October 2016 at 14:00:53 UTC, ag0aep6g wrote: As for ways to make this work: 1) You can move s to the heap yourself: auto below3(size_t n, S s = S.init) { import std.algorithm.mutation: moveEmplace; auto onHeap = cast(S*) new ubyte[S.sizeof]; moveEmplace(s,

Re: Variables with scoped destruction in closures

2016-10-14 Thread ag0aep6g via Digitalmars-d-learn
On 10/14/2016 12:18 PM, Nordlöw wrote: import std.algorithm.iteration : filter; import std.algorithm.mutation : move; import std.range : iota; static private struct S { import core.memory : GC; @disable this(this); this(int x) { _ptr =

Re: Variables with scoped destruction in closures

2016-10-14 Thread Nordlöw via Digitalmars-d-learn
On Friday, 14 October 2016 at 10:18:19 UTC, Nordlöw wrote: t_scope.d(23,6): Error: variable t_scope.below.s ... Correction, should be: t_scope.d(23,6): Error: variable t_scope.below1.s ...