https://issues.dlang.org/show_bug.cgi?id=15692
Issue ID: 15692
Summary: Allow struct member initializer everywhere
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
Currently it's only legal to use struct member initializer when declaring a
variable:
struct Foo { int a; int b; }
void main()
{
Foo foo = {
a: 3,
b: 4
};
}
It would be a big improvement if something as the following was allowed:
Foo{ a: 3, b: 4 }
Then it would be possible to use the member initializer syntax in all places a
regular struct initializer is supported. For example, together with "auto" and
when calling functions:
auto foo = Foo{ a: 3, b: 4 };
bar(Foo{ a: 3, b: 4 });
An alternative syntax could be to use parentheses instead:
auto foo = Foo(a: 3, b: 4);
--