fork(8) 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, typename std::enable_if<N == 3, void>::type* = nullptr)
  22. {
  23. return foo(a, b, true);
  24. }
  25.  
  26. template<int N>
  27. static int setupTempl(int a, int b, typename std::enable_if<N == 2, void>::type* = nullptr)
  28. {
  29. return foo(a, b);
  30. }
  31.  
  32. int main()
  33. {
  34. setupTempl<getArgumentCount(foo)>(1, 2);
  35.  
  36. return 0;
  37. }
  38.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int setupTempl(int, int, typename std::enable_if<(N == 3), void>::type*)’:
prog.cpp:23: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)
     ^~~
stdout
Standard output is empty