fork download
  1. #include <functional>
  2. #include <iostream>
  3. #include <string>
  4. #include <tuple>
  5. using namespace std;
  6.  
  7. template <typename... Tp, size_t begin = 0U>
  8. enable_if_t<begin == sizeof...(Tp), void> foo(tuple<Tp...>& t){
  9. cout << endl;
  10. }
  11.  
  12. template <typename... Tp, size_t begin = 0U>
  13. enable_if_t<begin < sizeof...(Tp), void> foo(tuple<Tp...>& t) {
  14. cout << get<begin>(t) << ' ';
  15. foo<Tp..., begin + 1>(t);
  16. }
  17.  
  18. int main() {
  19. tuple<int, string, float> t = make_tuple(42, "Jonathan Mee", 13.13);
  20.  
  21. foo(t);
  22. }
Compilation error #stdin compilation error #stdout 0s 3460KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'std::enable_if_t<(begin < sizeof... (Tp)), void> foo(std::tuple<_Elements ...>&) [with Tp = {int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, float}; unsigned int begin = 0u; std::enable_if_t<(begin < sizeof... (Tp)), void> = void]':
prog.cpp:21:7:   required from here
prog.cpp:15:23: error: no matching function for call to 'foo(std::tuple<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, float>&)'
  foo<Tp..., begin + 1>(t);
                       ^
prog.cpp:8:43: note: candidate: template<class ... Tp, unsigned int begin> std::enable_if_t<(begin == sizeof... (Tp)), void> foo(std::tuple<_Elements ...>&)
 enable_if_t<begin == sizeof...(Tp), void> foo(tuple<Tp...>& t){
                                           ^
prog.cpp:8:43: note:   template argument deduction/substitution failed:
prog.cpp:13:42: note: candidate: template<class ... Tp, unsigned int begin> std::enable_if_t<(begin < sizeof... (Tp)), void> foo(std::tuple<_Elements ...>&)
 enable_if_t<begin < sizeof...(Tp), void> foo(tuple<Tp...>& t) {
                                          ^
prog.cpp:13:42: note:   template argument deduction/substitution failed:
stdout
Standard output is empty