1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
template<class T>
struct test_member_x
{
struct yes {char c;};
struct no {char c[2];};
template<class U, int U::*> struct tst_member{};
template<class U>
static yes test_f(tst_member<U,&U::x>*);
template<class V>
static no test_f(...);
static const bool value = sizeof(test_f<T>(0))==sizeof(yes);
};
struct one
{
int x;
int y;
};
struct two
{
};
int main()
{
std::cout<<std::boolalpha;
std::cout<<test_member_x<one>::value<<"\n";
std::cout<<test_member_x<two>::value<<"\n";
return 0;
} |
Partager