__dtor vs __xdtor

HyperParrow via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 11 10:06:40 PDT 2017


On Friday, 11 August 2017 at 17:02:20 UTC, HyperParrow wrote:
> On Friday, 11 August 2017 at 16:53:02 UTC, bitwise wrote:
>> What do they do?
>> What's the difference?
>>
>> Thanks
>
> __xdtor() also calls the __dtor() that are mixed with template 
> mixins while __dtor() only call the __dtor() that matches to 
> the normal ~this(){}

Nice example that speaks by itself:

=================
int i;
struct Foo
{
     template ToMix(){ ~this(){++++i;}}
     ~this(){++i;}
     mixin ToMix;
}

void main()
{
     Foo* foo = new Foo;
     foo.__xdtor;
     assert(i==3);
     Foo* other = new Foo;
     foo.__dtor;
     assert(i==4); // and not 6 ;)
}
=================


More information about the Digitalmars-d-learn mailing list