C++ Logo

std-proposals

Advanced search

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

From: Alejandro Colomar <une+cxx_std-proposals_at_[hidden]>
Date: Thu, 26 Nov 2026 15:50:07 +0100
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.

It also requires more work from the compiler. Having a single function
prototype, the compiler doesn't need to have to guess which overload
should be chosen. It just invokes the default value when two
consecutive commas are parsed. With overloads, it must check the types,
and then guess based on that.

Also, when you get something wrong, it gets more difficult to figure
where the problem is. With a single prototype, it's trivial to find
where issues happen.


Have a lovely day!
Alex

> seems like a perfectly good solution.

-- 
<https://www.alejandro-colomar.es>

Received on 2026-11-26 14:50:13