On Tuesday, 28 May 2013 at 11:49:25 UTC, Gary Willoughby wrote:
Why does the following snippet print:
"Started name revision" instead of "Started my-app 1.0a"?
import std.stdio;
enum application : string
{
name = "my-app",
revision = "1.0a",
}
void main(string[] arguments)
{
writefln("Started %s %s", application.name,
application.revision);
}
I don't really know what the correct way of doing this is. There
really ought to be a property .value of enums.
The stringof property will return what you want, although
annoyingly with quotation marks around it ([1 .. $-1] on the end
will clear that up of course). For types other than string it
returns cast(application)value as a string, which is not
particularly helpful.
BTW this only happens with named enums, anonymous enums print the
value not the name.
I don't know how much any of this is intended behaviour and how
much is just by chance.