struct initializer

bomat Tempest_spam at gmx.de
Fri Dec 1 20:20:32 UTC 2023


I completely agree with the OP, and I want to illustrate this by 
another example which I find quite bizarre:

```
struct S { int a; int b; }
S[] s_list = new S[0];

// this works
S s = { a:1, b:2 };
s_list ~= s;

// this does not
s_list ~= { a:1, b:2 };
```

I'm a C++ programmer in my day job and the very first instinct 
I'd have is to replace the first version by the second to reduce 
verbosity and eliminate an unnecessary copy.

However, for some reason the compiler is not able to deduce the 
type in the second case, so I'm out of luck.

I'm glad to hear that, with a compiler update, I will at least be 
able to do
```
s_list ~= S( a:1, b:2 );
```
instead of
```
s_list ~= S( 1, 2 );
```
but it still seems very inconsistent.


More information about the Digitalmars-d-learn mailing list