您的位置:首页 > 编程语言 > C语言/C++

c++ type trait 之 useful trait

2017-05-18 17:34 253 查看
#include <iostream>
#include <array>

using namespace std;
enum class color : char
{
yellow,
red,
bule
};
int main()
{
//row Array的维度
cout << rank<int []>::value << endl;
//extent<T,I = 0> 维度I的宽度
cout << extent<int[5][7],1>::value << endl;
//
remove_extent<int[5][3]>::type a = { 5,4,3 };//int[3]
remove_all_extents<int[5][3]>::type b = 5;//int
underlying_type<color>::type c = 'e'; // char
//使const int& decay(衰退为int)by value
decay<const int&>::type i = 5;// int
//enable_if<B,T> 若B为真则产出type T 否则产出void
enable_if<true, double>::type d = 3.11; // value
//conditional<B,T,D>若B为真则产出type T,否则产出 type D
conditional<true, string, double>::type s = "Marco";// string
//common_type<T,D> 得到类型T和类型D的共通类型
cout << typeid(common_type<int, double>::type).name() << endl;
//result_of<F,Args>见其他博文详细介绍
//alignment_of<T> alignment_storage<Len>
//alignment_storage<Len,Align>
//alignment_union<Len,Types...>见详细博文补充
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ type-trait