www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12597] New: Payload getter for std.typecons.Typedef


          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 puremagic.com
          Reporter: bearophile_hugs 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);

Apr 19 2014