C++11_Type Traits
版权声明:本文为博主原创文章,未经博主允许不得转载。
识别变量的type id,返回true或false,举一个简单使用的例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | template < typename T> void type_traits_output( const T& x) { cout << "\ntype traits for type : " << typeid (T).name() << endl; cout << "is_void\t" << is_void<T>::value << endl; cout << "is_integral\t" << is_integral<T>::value << endl; cout << "is_floating_point\t" << is_floating_point<T>::value << endl; cout << "is_arithmetic\t" << is_arithmetic<T>::value << endl; cout << "is_signed\t" << is_signed<T>::value << endl; cout << "is_unsigned\t" << is_unsigned<T>::value << endl; cout << "is_const\t" << is_const<T>::value << endl; cout << "is_volatile\t" << is_volatile<T>::value << endl; cout << "is_class\t" << is_class<T>::value << endl; cout << "is_function\t" << is_function<T>::value << endl; cout << "is_reference\t" << is_reference<T>::value << endl; } int main( int argc, const char * argv[]) { int a = 5; type_traits_output< int >(a); return 0; } |
输出结果
具体操作也不做太多解释了,很好理解.更多的Type Traits见
http://www.cplusplus.com/reference/type_traits/
以下是Type Traits的截图
希望会对大家有所帮助
如有不正确的地方请指正
参照<<侯捷 C++新标准 C++11>>
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· “你见过凌晨四点的洛杉矶吗?”--《我们为什么要睡觉》
· 提示词工程师自白:我如何用一个技巧解放自己的生产力
· C# 从零开始使用Layui.Wpf库开发WPF客户端
· C#/.NET/.NET Core技术前沿周刊 | 第 31 期(2025年3.17-3.23)
· 如何不购买域名在云服务器上搭建HTTPS服务