C++ Logo

std-proposals

Advanced search

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

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Sat, 28 Nov 2026 02:16:54 +0300
On 27 Nov 2026 03:17, Lénárd Szolnoki via Std-Proposals wrote:
>
> On 26 November 2026 11:47:25 GMT, Alejandro Colomar via Std-Proposals <std-proposals_at_[hidden]> 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).
>>
>>
>> What do you think?
>
> Just skipping the argument feels too subtle for me. Couldn't we do foo(default, 7) instead of foo(, 7)?

+1 for using the `default` keyword to explicitly request the default
value for the argument. I don't like the empty expression before the
comma since it makes the code less readable and more prone to accidental
typos e.g. if the user doesn't notice that his keyboard bounced.

I also think the proposal should at least explore the same extension in
other contexts, such as template arguments. Note that default parameters
are already allowed in the middle of function template argument lists,
and this new mechanism could enable cases that were previously difficult
or impossible to achieve.

  template< typename T = std::string, typename U >
  T to_string(U&&);

  int x = 10;
  // Force floating-point string representation
  auto str = to_string< default, double >(x);
  // Obtain a wide string int representation, possible today
  std::wstring wstr = to_string< std::wstring >(x);

Received on 2026-11-27 23:17:00