-
Notifications
You must be signed in to change notification settings - Fork 258
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
[SUGGESTION] Aggregate initialization of structs/objects #401
Comments
See 1886ed2#r110677033. |
Also currently on that assignment, parens got removed, which popped little evil comma operator. Reproduction example
|
That's #321. |
Actually its not allowed to write custom constructor for @struct |
I have read p0707 proposal, and I see what is meant by |
Small proof of concept, only for ints. Before line Line 725 in 768f125
After which this cpp2 compiles:
Which generates cpp2 Which emits cpp1 |
Closing in favor of #426 to avoid duplication |
I haven't found a way to aggregate initialize struct.
Background: I'm working with Entity-Component-System. It supposes to have many POD structs. Writing constructor in each is cumbersome.
In C++ they could be simply initialized with
S s { 1, 7 };
I don't know if I missed correct syntax or it is intended, or is it bug.
S : @struct type = {
public x : int;
public y : float;
}
main: () = {
//s1: S = (1, 2); //cpp2 Ok, cpp1 no matching ctor S s1 {1, 2};
//s2: S;
//s2 = (1, 2); //cpp2 Ok, cpp1 no matching ctor s2.construct(1,2);
}
foo: (inout s3 : S) = {
//s3 = (1, 2); //cpp2 Ok, cpp1 no viable overloaded = s3 = 1, 2;
//s4 = ((1, 2)); //cpp2 Ok, cpp1 no viable overloaded = s4 = 1, 2;
//s5 = (.x=1, .y=2); //I know named not in cpp2 yet
//s6 = {1, 2}; //cpp2 ill formed initializer at {
//also tried for fun s7 = (copy (1, 2) - it emits cpp1 copy(1,2)
}`If it is intended to not have aggregate init, it would be good to have some meta facility, like one autogenerated constructor, which have as parameters all data members in order.
The text was updated successfully, but these errors were encountered: