Date: Thu, 26 Nov 2026 22:32:34 +0100
Hi Bo,
> Date: 2026-11-26 21:29:02+0100
> From: Bo Persson via Std-Proposals <std-proposals_at_[hidden]>
>
> 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. :-)
2 functions where we could do with 1 is already an improvement, IMO.
And having better diagnostics is also an improvement.
And not having to guess which overload is being used is also nice.
>
> If you have 3 default parameters, all in the wrong order, something is
> seriously wrong. I would refactor that code to make it better.
There are some cases where you need to have the arguments in a specific
order for historic reasons.
Have a lovely night!
Alex
> Date: 2026-11-26 21:29:02+0100
> From: Bo Persson via Std-Proposals <std-proposals_at_[hidden]>
>
> 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. :-)
2 functions where we could do with 1 is already an improvement, IMO.
And having better diagnostics is also an improvement.
And not having to guess which overload is being used is also nice.
>
> If you have 3 default parameters, all in the wrong order, something is
> seriously wrong. I would refactor that code to make it better.
There are some cases where you need to have the arguments in a specific
order for historic reasons.
Have a lovely night!
Alex
-- <https://www.alejandro-colomar.es>
Received on 2026-11-26 21:32:41
