§23.3.1:
An array is an aggregate (8.5.1) that can be initialized with the syntax array a<T, N> = { initializer-list };
where initializer-list is a comma separated list of up to N elements whose types are convertible to T.
In C++03, POD was defined in terms of aggregate: a class where every subobject is native or an aggregate is POD. So, by backwards compatibility, a C++0x std::array
is POD.
Or, to be anal, one can compare the bullet-points of §9/5 (defining trivial class) 9/6 (defining standard-layout) and 9/9 (combining preceding requirements into POD) with those of 8.5.1/1, which defines aggregates.
8.5.1:
An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no brace-or-equal- initializers for non-static data members (9.2), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).
Indeed the requirements in Clause 9 cover array
as long as its element type is also POD and the implementation does not declare operator=
or move
inside array
in addition to the specifications.
To be really anal, 17.5.2.2 says
- For the sake of exposition, Clauses 18 through 30 and Annex D do not describe copy/move constructors, assignment operators, or (non-virtual) destructors with the same apparent semantics as those that can be generated by default (12.1, 12.4, 12.8).
- It is unspecified whether the implementation provides explicit definitions for such member function signa- tures, or for virtual destructors that can be generated by default.
The note in the pseudo-code for template class array
is
// No explicit construct/copy/destroy for aggregate type
Does construct/copy/destroy
include operator=
(assignment) or move
? It probably should, but I don't think, by the strictest reading, it does.
Note that this "affects" not only POD-ness, but also trivial copyability as Johannes mentions.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…