Home  >  Article  >  Backend Development  >  Why Were Default Move Implementations Absent in Early C 11 Drafts?

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

Barbara Streisand
Barbara StreisandOriginal
2024-11-19 19:13:02181browse

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.

The above is the detailed content of Why Were Default Move Implementations Absent in Early C 11 Drafts?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn