"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Were Default Move Implementations Absent in Early C++11 Drafts?

Why Were Default Move Implementations Absent in Early C++11 Drafts?

Published on 2024-11-19
Browse:235

Why Were Default Move Implementations Absent in Early C  11 Drafts?

Why Are Default Move Implementations Absent from Early C 11 Drafts?

In early versions of the C 11 standard, the implicit generation of move constructors and assignment operators was a topic of debate. This led to changes in subsequent drafts, resulting in the following behavior in currently available compilers:

Implicit Move Semantics

Since the November release of the C Standard (N3225), implicit move constructors and assignment operators can be generated under the following conditions:

  • The class has no user-declared copy constructor.
  • The class has no user-declared copy assignment operator.
  • The class has no user-declared move assignment operator.
  • The class has no user-declared destructor.
  • The move constructor would not be implicitly defined as deleted.

Explaining the Absence in Early Drafts

The decision not to include default move constructor/assignment implementations in early drafts was a result of concerns about the potential for confusion and unexpected behavior. However, subsequent revisions have addressed these concerns by tightening the conditions for implicit move generation.

Workaround

If you're looking for a way to utilize move semantics without writing explicit move constructors/assignment operators, you can use [GManNickG's macro](https://stackoverflow.com/a/12316884/8674521). This macro generates the necessary move semantics for your class.

By implementing move semantics, you can opt out of providing a swap member function as well.

Latest tutorial More>

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