Skip to content

Instantly share code, notes, and snippets.

@motonacciu
Created July 24, 2012 22:00
Show Gist options
  • Select an option

  • Save motonacciu/3172970 to your computer and use it in GitHub Desktop.

Select an option

Save motonacciu/3172970 to your computer and use it in GitHub Desktop.
// 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