fork download
  1. #include <iostream>
  2.  
  3. struct foo1 { };
  4. struct foo2 { typedef int bar; };
  5.  
  6. template<typename T>
  7. class has_bar
  8. {
  9. typedef char yes;
  10. typedef struct { yes no_[2]; } no;
  11.  
  12. static T make();
  13.  
  14. template<typename U>
  15. static yes check(U&&, typename U::bar*);
  16. template<typename U>
  17. static no check(U&&, ...);
  18.  
  19. public:
  20. enum { value = sizeof(check(make(), nullptr)) == sizeof(yes) };
  21. };
  22.  
  23. int main()
  24. {
  25. std::cout
  26. << has_bar<foo1>::value << '\n'
  27. << has_bar<foo2>::value << '\n';
  28. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty