Bug 11571 – introduce "originalType" in std.conv

Status
REOPENED
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-21T11:14:20Z
Last change time
2024-12-01T16:19:10Z
Assigned to
No Owner
Creator
monarchdodra
Moved to GitHub: phobos#10011 →

Comments

Comment #0 by monarchdodra — 2013-11-21T11:14:20Z
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++"
Comment #1 by andrej.mitrovich — 2014-03-31T04:56:12Z
Already implemented in std.traits, named exactly OriginalType.
Comment #2 by monarchdodra — 2014-03-31T05:14:28Z
(In reply to comment #1) > Already implemented in std.traits, named exactly OriginalType. Did you even *read* the issue? > I'd like to request the function "originalType", which would be std.traits' "OriginalType", but that operates on values.
Comment #3 by andrej.mitrovich — 2014-03-31T05:19:35Z
(In reply to comment #2) > > I'd like to request the function "originalType", which would be std.traits' > "OriginalType", but that operates on values. Missed that part. Although it's kind of very trivial for inclusion..
Comment #4 by monarchdodra — 2014-03-31T13:49:41Z
(In reply to comment #3) > (In reply to comment #2) > > > I'd like to request the function "originalType", which would be std.traits' > > "OriginalType", but that operates on values. > > Missed that part. Although it's kind of very trivial for inclusion.. Yes, but it *does* trigger inference. EG: a.originalType; vs cast(OriginalType!(typeof(a))a; It's really no different from: - appender - representation - tuple - [un]signed - zip - ... All of these functions are trivial. But convenient. It also helps avoiding things like "if (is(T E == enum)) ..." altogether, if you can just paste ".originType" after it, and be done with it... ...Unless you have an enum type that's whose values are a subset of another enum (recursion)? I don't think a lot of code in phobos supports that :D
Comment #5 by robert.schadek — 2024-12-01T16:19:10Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10011 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB