[Issue 5061] New: std.traits.arrayTarget

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 15 21:45:21 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=5061

           Summary: std.traits.arrayTarget
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: mchaten at gmail.com


--- Comment #0 from Mike Chaten <mchaten at gmail.com> 2010-10-15 21:44:45 PDT ---
I've been in need of getting the type of the contents of an array. Phobos
includes a function to get the type of the pointer target.

I propose a simple template, arrayTarget to std.traits to implement this
functionality.

The following works under DMD 2.049, Linux/x86

template arrayTarget(T:T[]) {
        alias T arrayTarget;
}
unittest {
        assert(is(arrayTarget!(int[5][]) == int[5]));
        assert(is(arrayTarget!(int[5]) == int));
        assert(is(arrayTarget!(int[]) == int));
        assert(is(arrayTarget!(int[][]) == int[]));
        assert(__traits(compiles,arrayTarget!(int)) == false);
        assert(__traits(compiles,arrayTarget!(int *)) == false);
}

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


More information about the Digitalmars-d-bugs mailing list