[Issue 12597] Payload getter for std.typecons.Typedef

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Sep 25 14:09:19 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12597

--- Comment #12 from bearophile_hugs at eml.cc ---
(In reply to monkeyworks12 from comment #11)
> I think this enhancement request should be closed now that
> https://github.com/D-Programming-Language/phobos/pull/2116 has been merged.
> With that PR, your first example now becomes:
> 
> void main() {
>     import std.typecons: Typedef;
>     import std.math: sin;
>     alias Angle = Typedef!double;
>     Angle x = 0.5;
>     auto y1 = sin(x); // Error.
>     auto y2 = sin(cast(TypedefType!Angle)x); // OK.
> }
> 
> A bit verbose, but it accomplishes what you want and is more DRY and safer
> than cast(double)x.

This ER asks for a function like "typedefVal" that's usable like:

auto y2 = x.typedefVal.sin; // OK.

Casts are unsafe, their usage should be minimized in D code. So this ER is
still valid.

--


More information about the Digitalmars-d-bugs mailing list