www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11707] New: "data" property for std.typecons.Typedef?

https://d.puremagic.com/issues/show_bug.cgi?id=11707

           Summary: "data" property for std.typecons.Typedef?
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



Here std.typecons.Typedef is used to define a strong type, but later it can't
be used as array index:

void main() {
    import std.typecons: Typedef;
    alias Idx = Typedef!uint;
    int[5] data;
    auto i = Idx(1);
    data[i] = 10;
}


dmd 2.065alpha gives:

temp.d(6): Error: cannot implicitly convert expression (i) of type
Typedef!(int, 0) to uint


A simple solution is to cast:

data[cast(size_t)i] = 10;

But in some cases this could be better, a property for Typedef, that returns
the wrapped data:

data[i.data] = 10;

This is less greppable than the cast(), but I think it's explicit enough.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 07 2013