fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <typeinfo>
  4. typedef char const *pchar;
  5. template<typename T> struct TypeName {
  6. static std::string Get() { return "unknown"; }
  7. };
  8. template<> struct TypeName<int> {
  9. static std::string Get() { return "int"; }
  10. };
  11. template<> struct TypeName<double> {
  12. static std::string Get() { return "double"; }
  13. };
  14. template<> struct TypeName<std::string> {
  15. static std::string Get() { return "string"; }
  16. };
  17.  
  18. template<> struct TypeName<char*> {
  19. static std::string Get() { return "char*"; }
  20. };
  21.  
  22. template<std::size_t N> struct TypeName<char[N]> {
  23. static std::string Get() { return "char[N]"; }
  24. };
  25. template<std::size_t N> struct TypeName<const char[N]> {
  26. static std::string Get() { return "const char[N]"; }
  27. };
  28. void myprint()
  29. {
  30. }
  31.  
  32. template <typename T, typename... Args>
  33. void myprint(const T& value, const Args&... args)
  34. {
  35. std::cout << TypeName<T>::Get() << ": " << value << std::endl;
  36. myprint(args...);
  37. }
  38.  
  39. int main()
  40. {
  41. char *s = "adsf";
  42. std::string some_str = "some string";
  43. myprint(5, 4.0, "asdf", 1, s, some_str);
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 3020KB
stdin
Standard input is empty
stdout
int: 5
double: 4
char[N]: asdf
int: 1
char*: adsf
string: some string