fork 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(typename 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. struct has_helloworld_class {
  21. using helloworld = int;
  22. };
  23.  
  24. class no_helloworld_class {
  25. };
  26.  
  27. int main () {
  28. cout << has_helloworld<has_helloworld_class>::value << endl;
  29. cout << has_helloworld<no_helloworld_class> ::value << endl;
  30. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
1
0