栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

模板与泛型编程之is

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

模板与泛型编程之is

一、std::is_union
std::is_union是c++11标准中出现的一个类模板。由于判断某个类型是否是一个联合类型

struct A 
{
	int a;
};

union B
{
	int num;
	char type;
};

int main()
{
	
	cout<::value << endl;
	cout<::value << endl;
	system("pause");
	return 0;
}

目前std::is_union的实现需要编译器内部的支持,所以暂时没有实现源码可供参考借鉴。
在c++17中有引入了变量模板,简化std::is_union的书写。

template
inline constexpr bool is_unionn_v = is_union::value

所以可做如下更改:

cout< << endl;
cout< << endl;

结果:

二、std::is_class
std::is_class是c++11标准中出现的一个类模板。由于判断某个类型是否是一个类类型(联合不是类类型)

struct A 
{
	int a;
};

union B
{
	int num;
	char type;
};

int main()
{
	
	cout<::value << endl;
	cout<::value << endl;
	system("pause");
	return 0;
}

在c++17中有引入了变量模板,简化std::is_class的书写。

template
inline constexpr bool is_class_v = is_class::value

所以在main()函数中代码可以进行如下修改,结果是一样的。

int main()
{
	
	cout<<< endl;
	cout<<< endl;
	system("pause");
	return 0;
}

结果:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1012394.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号