且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么在C ++ 20中不推荐使用std :: is_pod?

更新时间:2022-12-31 16:49:15

POD被替换为两个类别,这些类别提供了更多细微差别。 c ++标准会议在2017年11月对此有这样的说法:


不再使用普通旧数据(POD)的概念。它已被两个更细微的类别所取代,即平凡的和标准布局。 POD等效于简单且标准的布局,但是对于许多代码模式而言,仅将琐碎或标准布局的限制更窄些是合适的;为了鼓励这种精确度,因此不赞成使用 POD的概念。库特征is_pod也已被相应弃用。


对于简单数据类型,请使用 is_standard_layout 函数,对于琐碎的数据类型(例如简单结构),请使用 is_trivial 函数。 / p>

std::is_pod will be probably deprecated in C++20.
What's the reason for this choice? What should I use in place of std::is_pod to know if a type is actually a POD?

POD is being replaced with two categories that give more nuances. The c++ standard meeting in november 2017 had this to say about it:

Deprecating the notion of "plain old data" (POD). It has been replaced with two more nuanced categories of types, "trivial" and "standard-layout". "POD" is equivalent to "trivial and standard layout", but for many code patterns, a narrower restriction to just "trivial" or just "standard layout" is appropriate; to encourage such precision, the notion of "POD" was therefore deprecated. The library trait is_pod has also been deprecated correspondingly.

For simple data types use the is_standard_layout function, for trivial data types (such as simple structs) use the is_trivial function.