Let's have a simple snippet:
template<class T, class... Args>
struct A {
void operator()() { std::cout << "A"; }
};
template<class T, class... Args>
struct A<T, double, Args...> {
void operator()() { std::cout << "B"; }
};
template<class T, class B, class... Args>
struct A<T, B, double, Args...> {
void operator()() { std::cout << "C"; }
};
What can I use this way:
int main() {
A<int, int, int> a;
A<int, double, int> b;
A<int, int, double> c;
a(); b(); c();
return 0;
}
Correctly returns "ABC"
. But when I declare A<int, double, double> d;
, I get an explicit compile-time error ambiguous class template instantiation for struct A<int, double, double>
.
Question: Is it possible to do some kind of trick (possibly using SFINAE) to take into account the second argument of the template, since it will have a higher priority and the specification returning B will be used? (Ignoring type double
in third position)
NOTE: types double
and int
are used to simplify the example, I will use type properties. And so I would like to avoid specialization as a solution:
template<class T, class... Args>
struct A<T, double, double, Args...> {
void operator()() { std::cout << "D"; }
};