Struct initializer in UDA

realhet real_het at hotmail.com
Mon Sep 28 05:18:03 UTC 2020


On Sunday, 27 September 2020 at 11:59:49 UTC, Anonymouse wrote:
> On Sunday, 27 September 2020 at 10:17:39 UTC, realhet wrote:
>> On Saturday, 26 September 2020 at 17:13:17 UTC, Anonymouse 
>> wrote:
>>> On Saturday, 26 September 2020 at 16:05:58 UTC, realhet wrote:

That looks the closes to the python named parameters or the 
struct initializer.

For my use case this opDispatch trick seems to be more flexible 
than the named-parameters thing:

@(FieldProps().range(-360, 360).format("%.2f").caption("Turret 
rotation").unit("deg")) float alpha = 0;

for example if I use the name: "logRange" it can also set the 
isLogarithmic flag as a side effect to true inside the FieldProps 
struct. Just by choosing a slightly different name.

With this idealized format it would be not possible:
@FieldProps{ range: {-360, 360}, format:"%.2f", caption:"Turret 
rotation", unit:"deg"} float alpha = 0;

The more work inside the struct is not a problem, because I'm 
willing to use it from 1000 places. Also __traits(allMembers) can 
help.

Thank you!


More information about the Digitalmars-d-learn mailing list