www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - enum toString()?

reply Nick Sabalausky <a a.a> writes:

the syntax and name of the text output function wrong):

enum Shape {Circle, Square};
Shape myShape = Circle;

forget)

That would display the text "Circle". Is this possible in D? If not, is 
it something what would require reflection?
Feb 25 2005
next sibling parent "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
AFAIK, it's not currently supported. I think it's something that would 
be nice to have, but I suspect this is a D 2.x feature, if ever.


"Nick Sabalausky" <a a.a> wrote in message 
news:cvof4j$1te2$1 digitaldaemon.com...

 have the syntax and name of the text output function wrong):

 enum Shape {Circle, Square};
 Shape myShape = Circle;

 (I forget)

 That would display the text "Circle". Is this possible in D? If not, 
 is it something what would require reflection? 
Feb 25 2005
prev sibling parent "Charlie Patterson" <charliep1 excite.com> writes:
"Nick Sabalausky" <a a.a> wrote in message 
news:cvof4j$1te2$1 digitaldaemon.com...
 enum Shape {Circle, Square};
 Shape myShape = Circle;
 writeln(myShape.ToString());
This is something I've wanted for a long time, too. Enums are nice to self-document a program but also get speed by using simple, small ints. However, when it comes time to debug, it is a pain and error-pront to have to create a ShapeToString(Shape) function for each enum. Likewise, it would be nice to read them in: Shape myShape.FromString( "Circle" ); Then a config file could use the actual enum name and save us from writing the common StringToShape(String) function as well.
Feb 28 2005