fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  
  5. template <typename T, typename... Args>
  6. struct Printer {
  7. std::ostream& print(std::ostream& os, const T& t, const Args&... rest) const {
  8. os << t << " ";
  9. return Printer<Args...>().print(os, rest...);
  10. }
  11. };
  12.  
  13. template <typename T>
  14. struct Printer<T> {
  15. std::ostream& print(std::ostream& os, const T& t) const {
  16. os << t << std::endl;
  17. return os;
  18. }
  19. };
  20.  
  21.  
  22. template <typename T, typename... Args>
  23. std::ostream& print(std::ostream& os, const T& t, const Args&... rest) {
  24. return Printer<T, Args...>().print(os, t, rest...);
  25. }
  26.  
  27. int main()
  28. {
  29. print(std::cout, std::string("hepup"));
  30. print(std::cout, 1, 2.23434);
  31. print(std::cout, "hello", '\n', 3.134, true, 1e8);
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 4476KB
stdin
Standard input is empty
stdout
hepup
1 2.23434
hello 
 3.134 1 1e+08