auto storage class - infer or RAII?

Kristian Kilpi kjkilpi at gmail.com
Tue Nov 14 02:27:40 PST 2006


On Sun, 12 Nov 2006 20:59:05 +0200, Walter Bright  
<newshound at digitalmars.com> wrote:

> Carlos Santander wrote:
>> I don't think they're valid concerns (meaning they're subjective, not  
>> everyone will have those ideas), but I think we (the D community) just  
>> want a way to clearly differentiate both meanings of auto. So, choose  
>> any two words: auto/scope, var/auto, def/scoped, foo/bar, and let's  
>> move on.
>
> I think the auto/scope is probably the best idea.
>
>> Also keep in mind that your option #5 (auto c = Class()) doesn't seem  
>> to be a popular proposal (based on what has been said in the ng).
>
> I'm a bit surprised at that, but the negative reaction to it is pretty  
> clear.

Well I kind of like it. Unfortunate it breaks the static opCall, so it  
would be too confusing to have I think. E.g.

   Class b;
   auto c = Class();

   b = Class();  //wha? calls static opCall?


The following (shorthand) notation won't have that problem:

   Class c();

Later new values cannot be assigned to 'c':

   Class c(10, 2);

   c = new Class;  //error

You could also use this notation with classes:

   class Foo {
     int v = 1;
     Bar b(10);
   }

'b' is binded to 'Foo', it gets destroyed with it. This notation would  
remove the initialization of objects from the constructors to declaration  
lines (a nice ability to have sometimes). Which is consistent with  
initialization of non-object variables.

I think this would be great to have as a shorthand, an *alternative* way  
to create scoped/binded objects.



More information about the Digitalmars-d mailing list