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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 7 18:44:08 PDT 2013


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



--- Comment #34 from Kenji Hara <k.hara.pg at gmail.com> 2013-04-07 18:44:04 PDT ---
(In reply to comment #33)
[snip]

That's the rule described in TDPL. I can completely agree with you.
I believe that my patch implements it enough.

----

I'd like to add one note for your better understand.

>     // vs specialized parameter
>     int f4(int a) { return 1; }
>     int f4(T:int)(T b) { return 2; }
> 
> These two functions are in the same equivalence classes because they accept
> the same argument sets: f4_1 <= f4_2 and f4_2 <= f4_1. So any call that would
> match these two would be ambiguous. 

That's true if and only if one int argument is given. In D, the template
specialized parameter (T:int) means "T should exactly matches to int".

  int fx(T:int)(T b) { return 2; }
  void main() { fx(1L); }

  test.d(2): Error: template test.fx does not match any function template
declaration. Candidates are:
  test.d(1):        test.fx(T : int)(T b)
  test.d(2): Error: template test.fx(T : int)(T b) cannot deduce template
function from argument types !()(long)

So, f4 would match to non-template version if a non-int argument is given.

  assert(f4(1L) == 1);   // not ambiguous

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