title: How to get the type of a template, like template <typename T>, and to check if T is int or float or a class
body: <p>the problem is described briefly as below:</p>
  
  <pre><code>template &lt;typename T&gt;
  void display(T data){
      if(is_int(T)) // how to check if T is int in this function is_int
          printf("&lt;int&gt; %d", data);
      if(is_float(T)) // how to check if T is float in this function is_float
          printf("&lt;int&gt; %f", data);
      if(is_class(T)) // how to check if T is class in this function is_class
          data.display();
  }
  </code></pre>
  
  <p>Here suppose that T can be type of int or float or a class. </p>
  
  <p>If I define some variables and want to display their values using the same function:</p>
  
  <pre><code>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));
  </code></pre>
  
  <p>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(<a href="https://stackoverflow.com/questions/16132123/c-templates-how-to-find-whether-the-template-type-is-a-basic-type-or-a-class">C++ templates - How to find whether the template type is a basic type or a class</a>). </p>
  
  <p>And using std::is_integral::value doesn't apply for the case like this:</p>
  
  <pre><code>display(new int(3));
  display(new float(1.899));
  display(new float(1));
  </code></pre>
  
  <p>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()?</p>