当前位置:网站首页>判断是否为void类型
判断是否为void类型
2022-07-23 01:33:00 【发如雪-ty】
c++标准库中有一个类模板is_void ,用来判断某个类型是不是void类型。在main()函数中做一些测试:
int main()
{
cout << std::is_void<int>::value << endl;
cout << std::is_void<void>::value << endl;
system("pause");
return 0;
}
结果:
那is_void是怎么实现的呢?其实,is_void就可以看作是一个值萃取模板。
template<typename T>
struct TraitsVoid
{
static const int value = 0;
};
template<>
struct TraitsVoid<void>
{
static const int value = 1;
};
int main()
{
cout << TraitsVoid<int>::value << endl;
cout << TraitsVoid<void>::value << endl;
system("pause");
return 0;
}
结果:
边栏推荐
- IBM:到2030年实现容错量子优势
- Learn the distributed architecture notes sorted out by Alibaba in one month
- Group before getting the maximum value in stream operation
- 【无标题】
- 35岁程序员,早到的中年危机
- Notifyicondata tray used by BCG
- Trigger event when input is completed
- Server memory performance tuning
- AIRIOT答疑第5期|如何使用低代码业务流引擎?
- 我是新手,听说开户有保本的理财产品,是什么?
猜你喜欢

程序员不会 jvm?骨灰级工程师:全等着被淘汰吧!这是必会技能!
![[C language] file operation](/img/d3/5e5ce369dd3315089b529cf69b36c0.png)
[C language] file operation

C语言经典练习题(1)——“水仙花数“

Repeat: the difference between Pearson Pearson correlation coefficient and Spearman Spearman correlation coefficient

服务器托管、服务器租用、云主机各自的优势

【bug 简单处理】

PyG利用MessagePassing搭建GCN实现节点分类

复盘:什么是B+树?你知道B+树怎么构建有序表的吗?B+树有什么特点

Huawei applications have called the checkappupdate interface. Why is there no prompt for version update in the application

【MySQL从入门到精通】【高级篇】(七)设计一个索引&InnoDB中的索引方案
随机推荐
QT显示中文乱码
1059 Prime Factors
【管理篇 / 升级】* 02. 查看升级路径 * FortiGate 防火墙
rust allow dead_code
程序员不会 jvm?骨灰级工程师:全等着被淘汰吧!这是必会技能!
Cbcgpcolordialog control used by BCG
万物互联时代,看IoT测试如何应对“芯”挑战
给我五分钟,给你一片“云”
wallys/WiFi6 MiniPCIe Module 2T2R2×2.4GHz 2x5GHz MT7915 MT7975
【面试:并发篇21:多线程:活跃性】死锁、活锁、饥饿
涅槃重生!字节大牛力荐大型分布式手册,凤凰架构让你浴火成神
IBM:到2030年实现容错量子优势
35岁程序员,早到的中年危机
BCG 使用之NOTIFYICONDATA托盘
VS Code快捷键设置
Easyv semi annual ranking of "popular content on official websites"
【无标题】
FPGA出错的积累
[HLS] Call of queuing function in pipeline simulation
力扣(LeetCode)203. 移除链表元素(2022.07.22)