C++ Logo

std-discussion

Advanced search

Re: enabling default keyword for default method and function values

From: Andrew Tomazos <andrewtomazos_at_[hidden]>
Date: Tue, 12 Nov 2019 15:03:18 +1100
+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.


On Tue, Nov 12, 2019 at 3:00 AM Vishal Oza via Std-Discussion <
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]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>

Received on 2019-11-11 22:05:50