C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Implicitly accepting leading default function/template argument values

From: Bo Persson <bo_at_[hidden]>
Date: Sun, 6 Mar 2022 22:05:37 +0100
On 2022-03-06 at 20:03, Lénárd Szolnoki via Std-Proposals wrote:
> Hi,
>
> On Sun, 6 Mar 2022 19:54:04 +0100
> Bo Persson via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
>> On 2022-03-06 at 17:17, David Jones via Std-Proposals wrote:
>>> ​Under your proposal, it would have to mean the same as "x =
>>> f(1, 2, /*some defaulted thing*/)".
>>>
>>> Under my proposal, "x = f(1,2,)" and "x = f(1,2)" would be
>>> identical, as long is f is a function with default values supplied
>>> for every argument after the second.
>>>
>>
>> I'm not convinced that turning typos into valid code is an
>> improvement. :-)
>>
>> How do we know that f(1,2,) means "I want a default 3rd parameter"
>> and not "oops, I slipped on the keyboard"?
>
> In my understanding f(1,2,) and f(1,2) could mean the same thing
> always, not only when there are default parameters in the function
> declaration. So there is no "subtle difference" to worry about.
>

The "subtle difference" is that with f(1,2,) I might have intended to
type f(1,2,0), but somehow missed something in the 0 shift+0 sequence at
the end of the call.


Alternate proposals using "default" for default values look a lot better
to me.

Received on 2022-03-06 21:05:46