banana

Andrew Fedoniouk news at terrainformatica.com
Thu Jul 27 11:02:04 PDT 2006


> void main()
> {
>   auto i = 10;
>   auto foo = new Foo;
>   auto scope bar = new Bar;
>   auto scope wumpus = new Wumpus;
> }
>

Conceptually 'auto' as a scope variable indicator is redundant.

In 'ideal D world' struct shall have ctor/dtor and entities
required stack allocation shall be declared as structs - not classes.

So if you need pure stack allocated object use struct with dtor.
And if you need class instance to be managed by stack variable use
simple struct based smart pointer:

struct local(T)
{
    T ptr;
    void opAssign(T t) { ptr = t; }
    ~this() { delete ptr; }
}

void main()
{
    local!(Bar) bar = new Bar; // opAssign invovation
    ... do something ...
} // implicit dtor invocation happens here ->  delete bar.ptr

Andrew Fedoniouk.
http://terrainformatica.com








More information about the Digitalmars-d mailing list