C++ Logo

std-proposals

Advanced search

Re: Video Intro to WG21/D2288 C++ Designated Arguments

From: Hani Deek <Hani_deek_at_[hidden]>
Date: Mon, 22 Nov 2021 19:21:41 +0000
I have not studied this issue carefully, but I think that one simple way to implement your proposal without introducing new things into the language is to allow the following syntax

void f(int x = 0, struct { int y = 43; int z = 23; } v = {});

As a shorthand for the following syntax

struct S { int y = 43; int z = 23; };
void f(int x = 0, S v = {});

That is, allow a struct/class to be declared and defined inside the function declaration. The struct/class may be named or not.

Then we can call the function in a regular way

f(0, { .y{43}, .z{23} });

Of course, the syntax that you propose is more brief. However, the brevity comes at the expense of complicating the language by introducing completely new things and completely new syntax.

Received on 2021-11-22 13:21:46