[Issue 15692] New: Allow struct member initializer everywhere
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Feb 16 05:20:10 PST 2016
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: nobody at puremagic.com
Reporter: doob at me.com
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);
--
More information about the Digitalmars-d-bugs
mailing list