C++ Logo

std-discussion

Advanced search

Re: enabling default keyword for default method and function values

From: Vishal Oza <vickoza_at_[hidden]>
Date: Tue, 12 Nov 2019 07:41:37 -0600
I think you have a point however. I think that using name values might have
some issues if the variable are not named in the declaration but defined in
the definition or the declaration and definition have different names. This
might be fine but reorder might be a side issue and should not be pushed as
a part of the proposal.

On Nov 12, 2019 4:01 AM, "David Brown" <david.brown_at_[hidden]> wrote:

> On 12/11/2019 05:03, Andrew Tomazos via Std-Proposals wrote:
> > +std-proposals
> >
> > I actually think it would be better to have named parameters. That way:
> >
> > auto fooval = foo(13, default, default, &foobazval);
> >
> > is instead:
> >
> > auto fooval = foo(bar: 13, foobaz: &foobazval);
> >
> > which I think reads a lot better. I suspect you only want this default
> > feature so that you can default parameters in the middle of the list
> > without defaulting those at the end.
>
> I would very much like to see named parameters supported (regardless of
> details of the syntax), and I agree that this would remove the need for
> this "default" proposal. But I think it would be better to have both,
> so that you can write, for example:
>
> auto fooval = foo(bar : 13, foobaz : &foobazval, baz : default);
>
> Named parameters let you change the order, and skip default values. But
> sometimes you might want to make it explicit that you are leaving a
> parameter as the default.
>
> David
>
>
>
> >
> >
> > On Tue, Nov 12, 2019 at 3:00 AM Vishal Oza via Std-Discussion
> > <std-discussion_at_[hidden]
> > <mailto:std-discussion_at_[hidden]>> wrote:
> >
> > I just wanted to know if the following idea is a bad idea. Should we
> > enable using the default keyword to function input value parameter
> > if we only care about one parameter that have default parameters
> > both before and after the parameter we care about?
> > For example:
> >
> > int foo(int bar = 3, int baz = 7, int* foobar = nullptr, int* foobaz
> > = nullptr) { ... }
> > ...
> >
> > int foobazval = 78;
> > auto fooval = foo(13, default, default, &foobazval); // =
> > foo(13, 7, nullptr, &foobazval)
> >
> >
> > The exceptions are references where there should never be a
> > default value and possibly type with no default this is only a
> > possibly because the type could be the same value as the type if the
> > type was default constructed.
> > --
> > Std-Discussion mailing list
> > Std-Discussion_at_[hidden] <mailto:Std-Discussion_at_lists.
> isocpp.org>
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> >
> >
>
>

Received on 2019-11-12 07:43:58