C++ Logo

std-proposals

Advanced search

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

From: Bo Persson <bo_at_[hidden]>
Date: Thu, 26 Nov 2026 21:29:02 +0100
On 2026-11-26 at 15:50, Alejandro Colomar via Std-Proposals wrote:
> Hi Bo,
>
>> Date: 2026-11-26 15:28:21+0100
>> From: Bo Persson via Std-Proposals <std-proposals_at_[hidden]>
>>
>> On 2026-11-26 at 12:47, Alejandro Colomar via Std-Proposals wrote:
>>>
>>> The proposal for C++ would then be so that one can write code like this:
>>>
>>> int foo(int a = 42, int b);
>>>
>>> And call it as
>>>
>>> foo(, 7); // Evaluates as foo(42,7)
>>>
>>> This would replace some cases which are currently handled with
>>> overloads, which are a much heavier machinery (and also more difficult
>>> to diagnose).
>>>
>>>
>> How is an overload "much heavier"?
>>
>> To me
>>
>> int foo(int b) { return foo(42, b); }
>
> It requires more source code. Consider for example, if you have 2 or 3
> parameters with default arguments, you'll need to write 2^2 or 2^3
> overloads, which grows exponentially.
>
But you don't have that. :-)

If you have 3 default parameters, all in the wrong order, something is
seriously wrong. I would refactor that code to make it better.

Received on 2026-11-26 20:29:08