Get enum value name as string at compile time?

Steven Schveighoffer schveiguy at
Mon Sep 14 03:48:51 UTC 2020

Consider the enum:

enum Foo { a, b }

Foo.a.stringof => "a"
enum x = Foo.a;
x.stringof => "cast(Foo)0"

Is there another way I can take an enum value that's known at compile 
time (but not the actual identifier), and get the name of it? I know I 
can use a switch, or to!string. But I was hoping this was easy for the 
compiler to figure out some way without involving CTFE.


More information about the Digitalmars-d-learn mailing list