Get name of enum val at compile-time?

Jonathan M Davis jmdavisProg at gmx.com
Sun Jan 15 00:57:49 PST 2012


On Sunday, January 15, 2012 03:53:09 Nick Sabalausky wrote:
> Is there a way to get the name of an enum value at compile-time?
> 
> For instance:
> 
> import std.stdio;
> enum Foo { hello }
> void main()
> {
>     writeln(Foo.hello);
> }
> 
> That prints "hello". But what I need is to get "hello" into a string at
> compile-time.
> 
> Of course, I could just manually write a ctfe-able "fooToString()", or
> implement something like std.typecons.defineEnum (which appears to be
> deprecated now). But I'm wondering if I'm overlooking a better solution.

to!string(Foo.hello)

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list