54 lines
4.4 KiB
HTML
54 lines
4.4 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>std::promise<R>::get_future</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_thread_promise_get_future 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%">std::promise<R>::</span>get_future</h1>
|
|
<div id="bodyContent">
|
|
<div id="contentSub"><span class="subpages">< <a href="cpp.html">cpp</a>‎ | <a href="cpp-thread.html">thread</a>‎ | <a href="cpp-thread-promise.html">promise</a></span></div>
|
|
<div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr" xml:lang="zh">
|
|
<table class="t-dcl-begin">
|
|
<tbody>
|
|
<tr class="t-dcl t-since-cxx11">
|
|
<td>
|
|
<div><span class="mw-geshi cpp source-cpp"><a href="cpp-thread-future.html"><span class="kw2180">std::<span class="me2">future</span></span></a><span class="sy1"><</span>T<span class="sy1">></span> get_future<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span></span></div>
|
|
</td>
|
|
<td class="t-dcl-nopad"></td>
|
|
<td><span class="t-mark-rev t-since-cxx11">(C++11 起)</span></td>
|
|
</tr>
|
|
<tr class="t-dcl-sep">
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>返回与 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="sy2">*</span>this</span></span> 关联同一状态的 future 对象。</p>
|
|
<p>若 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="sy2">*</span>this</span></span> 无共享状态,或已调用 <code>get_future</code> 则抛出异常。可使用 <span class="t-lc"><a href="cpp-thread-future-share.html">std::future::share</a></span> 以获取 promise-future 交流通道的多个“弹出”端。</p>
|
|
<p>对此函数的调用与对 <span class="t-lc"><a href="cpp-thread-promise-set_value.html">set_value</a></span> 、 <span class="t-lc"><a href="cpp-thread-promise-set_exception.html">set_exception</a></span> 、 <span class="t-lc"><a href="cpp-thread-promise-set_value_at_thread_exit.html">set_value_at_thread_exit</a></span> 或 <span class="t-lc"><a href="cpp-thread-promise-set_exception_at_thread_exit.html">set_exception_at_thread_exit</a></span> 的调用不造成数据竞争(但它们不必彼此同步)。</p>
|
|
<h3><span class="mw-headline" id=".E5.8F.82.E6.95.B0">参数</span></h3>
|
|
<p>(无)</p>
|
|
<h3><span class="mw-headline" id=".E8.BF.94.E5.9B.9E.E5.80.BC">返回值</span></h3>
|
|
<p>指代 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="sy2">*</span>this</span></span> 的共享状态的 <code>future</code> 。</p>
|
|
<h3><span class="mw-headline" id=".E5.BC.82.E5.B8.B8">异常</span></h3>
|
|
<p>遇到下列条件时抛出 <span class="t-lc"><a href="cpp-thread-future_error.html">std::future_error</a></span> :</p>
|
|
<ul>
|
|
<li><span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="sy2">*</span>this</span></span> 无共享状态。设置 error_category 为 <a href="cpp-thread-future_errc.html"><tt>no_state</tt></a> 。</li>
|
|
</ul>
|
|
<ul>
|
|
<li>已在与 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="sy2">*</span>this</span></span> 拥有同一共享状态的 promise 上调用 <code>get_future()</code> 。设置 error_category 为 <a href="cpp-thread-future_errc.html"><tt>future_already_retrieved</tt></a> 。</li>
|
|
</ul>
|
|
</div>
|
|
<div class="visualClear"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|