Designated initializers to function argument

Ki Rill rill.ki at yahoo.com
Tue Jul 11 15:16:54 UTC 2023


In C I can do the following:
```C
void apply(struct Appearance a) {...}

// usage
apply((struct Appearance) {
     .color = BLACK,
     .strokeWidth = 4
});
```

Can I do the same in D without creating a struct variable 
separately?
```D
void apply(Appearance a) {...}

// currently accepts
Appearance a = { color: BLACK, strokeWidth: 4 };
apply(a);

// would like this
apply({ color: BLACK, strokeWidth: 4 });

// or this
apply(Appearance(color: BLACK, strokeWidth: 4)); // other fields 
are default initialized: strokeOpacity, fillOpacity, etc...

```


More information about the Digitalmars-d-learn mailing list