auto storage class - infer or RAII?

Dave Dave_member at pathlink.com
Sun Nov 12 11:50:53 PST 2006


Don Clugston wrote:
> 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.
> 

I realize 'auto' is technically the default storage class, but was suggesting when both a storage 
class and type are absent, 'infer' would be used (and not as a storage class) instead of auto.

>> '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.
> 

I think so too, but I don't think 'infer' would be necessary in those cases, even for the sake of 
consistency.

>> 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