Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <tuple>
- namespace foo
- {
- template <typename T>
- struct print final
- {
- const T& _x;
- constexpr print(const T& x) noexcept : _x{x}
- {
- }
- };
- template <typename T>
- auto& operator<<(std::ostream& os, const print<std::vector<T>>& v)
- {
- for(const auto& x : v._x) os << x << " ";
- return os;
- }
- template <typename... Ts>
- auto& operator<<(std::ostream& os, const print<std::tuple<Ts...>>& v)
- {
- (os << ... << print{std::get<Ts>(v._x)});
- return os;
- }
- }
- int main()
- {
- std::vector<int> v{1,2,3,4,5};
- std::cout << foo::print{v} << std::endl;
- auto t{std::make_tuple(std::vector<int>{1,2,3,4,5})};
- std::cout << foo::print{v} << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement