做资料分享网站有哪些,html网页设计实训报告范文,电话营销销售系统,电子印章在线制作网站前言#xff1a;
#include type_traits
type_traits 又叫类型萃取#xff0c;是一个在编译阶段用于进行 类型判断/类型变更 的库#xff0c;在c11中引入。因为其工作阶段是在编译阶段#xff0c;因此被大量应用在模板编程中#xff0c;同时也可以结合 constexpr…前言
#include type_traits
type_traits 又叫类型萃取是一个在编译阶段用于进行 类型判断/类型变更 的库在c11中引入。因为其工作阶段是在编译阶段因此被大量应用在模板编程中同时也可以结合 constexpr 这种在编译阶段就进行计算的语句进行编译阶段的运算。 类型判断
判断模板类型是不是class类型
templatetypename T
void function(T){if(std::is_class(T)){printf(T is class type);}
}
判断两个模板类型是否相同
templatetypename Ttypename U
void function(T,U){if(std::is_same(T,U)){printf(T and U is same type);}
} 类型变更
移除/添加const限制
templatetypename T
void removeConst(T t){std::remove_constT(t);
}templatetypename T
void removeConst(T t){std::add_constT(t);
} 更多功能参考
Standard library header type_traits (C11) - cppreference.com