在C++标准[temp.over.link]中,解释了函数模板等价性的确定不应涉及编译器的“英勇努力”。
例如,C++ 标准提出了以下建议:
// guaranteed to be the same
template <int I> void f(A<I>, A<I+10>);
template <int I> void f(A<I>, A<I+10>);
// guaranteed to be different
template <int I> void f(A<I>, A<I+10>);
template <int I> void f(A<I>, A<I+11>);
// ill-formed, no diagnostic required
template <int I> void f(A<I>, A<I+10>);
template <int I> void f(A<I>, A<I+1+2+3+4>);
Run Code Online (Sandbox Code Playgroud)
此规则是否也适用于涉及元编程的情况,如下例所示?
template<class T>
struct t_{
using type = T;
};
//ill-formed or different?
template<class T> T f(T);
template<class T> typename t_<T>::type f(T);
Run Code Online (Sandbox Code Playgroud)