Last active
August 29, 2015 14:14
-
-
Save ScatteredRay/0f1778aacfef0e75dcbd to your computer and use it in GitHub Desktop.
Static member existance check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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