Re: print enum value rather name from enum X : string

2018-02-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 13, 2018 01:55:59 Marc via Digitalmars-d-learn wrote: > Thanks for you always well-thought-out answer. I was going to > print it with writefln() calls more than anywhere else so to > avoid casts in all those places, which would make it ugly, I just > used > > > enum foo = "a";

Re: print enum value rather name from enum X : string

2018-02-12 Thread Marc via Digitalmars-d-learn
On Monday, 12 February 2018 at 17:29:47 UTC, Jonathan M Davis wrote: On Monday, February 12, 2018 17:07:50 Marc via Digitalmars-d-learn wrote: [...] If you actually use the enum values anywhere other than with anything from std.conv, std.format, or std.stdio, then when they get converted to

Re: print enum value rather name from enum X : string

2018-02-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 12, 2018 17:07:50 Marc via Digitalmars-d-learn wrote: > If I have an enum like this: > > enum S : string { > > > > foo = "a", > > baa = "b" > > > >} > > when I printed it, to my surprise I get the enum field name > > rather value: > > writefln("%s v%s", S.foo, S.baa); > >

print enum value rather name from enum X : string

2018-02-12 Thread Marc via Digitalmars-d-learn
If I have an enum like this: enum S : string { foo = "a", baa = "b" } when I printed it, to my surprise I get the enum field name rather value: writefln("%s v%s", S.foo, S.baa); output: foo vbaa instead of a vb a cast solves it but without cast everywhere I