fork(15) download
  1. #include <cstdint>
  2.  
  3. #define DEFINE_HAS_SIGNATURE(traitsName, funcName, signature) \
  4.   template <typename U> \
  5.   class traitsName \
  6.   { \
  7.   private: \
  8.   template<typename T, T> struct helper; \
  9.   template<typename T> \
  10.   static std::uint8_t check(helper<signature, &funcName>*); \
  11.   template<typename T> static std::uint16_t check(...); \
  12.   public: \
  13.   static \
  14.   constexpr bool value = sizeof(check<U>(0)) == sizeof(std::uint8_t); \
  15.   }
  16.  
  17. DEFINE_HAS_SIGNATURE(has_foo, T::foo, void (*)(void));
  18.  
  19. struct StaticFoo { static void foo(); };
  20. struct NormalFoo { void foo(); };
  21. struct NoFoo {};
  22.  
  23. static_assert(has_foo<StaticFoo>::value, "Unexpected value");
  24. static_assert(!has_foo<NormalFoo>::value, "Unexpected value");
  25. static_assert(!has_foo<NoFoo>::value, "Unexpected value");
  26.  
  27. int main()
  28. {
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty