C++ Logo

std-discussion

Advanced search

Re: enabling default keyword for default method and function values

From: Edward Diener <eldlistmailingz_at_[hidden]>
Date: Mon, 11 Nov 2019 18:28:21 -0500
On 11/11/2019 11:00 AM, Vishal Oza via Std-Discussion 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.
>

I have also often thought that it would be useful, and cost very little,
if the 'default' keyword could be used to specify the default value any
time a function, function template, or class template specified default
values for their parameters. This would eliminate the need for the
programmer to have to manually specify as an argument the correct
default value for a parameter, when the compiler already has that
information in the definition of a construct that allows it to
automatically know what that default value actually is.

I do not understand your discussion above regarding the exceptions to
such a suggested addition to the C++ standard. As long as there is a
default value for a parameter specified, why should I care what type
that parameter is when proposing that the 'default' keyword be used to
signify that value as an argument ?

Received on 2019-11-11 20:52:22