[Issue 10812] New: Improve Template Pattern Matching

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 12 15:17:41 PDT 2013


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

           Summary: Improve Template Pattern Matching
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: monkeyworks12 at hotmail.com


--- Comment #0 from monkeyworks12 at hotmail.com 2013-08-12 15:17:40 PDT ---
import std.typecons;

template Pair(T, U)
{
    alias Pair = Tuple!(T, U);
}

T left(T, U)(Pair!(T, U) t)
{
    return t[0];
}

void main()
{
        //Error: template left(T, U)(Pair!(T, U) t) cannot deduce 
        //template function from argument types !()(Tuple!(int, string))
    auto t = Pair!(int, string)(0, "");
    assert(left(t) == 0);
}

This is really annoying, and it's going to get even worse when the new alias(T)
syntax is introduced. I know that aliases are expanded before other stuff, but
using `typedef Tuple!(T, U) Pair` instead gives the same error message.
*Ideally*, I could also do something like this (this currently doesn't
compile):

T left(T, U, Tup: Pair!(T, U))(Tup t)
{
    return t[0];
}

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