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: Ivan Matek <libbooze_at_[hidden]>
Date: Sun, 21 Aug 2022 13:38:08 +0200
On Thu, Aug 18, 2022 at 11:57 PM Drew Gross via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> could be equivalent to
>
> struct S {
> int a;
> S() /* some tag that designates this constructor as "the
> aggregate/designated initializer constructor" */ { std::cout <<
> "constructed an S instance: " << a << std::endl; };
> };
>
> int main() {
> S s = S{.a = 1};
> };
>
>
>
You are probably right, except no constructor argument signature might be
confusing, so maybe

S(auto&&) = match;
or
S(auto&&) = agg_like;

Received on 2022-08-21 11:38:19