C++ concepts: StandardLayoutType

From cppreference.com
< cpp‎ | concept
 
 
 

Specifies that a type is standard layout type. Standard layout types are useful for communicating with code written in other programming languages.

Note, that the standard doesn't define a named requirement or concept with this name. This is a type category defined by the core language. It is included here as concept only for consistency.

[edit] Requirements

  • All non-static data members have the same access control
  • Has no virtual functions or virtual base classes
  • All non-static data members and base classes are themselves standard layout types
  • Has no two base class subobjects of the same type
struct Q {};
struct S : Q { };
struct T : Q { };
struct U : S, T { };         // not a standard-layout class
  • Has all non-static data members declared in the same class (either all in the derived or all in some base)
struct B { int i; };         // standard-layout class
struct C : B { };            // standard-layout class
struct D : C { };            // standard-layout class
struct E : D { char : 4; };  // not a standard-layout class
  • None of the base class subobjects has the same type as
  • for non-union types, as the first non-static data member (see empty base optimization), and, recursively, the first non-static data member of that data member if it has non-union class type, or all non-static data members of that data member if it has union type, etc.
  • for union types, as any non-static data members, and, recursively, the first non-static data member of every member of non-union class type and all non-static data members of all members of union type, etc.

[edit] Properties

See Standard layout.

[edit] See also

checks if a type is standard-layout type
(class template)