auto storage class - infer or RAII?
Hasan Aljudy
hasan.aljudy at gmail.com
Sat Nov 11 20:51:20 PST 2006
Walter Bright wrote:
> The auto storage class currently is a little fuzzy in meaning, it can
> mean "infer the type" and/or "destruct at end of scope". The latter only
> has meaning for class objects, so let's look at the syntax. There are 4
> cases:
>
> class Class { }
>
> 1) auto c = new Class();
> 2) auto Class c = new Class();
> 3) auto c = some_expression();
> 4) auto Class c = some_expression();
>
> The ambiguity can be resolved by saying that if auto is used for type
> inference, i.e. cases (1) and (3), then it does not mean RAII. If it is
> not used for type inference, i.e. cases (2) and (4), then it does mean
> RAII.
C'mon man, just introduce the "var" keyword and make everyone happy! <g>
>
> In the future, I'd like the following to work:
>
> 5) auto c = Class();
>
> which would mean type inference *and* RAII.
eeeh .. ?
no no, that's awful!!
why would a RAII declaration have no "new"? Is it because it's going to
be on the stack?
Why don't you instead introduce a special case for "new" to make it
allocate on the stack, i.e.
var c = new(stack) Class(); //or newStack Class(); //or something else
which is a clean straight-forward version of:
http://digitalmars.com/d/memory.html#stackclass
More information about the Digitalmars-d
mailing list