One step out of the TypeInfo stalemate
Paul Backus
snarwin at gmail.com
Wed Jul 29 17:36:56 UTC 2020
On Wednesday, 29 July 2020 at 16:46:55 UTC, Alexandru Ermicioi
wrote:
> On Wednesday, 29 July 2020 at 13:27:02 UTC, Paul Backus wrote:
>>
>> Well, just about anything is better than the current __traits
>> syntax. IMO an easy improvement would be to provide some
>> syntax sugar so you could write
>>
>> T.__hasMember("member")
>>
>> and the compiler would lower it to
>>
>> __traits(hasMember, T, "member")
>
> Yep, true. Though, there is already a proper place for such
> reflection logic which are type info classes, hence I think
> lots of methods found in std.traits could just be moved under
> right type info classes.
The main disadvantage of using TypeInfo for this is that it
doesn't work without the D runtime (i.e., in BetterC).
It's also a bit less efficient. A __traits expression is
essentially a single function call inside the compiler. Using
TypeInfo requires CTFE and/or template instantiation, so
switching std.traits to it would make compile times (slightly)
longer.
More information about the Digitalmars-d
mailing list