using DMD git HEAD

struct A
{
    B* b;

    ~this()
    {
        doStuff();
    }
}

struct B
{
    ~this()
    {
        doOtherStuff();
    }
}

example usage:

void main()
{
    A a;
    a.b = new B;
}


Requirements:

doOtherStuff must be called before doStuff.
doOtherStuff and doStuff must be called exactly once each.

Possible solution:

insert a b.__dtor(); before doStuff. Unfortunately b.__dtor() is called again on exit (by the GC I assume). doOtherStuff can be guarded with a flag to prevent this.

b.destroy() doesn't seem to actually call B.__dtor().


Is there a "right" way to do this?

Reply via email to