Hello, anyone can help me make this better?
The functionality I want to achieve is: While serializing the
fields of a struct, I want it to check the @STORED UDA on every
field. If there is no fields are marked with @STORED, that means
every field must be serialized. Otherwise only the marked one.
I had problems using map and any, so I come up with this lame
foreach version: It works, but I think it does it in runtime.
bool anySTORED = false;
static foreach(fieldName; FieldNameTuple!T)
mixin("anySTORED |= hasUDA!(data.*, STORED);".replace("*",
fieldName));
static foreach(fieldName; FieldNameTuple!T){{
mixin("const thisSTORED = hasUDA!(data.*,
STORED);".replace("*", fieldName));
if(thisSTORED || !anySTORED)
mixin("streamAppend_json!(dense, fieldName)(st, data.*,
nextIndent);".replace("*", fieldName));
}}
Thanks in advance!
(ps: I just love string mixins, I know :D)