RAII and Deterministic Destruction
rsw0x via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Aug 25 18:32:04 PDT 2015
On Tuesday, 25 August 2015 at 22:35:57 UTC, Jim Hewes wrote:
> 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
To add to what the other people said,
there exists scoped!T in std.typecons to allocate a class on the
stack, and Unique/RefCounted as you mentioned. AFAIK refcounted
is in the process of being overhauled, but the user should notice
no differences.
More information about the Digitalmars-d-learn
mailing list