fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template <int Arg>
  5. void foo()
  6. {
  7. std::cout << Arg << ' ';
  8. }
  9.  
  10. template <int First, int... Rest, typename T = std::enable_if_t<(sizeof...(Rest) > 0)>>
  11. void foo()
  12. {
  13. std::cout << First << ' ';
  14. foo<Rest...>();
  15. }
  16.  
  17. int main()
  18. {
  19. foo<1, 2, 3>();
  20. foo<1, 2, 3, bool>();
  21.  
  22. return 0;
  23. }
Compilation error #stdin compilation error #stdout 0s 4284KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:20:21: error: no matching function for call to ‘foo()’
  foo<1, 2, 3, bool>();
                     ^
prog.cpp:5:6: note: candidate: template<int Arg> void foo()
 void foo()
      ^~~
prog.cpp:5:6: note:   template argument deduction/substitution failed:
prog.cpp:20:21: error: wrong number of template arguments (4, should be 1)
  foo<1, 2, 3, bool>();
                     ^
prog.cpp:11:6: note: candidate: template<int First, int ...Rest, class T> void foo()
 void foo()
      ^~~
prog.cpp:11:6: note:   template argument deduction/substitution failed:
stdout
Standard output is empty