I'm puzzled by the way destroy works when passed a pointer to a struct, observe:
----------------------code.d----------------------
int i;

struct C
{
        this(ref int i)
        {
                ++i;
                ii = &i;
        }
        
        ~this()
        {
                --(*ii);
        }
        int* ii;
}
unittest
{
    C c = C(i);
    C* cc = &c;
    destroy(cc);
    assert(i == 0); // dtor not called
    destroy(*cc);
    assert(i == 0); // dtor called
}
int main()
{
        
        return 0;
}
----------------------code.d----------------------
destroy(cc) -> does c = C.init
destroy(*cc); -> calls the C dtor

Is this by design? If so - how can I destroy and get the dtor called without dereferencing the pointer? Currently I resort to calling delete on the pointer so dtor gets called.

Reply via email to