fork(1) 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. #define IsMember(MEM) \
  26. template <typename T> \
  27. std::is_member_pointer<decltype(&T::MEM)> is_member_##MEM(int); \
  28. template<typename T> \
  29. decltype(T::MEM, std::true_type{}) is_member_##MEM(long); \
  30. template <typename T> \
  31. std::false_type is_member_##MEM(...); \
  32. template <typename T> \
  33. using IsMember_##MEM = decltype(is_member_##MEM<T>(0));
  34.  
  35. IsMember(foo);
  36.  
  37. static_assert(IsMember_foo<A>{}, "No");
  38. static_assert(IsMember_foo<B>{}, "No");
  39. static_assert(!IsMember_foo<C>{}, "No");
  40. static_assert(!IsMember_foo<D>{}, "No");
  41. static_assert(IsMember_foo<E>{}, "No");
  42. static_assert(!IsMember_foo<F>{}, "No");
  43. static_assert(!IsMember_foo<G>{}, "No"); // struct G { };
  44.  
  45. int main () {}
Success #stdin #stdout 0s 3408KB
stdin
Standard input is empty
stdout
Standard output is empty