Bug 3999 and 4261
Andrej Mitrovic
andrej.mitrovich at gmail.com
Wed Sep 1 13:53:51 PDT 2010
I thought to!string(Enum) already does this? This was the example I
posted in bug report 4261:
import std.conv : to;
import std.stdio: writeln;
void main()
{
enum Foo { Zero, One }
Foo f = Foo.One;
writeln(to!string(f));
}
Prints: One
On Wed, Sep 1, 2010 at 10:50 PM, Jonathan M Davis <jmdavisprog at gmail.com> wrote:
> On Wednesday, September 01, 2010 12:59:01 Nick Sabalausky wrote:
>> "Jonathan M Davis" <jmdavisprog at gmail.com> wrote in message
>> news:mailman.33.1283368612.858.digitalmars-d at puremagic.com...
>>
>> > Personally, I don't really care about using enum the way it is. Having
>> > enums
>> > freely converting to and from their base type is more of a concern,
>> > though I'm
>> > not sure how much that really does or doesn't matter.
>>
>> I find it to be a pain nearly every time I need to convert one to a string.
>
> I wasn't even aware that there was a way. If I had to guess, I would assume that
> it involves stringof, but I'd have to try it. Now, assuming that that's the
> case, it would be pretty easy to write a template function which takes the enum
> type and the value to stringify, and it returns the string version of that enum
> value (or throws if it's not a valid value for that enum type). I can see how
> having it as a distinct type would be more desirable for that though, since then
> you could likely just use stringof on it directly.
>
> - Jonathan M Davis
>
More information about the Digitalmars-d
mailing list