Skip to main content

C++ named requirements: TriviallyCopyable (since C++11)

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

Requirements

The following types are collectively called trivially copyable types:

Notes

In general, for any trivially copyable type T and an object obj1 of T, the underlying bytes of obj1 can be copied into an array of char, or unsigned char,
or std::byte (since C++17) or into obj2, a distinct object of T. Neither obj1 nor obj2 may be a potentially-overlapping subobject.

If the underlying bytes of obj1 are copied into such an array, and then the resulting content is copied back into obj1, obj1 will hold its original value. If the underlying bytes of obj1 are copied into obj2, obj2 will hold obj1's value.

Underlying bytes can be copied by std::memcpy or std::memmove, as long as no living volatile object is accessed.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DRApplied toBehavior as publishedCorrect behavior
CWG 1734C++11C++03 POD with deleted non-trivial assignment was not trivialdeleted ctors/operators allowed
CWG 2094C++11Volatile scalar types are not trivially copyable (CWG 1746)made trivially copyable

C++ named requirements: TriviallyCopyable (since C++11)

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

Requirements

The following types are collectively called trivially copyable types:

Notes

In general, for any trivially copyable type T and an object obj1 of T, the underlying bytes of obj1 can be copied into an array of char, or unsigned char,
or std::byte (since C++17) or into obj2, a distinct object of T. Neither obj1 nor obj2 may be a potentially-overlapping subobject.

If the underlying bytes of obj1 are copied into such an array, and then the resulting content is copied back into obj1, obj1 will hold its original value. If the underlying bytes of obj1 are copied into obj2, obj2 will hold obj1's value.

Underlying bytes can be copied by std::memcpy or std::memmove, as long as no living volatile object is accessed.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DRApplied toBehavior as publishedCorrect behavior
CWG 1734C++11C++03 POD with deleted non-trivial assignment was not trivialdeleted ctors/operators allowed
CWG 2094C++11Volatile scalar types are not trivially copyable (CWG 1746)made trivially copyable