点击(此处)折叠或打开
-
#include <iostream>
-
-
class Test1
-
{
-
public:
-
static void getuid()
-
{
-
std::cout << "has getuid func!" << std::endl;
-
}
-
};
-
-
class Test2
-
{
-
};
-
-
template<typename T, bool b>
-
struct TBaseImpl
-
{
-
};
-
-
template<typename T>
-
struct TBaseImpl<T, true>
-
{
-
static void getuid()
-
{
-
T::getuid();
-
}
-
};
-
-
template<typename T>
-
struct TBaseImpl<T, false>
-
{
-
static void getuid()
-
{
-
std::cout << "not found getuid!" << std::endl;
-
}
-
};
-
-
template<typename T>
-
class has_getuid
-
{
-
public:
-
template<typename C>
-
static char test(typeof(&C::geuid));
-
-
template<typename C>
-
static long test(...);
-
-
enum { value = sizeof(test<T>(0)) == sizeof(char) };
-
};
-
-
int main()
-
{
-
TBaseImpl<Test2, has_getuid<Test2>::value>::getuid();
-
TBaseImpl<Test1, has_getuid<Test1>::value>::getuid();
-
return 0;
- }