Thread overview
hasElaborateDestructor
Apr 27
claptrap
Apr 27
Luna
6 days ago
Nick Treleaven
April 27

What the heck does elaborate mean in this context? I mean a type has a destructor or not right? Why is a struct destructor called "elaborate" and a class destructor not?

Or is this just another case of programmers cant think up sensible names for stuff?

April 27

On Sunday, 27 April 2025 at 21:43:26 UTC, claptrap wrote:

>

What the heck does elaborate mean in this context? I mean a type has a destructor or not right? Why is a struct destructor called "elaborate" and a class destructor not?

Or is this just another case of programmers cant think up sensible names for stuff?

Elaborate refers to destructors which are not automatically generated by the D compiler; eg. If you have a type with subtypes that can be destroyed D will automatically set up a destructor that handles the destruction chain for you. But if you define your own destructor; potentially in a template your destructor now becomes elaborate since it has more functionality than just ensuring its children are destroyed if needed. Elaborate destructors only apply to structs however, not classes.

April 28

On Sunday, 27 April 2025 at 21:43:26 UTC, claptrap wrote:

>

What the heck does elaborate mean in this context? I mean a type has a destructor or not right? Why is a struct destructor called "elaborate" and a class destructor not?

Or is this just another case of programmers cant think up sensible names for stuff?

hasElaborateDestruction!T is true if and only if (a) T has a destructor, and (b) a local variable of type T will have that destructor called on it at the end of its scope. It returns false for classes because classes are reference types, and the destructor on a class instance is not called when the reference goes out of scope.

A more accurate name would be hasElaborateDestruction.

April 28

On Sunday, 27 April 2025 at 21:43:26 UTC, claptrap wrote:

>

What the heck does elaborate mean in this context? I mean a type has a destructor or not right? Why is a struct destructor called "elaborate" and a class destructor not?

Or is this just another case of programmers cant think up sensible names for stuff?

Renamed to hasComplexDestruction in Phobos 3. You can even use phobos.sys.traits in your code right now since it's just a template and the module ships with the standard Phobos distribution.

6 days ago

On Sunday, 27 April 2025 at 22:01:11 UTC, Luna wrote:

>

Elaborate refers to destructors which are not automatically generated by the D compiler; eg. If you have a type with subtypes that can be destroyed D will automatically set up a destructor that handles the destruction chain for you. But if you define your own destructor; potentially in a template your destructor now becomes elaborate since it has more functionality than just ensuring its children are destroyed if needed. Elaborate destructors only apply to structs however, not classes.

An elaborate destructor can either be directly declared for a type or generated by the compiler due to its fields:

    static struct S2 { ~this() {} }
    static struct S3 { S2 field; }
    static assert( hasElaborateDestructor!S2);
    static assert( hasElaborateDestructor!S3);