Is D 0.163 D 1.0?
Regan Heath
regan at netwin.co.nz
Tue Jul 25 05:40:28 PDT 2006
On Tue, 25 Jul 2006 21:39:29 +1000, Derek <derek at psyc.ward> wrote:
> On Tue, 25 Jul 2006 00:53:02 -0700, Walter Bright wrote:
>
>> Derek wrote:
>>> On Mon, 24 Jul 2006 00:33:23 +0000 (UTC), Andrei Khropov wrote:
>>>
>>>> And what about double meaning of 'auto'?
>>>
>>> In general 'auto' is a poor choice for both meanings. 'auto' is
>>> obviously
>>> shorthand for automatic, but automatic what???
>>>
>>> Walter, given that 'auto' as a keyword is not going to be removed from
>>> the
>>> language, how can one currently declare a type-inferred variable that
>>> has
>>> RAII properties?
>>>
>>
>> Regan Heath penned the solution I thought I'd posted a while back, but
>> maybe I hadn't:
>>
>>> 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)
>
> I'm sorry but I'm just not getting it. I just tried this example using
> v0.163 and it fails to compile.
It's not yet implemented.
> I did ask "how can one *CURRENTLY* declare ...".
I was replying to Shaun when I put forward the syntax above, not you ;)
> So I guess one can't do it just now and the example is something yet to
> be implemented.
Correct.
> If so, it means that the opCall paradigm will be removed from classes. Is
> that intentional?
My opinion is that _static_ opCall is of very limited use for classes. I
won't miss it. Heck, my vote is for struct constructors and the removal of
static opCall entirely.
> And I assume that if the class was declared as ...
>
> auto class A {}
>
> then every object declared with the class would have to be ..
>
> A a = A();
> auto a = A();
Yes. I assume it would be an error to use 'new' on an 'auto class', but, I
don't really like the idea of 'auto class'es at all.
> But how does this proposed syntax handle variable-length arrays?
>
> char[] a = read(filename);
>
> Is 'a' destroyed at end of scope?
No.
It's my understanding that the purpose of 'auto'(destruction) is to
guarantee a call to a class destructor, not to delete memory. After all,
the GC will delete the array (assuming it's unreferenced) when it next
does a collect. I think it should be illegal to apply 'auto'(destruction)
to anything other than a class reference.
Regan
More information about the Digitalmars-d
mailing list