C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Parameters with default values at arbitrary positions, with empty arguments

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Sat, 28 Nov 2026 01:21:20 +0000
On 28 November 2026 00:13:59 GMT, Alejandro Colomar via Std-Proposals <std-proposals_at_[hidden]> wrote:
>Hi Barry,
>
>> Date: 2026-11-27 19:01:43-0500
>> From: Barry Revzin <barry.revzin_at_[hidden]>
>>
>> On Fri, Nov 27, 2026, 8:28 AM Alejandro Colomar via Std-Proposals <
>> std-proposals_at_[hidden]> wrote:
>>
>> > Hi David,
>> >
>> > > Date: 2026-11-27 13:57:10+0100
>> > > From: David Brown <david.brown_at_[hidden]>
>> > >
>> > [...]
>> > > > Hmmm, yeah, so two people here have expressed preference for 'default'.
>> > > > When implementing this with macros in C, I also tried first to use the
>> > > > 'default' keyword, but I couldn't find a way to do it.
>> > >
>> > > I would certainly greatly prefer having "default" rather than omitting
>> > the
>> > > argument entirely
>> >
>> > Thanks!
>> >
>> > > - though I am still not convinced that default values in
>> > > arbitrary positions is a good idea. (I'd rather see progress made
>> > towards
>> > > name arguments in calls, as supported in many other languages - if that
>> > ever
>> > > makes it to C++, then this whole idea is moot.)
>> >
>> > I dislike named parameters. They make the call too long, and don't give
>> > much benefit.
>> >
>>
>>
>> They give tremendous readability and clarity benefit, and alleviate
>> problems with multi-argument functions.
>>
>> In C++, the best you can do right now is approximate named function
>> arguments by using designated initialization with a struct. This is more
>> limited than named arguments would be, and mildly tedious on the author
>> side, but the fact that people do it anyway - and many people are happy to
>> learn this idiom - is a pretty clear indicator of the value of using names.
>
>FWIW, the don't add any readability to me. I'm not saying you should
>not like them. I'm only saying that _I_ don't like them. And I will
>not accept that default arguments should not be pursued because others
>like named arguments.
>
>That said, if you like named arguments, you're welcome to ask for named
>arguments to be implemented and/or standardized. I'm not going to say
>you shouldn't, nor will tell you what you should like.
>
>> > 'default' better expresses the intent: this parameter has a default
>> > value.
>> >
>>
>> This might be literally true but practically speaking is definitely false.
>>
>> Yes, in some sense, it expresses the intent that sort(r, default, f) is
>> using the default value of the 2nd parameter. However, this does absolutely
>> nothing to express the actual intent of the code, because you have to
>> actually know the order of all the parameters, which is usually not
>> relevant to either the caller or the reader. This also scales terribly when
>> the one argument you want to specify is the 6th one. Or was it the 7th? Or
>> 5th? It also doesn't hold up very well on refactoring.
>>
>> On the other hand, sort(r, by: f) (or whatever syntax) actually does
>
>Now you need to answer more questions: which parameter is r? If you
>name one argument, you should name them all, or you have a bunch of
>questions that are hard to answer. We currently have issues in
>designated initializers, precisely when one only designates some
>member.

I would impose that positional arguments must never follow named arguments. That makes it simpler.

>
>Also, this makes the names that a library uses become part of the API,
>which is something that libraries may not want to expose.

That ship has sailed somewhat with reflection. Having said that, the declaration syntax could have explicit opt-in syntax for allowing certain parameters to bind to named arguments.

>
>
>Have a lovely night!
>Alex
>
>> express the intent, very clearly, in a way that works great regardless of
>> which argument(s) you actually want to specify. You don't even need to know
>> what order we go in.
>>
>> The explicit default is at least better than sort(r,,f), which has the same
>> counting and lack-of-intent-or-clarity problem but is additionally
>> indistinguishable from a typo. But it's really not a good solution to the
>> problem.
>>
>> Barry
>

Received on 2026-11-28 01:21:30