Implicit Move Constructors and Assignment Operators in Early C 11 Drafts
Despite the widespread implementation of default copy constructors and assignment operators in C , the absence of default move constructors and assignment operators in early drafts of the C 11 standard has raised questions among programmers.
Reasons for Initial Absence
The implicit generation of move operations has been a subject of ongoing debate within the C community. Early drafts of the C 11 standard lacked these implicit features due to concerns over preserving code that relied on non-movable types. Furthermore, the behavior of std::move with non-movable objects utilizing the assignment operator complicated the issue.
Current Specification
As of the November N3225 specification, if a class does not explicitly define a move constructor, it will be implicitly declared as defaulted under the following conditions:
Similar conditions apply to the implicit declaration of the move assignment operator. These changes align with the principles outlined in N3203 and N3201, which advocate for stricter conditions on implicit move generation.
Workaround
In the absence of implicit move operations in early C 11 drafts, one workaround is to manually implement a move assignment operator and move constructor. To avoid implementing these operators in every class, a macro solution can be employed. GManNickG's answer in the Stack Overflow question provides a suitable example.
The above is the detailed content of Why Were Implicit Move Constructors and Assignment Operators Absent in Early C 11 Drafts?. For more information, please follow other related articles on the PHP Chinese website!