C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Are there any plans to allow opting in into designated initializers for my nonaggregate classes/structs?

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Fri, 19 Aug 2022 11:22:05 +0200
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_at_[hidden]> 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_at_[hidden]>; CC:Ivan Matek <libbooze_at_[hidden]>; 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 [[agg_init]] attribute? -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-08-19 09:22:08