C++ Logo

STD-PROPOSALS

Advanced search

Subject: [std-proposals] Allow "default" keyword for default arguments
From: Edward Diener (eldlistmailingz_at_[hidden])
Date: 2020-02-04 10:43:33


My proposal is simply that whenever a template argument or a function
argument has a default value the keyword "default" can be used to
specify that value when instantiating a template or calling a function.

The proverbial case for this is when a template or a function has more
than one default value and the programmer wants to specify a value for a
default while accepting other default values, whatever they may be. In
this case I do not think it should be necessary for the programmer to
know or care what the other default values are in order to set value(s)
for particular defaults. By using the "default" keyword the programmer
can do this more easily. In my proposal the use of the keyword "default"
for a template or function argument which does not have a default value
is a compiler error.

I am aware of someone else's proposal along the same lines but I want to
disassociate myself from that proposal completely, as it attempted to
add a number of unnecessary and irrelevant provisos. My proposal is
straightforward and is not intended to represent anything more
complicated than what I have stated above.

I have no idea whether this has ever been proposed officially to the C++
standards committee, or what the outcome of such a proposal was, but if
anybody does know I would be curious why the proposal was rejected. I am
aware of workarounds to the issue which I intend to solve with this
proposal, and I am aware of the attitude that the programmer should have
to know and actively repeat a default value in order to specify
arguments for further default values in positional arguments, but I see
no reason why using the "default" keyword could not be used to make
things easier for the programmer in this respect. Ease of language use
should be important, especially when that ease incurs no great effort in
implementation, which I believe my proposal entails.


STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups