Bug 2087 – Merge stc.typecons.defineEnum with enum
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P5
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-05-09T09:54:00Z
Last change time
2015-06-09T01:21:36Z
Keywords
spec
Assigned to
nobody
Creator
arkangath
Comments
Comment #0 by arkangath — 2008-05-09T09:54:05Z
I find that nearly (if not) every enum in my code is defined using std.typecons.defineEnum for the toString() and fromString() functionality.
I'd suggest moving this into the language itself. Like Objects, an enum will have a .toString property which does exactly what is defined on the defineEnum mixin.
The fromString() isn't as important, but since we're at it, why not do the full round?
Defining enums with this mixin wrecks chaos on IDE parsers, as I try to use "MsgType" as a variable type and the IDE's parser never knows of it.
Comment #1 by kennytm — 2011-06-10T12:25:21Z
enum is not a class, there will not be enum.toString. Nevertheless, std.conv.to supports converting between an enum and string for a number of versions already. std.typecons.defineEnum has also been deprecated.