类型特性
 类型特性定义一个编译时基于模板的结构,以查询或修改类型的属性。
试图特化定义于 <type_traits> 头文件的模板导致未定义行为,除了 std::common_type 可依照其所描述特化。
定义于<type_traits>头文件的模板可以用不完整类型实例化,除非另外有指定,尽管通常禁止以不完整类型实例化标准库模板。
  
属性查询
继承自 std::integral_constant
成员常量
| value [静态] | alignof(T) (公开静态成员常量) | 
成员函数
| operator std::size_t | 转换对象为 std::size_t ,返回 value(公开成员函数) | 
| operator() (C++14) | 返回 value(公开成员函数) | 
成员类型
| 类型 | 定义 | 
| value_type | std::size_t | 
| type | std::integral_constant<std::size_t, value> | 
获取类型的对齐要求
std::alignment_of| template< class T > | (C++11 起) | 
提供等于 T 类型对齐要求的成员常量 value ,如同用 alignof 表达式获得。若 T 是数组类型,则返回元素类型的对齐要求,若 T 是引用类型,则返回备用用类型的对齐要求。
若 alignof(T) 不是合法表达式,则行为未定义。
辅助变量模板
| template< class T > | (C++17 起) | 
可能的实现
template< class T >
struct alignment_of : 
std::integral_constant<std::size_t,alignof(T)> {};注意
此类型特性先于 alignof 关键词出现,该关键词能用于较简明地获得相同值。
调用示例
#include <iostream>
#include <type_traits>class A {};class B
{int b;
};class C
{int b;double c;
};int main()
{std::cout << "std::alignment_of<int>::value:        "<< std::alignment_of<int>::value << std::endl;std::cout << "std::alignment_of<double>::value:     "<< std::alignment_of<double>::value << std::endl;std::cout << "std::alignment_of<char>::value:       "<< std::alignment_of<char>::value << std::endl;std::cout << "std::alignment_of<uint8_t>::value:    "<< std::alignment_of<uint8_t>::value << std::endl;std::cout << "std::alignment_of<uint64_t>::value:   "<< std::alignment_of<uint64_t>::value << std::endl;std::cout << "std::alignment_of<std::string>::value:"<< std::alignment_of<std::string>::value << std::endl;std::cout << "std::alignment_of<A>::value:          "<< std::alignment_of<A>::value << std::endl;std::cout << "std::alignment_of<A>():               "<< std::alignment_of<A>() << std::endl; // 另一种语法std::cout << "std::alignment_of<B>():               "<< std::alignment_of<B>() << std::endl; // 另一种语法std::cout << "std::alignment_of<C>():               "<< std::alignment_of<C>() << std::endl; // 另一种语法return 0;
}输出
