SFINAE

#include

template

struct is_pointer

{

template

static char is_ptr(U *);

template

static char is_ptr(M C::*);

template

static char is_ptr(U(*)());

template

static double is_ptr(...);

enum { value = sizeof(is_ptr((T)(0))) == sizeof(char) };

};

template

struct has_no_destroy {

template

static char test(decltype(&C::no_destroy));

template

static int test(...);

const static bool value = (sizeof(test(0)) == 1);

};

struct Foo {

int bar;

};

void testTypeCheck() {

typedef int * IntPtr;

typedef int Foo::* FooMemberPtr;

typedef int(*FuncPtr)();

printf("%d\n", is_pointer::value);        // prints 1

printf("%d\n", is_pointer::value);  // prints 1

printf("%d\n", is_pointer::value);      // prints 1

printf("%d\n", is_pointer::value);          // prints 0

}

int main()

{

testTypeCheck();

getchar();

}

你可能感兴趣的:(SFINAE)