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

在 C + + 20中,std::is_pod可能会被弃用。
为什么要这么做?我应该用什么来代替 std::is_pod来知道一个类型是否实际上是一个 POD?

16485 次浏览

POD 正在被两个更有细微差别的类别所取代。 C + + 2017年11月标准会议对此有这样的说法:

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.

对于简单数据类型使用 is_standard_layout函数,对于普通数据类型(如简单结构)使用 is_trivial函数。