core.reflect vs. __traits
Stefan Koch
uplink.coder at googlemail.com
Sat Jul 3 15:24:21 UTC 2021
On Saturday, 3 July 2021 at 15:09:38 UTC, Steven Schveighoffer
wrote:
> 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
Fair point.
And getMember does look somewhat nicer than the string mixin as
well ;)
More information about the Digitalmars-d
mailing list