fork download
  1. #include <tuple>
  2. #include <initializer_list>
  3. #include <iostream>
  4. #include <string>
  5. #include <vector>
  6.  
  7. template<typename Fun, typename...Ts>
  8. void sequential_foreach(Fun f, const Ts&... args) {
  9. auto fun = [&](const auto& arg){f(arg); return 0;};
  10. (void) std::initializer_list<int>{ fun(args)... };
  11. }
  12.  
  13. template<typename...Ts>
  14. void print_all(std::ostream& stream, const Ts&... args) {
  15. sequential_foreach(
  16. [&](const auto& arg){stream << arg;},
  17. args...
  18. );
  19. }
  20.  
  21. int main()
  22. {
  23. std::string s1("string1");
  24. std::string s2("string2");
  25. print_all(std::cout, s1, s2);
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
string1string2