fork(2) download
  1. //User types
  2. struct field_t{};
  3. struct other_t{};
  4. struct StructT{other_t field;field_t other;};
  5. //Implementation detail
  6. template<typename T,typename FIELD_T>
  7. struct type_has_field{
  8. struct Fallback {FIELD_T field;};
  9. struct Derived:T,Fallback{};
  10. template<typename C, C> struct ChT;
  11. template<typename C> static char (&f(ChT<FIELD_T Fallback::*, &C::field>*))[1];
  12. template<typename C> static char (&f(...))[2];
  13.  
  14. static bool const value = sizeof(f<Derived>(0)) == 2;
  15. };
  16. //Experiment
  17.  
  18. static_assert(
  19. false==type_has_field<StructT,field_t>::value,
  20. "field_t StructT::field - should not exist"
  21. );
  22.  
  23. int main(){return 0;}
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:18:1: error: static assertion failed: field_t StructT::field - should not exist
 static_assert(
 ^
stdout
Standard output is empty