[Issue 9839] New: std.traits.Select to alias variables too

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 30 13:05:09 PDT 2013


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

           Summary: std.traits.Select to alias variables too
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-03-30 13:05:07 PDT ---
Currently Select can't be used with variable names:


import std.traits: Select;
void main() {
    uint[] a1;
    ulong[] a2;
    alias T = int;
    alias T1 = Select!(T.sizeof == uint.sizeof, uint, ulong);
    alias a = Select!(is(T1 == uint), a1, a2);
}



DMD 2.063alpha:

temp.d(7): Error: template instance Select!(true, a1, a2) Select!(true, a1, a2)
does not match template declaration Select(bool condition, T, F)



So I suggest to add an alias version of Select (in future when built-in types
will become alias-able, the Select without alias will be removed):


template Select(bool b, alias A1, alias A2) {
    static if (b)
        alias Select = A1;
    else
        alias Select = A2;
}

template Select(bool b, T1, T2) {
    static if (b)
        alias Select = T1;
    else
        alias Select = T2;
}

void main() {
    uint[] a1;
    ulong[] a2;
    alias T = int;
    alias T1 = Select!(T.sizeof == uint.sizeof, uint, ulong);
    alias a = Select!(is(T1 == uint), a1, a2);
}

-- 
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