Auto syntax revisited

AgentOrange AgentOrange_member at pathlink.com
Tue Feb 21 02:32:08 PST 2006


In article <ops5bhg5ol23k2f5 at nrage.netwin.co.nz>, Regan Heath says...
>
>On Mon, 20 Feb 2006 21:23:26 +0100, Fredrik Olsson <peylow at gmail.com>  
>wrote:
>> After some discussion on #d I though why not put my thoughts into more  
>> permanent writing.
>>
>> Keyword auto is used for two reasons; implicit type and making sure the  
>> object is destroyed when going out of scope. I suggest a new keyword for  
>> the latter: local.
>>
>> local auto foo = new Bar();
>>
>> Why? First of auto is only used for the implicit type, so no confusion.  
>>   The keyword local in itself describes pretty to the point what is  
>> supposed to happen with the variable. And nothing is said about the  
>> stack, so we are future proof if in the future we would like to also  
>> have:
>>
>> local auto foo = Bar();
>>
>> Where Bar(); is a function returning an Object, but we still want the  
>> object to be destructed when going out of this scope. The implementation  
>> is quite different as the Object would need to be on heap, but the  
>> syntax is the same. So local would indicate what should be done (destroy  
>> when out of scope), not how it should be done (allocate on stack or  
>> whatever).
>>
>> Even this could be possible, without syntax changes:
>> {
>>    local Foo bar;
>>    // some code
>>    Baz(bar); // Jupp Baz have a inout parameter returning an object.
>> } // And bar is still destroyed if set to something here...
>
>I thought the plan was to deprecate "auto" WRT declaring stack based auto  
>destructed class instances, resulting in:
>
>class A {}
>
>A a = new A(); //heap alloc
>A a = A();     //stack alloc, destruct at scope exit
>
>So, "auto" would only mean "automatic type determination":
>
>auto a = new A(); //heap alloc, 'a' is of type reference to 'A'
>auto a = A();     //stack alloc, destruct at scope exit, 'a' is of type  
>reference to 'A'
>
>Regan

are we going to lose static opCall? yikes!





More information about the Digitalmars-d mailing list