std::is_pod

来自cppreference.com
< cpp‎ | types
 
 
元编程库
类型特性
类型类别
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
类型属性
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(C++20 前)
is_pod
(C++11)(C++20 中弃用)
(C++11)
类型特性常量
元函数
(C++17)
受支持操作
关系与属性查询
类型修改
(C++11)(C++11)(C++11)
类型变换
(C++11)
(C++11)
(C++17)
(C++11)(C++20 前)(C++17)
编译时有理数算术
编译时整数序列
 
在标头 <type_traits> 定义
template< class T >
struct is_pod;
(C++11 起)
(C++20 中弃用)

如果 T简旧数据(POD)类型,那么提供等于 true 的成员常量 value 。对于任何其他类型,valuefalse

如果 std::remove_all_extents_t<T> 是不完整类型且不是(可有 cv 限定的)void,那么行为未定义。

添加 is_pod is_pod_v (C++17 起) 的特化的程序行为未定义。

模板形参

T - 要检查的类型

辅助变量模板

template< class T >
inline constexpr bool is_pod_v = is_pod<T>::value;
(C++17 起)
(C++20 中弃用)

继承自 std::integral_constant

成员常量

value
[静态]
T 是简旧数据(POD)类型则为 true ,否则为 false
(公开静态成员常量)

成员函数

operator bool
转换对象为 bool ,返回 value
(公开成员函数)
operator()
(C++14)
返回 value
(公开成员函数)

成员类型

类型 定义
value_type bool
type std::integral_constant<bool, value>

示例

#include <iostream>
#include <type_traits>
 
struct A
{
    int m;
};
 
struct B
{
    int m1;
private:
    int m2;
};
 
struct C
{
    virtual void foo();
};
 
int main()
{
    std::cout << std::boolalpha;
    std::cout << std::is_pod<A>::value << '\n';
    std::cout << std::is_pod<B>::value << '\n';
    std::cout << std::is_pod<C>::value << '\n';
}

输出:

true
false
false

参阅

检查是否是一个标准布局类型
(类模板)
检查类型是否平凡
(类模板)