fork download
  1. #include <type_traits>
  2. #include <iostream>
  3.  
  4. int foo(int a, int b)
  5. {
  6. return 1;
  7. }
  8.  
  9. //int foo(int a, int b, bool c)
  10. //{
  11. // return 0;
  12. //}
  13.  
  14. template <typename R, typename ... Types>
  15. constexpr size_t getArgumentCount(R(*)(Types ...))
  16. {
  17. return sizeof...(Types);
  18. }
  19.  
  20. template<int N>
  21. static int setupTempl(int a, int b)
  22. {
  23. static_assert(N == N, "invalid N");
  24. return 0;
  25. }
  26.  
  27. template<>
  28. static int setupTempl<2>(int a, int b)
  29. {
  30. return foo(a, b);
  31. }
  32.  
  33. template<>
  34. static int setupTempl<3>(int a, int b)
  35. {
  36. return foo(a, b, true);
  37. }
  38.  
  39. int main()
  40. {
  41. setupTempl<getArgumentCount(foo)>(1, 2);
  42.  
  43. return 0;
  44. }
  45.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:28:1: error: explicit template specialization cannot have a storage class
 static int setupTempl<2>(int a, int b)
 ^~~~~~
prog.cpp: In function ‘int setupTempl(int, int) [with int N = 3]’:
prog.cpp:36:27: error: too many arguments to function ‘int foo(int, int)’
      return foo(a, b, true);
                           ^
prog.cpp:4:5: note: declared here
 int foo(int a, int b)
     ^~~
prog.cpp: At global scope:
prog.cpp:34:1: error: explicit template specialization cannot have a storage class
 static int setupTempl<3>(int a, int b)
 ^~~~~~
stdout
Standard output is empty