fork download
  1. #include <string>
  2. #include <cstdio>
  3.  
  4. void set(const char *s1, const char *s2, const char *s3)
  5. {
  6. /// Common implementation
  7. std::printf("s1: %s, s2: %s, s3: %s\n", s1, s2, s3);
  8. }
  9.  
  10. const char *conv(const char *s)
  11. {
  12. return s;
  13. }
  14. const char *conv(const std::string &s)
  15. {
  16. return s.c_str();
  17. }
  18.  
  19. template<typename T1, typename T2, typename T3>
  20. void set(const T1 &s1, const T2 &s2, const T3 &s3)
  21. {
  22. set(conv(s1), conv(s2), conv(s3));
  23. }
  24.  
  25. int main()
  26. {
  27. std::string s1 = "sss111";
  28. std::string s2 = "TWO";
  29. const char * s3 = "III help";
  30.  
  31. set(s1, s2, s3);
  32. set("Hello!", s3, s1);
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
s1: sss111, s2: TWO, s3: III help
s1: Hello!, s2: III help, s3: sss111