Remove declaration 'auto' for RAII?
Tom
Tom_member at pathlink.com
Tue Mar 14 18:27:17 PST 2006
In article <op.s6fkcmh7po9bzi at moe>, Chris Miller says...
>
>On Mon, 13 Mar 2006 10:02:49 -0500, Tom <Tom_member at pathlink.com> wrote:
>
>> In article <dv3u5j$2ot1$1 at digitaldaemon.com>, Jarrett Billingsley says...
>>>
>>> "Chris Miller" <chris at dprogramming.com> wrote in message
>>> news:op.s6csodzipo9bzi at moe...
>>>> There is a problem with auto when declaring variables!
>>>>
>>>> Not only does it have 2 meanings, but when using it for implicit type
>>>> inference, it no longer has the RAII quality. So if you say "auto foo
>>>> = 1"
>>>> is much like "static bar = 1", you are mistaken. The 2nd one doesn't
>>>> cause
>>>> it to be non-static, so why does the 1st make it non-RAII?
>>>>
>>>> If auto for implicit type inference stays, I propose removing it for
>>>> RAII
>>>> in declarations. If you want RAII you can simply use scope(exit) delete
>>>> baz; after the declaration.
>>
>> Sorry, why to do that? I don't want to be forced to free every object
>> manually
>> with scope(exit)? Then it wouldn't be RAII anymore! Or I don't
>> understand your
>> point.
>
>They accomplish the same thing, but perhaps scope can be used to indicate
>RAII:
> scope(raii) Foo f = new Foo;
>or scope(auto)
>etc
Oh I see. But to be obliged to add 'scope(exit) delete foo' after every RAII
declaration isn't nice at all (though it is actually possible as an alternative
to 'auto').
I think I'd prefer replace RAII-'auto' for the keyword 'local' since that
keyword is straightforward to what it means.
And now it comes to me the question: why is so important to have implicit type
inference?
Tom;
More information about the Digitalmars-d
mailing list