Reputation: 12174
This is inspired by this post where non-trivial designated initializers are not supported.
I've already read this post and some answers claim this feature is already supported.
However, using C++17 and this code:
struct s {
int a[2];
s (int b): a{[1]=b} {} // error
};
s foo(1);
I still get the error:
sorry, unimplemented: non-trivial designated initializers not supported
s (int b): a{[1]=b} {}
I was thinking this feature is really helpful.
So my questions:
Is there a plan to support this for future C++ versions (post C++17)?
COMPILER
GNU C++17 - Check wandbox
Upvotes: 2
Views: 2861
Reputation: 302708
The proposal adopted to add designated initializers to C++20 (p0329r0) is limited, intentionally (Note that as an official language feature, it's specifically a C++20 feature - but gcc and clang have supported essentially this feature for a long time already):
C++ is a more complex language than C, and we have more things to worry about. So the rules we get are that you cannot mix designators and values, the designators appear in declaration order, are unique, and are neither nested nor array indices. This is already a very useful language feature, as-is.
If not, what is the biggest hindrance why it's not going to be supported
Motivation, probably. Do we really need that syntax? Is it a problem that needs solving? On the downside, there may be parsing ambiguities - you might be able to construct array index initializers that look a lot like lambdas. But if you think it's sufficiently worthwhile, you could write a proposal.
Upvotes: 5