In the C++ standard [temp.over.link], it is explained that the determination of function template equivalence should not involve "heroic efforts" of the compiler.
As an example, the C++ standard propose this:
// 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>);
Is this rule also applies to cases involving meta programming, as in the example below?
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);
Let's start with the simple case:
template <typename T> using id = T;
template<class T> T f(T);
template<class T> id<T> f(T);
This to me is clearly ill-formed, no diagnostic required, per the relevant rule. The two declarations are functionally equivalent, but not in a way that's simply renaming template parameters (and there aren't any dependent names to consider).
With the more complicated case:
template <typename T> struct id_t { using type = T; };
template <typename T> using id = typename id_t<T>::type;
template<class T> T f(T);
template<class T> id<T> f(T);
I think this is probably not ill-formed, because they aren't truly functionally equivalent. There could be specializations of id_t
such that these two declarations are actually different - so these are actually different declarations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With