I have to implement a non-member function isHomogenous(Triple triple) for a template class defined as:
template <typename T1, typename T2, typename T3>
class Triple
{
public:
Triple()
{ }
Triple(const T1 &a, const T2 &b, const T3 &c) : a(a), b(b), c(c)
{ }
...
The isHomogenous function should return a bool value indicating whether all of the three values in the parameter triple are of the same type. I have tried:
template <typename T> bool isHomogenous(Triple<T, T, T> triple) {
return true;
}
template <typename T1, typename T2, typename T3> bool isHomogenous(Triple<T1, T2, T3> triple) {
return false;
}
This doesn’t work, can you hint me on a solution?
A function template cannot be partially specialized.
One alternative is to define it as a static member function (or in your case just a value!) of a class template, and then just provide an ordinary function template wrapper, like …
and another way is to use C++11
std::is_same: