Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

is_standard_layout vs is_pod

34 views
Skip to first unread message

Daniel

unread,
Jan 24, 2020, 1:17:52 AM1/24/20
to
Can someone explain what is the difference between is_standard_layout and is_pod, and why the latter is being deprecated in 2020?

Thanks,
Daniel

Bo Persson

unread,
Jan 24, 2020, 4:15:04 AM1/24/20
to
On 2020-01-24 at 07:17, Daniel wrote:
> Can someone explain what is the difference between is_standard_layout and is_pod, and why the latter is being deprecated in 2020?
>

The is_pod tests several conditions that have been separated into
is_standard_layout and is_trivial.

So, is_pod is no longer used by the standard library (except as the
deprecated type trait).


Bo Persson

James Kuyper

unread,
Jan 25, 2020, 12:07:47 AM1/25/20
to
On 1/24/20 1:17 AM, Daniel wrote:
> Can someone explain what is the difference between is_standard_layout and is_pod, and why the latter is being deprecated in 2020?

"Scalar types, POD classes (Clause 9), arrays of such types and
cv-qualified versions of these types (3.9.3) are collectively called POD
types. ... Scalar types, standard-layout class types (Clause 9), arrays
of such types and cv-qualified versions of these types (3.9.3) are
collectively called standard-layout types." (3.9p9)

Scalar types are, by definition, both POS type and standard-layout
types. Therefore, it's only for classes that there's a difference.

"A POD struct 109 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." (9p10).

A POD class is by definition a standard-layout class, but the reverse is
not true. A standard-layout class that is non-trivial or has non-static
non-POD data members will not qualify as a POD class.

Things that could make a standard-layout class non-trivial include (9p6):
1. A missing default ctor.
2. A non-trivial default constructor.
3. Not trivially copyable

Thing that would prevent a standard-layout class from being trivially
copyable include (9p6):
1. a non-trivial copy ctor
2. a non-trivial move ctor
3. a non-trivial copy assignment operator
4. a non-trivial move constructor
5. a non-trivial dtor.

A user-provided function is never trivial, and the same rules apply
recursively to both base classes and non-static data members (12.1p4,
12.4p5, 12.8p12, 12.8p25).

Note that POD classes can have base classes, static data members, and
member functions. A standard-layout class can have all of those things
and non-trivial special member functions.
0 new messages