I am a big fan of using ad-hoc structs and designated initializers to emulate named parameters for my functions.
struct Args {
int a;
int b;
};
int f(Args a) {
return a.a + a.b;
}
int g() {
return f({.a = 1, .b = 2}); // Works! That's what I want.
return f({1, 2}); // Also works. I want to forbid this, though.
}
However, those structs can still be initialized by a positional initializer list. I.e., you can still call f({1, 2}).
I want to forbid this and force the caller to explicitly name the parameters also at the call-site. How can I do so in C++20?