Automatic Generation of Move Operations
In C 11, the introduction of move semantics raised questions about the circumstances under which move constructors and move assignment operators are automatically generated.
Under C 11, move operations are not automatically generated like copy constructors and copy assignment operators. The compiler only generates move semantics if certain conditions are met:
Understanding these rules helps guide the implementation of classes that utilize move semantics. The table from Howard Hinnant's presentation provides a concise overview of the automatic generation of special members, including move operations:
Declaration | Copy Constructor | Copy Assignment Operator | Move Constructor & Move Assignment Operator |
---|---|---|---|
None | Generated | Generated | Not Generated |
Copy Constructor | Not Generated | Generated | Not Generated |
Copy Assignment Operator | Not Generated | Not Generated | Not Generated |
Move Constructor | Not Generated | Not Generated | Not Generated |
Move Assignment Operator | Not Generated | Not Generated | Not Generated |
Destructor | Not Generated | Not Generated | Not Generated |
Copy Constructor & Copy Assignment Operator | Not Generated | Not Generated | Not Generated |
Copy Constructor & Move Constructor | Not Generated | Not Generated | Not Generated |
Copy Constructor & Move Assignment Operator | Not Generated | Not Generated | Not Generated |
Copy Assignment Operator & Move Constructor | Not Generated | Not Generated | Not Generated |
Copy Assignment Operator & Move Assignment Operator | Not Generated | Not Generated | Not Generated |
Move Constructor & Destructor | Not Generated | Not Generated | Not Generated |
Move Assignment Operator & Destructor | Not Generated | Not Generated | Not Generated |
Copy Constructor & Copy Assignment Operator & Move Constructor | Not Generated | Not Generated | Not Generated |
Copy Constructor & Copy Assignment Operator & Move Assignment Operator | Not Generated | Not Generated | Not Generated |
Copy Constructor & Move Constructor & Move Assignment Operator | Not Generated | Not Generated | Generated |
Copy Assignment Operator & Move Constructor & Move Assignment Operator | Not Generated | Not Generated | Generated |
By recognizing these rules, developers can ensure that their classes properly utilize move semantics and achieve optimal efficiency.
The above is the detailed content of When Are Move Constructors and Move Assignment Operators Automatically Generated in C 11?. For more information, please follow other related articles on the PHP Chinese website!