www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - hasElaborateDestructor

reply claptrap <clap trap.com> writes:
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?
Apr 27
next sibling parent reply Luna <luna foxgirls.gay> writes:
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.
Apr 27
parent Nick Treleaven <nick geany.org> writes:
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: ```d static struct S2 { ~this() {} } static struct S3 { S2 field; } static assert( hasElaborateDestructor!S2); static assert( hasElaborateDestructor!S3); ```
Apr 30
prev sibling next sibling parent Paul Backus <snarwin gmail.com> writes:
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`.
Apr 27
prev sibling parent Adam Wilson <flyboynw gmail.com> writes:
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.
Apr 28