It's a common situation, when we have a class template that implements some functionality:
// Generic implementation.
template <class T>
class data_processor {
double process(const T& v1, const T& v2, const T& v3);
};
Now, imagine that we have two additional versions of that class, one for integral, and another for real types:
// Integral types optimized version.
template <class T>
class data_processor_integral {
typedef int fast_int_t;
double process(fast_int_t v1, fast_int_t v2, fast_int_t v3);
};
// SSE optimized version for float types.
template <class T>
class data_processor_sse {
double process(double v1, double v2, double v3);
};
Now the question: How to make the compiler to automatically choose the correct class for a specified type?