[Issue 1528] [tdpl] overloading template and non-template functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 1 18:17:14 PST 2013


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



--- Comment #23 from Kenji Hara <k.hara.pg at gmail.com> 2013-03-01 18:17:08 PST ---
(In reply to comment #22)
> Ah, now I see what you mean. You are matching foo!tiargs(funargs).
> 
> I was talking about resolving template vs. non-template overloads in the
> foo(funargs) setting.

I'm talking about both. You can think type parameters deduction and function
arguments matching separately. For example:

void foo(T)(T) {}
void foo(T:int)(T) {}

With first overload version,
Phase 1: T is deduced to int. ==> MATCHconvert.
Phase 2: 1 matches T (==already deduced to int). ==> MATCHexact.

With second overload version,
Phase 1: T is deduced to int and is specialized to int. ==> MATCHexact.
Phase 2: 1 matches T (==already deduced to int). ==> MATCHexact.

Finally, foo(T)(T) is less specialized than foo(T:int)(T).

I explain more complicated case.

void bar(int, int) {}
void bar(T)(T, int) {}
bar(1, 1L);

With first overload version,
Phase 1: normal function is treated as having empty template parameter list, so
         matching is always exact ==> MATCHexact
Phase 2: int <- 1 == MATCHexact, int <- 1L == MATCHconvert. ==> MATCHconvert

With second overload version,
Phase 1: T <- typeof(int). ==> MATCHconvert
Phase 2: T <- 1 == MATCHexact, int <- 1L == MATCHconvert ==> MATCHconvert

>From the comparison of Phase 1 result, bar(int, int) is more specialized than
bar(T)(T, int) for function arguments (1, 1L).

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