struct initializer

Dom DiSc dominikus at scherkl.de
Fri Dec 1 13:02:06 UTC 2023


On Thursday, 30 November 2023 at 14:10:35 UTC, zjh wrote:
> On Wednesday, 29 November 2023 at 16:38:36 UTC, Dom DiSc wrote:
>
> ```d
>> struct S { int a; int b; }
>> S2 fun3() { return S2( 5, 2 ); }
> ```
>
> Here,`S2( 5, 2 );` violeit `DRY` principle.

Yes. I think if we have the brackets form, it should be allowed 
here:

```d
S Fun(){ return { 5, 2 }; }
```

This IS an initialization and the type is known. Requiring the 
repetition of the type is also here annoying.
So it is not a syntax reserved for initialization, but only for 
initialization with equals operator. I think this is inconsequent.
Either allow it for all initializations, or get rid of it, like 
DIP 1031 suggested.



More information about the Digitalmars-d-learn mailing list