Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <tuple>
  4.  
  5. namespace foo
  6. {
  7. template <typename T>
  8. struct print final
  9. {
  10. const T& _x;
  11. constexpr print(const T& x) noexcept : _x{x}
  12. {
  13. }
  14. };
  15.  
  16. template <typename T>
  17. auto& operator<<(std::ostream& os, const print<std::vector<T>>& v)
  18. {
  19. for(const auto& x : v._x) os << x << " ";
  20. return os;
  21. }
  22.  
  23. template <typename... Ts>
  24. auto& operator<<(std::ostream& os, const print<std::tuple<Ts...>>& v)
  25. {
  26. (os << ... << print{std::get<Ts>(v._x)});
  27. return os;
  28. }
  29. }
  30.  
  31. int main()
  32. {
  33. std::vector<int> v{1,2,3,4,5};
  34. std::cout << foo::print{v} << std::endl;
  35.  
  36. auto t{std::make_tuple(std::vector<int>{1,2,3,4,5})};
  37. std::cout << foo::print{v} << std::endl;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement