可以使用define来简化.
- 方法1
template
struct is_double
{
operator bool()
{
return false;
}
};
template
struct is_double
{
operator bool()
{
return true;
}
};
//使用方法
if (!is_double())
- 方法2
#include
#include
using namespace std;
struct FalseType
{
static bool Get()
{
return false;
}
};
struct TrueType
{
static bool Get()
{
return true;
}
};
template
struct TypeTraits
{
typedef FalseType PODTYPE;
};
template
struct TypeTraits
{
typedef TrueType PODTYPE;
};
template
struct TypeTraits
{
typedef TrueType PODTYPE;
};
template
struct TypeTraits
{
typedef TrueType PODTYPE;
};
template
struct TypeTraits
{
typedef TrueType PODTYPE;
};
//使用方法
TypeTraits::PODTYPE::Get()