fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename T>
  5. class has_helloworld
  6. {
  7. typedef char yes;
  8. typedef long no;
  9.  
  10. template <typename C>
  11. static yes test(decltype(&C::helloworld));
  12.  
  13. template <typename C>
  14. static no test(...);
  15.  
  16. public:
  17. enum { value = sizeof(test<T>(nullptr)) == sizeof(yes) };
  18. };
  19.  
  20. class has_helloworld_class {
  21. public:
  22. void helloworld() {};
  23. };
  24.  
  25. class no_helloworld_class {
  26. };
  27.  
  28. int main () {
  29. cout << has_helloworld<has_helloworld_class>::value << endl;
  30. cout << has_helloworld<no_helloworld_class> ::value << endl;
  31. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
1
0