Is D 0.163 D 1.0?

Walter Bright newshound at digitalmars.com
Wed Jul 26 02:30:21 PDT 2006


Chad J wrote:
>>> class A {}
>>>
>>> A a = new A(); //normal
>>> A a = A(); //destroyed at end of scope
>>>
>>> and with auto..
>>>
>>> auto a = new A(); //normal
>>> auto a = A(); //destroyed at end of scope
>>>
>>> Simple, elegant, obvious (IMO) 
>>
>>
> 
> Myself I would prefer not to have that.  It creates an ambiguity between 
>  a static opCall on A and the storage attribute.
> So:
> 
> class A
> {
>   static A opCall() { ...do something... }
> }
> 
> A a = A(); // destroyed at end of scope, or call A.opCall()?
> 
> I prefer the storage attribute have it's own keyword.  Perhaps give 
> storage 'auto' and type inference 'var'.  For me, that makes it more 
> obvious, since to my eyes it would be a keyword that I've never seen 
> before and now need to look up in the spec - otherwise it's just a 
> static opCall :(.

The idea is that 'auto' means type inference, not RAII. To get RAII 
behavior, use A(), which invokes the constructor for A. (If A.opCall is 
called, it isn't a constructor, and so an RAII object is not created.)

The old syntax:

	auto A a = new A();

will still be supported as a deprecated feature.



More information about the Digitalmars-d mailing list