monarchdodra reported this on 2013-11-21T11:14:20Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=11571
CC List
- andrej.mitrovich (@AndrejMitrovic)
Description
std.traits has "Unsigned"/"Signed" to operate on types, and their convenient helpers in std.conv "unsigned"/"signed", to operate on values.
EG:
uint a;
b = a.signed;
I'd like to request the function "originalType", which would be std.traits' "OriginalType", but that operates on values.
This would make it an easy and convenient way to strip the enum characteristic information of an enumerate, and simply operate on the value represented by said enum.
This would be useful, amongst others, in templates, to a), limit intanciations, and b), to avoid operating on enums, which always tends to throw them off. Also, it could be useful to print string enums, to "observe" the difference between the enum *name* (printed by default), and the enum *value* (the string carried by said enum).
For example:
enum LinkageType : string
{
D = "D", ///
C = "C", /// ditto
Windows = "Windows", /// ditto
Pascal = "Pascal", /// ditto
Cpp = "C++" /// ditto
}
writeln(LinkageType.Cpp); //prints "Cpp"
writeln(LinkageType.Cpp.originalType); //prints "C++"