fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template <typename ClassType>
  5. static std::true_type test(decltype(&ClassType::helloworld));
  6.  
  7. template <typename ClassType>
  8. static std::false_type test(...);
  9.  
  10. struct has_helloworld_class {
  11. void helloworld();
  12. };
  13.  
  14. struct no_helloworld_class {
  15. };
  16.  
  17. int main () {
  18. using namespace std;
  19.  
  20. cout << decltype(test<has_helloworld_class>(nullptr))::value << endl;
  21. cout << decltype(test<no_helloworld_class>(nullptr))::value << endl;
  22. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
1
0