scope(~this)

thedeemon via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 15 01:17:11 PDT 2017


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.


More information about the Digitalmars-d-learn mailing list