[Issue 4261] Bad textual printing of enums

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Aug 29 21:16:49 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4261


Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich at gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2010-08-29 21:16:37 PDT ---
When you need to get the name of the enumerated value, you have to use the 'to'
template function from std.conv, as described in TDPL. Your example then
becomes:

import std.conv : to;
import std.stdio: writeln;
void main() 
{
    enum Foo { Zero, One }
    Foo f = Foo.One;
    writeln(to!string(f));
}

Prints: One

It wouldn't make much sense for an enum to behave differently in different
contexts (e.g. comparing it in an if statement vs. using it with a writeln).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list