auto storage class - infer or RAII?

Tomas Lindquist Olsen tomas at famolsen.dk
Sun Nov 12 19:52:23 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.
> 
> In the future, I'd like the following to work:
> 
> 5) auto c = Class();
> 
> which would mean type inference *and* RAII.

I'd like to see 'auto' remain as it is except for RAII. RAII only makes 
sense for classes and dynamic arrays, for these 'auto' would only be 
useful for automatic type inference. E.g: 'auto C c = new C;' is useless 
and the same as 'C c = new C;'

I'd like to see 'scoped' as a new storage class for classes and dynamic 
arrays. Using it for anything else should be an error. This would mean 
that 'auto class' would become 'scoped class' too.

I'd hate to see 'var', 'let', 'def' etc. introduced as new keywords! 
Typing time differences for 3-6 letters is in the milliseconds for most 
coders (I would think)

I hope I haven't missed something fundamental, and would be extremely 
pleased if D 1.0 turns out like this :)

*shivers* by the thought of 'var'



More information about the Digitalmars-d mailing list