auto storage class - infer or RAII?

Don Clugston dac at nospam.com.au
Sun Nov 12 07:26:57 PST 2006


Dave wrote:
> Kyle Furlong wrote:
>> Chris Miller wrote:
>>> On Sat, 11 Nov 2006 13:48:00 -0500, Walter Bright 
>>> <newshound at digitalmars.com> 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:
>>>>
>>>
>>> Choosing from your list I guess "auto" for auto destruction and 
>>> "infer" for auto type deduction.
>>>
>>> However, I tend to prefer "scope" (without parentheses following) for 
>>> auto destruction, which frees up "auto" for auto type deduction:
>>>
>>>    scope Object o = new Object(); // Destructed at end of scope.
>>>    scope auto q = new Foo(); // Auto type deduction and end-of-scope 
>>> destruction.
>>
>> scope has my vote, its elegant, as raii is functionally similar to the 
>> scope(x) construct.
> 
> Vote++.
> 
> But Walter specifically (and I think purposefully) left out any mention 
> of new keywords. Nonetheless I'd like to see auto deprecated in favor of 
> 'infer'. 'scope' and 'infer' both describe exactly what they are used 
> for. 
Not so, 'auto' *never* means 'type inference'. It's the absence of a 
type that means type inference. But the usage of auto to mean both 
'raii' and 'local variable storage class' is really confusing people.

> 'auto' just seems too much like a deprecated artifact of C.

Agreed, but I don't know of anything better.

const infer x = 3.5;
static infer x = 4.5L;

are too wordy.

> Based on previous discussions though, 'auto' is here to stay one way or 
> the other forever. I sincerely don't understand Walter's infatuation 
> with 'auto', but it is what it is.



More information about the Digitalmars-d mailing list