On Monday, 27 September 2021 at 22:51:01 UTC, russhy wrote:
>using traits:
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.