Struct initializer in UDA

Anonymouse zorael at
Sat Sep 26 17:13:17 UTC 2020

On Saturday, 26 September 2020 at 16:05:58 UTC, realhet wrote:
> Hi,
>   struct S{int a, b, c=9, d, e, f;}
> Is there a way or a trick to declare an UDA by using a nice 
> struct initializer?
> It would be nice to be able to use the form:
>   @S{f:42} int a;  //or something similar to this.
> instead of this longer and error-prone way:
>   @S(0, 0, 0, 9, 0, 42) int a;

I don't think you can currently, no, but I'd be happy to be 
proven wrong.

The closest I can get is @(S.init.c(9).f(42)) with use of 
opDispatch, which is easier to read but still ugly.

More information about the Digitalmars-d-learn mailing list