In Josuttis\' and Vandevoorde\'s well-known book on templates, C++ Templates: The Complete Guide, they discuss details regarding the overloading of function templates.
I
Apologies for the earlier, incorrect answer. The example does indeed seem to be correct, and there is actually a similar example in the standard itself (C++11, 14.5.6.1/1-2). Let me just quote it in its entirety:
It is possible to overload function templates so that two different function template specializations have the same type. [ Example:
// file1.c template<class T> void f(T*); void g(int* p) { f(p); // calls f<int>(int*) } // file2.c template<class T> void f(T); void h(int* p) { f(p); // calls f<int*>(int*) }
— end example ]
- Such specializations are distinct functions and do not violate the one definition rule (3.2).
In your case, you have two different function templates, both called f1
(which is fine because you can overload function templates), and they happen to have specializations which have the same type.