Created
July 24, 2012 22:00
-
-
Save motonacciu/3172970 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
| // Define a type which holds an unsigned integer value | |
| template<std::size_t> struct int_{}; | |
| template <class Tuple, size_t Pos> | |
| std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos> ) { | |
| out << std::get< std::tuple_size<Tuple>::value-Pos >(t) << ','; | |
| return print_tuple(out, t, int_<Pos-1>()); | |
| } | |
| template <class Tuple> | |
| std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<1> ) { | |
| return out << std::get<std::tuple_size<Tuple>::value-1>(t); | |
| } | |
| template <class... Args> | |
| ostream& operator<<(ostream& out, const std::tuple<Args...>& t) { | |
| out << '('; | |
| print_tuple(out, t, int_<sizeof...(Args)>()); | |
| return out << ')'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment