[Issue 4261] Bad textual printing of enums

2015-06-09 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=4261

Andrei Alexandrescu  changed:

   What|Removed |Added

Version|unspecified |D2

--


[Issue 4261] Bad textual printing of enums

2011-06-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=4261


kenn...@gmail.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||kenn...@gmail.com
 Resolution||FIXED


--- Comment #5 from kenn...@gmail.com 2011-06-02 11:13:54 PDT ---
Recently fixed by Phobos pull #65.

https://github.com/D-Programming-Language/phobos/commit/cbe0d06965db56599f9b35e7e2a131a99dbd9ed2

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


[Issue 4261] Bad textual printing of enums

2010-08-31 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=4261



--- Comment #4 from bearophile_h...@eml.cc 2010-08-31 18:57:48 PDT ---
What I am saying in bug 3999 is relative to just the case where the enum has a
EnumTag. In this case I prefer the enum to be like a typedef (as the C++0x
"enum class") and require a cast if you want to use/compare it as/to the base
type.

In your example red, green and blue are inside an anonymous enum (it lacks a
EnumTag), so in this case the cast is not necessary. So that code is not
affected.

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


[Issue 4261] Bad textual printing of enums

2010-08-30 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=4261



--- Comment #3 from Andrej Mitrovic  2010-08-30 
05:47:34 PDT ---
I'm not sure I understand what you're saying. An enum in D is a list of
symbolic values of any type (except classes).

For example:

module enums;

import std.stdio;

struct Color
{
ubyte r, g, b;
}

enum { red = Color(255, 0, 0), green = Color(0, 255, 0), blue = Color(0, 0,
255) }

void foo(Color c)
{
writefln("%s %s %s", c.r, c.g, c.b);
}

void main()
{
foo(blue);
}

enums are also used in CTFE, e.g.:

enum float value = someFunc();  // CTFE

Having to use a cast everywhere for an enum would break a lot of code.

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


[Issue 4261] Bad textual printing of enums

2010-08-30 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=4261



--- Comment #2 from bearophile_h...@eml.cc 2010-08-30 04:37:55 PDT ---
Enums aren't numbers, they are symbols that the language/CPU often represents
with numbers.

See also bug 3999

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


[Issue 4261] Bad textual printing of enums

2010-08-30 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=4261


Andrej Mitrovic  changed:

   What|Removed |Added

 CC||andrej.mitrov...@gmail.com


--- Comment #1 from Andrej Mitrovic  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: ---