core.reflect vs. __traits
Stefan Koch
uplink.coder at googlemail.com
Sat Jul 3 13:15:58 UTC 2021
On Saturday, 3 July 2021 at 13:09:26 UTC, Steven Schveighoffer
wrote:
> On 7/3/21 7:59 AM, Stefan Koch wrote:
>> result ~= " " ~ m ~ " = " ~
>> to!string(cast(int)mixin("TOK." ~ m)) ~ ",\n";
>
> "because [the `__traits` version uses] a mixin"
>
> What about:
>
> ```d
> result ~= " " ~ m ~ " = " ~ to!string(int(__traits(getMember,
> TOK, m))) ~ ",\n";
> ```
>
> -Steve
That needs TOK as a template type parameter as well. and
therefore forces you to extract the strings at compile time into
an auxiliary data-structure. (most likely `string[]`)
More information about the Digitalmars-d
mailing list