DIP 1031--Deprecate Brace-Style Struct Initializers--Community Review Round 1 Discussion

Aliak something at something.com
Sat Feb 15 22:17:27 UTC 2020


On Saturday, 15 February 2020 at 21:59:26 UTC, John Colvin wrote:
> On Thursday, 13 February 2020 at 07:29:00 UTC, Mike Parker 
> wrote:
>> [...]
>
> :(
>
> I really like them and would prefer to have them do more.
>
> So currently I can write this:
>
> struct Q { int b; string c; }
> struct S { int a; Q q; }
> S s = { a: 3, q: { b: 5, c: "hello" } }
>
> and that's great.
>
> But what I'd really love to be able to do would be this:
>
> S foo()
> {
>     return { a: 3, q: { b: 5, c: "hello" } };
> }
>
> and
>
> Tuple!(int, "a", int, "b") bar()
> {
>     return { x: 3, y: 7 };
> }
>
> and even
>
> auto bar()
> {
>     return { x: 3, y: 7 };
> }
> static assert(is(typeof(bar()) == Tuple!(int, "x", int, "y")));
>
> Although probably not lowering to the phobos std.typecons.Tuple 
> for obvious reasons.
>
>
> Anonymous structures are great.

I know this statement is completely unconstuctive but

😍


More information about the Digitalmars-d mailing list