Skip to content

Instantly share code, notes, and snippets.

@ScatteredRay
Last active August 29, 2015 14:14
Show Gist options
  • Save ScatteredRay/0f1778aacfef0e75dcbd to your computer and use it in GitHub Desktop.
Save ScatteredRay/0f1778aacfef0e75dcbd to your computer and use it in GitHub Desktop.
Static member existance check
template<typename T>
struct Has_My_Static {
typedef char yes[1];
typedef char no[2];
template<void*> struct exist_check;
template<typename U, U> struct type_check; // Use this for type checking.
#ifdef _MSC_VER
template<typename C> static yes& chk(C*, exist_check<(void*)&C::MyStatic>*);
#else
template<typename C> static yes& chk(C*, typeof(&C::MyStatic));
#endif
static no& chk(...);
static bool const value = sizeof(chk((T*)nullptr, nullptr)) == sizeof(yes);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment