Jim Hewes wrote:
Maybe it's better to think of memory and non-memory resources as different things and handle them differently as opposed to lumping them together using the same mechanism. I'm not sure if there is already a way to deal with this in D as I'm not quite that familiar with D.
It requires that you design your classes differently. You were pretty much asking, if you don't change your design from something that worked in C++, will it work in D? And it won't, if you use D classes.
If you use D structs in D2, you get constructors and destructors for them, and you can use RAII like in C++. In D1 and D2, you can use scope classes (or scope instances).
In D, you could use the C# approach, though you don't have a using statement. You can instead use scope:
scope foo = new Disposable; // do stuff Or: auto foo = new Disposable; scope (exit) foo.dispose();
