fork(2) download
  1. #include <type_traits>
  2.  
  3. struct A {
  4. int foo;
  5. };
  6.  
  7. struct B : A {};
  8.  
  9. struct C {
  10. static int foo;
  11. };
  12.  
  13. struct D : C {};
  14.  
  15. struct E {
  16. int &foo;
  17. };
  18.  
  19. struct F {
  20. static int &foo;
  21. };
  22.  
  23. struct G {};
  24.  
  25. template <typename T>
  26. std::is_member_pointer<decltype(&T::foo)> is_member_foo(int);
  27.  
  28. template <typename T>
  29. decltype(T::foo, std::true_type{}) is_member_foo(long);
  30.  
  31. template <typename T>
  32. std::false_type is_member_foo(...);
  33.  
  34. template <typename T>
  35. using IsMemberFoo = decltype(is_member_foo<T>(0));
  36.  
  37. static_assert(IsMemberFoo<A>{}, "No");
  38. static_assert(IsMemberFoo<B>{}, "No");
  39. static_assert(!IsMemberFoo<C>{}, "No");
  40. static_assert(!IsMemberFoo<D>{}, "No");
  41. static_assert(IsMemberFoo<E>{}, "No");
  42. static_assert(!IsMemberFoo<F>{}, "No");
  43. static_assert(!IsMemberFoo<G>{}, "No"); // struct G { };
  44.  
  45. int main () {}
Success #stdin #stdout 0s 3408KB
stdin
Standard input is empty
stdout
Standard output is empty