fork download
  1. #include <tuple>
  2. #include <iostream>
  3.  
  4. template<int N> using Int = std::integral_constant<int, N>;
  5. template<bool B> using Bool = std::integral_constant<Bool, N>;
  6. template<typename Tuple> using TupleSize = typename std::tuple_size<Tuple>::type;
  7.  
  8. template<class Ch, class Tr, class Tuple, std::size_t I>
  9. void print_tuple(std::basic_ostream<Ch,Tr>& os, Tuple const& t, Int<I>){
  10. do_the_printing(std::get<I>(t), Bool<I != 0>{} /* tells whether to have delimiters before */);
  11. print_tuple(os, t, int_<I+1>{});
  12. }
  13.  
  14. // also handles empty tuples nicely
  15. template<class Ch, class Tr, class Tuple>
  16. void print_tuple(std::basic_ostream<Ch,Tr>& os, Tuple const& t, TupleSize<Tuple>) {}
  17.  
  18. template<class Ch, class Traits, class Tuple>
  19. void print(std::basic_ostream<Ch,Traits>& os, Tuple const& t){
  20. os << "(";
  21. print_tuple(os, t, int_<0>{});
  22. os << ")";
  23. }
  24.  
  25. int main(){
  26. print(std::cout, std::make_tuple(5, "Hello", -0.1));
  27. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:17: error: expected unqualified-id before 'using'
prog.cpp:5:18: error: expected unqualified-id before 'using'
prog.cpp:6:26: error: expected unqualified-id before 'using'
prog.cpp:9:65: error: 'Int' has not been declared
prog.cpp:9:68: error: expected ',' or '...' before '<' token
prog.cpp: In function 'void print_tuple(std::basic_ostream<_CharT, _Traits>&, const Tuple&, int)':
prog.cpp:10:35: error: 'Bool' was not declared in this scope
prog.cpp:10:47: error: expected primary-expression before '{' token
prog.cpp:11:22: error: 'int_' was not declared in this scope
prog.cpp:11:31: error: expected primary-expression before '{' token
prog.cpp: At global scope:
prog.cpp:16:65: error: 'TupleSize' has not been declared
prog.cpp:16:74: error: expected ',' or '...' before '<' token
prog.cpp: In function 'void print(std::basic_ostream<_CharT, _Traits>&, const Tuple&)':
prog.cpp:21:22: error: 'int_' was not declared in this scope
prog.cpp:21:29: error: expected primary-expression before '{' token
stdout
Standard output is empty