fork download
  1. #include <type_traits>
  2. #include <utility>
  3. #include <iostream>
  4.  
  5. template<typename... Ts>
  6. struct typelist
  7. {};
  8.  
  9. namespace impl
  10. {
  11. struct sfinae_result{};
  12.  
  13. template<typename F , typename ARGS , typename ENABLED = sfinae_result>
  14. struct is_valid_call;
  15.  
  16. template<typename F , typename... ARGS>
  17. struct is_valid_call<F,typelist<ARGS...>,
  18. decltype( std::declval<F>()(std::declval<ARGS>()...) )
  19. > :
  20. public std::true_type
  21. {};
  22.  
  23. template<typename F , typename... ARGS>
  24. struct is_valid_call<F,typelist<ARGS...>,sfinae_result> :
  25. public std::false_type
  26. {};
  27. }
  28.  
  29. template<typename F , typename... ARGS>
  30. struct is_valid_call : public impl::is_valid_call<F,typelist<ARGS...>>
  31. {};
  32.  
  33. void foo( int ){}
  34.  
  35. struct bar
  36. {};
  37.  
  38. constexpr const bool ok = is_valid_call<decltype(foo),int>::value;
  39. constexpr const bool nook = is_valid_call<decltype(foo),bar>::value;
  40.  
  41. int main()
  42. {
  43. std::cout << std::boolalpha;
  44. std::cout << "ok: " << ok << std::endl;
  45. std::cout << "nook: " << ok << std::endl;
  46. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
ok: false
nook: false