fork(5) 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_static_foo, T::foo, void (*)(void)); // signature is the important part for static. it is not (T::*)
  18.  
  19. class StaticFoo
  20. {
  21. public:
  22. static void foo();
  23. };
  24.  
  25. class Foo
  26. {
  27. public:
  28. void foo();
  29. };
  30.  
  31. class Bar
  32. {
  33. };
  34.  
  35. static_assert(has_static_foo<StaticFoo>::value, "");
  36. static_assert(!has_static_foo<Foo>::value, "");
  37. static_assert(!has_static_foo<Bar>::value, "");
  38.  
  39. int main()
  40. {}
  41.  
Success #stdin #stdout 0s 3136KB
stdin
Standard input is empty
stdout
Standard output is empty