fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <vector>
  5.  
  6. template<class T>
  7. void func(const T& t)
  8. {
  9. std::cout << t << std::endl;
  10. }
  11.  
  12. template<class First, class... Rest>
  13. void func(const First& first, const Rest&... rest)
  14. {
  15. func(first);
  16. func(rest...);
  17. }
  18.  
  19. template<class T>
  20. std::ostream& operator<<(std::ostream& ofs, const std::vector<T>& vec)
  21. {
  22. std::stringstream str;
  23. for(auto p = vec.begin(); p != vec.end(); p++)
  24. str << ',' << *p;
  25.  
  26. return ofs << '{' << str.str().substr(1) << '}';
  27. }
  28.  
  29.  
  30. int main()
  31. {
  32. std::vector<int> vec = {1, 2, 3};
  33.  
  34. func(10, 10.5, std::string("hoge"), vec);
  35. }
  36.  
Success #stdin #stdout 0s 2968KB
stdin
Standard input is empty
stdout
10
10.5
hoge
{1,2,3}