Home > Backend Development > C++ > When Does the C 11 Compiler Automatically Generate Move Operations?

When Does the C 11 Compiler Automatically Generate Move Operations?

Patricia Arquette
Release: 2024-11-27 07:53:12
Original
308 people have browsed it

When Does the C  11 Compiler Automatically Generate Move Operations?

Rules for Automatic Generation of Move Operations

In C 11, the compiler's ability to automatically generate move operations differs from the rules for copy operations in C 98.

Move Constructor and Move Assignment Operator

Under the following conditions, the compiler will automatically generate a move constructor and move assignment operator:

  • The class has no user-declared copy constructor.
  • The class has no user-declared copy assignment operator.
  • The class has no explicitly declared move constructor or move assignment operator.

Cases Where Move Operations Are Not Automatically Generated

The compiler will not automatically generate move operations if any of the following conditions are met:

  • The class has a user-declared copy constructor and/or copy assignment operator.
  • The class has an explicitly declared, but not defined, move constructor or move assignment operator.
  • The class declares a destructor.

Tool for Verifying Automatic Generation Rules

The following resource provides a visual representation of the rules for automatic generation of special members, including move operations:

[Image of Howard Hinnant's ACCU 2014 presentation slide](https://i.sstatic.net/b2VBV.png)

Additional Clarification

The red squares in the table indicate deprecated behavior. If you wish to avoid relying on deprecation, consider following the "rule of 3" from C 98/03: declare both copy members if you declare the destructor, or declare at least one copy member.

The above is the detailed content of When Does the C 11 Compiler Automatically Generate Move Operations?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template