How to do reflection on alias symbols
Arafel
er.krali at gmail.com
Fri Nov 17 09:11:30 UTC 2023
On 17/11/23 2:48, Jonathan M Davis wrote:
> On Thursday, November 16, 2023 6:04:43 PM MST Jonathan M Davis via
> Digitalmars-d-learn wrote:
>
> Actually, it looks like there's already an old bug report on the issue:
>
> https://issues.dlang.org/show_bug.cgi?id=12363
>
> So, it has been reported, but it looks it's one of those that's gone under
> the radar.
>
> - Jonathan M Davis
>
Thanks for finding it!
I think that in general D could do with a more systematic approach to
reflection. For me, it's one of its greatest features, and it's a bit of
a pity that it needs to be done in such an ad-hoc manner with all kind
of corner cases.
I mean, in order to know if something is an `enum`, I need to do:
```d
enum isEnum(alias a) = is(typeof(a)) && !is(typeof(&a));
```
which feels like the wrong approach, and too much error-prone. I also
fear I'm forgetting to consider some corner case.
There is `is(E == enum)`, but it only works on types, and fails for
anonymous enums, because `typeof` returns the base type.
I know that `std.traits` was precisely supposed to hide these dirty
details, but as of now it also seems to be missing this kind of
systematic approach: I'd like things like `isEnum!symbol`, and also
`isAlias!symbol`, etc.
But I think I digress a bit too much, this would be a topic rather for
the general forum.
Thanks again for your help!
More information about the Digitalmars-d-learn
mailing list