C++ Logo

std-proposals

Advanced search

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

From: Tony V E <tvaneerd_at_[hidden]>
Date: Fri, 27 Nov 2026 20:25:42 -0500
On Fri, Nov 27, 2026 at 7:02 PM Barry Revzin via Std-Proposals <
std-proposals_at_[hidden]> wrote:

>
>
>
>> '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
> 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.
>
>
Speaking of named params - since sort({.range = r, .by = f}) has become so
common, does that suggest a syntax? ie just get rid of the { } ?
sort(.range = r, .by = f) ? Or sort(.range r, .by f) ?
I don't think .foo is ambiguous in that context?

Just curious.

-- 
Be seeing you,
Tony

Received on 2026-11-28 01:25:57