is_pod 类
测试,如果类型是使用。
template<class Ty>
struct is_pod;
参数
- Ty
查询的类型。
备注
如果类型 Ty 是纯旧数据 (POD),is_pod<Ty>::value 为 true。 否则它是 false。
算术类型、枚举类型、指针类型和成员为指针类型是使用。
使用类型的 CV 限定生成本身 POD 类型。
数组使用本身使用。
结构或联合,所有非静态数据成员是 PODS,本身是 PODS,如果有:
没有用户声明的构造函数。
没有私有或受保护的非静态数据成员。
非基类
没有虚函数。
未引用类型的非静态数据成员。
没有用户定义的复制赋值运算符。
没有用户定义的析构函数。
因此,您可以生成包含递归使用结构和数组的 POD 结构和数组。
示例
// std_tr1__type_traits__is_pod.cpp
// compile with: /EHsc
#include <type_traits>
#include <iostream>
struct trivial
{
int val;
};
struct throws
{
throws() throw(int)
{
}
throws(const throws&) throw(int)
{
}
throws& operator=(const throws&) throw(int)
{
}
int val;
};
int main()
{
std::cout << "is_pod<trivial> == " << std::boolalpha
<< std::is_pod<trivial>::value << std::endl;
std::cout << "is_pod<int> == " << std::boolalpha
<< std::is_pod<int>::value << std::endl;
std::cout << "is_pod<throws> == " << std::boolalpha
<< std::is_pod<throws>::value << std::endl;
return (0);
}
要求
标头: <type_traits>
命名空间: std