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 <bool ... bools>
  21. static int fooImpl(int a, int b) {
  22. return foo(a, b, bools...);
  23. }
  24.  
  25. template<int N>
  26. static int setupTempl(int a, int b, typename std::enable_if<N == 3, void>::type* = nullptr)
  27. {
  28. return fooImpl<true>(a, b);
  29. }
  30.  
  31. template<int N>
  32. static int setupTempl(int a, int b, typename std::enable_if<N == 2, void>::type* = nullptr)
  33. {
  34. return fooImpl<>(a, b); // fooImpl(a, b)
  35. }
  36.  
  37. int main()
  38. {
  39. setupTempl<getArgumentCount(foo)>(1, 2);
  40.  
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 4524KB
stdin
Standard input is empty
stdout
Standard output is empty