I have a function call:
template <typename A, typename B> bool foo();
I would like to override it so that any calls where A and B are the same type go to a special function override. I'm thinking of something like:
template<typename A>
bool foo<A,A>()
{ return false; }
However, this code does not compile, and I can't find any code that might work. My recourse so far has been to explicitly override all possible types:
template<> bool foo<class1,class1>() { return false; }
template<> bool foo<class2,class2>() { return false; }
template<> bool foo<class3,class3>() { return false; }
but this is inelegant and requires maintenance when new classes are brought in.
Thanks for any thoughts.
Edit: To be clear, when A is not the same type as B, I have code like this:
template<typename A, typename B>
bool foo() {
Thing<A,B> instance; // Thing<A,A> is never legal and will not compile
}
(The code gets called because I'm trying all possible combinations of B against A and vice-versa. I was hoping to deal with this easily with the compiler, rather than implement if-then tests on every B to make sure it doesn't match A. Maybe there's a better way of doing this, but I thought this design would be elegant.)