RAII and Deterministic Destruction

Jim Hewes via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 25 15:35:57 PDT 2015


Although C++ can be ugly, one reason I keep going back to it rather then 
commit more time to reference-based languages like C# is because I like 
deterministic destruction so much. My question is whether D can REALLY 
handle this or not. I've not been sure about this for some time so now 
I'm just going to come out and finally ask.

I know about this RAII section in the documentation: 
http://dlang.org/cpptod.html#raii
But I don't believe that handles all cases, such as having classes as 
member variables of other classes. (Do the members get destructors 
called too?)

Then there is std.typecons.Unique and  std.typecons.RefCounted. With 
these, can I really get deterministic destruction for all cases like I 
would in C++?

If so, it might be a good idea to emphasize this more in the 
documentation because I'd think people coming from C++ would be looking 
for this.

Jim


More information about the Digitalmars-d-learn mailing list