Created
June 26, 2017 15:08
-
-
Save vittorioromeo/f4103b2076b3e352d91cb40858076bcb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment