tupleof of class instance... but enumerate _all_ the instance variables
bauss
jacobbauss at gmail.com
Mon Jun 30 21:37:20 UTC 2025
On Monday, 30 June 2025 at 16:37:01 UTC, Andy Valencia wrote:
> On Saturday, 28 June 2025 at 10:41:47 UTC, Nick Treleaven wrote:
>> static foreach (field; B.tupleof)
>> {{
>> enum s = __traits(identifier, field);
>> pragma(msg, s);
>> // access runtime field
>> __traits(getMember, d, s)++;
>> }}
>
> One last question, if you would? Why the double open braces?
> I tried, and got:
>
> tst57.d(26): Error: declaration `tst57.main.s` is already
> defined
> tst57.d(26): `variable` `s` is defined here
>
> if I changed to a single open brace?
>
> Thanks again,
> Andy
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".
More information about the Digitalmars-d-learn
mailing list