fork download
  1. #include <type_traits>
  2. #include <iostream>
  3.  
  4. struct test1 {
  5. void Invoke() {};
  6. };
  7.  
  8. struct test2 {
  9. template<typename> void Invoke() {};
  10. };
  11.  
  12.  
  13. enum class InvokableKind {
  14. NOT_INVOKABLE,
  15. INVOKABLE_FUNCTION,
  16. INVOKABLE_FUNCTION_TEMPLATE
  17. };
  18.  
  19. template<typename Functor, class Enable = void>
  20. struct get_invokable_kind {
  21. const static InvokableKind value = InvokableKind::NOT_INVOKABLE;
  22. };
  23.  
  24. template<typename Functor>
  25. struct get_invokable_kind<
  26. Functor,
  27. decltype(Functor().Invoke())
  28. >
  29. {
  30. const static InvokableKind value = InvokableKind::INVOKABLE_FUNCTION;
  31. };
  32.  
  33. template<typename Functor>
  34. struct get_invokable_kind<
  35. Functor,
  36. decltype(Functor().Invoke<void>())
  37. >
  38. {
  39. const static InvokableKind value = InvokableKind::INVOKABLE_FUNCTION_TEMPLATE;
  40. };
  41.  
  42.  
  43. int main() {
  44. using namespace std;
  45.  
  46. cout << (get_invokable_kind<test1>::value == InvokableKind::INVOKABLE_FUNCTION) << endl;
  47. cout << (get_invokable_kind<test2>::value == InvokableKind::INVOKABLE_FUNCTION_TEMPLATE) << endl;
  48.  
  49. }
  50.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:37:3: error: template argument 2 is invalid
stdout

Standard output is empty