您当前的位置: 首页 >  c++

柳鲲鹏

暂无认证

  • 0浏览

    0关注

    4642博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

使用C++模板判断是否基本类型

柳鲲鹏 发布时间:2019-03-12 16:56:23 ,浏览量:0

可以使用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()

 

关注
打赏
1665724893
查看更多评论
立即登录/注册

微信扫码登录

0.0504s