Struct Initialization syntax
John Colvin
john.loughran.colvin at gmail.com
Mon Jul 23 18:31:03 UTC 2018
On Monday, 23 July 2018 at 16:57:20 UTC, H. S. Teoh wrote:
> On Mon, Jul 23, 2018 at 04:26:42PM +0000, Seb via Digitalmars-d
> wrote:
>> tl;dr: the currently proposed syntax options are:
>> ---
>> struct S
>> {
>> int a = 2, b = 4, c = 6;
>> }
>> void foo()
>> {
>> bar(S({c: 10})); // Option 1
>> bar(S(c: 10)); // Option 2
>> bar(S{c: 10}); // Option 3
>> }
>> ---
>>
>> So the struct-initialization DIP has been stalled for too long
>> and I think it's time we finally get this story done.
>
> +1.
>
>
>> I personally prefer option 2, but this might be in conflict to
>> named arguments which we hopefully see in the near future too.
>
> Yeah.
>
>
>> Hence, I'm leaning forward to proposing Option 1 as the
>> recommended Option for the DIP (that's also what the PoC DMD
>> PR implements). What's your take on this?
> [...]
>
> I don't like option 1 because it resembles anonymous function
> syntax and AA initialization syntax, but is actually neither.
Seeing as we already have
S s = { c : 10 };
I'd say it would be fairer to say it resembles anonymous function
syntax and AA initialisation syntax, but mostly it resembles the
existing struct initialisation syntax.
More information about the Digitalmars-d
mailing list