fork download
  1. #include <iostream>
  2.  
  3. #include <typeinfo>
  4.  
  5. template <typename T>
  6. struct Type
  7. {
  8. static char const* name()
  9. {
  10. return typeid(T).name();
  11. }
  12. };
  13.  
  14.  
  15. template <>
  16. struct Type<int>
  17. {
  18. static char const* name()
  19. {
  20. return "[[int]]";
  21. }
  22. };
  23.  
  24. template <typename T>
  25. void foo(T t)
  26. {
  27. std::cout <<"type:" <<Type<T>::name() << std::endl;
  28. std::cout <<"value:" << t << std::endl;
  29. }
  30.  
  31. int main() {
  32. // your code goes here
  33. foo('a');
  34. unsigned char a;
  35. foo(a -1);
  36. return 0;
  37. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
type:c
value:a
type:[[int]]
value:-1