fork download
  1. #include <iostream>
  2.  
  3. #define MAKE_TYPE_NAME(type) \
  4.   template <> \
  5.   struct typename_of<type> { \
  6.   constexpr static const char* value = #type; \
  7.   }
  8.  
  9. //
  10. template < typename >
  11. struct typename_of;
  12.  
  13. MAKE_TYPE_NAME( int );
  14. MAKE_TYPE_NAME( double );
  15. MAKE_TYPE_NAME( int(double) );
  16. MAKE_TYPE_NAME( int(int,double) );
  17. MAKE_TYPE_NAME( int(*)(double) );
  18. MAKE_TYPE_NAME( int[10] );
  19. MAKE_TYPE_NAME( int(*)[10] );
  20. MAKE_TYPE_NAME( int(*[10])(double) );
  21.  
  22.  
  23. //
  24. template < typename T >
  25. void foo()
  26. {
  27. std::cout << typename_of<T>::value << std::endl;
  28. }
  29.  
  30.  
  31. int main() {
  32.  
  33. foo<int>();
  34. foo<double>();
  35.  
  36. foo<int(double)>();
  37. foo<int(int,double)>();
  38. foo<int(*)(double)>();
  39.  
  40. foo<int[10]>();
  41. foo<int(*)[10]>();
  42.  
  43. foo<int(*[10])(double)>();
  44. }
  45.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
int
double
int(double)
int(int,double)
int(*)(double)
int[10]
int(*)[10]
int(*[10])(double)