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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Apr 19 03:23:08 PDT 2014


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

          Issue ID: 12597
           Summary: Payload getter for std.typecons.Typedef
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: bearophile_hugs at eml.cc

Currently if you want to call a function sin/cos on a Typedef (here used to
define a strongly typed angle), you need a cast:

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(double)x); // OK.
}


So to avoid the unsafe cast I suggest to add a getter to Typedef:

auto y3 = sin(x.get);

--


More information about the Digitalmars-d-bugs mailing list