72 lines
5.5 KiB
HTML
72 lines
5.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh" dir="ltr" class="client-nojs" xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh">
|
|
<head><meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<title>C++ 具名要求:可移动构造 (MoveConstructible) (C++11 起)</title>
|
|
<link rel="stylesheet" href="ext.css" />
|
|
<link rel="stylesheet" href="site_modules.css" />
|
|
</head>
|
|
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_named_req_MoveConstructible skin-cppreference2 action-view cpp-navbar">
|
|
<div id="cpp-content-base">
|
|
<div id="content"><a id="top"></a>
|
|
<h1 id="firstHeading" class="firstHeading"><span style="font-size:0.7em; line-height:130%">C++ 具名要求:</span><span style="font-style:italic">可移动构造</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(MoveConstructible)</span> <span class="t-mark-rev t-since-cxx11">(C++11 起)</span></h1>
|
|
<div id="bodyContent">
|
|
<div id="contentSub"><span class="subpages">< <a href="cpp.html">cpp</a>‎ | <a href="cpp-named_req.html">named req</a></span></div>
|
|
<div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr" xml:lang="zh">
|
|
<p>指定该类型的实例可以从一个<a href="cpp-language-value_category.html">右值</a>实参构造。</p>
|
|
<h3><span class="mw-headline" id=".E8.A6.81.E6.B1.82">要求</span></h3>
|
|
<p>以下情况下,类型 <code>T</code> 满足<span style="font-style:italic">可移动构造</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(MoveConstructible)</span> :</p>
|
|
<p>给定</p>
|
|
<ul>
|
|
<li><code>T</code> 类型的<a href="cpp-language-value_category.html">右值表达式</a> <code>rv</code></li>
|
|
<li>任意标识符 <code>u</code></li>
|
|
</ul>
|
|
<p>下列表达式必须合法且拥有其指定的效果</p>
|
|
<table class="wikitable">
|
|
<tr>
|
|
<th>表达式</th>
|
|
<th>后条件</th>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="t-c"><span class="mw-geshi cpp source-cpp">T u <span class="sy1">=</span> rv<span class="sy4">;</span></span></span></td>
|
|
<td><code>u</code> 的值等于 <code>rv</code> 在初始化前的值。<code>rv</code> 的新值未指明。</td>
|
|
</tr>
|
|
<tr>
|
|
<td><span class="t-c"><span class="mw-geshi cpp source-cpp">T<span class="br0">(</span>rv<span class="br0">)</span></span></span></td>
|
|
<td><code>T(rv)</code> 的值等于 <code>rv</code> 在初始化前的值。<code>rv</code> 的新值未指明。</td>
|
|
</tr>
|
|
</table>
|
|
<h3><span class="mw-headline" id=".E6.B3.A8.E8.A7.A3">注解</span></h3>
|
|
<p>类不必为满足此要求而实现<a href="cpp-language-move_constructor.html">移动构造函数</a>:接收 <code>const T&</code> 实参的<a href="cpp-language-copy_constructor.html">复制构造函数</a>也能绑定右值表达式。</p>
|
|
<p>若<span style="font-style:italic">可移动构造</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(MoveConstructible)</span> 类实现了移动构造函数,则它亦可实现<a href="cpp-utility-move.html">移动语义</a>,以从“构造后 <code>rv</code> 的值未指明”的事实中获利。</p>
|
|
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">参阅</span></h3>
|
|
<table class="t-dsc-begin">
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div">
|
|
<div><a href="cpp-types-is_move_constructible.html"><span class="t-lines"><span>is_move_constructible</span><span>is_trivially_move_constructible</span><span>is_nothrow_move_constructible</span></span></a></div>
|
|
<div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div>
|
|
</div>
|
|
</td>
|
|
<td>检查类型是否能从右值引用构造<br />
|
|
<span class="t-mark">(类模板)</span></td>
|
|
</tr>
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div">
|
|
<div><a href="cpp-concepts-move_constructible.html"><span class="t-lines"><span>move_constructible</span></span></a></div>
|
|
<div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx20">(C++20)</span></span></span></div>
|
|
</div>
|
|
</td>
|
|
<td>指定能移动构造一个类型的对象<br />
|
|
<span class="t-mark">(概念)</span></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="visualClear"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|