What is at least possible is to define a struct containing the same named member variables and use the struct as parameter in a constructor.


Perhaps you can inherit from an aggregate and expect the base class as parameter.

Then you can copy/move construct the base class, no need to forward all parameters individually.


You only would get double brackets at initialization.


MyClass c({ .a = 1, .b = 2 });

-----Ursprüngliche Nachricht-----
Von: Ivan Matek via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Do 18.08.2022 23:27
Betreff: [std-proposals] Are there any plans to allow opting in into designated initializers for my nonaggregate classes/structs?
An: std-proposals <std-proposals@lists.isocpp.org>;
CC: Ivan Matek <libbooze@gmail.com>;
Often I encounter the following problem:
I am happily using the readability benefit of designated initializers in my struct.
Then I notice I must add a functionality that makes it a nonaggregate (for example deleting copy constructor to prevent accidental expensive copy), then all my nice initialization must go away and I am forced to write a spammy "forwarding" constructor (one that does nothing, just initializes all variables with mathiing arguments).
I am not sure what syntax would be best, maybe
Std-Proposals mailing list