fork download
  1. #include <tuple>
  2. #include <iostream>
  3.  
  4. template<std::size_t> struct int_{};
  5.  
  6. template<class Ch, class Tr, class Tuple, std::size_t I>
  7. void print_tuple(std::basic_ostream<Ch,Tr>& os, Tuple const& t, int_<I>){
  8. print_tuple(os, t, int_<I-1>());
  9. os << ", " << std::get<I>(t);
  10. }
  11.  
  12. template<class Ch, class Tr, class Tuple>
  13. void print_tuple(std::basic_ostream<Ch,Tr>& os, Tuple const& t, int_<0>){
  14. os << std::get<0>(t);
  15. }
  16.  
  17. template<class Ch, class Traits, class... Args>
  18. std::ostream& operator<<(std::basic_ostream<Ch,Traits>& os,
  19. std::tuple<Args...> const& t)
  20. {
  21. os << "(";
  22. print_tuple(os, t, int_<sizeof...(Args)-1>());
  23. return os << ")";
  24. }
  25.  
  26. int main(){
  27. std::cout << std::make_tuple(5, "Hello", -0.1) << "\n";
  28. }
Success #stdin #stdout 0s 2828KB
stdin
Standard input is empty
stdout
(5, Hello, -0.1)