Home > Backend Development > C++ > How Do Automatic Move Operation Generation Rules Differ Between C 98 and C 11?

How Do Automatic Move Operation Generation Rules Differ Between C 98 and C 11?

Linda Hamilton
Release: 2024-11-29 05:32:16
Original
1052 people have browsed it

How Do Automatic Move Operation Generation Rules Differ Between C  98 and C  11?

Generation Rules for Automatic Move Operations

In C 98, the compiler could create copy constructors and copy assignment operators automatically through member-wise copy. This process extended to C 11 with the introduction of move semantics. However, the rules for automatic generation of move operations differ from those of copy operations.

Howard Hinnant's ACCU 2014 presentation provides a concise overview of these rules. The following table summarizes the key points:

</p>
<table>
<thead><tr>
<th> </th>
<th>Destructor</th>
<th>Move Constructor</th>
<th>Move Assignment Operator</th>
</tr></thead>
<tbody>
<tr>
<td>C  98/03</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td>C  11 (Defect Report 1492)</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td>C  11 Final</td>
<td>Yes</td>
<td>Yes<sup>*</sup>
</td>
<td>Yes<sup>*</sup>
</td>
</tr>
</tbody>
</table>
<p>

Yes: Automatically generated.
No: Not automatically generated.

*But only implicitly defined (not declared or declared=default). Explicit definitions suppress generation.

These rules indicate that while move constructors and move assignment operators are generally generated automatically in C 11, there are some cases where they may not be. For instance, if the destructor is explicitly defined, the move operations will not be generated. Similarly, explicitly defining move operations themselves suppresses automatic generation.

The above is the detailed content of How Do Automatic Move Operation Generation Rules Differ Between C 98 and C 11?. 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