Namespaces
Variants

std:: is_pod

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
is_pod
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
定义于头文件 <type_traits>
template < class T >
struct is_pod ;
(C++11 起)
(C++20 中弃用)

std::is_pod 是一个 UnaryTypeTrait

如果 T POD 类型 ("纯旧数据类型"),则提供值为 true 的成员常量 value 。对于其他任何类型, value false

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

如果程序为 std::is_pod std::is_pod_v 添加特化,则行为是未定义的。

目录

模板参数

T - 待检查的类型

辅助变量模板

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

继承自 std:: integral_constant

成员常量

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

成员函数

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

成员类型

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

示例

#include <type_traits>
struct A { int m; };
static_assert(std::is_pod_v<A> == true);
class B: public A { int m; };
static_assert(std::is_pod_v<B> == false);
struct C { virtual void foo(); };
static_assert(std::is_pod_v<C> == false);
int main() {}

缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的C++标准。

缺陷报告 应用于 发布时行为 正确行为
LWG 2015 C++11 T 可能是未知边界的
不完整类类型的数组
此情况下行为
未定义

另请参阅

检查类型是否为 标准布局 类型
(类模板)
(C++11) (deprecated in C++26)
检查类型是否为平凡类型
(类模板)
(C++11)
检查类型是否为标量类型
(类模板)

外部链接

为何在 C++20 中弃用 std::is_pod — StackOverflow