c 11 – 是否存在与std :: is_pod <>对应的类型谓词的连接?

前端之家收集整理的这篇文章主要介绍了c 11 – 是否存在与std :: is_pod <>对应的类型谓词的连接?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试用其他类型谓词来理解POD概念.

是否有完整的类型谓词列表,它们对应于std :: is_pod<>?

这是我目前的尝试不成立(VS2013).

struct C { // Does not assert as POD class
    int value;

    C() = default;

    C(int v) : value(v) { // Offends is_pod<>
    }
};

static_assert(std::is_trivial<C>::value,""); // Assert OK
static_assert(std::is_trivially_copyable<C>::value,""); // Assert OK
static_assert(std::is_standard_layout<C>::value,""); // Assert OK
static_assert(std::is_pod<C>::value,"");  // Assert fails. Why?

解决方法

is_trivial和is_standard_layout的组合等于is_pod,对非静态成员的一些其他限制进行模数,这些限制未被< type_traits>中的一个类型特征捕获.

the draft Standard的相关报价:

[类]

10 A POD struct is a non-union class that is both a trivial class
and a standard-layout class,and has no non-static data members of type non-POD struct,non-POD union (or array of such types). Similarly,a POD union is a union that is both a trivial class and a standard-layout class,non-POD union (or array of such types). A POD class is a class that is either a POD struct or a POD union.

原文链接:https://www.f2er.com/c/119315.html

猜你在找的C&C++相关文章