On Thursday, 24 May 2012 at 17:57:11 UTC, Steven Schveighoffer wrote:
On Thu, 24 May 2012 13:47:31 -0400, Tove <t...@fransson.se> wrote:

There's a big problem with this though. Your destructor *has no idea* whether it's being called from within a collection cycle, or from clear. You must assume the most restrictive environment, i.e. that the dtor is being called from the GC.

This is even true with struct dtors!

-Steve

If there is a clear location where a manual close() function can be called... then there are many safe solutions to automatically and safely call clear instead.

std.typecons.Unique

If you are a library creator, you could even use a factory to enforce wrapping in Unique... But I don't see any point of adding a non standard destructor function name, there are numerous ways to facilitate RAII.

Reply via email to