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.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3