I'd like to perform similar, but not identical computations for several integer types (16, 32, 64 bits) and floating point types (float, double, long double). Most of the code is identical, but some portions need to be done differently for ints and floats. For example, comparing ints can be done with a==b, while comparing floats should be done with abs(a-b)
One way to do that would be to isolate the parts of code that are different between ints and floats into small functions and specialize template for each type. However, I'd rather not to copy-paste identical code for each of the integer types and another code for each of the float types. Thus the question: is it possible to specialize template function for multiple types at once? Something semantically similar to the following if it was legal:
template<>
bool isEqual< short OR long OR long long >( T a, T b ) {
return a == b;
}
template<>
bool isEqual< float OR double OR long double >( T a, T b ) {
return abs( a - b ) < epsilon;
}
std::is_floating_point
.