fork(1) download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. ostringstream& make_string_impl(ostringstream&& s) { return s; }
  8.  
  9. template<typename T, typename... Ts>
  10. ostringstream& make_string_impl(ostringstream&& s, T&& t, Ts&&... ts) {
  11. s << t;
  12. return make_string_impl(std::move(s), std::forward<Ts>(ts)...);
  13. }
  14.  
  15. template<typename... Ts>
  16. string make_string(Ts&&... ts) {
  17. return make_string_impl(ostringstream{}, std::forward<Ts>(ts)...).str();
  18. }
  19.  
  20. int main() {
  21. cout << make_string("Hello, ", 5, " World!", '\n', 10.0, "\n0x", hex, 15, "\n");
  22. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Hello, 5 World!
10
0xf