tupleof of class instance... but enumerate _all_ the instance variables

Andy Valencia dont at spam.me
Mon Jun 30 23:35:34 UTC 2025


On Monday, 30 June 2025 at 21:37:20 UTC, bauss wrote:
>>>             static foreach (field; B.tupleof)
>>>             {{
>>>                 enum s = __traits(identifier, field);
>>>                 pragma(msg, s);
>>>                 // access runtime field
>>>                 __traits(getMember, d, s)++;
>>>             }}
> the static foreach will emit all code in scope, which means 
> each iteration will emit the code in the scope, so you double 
> brace it to create individual scopes that don't "overlap".

Thank you.  I hadn't thought of static foreach with that 
perspective before, but that makes sense.

Andy



More information about the Digitalmars-d-learn mailing list