On Wednesday, 15 March 2017 at 08:17:11 UTC, thedeemon wrote:
On Tuesday, 14 March 2017 at 14:35:11 UTC, Inquie wrote:
There is really no any arrays to keep track of or anything like that matter you stated.
...
3 steps:
...
3. The compiler calls all the delegates on destruction.

Here you are. "All the delegates" - where are they stored? This is the array of delegates I was talking about.

In a library solution you don't even need to think about the string mixins and variables copying. Just make a method that takes a delegate. Then call it like this:
scopeThis({ dealloc(x); });
The compiler will create the delegate for you and store x in the heap in the first place. In scopeThis() you just add the passed delegate to an array of other delegates, then in destructor call them. Seems rather trivial, I don't see a need for a language feature that affects all the classes and objects.

If it is trivial, can you write up a quick solution. I don't see how to accomplish it easily. If ScopeThis({dealloc(x);}); copies locals to the heap, then that solves part 1 trivially. But a bit of CT reflection is required to store the delegates in the class and I don't see it as being trivial... although it very well might be.

Reply via email to