Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a conjunction of type predicates that correspond to std::is_pod<>?

I try to understand the POD concept in terms of other type predicates.

Is there a complete list of type predicates that would correspond to std::is_pod<>?

Here is my current attempt which does not hold (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?
like image 606
ebaklund Avatar asked Jan 12 '14 13:01

ebaklund


1 Answers

The combination of is_trivial and is_standard_layout is equal to is_pod, modulo some other restrictions on non-static members that are not captured by one of the type traits in <type_traits>.

Relevant quote from the draft Standard:

[class]

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, and has no non-static data members of type non-POD struct, non-POD union (or array of such types). A POD class is a class that is either a POD struct or a POD union.

like image 84
TemplateRex Avatar answered Sep 29 '22 04:09

TemplateRex