Auto syntax revisited

Charles noone at nowhere.com
Mon Feb 20 14:03:07 PST 2006


> auto foo = local Bar();

This gets my vote , but why is everyone using 'auto' ( deduction )keyword
here, gets a little confusing since you're trying to replace the other auto
with local.  ( For people not in on the #d discussion ).


MyClass foo = local MyClass("parameters");

yes ?

So 'local' replaces 'new' for stack based allocations.



"Sean Kelly" <sean at f4.ca> wrote in message
news:dtdb2e$2lsp$1 at digitaldaemon.com...
> Fredrik Olsson 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();
>
> If we're moving towards stack-based auto classes then I'd prefer the
> distinction be associated with the object and not the reference.  ie.
>
> auto foo = local Bar();
>
> I think the distinction is important because foo can be reassigned to a
> non-local object.  Alternately, simply omitting 'new' entirely might be
> feasible, though the meaning there is less obvious.  As I said in #d:
>
> Foo Bar() { return new Foo(); }
>
> auto foo = Bar();
>
> looks like a stack-based initialization even though it's not.  But
> perhaps it doesn't matter in this case, as nothing will break if a
> heap-based instance is used in place of a stack-based instance, it's
> replacing things the other direction that can cause problems.
>
>
> Sean





More information about the Digitalmars-d mailing list