scope(~this)

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 15 13:55:34 PDT 2017


On Wednesday, 15 March 2017 at 20:36:27 UTC, H. S. Teoh wrote:
> But if the class declares this()
> and the (single) mixin template also declares this(), then the 
> mixin
> template's version is ignored and the class-declared this() is 
> run upon
> construction.

That's normal mixin template behavior: if the name of a mixed in 
object already exists in the instantiation scope, the existing 
one is preferred. This allows you to "override" mixin functions 
and is quite useful. You can also bring in the others via alias.

See my tip here for a related factoid:
http://arsdnet.net/this-week-in-d/2016-feb-07.html


That's what I *thought* was going on with the destructor too... 
but I confirmed both do in fact exist and seem to be merged by 
the compiler. I knew it did that with static dtors, but the spec 
says "a class can have only one destructor and it is always 
virtual" so idk what's going on. Bug, perhaps, but I now am 
inclined to believe it is a hidden feature.

Important note though: such behavior is already possible. Struct 
dtors of members are called when the class dtor runs too...

>  However, if there are two mixin templates both declaring
> this(), the compiler dies with an ICE. :-D

eek.


More information about the Digitalmars-d-learn mailing list