auto storage class - infer or RAII?

Boris Kolar boris.kolar at globera.com
Sat Nov 11 14:01:13 PST 2006


== Quote from Chris Miller (chris at dprogramming.com)'s article
>     scope Object o =3D new Object(); // Destructed at end of scope.

Excellent suggestion! I would also like to see scoped classes like:

scope class AutoDestroy {
}

AutoDestroy createAutoDestroyObject() {
    return new AutoDestroy();
}

void test() {
    AutoDestroy d = createAutoDestroyObject();
    // d will be destroyed here
}

This way, I can use classes with deterministic destruction the same way as other
classes. Scoped classes should also be able to be returned from functions, passed
as parameters, or be fields of other scoped classes. It is up to programmer (and
maybe, later, compiler escape analysis) to make sure variable doesn't escape scope.

This is the #1 feature on my wish list and I really, really need it. Absence of
good RAII is a major pain (auto classes are way too restricted).



More information about the Digitalmars-d mailing list