-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++: Provide constructors for auto-generated unions #279
Comments
This partially works with brace-init, for everything except for unions. // with C++17
const Heartbeat_1_0 hb{
1244, // uptime
{Health::NOMINAL},
{Mode::WARNING},
0x1
};
// with C++20 or extension
const Heartbeat_1_0 hb{
.uptime=1244, // uptime
.health={Health::NOMINAL},
.mode={Mode::WARNING},
.vssc=0x1
}; |
Indeed, the members are public. I guess I am going close this and walk away with shame. |
Unions would really need a constructor to initialize this way. We would need some kind of a tag dispatch to differentiate between different named variants. // proposed syntax
const Value_1_0 val{Value_1_0::natural_16_tag, 1, 2, 3}; And variant construction is a problem right now. At the moment we can't constuct specific variant, we can only set value after: Value_1_0 v;
v.set_natural_16({{10, 10, 0}}); |
I think the issue exists, just not for simple POD values as listed earlier. |
There is also the issue of missing value init (as in the opening post) |
Instead of:
Ty_1 val; val.foo = 123; val.bar = baz;
go like:
To facilitate immutability and URVO.
The text was updated successfully, but these errors were encountered: