C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Implicitly accepting leading default function/template argument values

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Tue, 8 Mar 2022 01:12:08 +0100
On 07/03/2022 22:35, Chris Ryan via Std-Proposals wrote:
>
> Something like this was potentially suggested foo(x=1,y=2.2). What if
> the parameter name conflicts with a local identifier name. Did you just
> set the local variables x to 1 and y to 2.2 or are you using the
> parameter name. I don't think parameter naming is viable, but if it
> were to be used, you would need to use something like a dot name
> (similar to named parameters structure initialization), to differentiate
> parameter names from locals.

In fact, if it weren't for the rules that force the initializations to
appear in declaration order, one could just suggest to use designated
initializers as a practical workaround:


struct foo_arguments { int x; double y = 3.14; string s = "hi"; };
void foo(foo_arguments);

foo({.x = 42; .s = "hi!"}); // OK, y = 3.14
foo({.y = -1}); // OK, x = 0, y = -1
foo({.y = -1, .x = 42}); // ERROR, cannot reorder


My 2 c,
-- 
Giuseppe D'Angelo

Received on 2022-03-08 00:12:12