Let’s assume we have a template function “foo”:
template<class T>
void foo(T arg)
{ ... }
I can make specialization for some particular type, e.g.
template<>
void foo(int arg)
{ ... }
If I wanted to use the same specialization for all builtin numeric types (int, float, double etc.) I would write those lines many times. I know that body can be thrown out to another function and just call of this is to be made in every specialization’s body, however it would be nicer if i could avoid writting this “void foo(…” for every type. Is there any possibility to tell the compiler that I want to use this specialization for all this types?
You could use
std::numeric_limitsto see whether a type is a numeric type (is_specializedis true for all float and integer fundamental types).