fork(25) download
  1. #include <iostream>
  2. #include <tuple>
  3.  
  4. namespace aux{
  5. template<std::size_t...> struct seq{};
  6.  
  7. template<std::size_t N, std::size_t... Is>
  8. struct gen_seq : gen_seq<N-1, N-1, Is...>{};
  9.  
  10. template<std::size_t... Is>
  11. struct gen_seq<0, Is...> : seq<Is...>{};
  12.  
  13. template<class Ch, class Tr, class Tuple, std::size_t... Is>
  14. void print_tuple(std::basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){
  15. using swallow = int[];
  16. (void)swallow{0, (void(os << (Is == 0? "" : ", ") << std::get<Is>(t)), 0)...};
  17. }
  18. } // aux::
  19.  
  20. template<class Ch, class Tr, class... Args>
  21. auto operator<<(std::basic_ostream<Ch, Tr>& os, std::tuple<Args...> const& t)
  22. -> std::basic_ostream<Ch, Tr>&
  23. {
  24. os << "(";
  25. aux::print_tuple(os, t, aux::gen_seq<sizeof...(Args)>());
  26. return os << ")";
  27. }
  28.  
  29. int main(){
  30. std::cout << std::make_tuple(5, "Hello", -0.1) << "\n";
  31. std::cout << std::make_tuple() << "\n";
  32. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
(5, Hello, -0.1)
()