Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/named req/TriviallyCopyable"

From cppreference.com
< cpp‎ | named req
m (s/collvectively/collectively)
m (s/Following type/The following types)
Line 3: Line 3:
  
 
===Requirements===
 
===Requirements===
Following type are collectively called ''trivially copyable types'':
+
The following types are collectively called ''trivially copyable types'':
  
 
*Scalar types<!-- CWG 2094 reverted CWG 1746 -->
 
*Scalar types<!-- CWG 2094 reverted CWG 1746 -->

Revision as of 06:34, 15 August 2020

 
 
C++ named requirements
 

Requirements

The following types are collectively called trivially copyable types:

  • Scalar types
  • Trivially copyable classes, i.e. classes satisfying following requirements:
    • Every copy constructor is trivial or deleted
    • Every move constructor is trivial or deleted
    • Every copy assignment operator is trivial or deleted
    • Every move assignment operator is trivial or deleted
    • At least one copy constructor, move constructor, copy assignment operator, or move assignment operator is non-deleted
    • Has a trivial non-deleted destructor
  • Arrays of TriviallyCopyable objects

This implies that a trivially copyable class has no virtual functions or virtual base classes.

Defect reports

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

DR Applied to Behavior as published Correct behavior
CWG 1734 C++11 C++03 POD with deleted non-trivial assignment was not trivial deleted ctors/operators allowed
CWG 2094 C++11 Volatile scalar types are not trivially copyable (CWG 1746) made trivially copyable

See also

checks if a type is trivially copyable
(class template) [edit]