fork download
  1. #include <cstdint>
  2. #include <functional>
  3. #include <iostream>
  4. #include <type_traits>
  5.  
  6. template<class F>
  7. struct function_traits;
  8.  
  9. // function pointer
  10. template<class... Args>
  11. struct function_traits<int (*)(Args...)>
  12. : public function_traits<int (Args...)> {};
  13.  
  14. template<class... Args>
  15. struct function_traits<int (Args...)>
  16. {
  17. static constexpr std::size_t arity = sizeof...(Args);
  18. };
  19.  
  20. template <typename Func,
  21. typename std::enable_if_t<function_traits<Func>::arity == 3>* = nullptr>
  22. bool call_read(Func read)
  23. {
  24. return true;
  25. }
  26.  
  27. template <typename Func,
  28. typename std::enable_if_t<function_traits<Func>::arity == 1>* = nullptr>
  29. bool call_read(Func read)
  30. {
  31. return true;
  32. }
  33.  
  34. int foo(int x, int y, int z)
  35. {
  36. return 0;
  37. }
  38.  
  39. int main()
  40. {
  41. call_read(foo);
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Standard output is empty