fork(1) download
  1. #include <iostream>
  2.  
  3. namespace with_spaces {
  4.  
  5. namespace detail {
  6. std::ostream& print(std::ostream& os) {
  7. return os;
  8. }
  9.  
  10. template <typename T>
  11. std::ostream& print(std::ostream& os, T&& t) {
  12. return os << std::forward<T>(t);
  13. }
  14.  
  15. template <typename T, typename U, typename... Args>
  16. std::ostream& print(std::ostream& os, T&& t, U&& u, Args&&... args) {
  17. return print(print(os, std::forward<T>(t)) << ' ', std::forward<U>(u), std::forward<Args>(args)...);
  18. }
  19. }
  20.  
  21. template <typename... Args>
  22. void print(Args&&... args) {
  23. detail::print(std::cout, std::forward<Args>(args)...) << std::endl;
  24. }
  25. }
  26.  
  27. namespace without {
  28. namespace detail {
  29. std::ostream& print(std::ostream& os) {
  30. return os;
  31. }
  32.  
  33. template <typename T>
  34. std::ostream& print(std::ostream& os, T&& t) {
  35. return os << std::forward<T>(t);
  36. }
  37.  
  38. template <typename T, typename... Args>
  39. std::ostream& print(std::ostream& os, T&& t, Args&&... args) {
  40. return print(print(os, std::forward<T>(t)), std::forward<Args>(args)...);
  41. }
  42. }
  43.  
  44. template <typename... Args>
  45. void print(Args&&... args) {
  46. detail::print(std::cout, std::forward<Args>(args)...) << std::endl;
  47. }
  48. }
  49.  
  50. #include <iomanip>
  51.  
  52. int main() {
  53. std::cout << std::boolalpha;
  54. with_spaces::print(1, "foo", new int(3), 0xFFFFFFFFFFULL, 42, 0 == 1);
  55. without::print(1, "foo", new int(3), 0xFFFFFFFFFFULL, 42, 0 == 1);
  56. }
  57.  
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
1 foo 0x87a5008 1099511627775 42 false
1foo0x87a5018109951162777542false