This question follows this one : Function overloading and template deduction priority
Considering the following classes :
template<typename T1, typename T2>
class Base {};
class Derived0 : public Base<double, double> {};
template<typename T1, typename T2, typename T3>
class Derived1 : public Base<T1, T2> {};
template<typename T1, typename T2, typename T3, typename T4>
class Derived2 : public Base<T3, T4> {};
And the following functions :
template<typename T> f(const T& x); // version A
template<typename T1, typename T2> f(const Base<T1, T2>& x); // version B
My problem is that f(double) will call version A (ok), f(Base<double, double>) will call version B (ok), but f(Derived1<double, double, double>) will call version A (see the link to the other question at the beginning).
Using C++11, how to block version A and force version B for all derived members of Base<T1, T2> whatever T1 and T2 are ?
Note : If possible, I would like to avoid to add helper classes and prefer adding members to the provided classes.
Here’s a trait that might work for you.
The trait class:
Application:
Example:
Generalization: We can make a more general trait to check if a type derives from a template instance:
Usage:
derives_from_template<T, Base>::valueetc.