While writing a C++ template function, I have to check that the variable type used by this function is integral. If it is the case, it should result in a compilation error.
template <class IT> void foo( IT first, IT last ) {
// check here that *first has integral type.
}
The trouble I have, is that this function template parameter is not directly the type used, but an iterator type.
Unfortunately, I am currently in an environment where I cannot use C++11, nor Boost, so I will have to try reinventing this wheel myself.
I ended up testing that the type is integral by defining a pointer to an array, using the parameter an array size. This generates a compilation error if the parameter type is non integral.
template <class IT> void foo( IT first, IT last ) {
int ( * fake_array_ptr )[*first]; // Error: size of array has non-integral type
}
My question is: Are there other more explicit ways to test whether a type is integral?