fork download
  1. #include <iostream>
  2.  
  3. struct P{};
  4.  
  5. struct S{bool operator()(){return true;}};
  6.  
  7. template <class TFunctor>
  8. class TIsCallable
  9. {
  10. typedef char TTwoChars[2];
  11. template <class T>
  12. static char Test(int[sizeof((*((T*)0))())]);
  13.  
  14. template <class>
  15. static TTwoChars& Test(...);
  16. public:
  17. static const bool Value_ = sizeof(Test<TFunctor>(0)) == 1;
  18. };
  19.  
  20. int main()
  21. {
  22. std::cout
  23. << TIsCallable<int>::Value_
  24. << TIsCallable<P>::Value_
  25. << TIsCallable<int (*)()>::Value_
  26. << TIsCallable<S>::Value_ << std::endl;
  27. }
  28.  
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
1111