core.reflect vs. __traits
Steven Schveighoffer
schveiguy at gmail.com
Sat Jul 3 15:09:38 UTC 2021
On 7/3/21 9:15 AM, Stefan Koch wrote:
> 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";
>> ```
>>
>
> 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[]`)
My point is, if `mixin("TOK." ~ m)` works, then `__traits(getMember,
TOK, m)` should also, and therefore no mixin required.
-Steve
More information about the Digitalmars-d
mailing list