the problem is described briefly as below:
template <typename T>
void display(T data){
if(is_int(T)) // how to check if T is int in this function is_int
printf("<int> %d", data);
if(is_float(T)) // how to check if T is float in this function is_float
printf("<int> %f", data);
if(is_class(T)) // how to check if T is class in this function is_class
data.display();
}
Here suppose that T can be type of int or float or a class.
If I define some variables and want to display their values using the same function:
int a = 10:
float b = 2.7;
A_Class c;
display(a);
display(b);
display(c);
display(new int(3));
display(new float(1.899));
display(new float(1));
I know that in C++, there is one solution for checking int and float(just for the issue of printing), that is to use std::cout, as explained in this question(C++ templates - How to find whether the template type is a basic type or a class).
And using std::is_integral::value doesn't apply for the case like this:
display(new int(3));
display(new float(1.899));
display(new float(1));
because these variables are classes not the basic types. So for this situation, how we judge the type(int or float) of new int(), new float()?