core.reflect vs c++ reflection

Stefan Koch uplink.coder at googlemail.com
Tue Sep 28 20:40:52 UTC 2021


On Monday, 27 September 2021 at 22:51:01 UTC, russhy wrote:
> using traits:
>
> ```D
> string enum_to_str(E)(E v) if (is(E == enum))
> {
>     final switch (v) with(E)
>     {
>         static foreach (m; __traits(allMembers, E))
>         {
>     case mixin(m):
>             return m;
>         }
>     }
> }
> ```
>
> core.reflect is nicer than traits because you actually get to 
> use actual D code
>
> But the casting is kinda ugly, and it gives me java 
> nightmares.. so the C++ actually feels much better

Yes the casting isn't great but all of that can be hidden with 
more library code.
The class oriented design of core.reflect is the way it is 
because it mirrors internals rather closely at this point.
I am open for improvement suggestions.


More information about the Digitalmars-d mailing list