fork(13) download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. using namespace std;
  5.  
  6. struct FooNo {};
  7. struct FooYes { int x; };
  8.  
  9. template <typename T, typename = int>
  10. struct HasX : false_type { };
  11.  
  12. template <typename T>
  13. struct HasX <T, decltype((void) T::x, 0)> : true_type { };
  14.  
  15. int main() {
  16. cout << HasX<FooYes>::value << endl;
  17. cout << HasX<FooNo>::value << endl;
  18. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
1
1