UDA initialize a user defined type attribute field

bearophile bearophileHUGS at lycos.com
Tue Feb 18 16:07:33 PST 2014


Arjan:

> MyAttrib instances may be initialized like this:
>
> auto myattrib = { defaultvalue:"null" };
>
> But this seems not possible when using MyAttrib as attribute.

This could become a D enhancement request.


> I guess the field MyAttrib.defaultvalue will be assigned the 
> value "fancy name"?

Unfortunately D doesn't have named arguments.

You can use chains, returning this from some methods:

MyAttrib().setName("Foo").setSz(10).setDefaultValue("Bar")

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list