88 lines
7.8 KiB
HTML
88 lines
7.8 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::stop_callback<Callback>::stop_callback</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_stop_callback_stop_callback 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::stop_callback<Callback>::</span>stop_callback</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-stop_callback.html">stop callback</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-cxx20">
|
|
<td>
|
|
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1"><</span><span class="kw1">class</span> C<span class="sy1">></span><br />
|
|
<span class="kw1">explicit</span> stop_callback<span class="br0">(</span> <span class="kw4">const</span> std<span class="sy4">::</span><span class="me2">stop_token</span><span class="sy3">&</span> st, C<span class="sy3">&&</span> cb <span class="br0">)</span> <span class="kw1">noexcept</span><span class="br0">(</span><span class="coMULTI">/*see below*/</span><span class="br0">)</span><span class="sy4">;</span></span></div>
|
|
</td>
|
|
<td>(1)</td>
|
|
<td><span class="t-mark-rev t-since-cxx20">(C++20 起)</span></td>
|
|
</tr>
|
|
<tr class="t-dcl t-since-cxx20">
|
|
<td>
|
|
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1"><</span><span class="kw1">class</span> C<span class="sy1">></span><br />
|
|
<span class="kw1">explicit</span> stop_callback<span class="br0">(</span> std<span class="sy4">::</span><span class="me2">stop_token</span><span class="sy3">&&</span> st, C<span class="sy3">&&</span> cb <span class="br0">)</span> <span class="kw1">noexcept</span><span class="br0">(</span><span class="coMULTI">/*see below*/</span><span class="br0">)</span><span class="sy4">;</span></span></div>
|
|
</td>
|
|
<td>(2)</td>
|
|
<td><span class="t-mark-rev t-since-cxx20">(C++20 起)</span></td>
|
|
</tr>
|
|
<tr class="t-dcl t-since-cxx20">
|
|
<td>
|
|
<div><span class="mw-geshi cpp source-cpp">stop_callback<span class="br0">(</span> <span class="kw4">const</span> stop_callback<span class="sy3">&</span> <span class="br0">)</span> <span class="sy1">=</span> delete<span class="sy4">;</span></span></div>
|
|
</td>
|
|
<td>(3)</td>
|
|
<td><span class="t-mark-rev t-since-cxx20">(C++20 起)</span></td>
|
|
</tr>
|
|
<tr class="t-dcl t-since-cxx20">
|
|
<td>
|
|
<div><span class="mw-geshi cpp source-cpp">stop_callback<span class="br0">(</span> stop_callback<span class="sy3">&</span> <span class="br0">)</span> <span class="sy1">=</span> delete<span class="sy4">;</span></span></div>
|
|
</td>
|
|
<td>(4)</td>
|
|
<td><span class="t-mark-rev t-since-cxx20">(C++20 起)</span></td>
|
|
</tr>
|
|
<tr class="t-dcl-sep">
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>构造新的 <code>stop_callback</code> 对象,保存并注册 <code>cb</code> 回调函数到给定的 <a href="cpp-thread-stop_token.html"><tt>std::stop_token</tt></a> 的关联状态中,为了之后若在关联的 <a href="cpp-thread-stop_source.html"><tt>std::stop_source</tt></a> 的关联停止状态上请求停止则调用</p>
|
|
<div class="t-li1"><span class="t-li">1)</span> 对给定的 <code>st</code> (复制),给定可调用回调函数 <code>cb</code> 构造 <code>stop_callback</code> 。</div>
|
|
<div class="t-li1"><span class="t-li">2)</span> 对给定的 <code>st</code> (移动),给定可调用回调函数 <code>cb</code> 构造 <code>stop_callback</code> 。</div>
|
|
<div class="t-li1"><span class="t-li">3-4)</span> <code>stop_callback</code> 既非<a href="cpp-named_req-CopyConstructible.html"><span style="font-style:italic">可复制构造</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(CopyConstructible)</span></a> 亦非<a href="cpp-named_req-MoveConstructible.html"><span style="font-style:italic">可移动构造</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(MoveConstructible)</span></a> 。</div>
|
|
<p>两个构造函数仅若 <code>Callback</code> 与 <code>C</code> 满足 <span class="t-c"><span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="me2">constructible_from</span><span class="sy1"><</span>Callback, C<span class="sy1">></span></span></span> 的 <a href="cpp-concepts-constructible_from.html"><code>constructible_from</code></a> 才参与重载决议。若 <code>Callback</code> 与 <code>C</code> 满足概念但不满足其语义要求,则行为未定义。</p>
|
|
<h3><span class="mw-headline" id=".E5.8F.82.E6.95.B0">参数</span></h3>
|
|
<table class="t-par-begin">
|
|
<tr class="t-par">
|
|
<td>st</td>
|
|
<td>-</td>
|
|
<td>用于注册此 <code>stop_callback</code> 对象 <a href="cpp-thread-stop_token.html"><tt>std::stop_token</tt></a> 的对象</td>
|
|
</tr>
|
|
<tr class="t-par">
|
|
<td>cb</td>
|
|
<td>-</td>
|
|
<td>若请求停止则调用的函数类型</td>
|
|
</tr>
|
|
</table>
|
|
<h3><span class="mw-headline" id=".E5.BC.82.E5.B8.B8">异常</span></h3>
|
|
<div class="t-li1"><span class="t-li">1-2)</span>
|
|
<div class="t-noexcept-full"><a href="cpp-language-noexcept_spec.html"><tt>noexcept</tt></a> 说明:
|
|
<div class="t-noexcept-box"><span class="t-cc"><span class="mw-geshi cpp source-cpp"><span class="kw1">noexcept</span><span class="br0">(</span><a href="cpp-types-is_constructible.html"><span class="kw525">std::<span class="me2">is_nothrow_constructible_v</span></span></a><span class="sy1"><</span>Callback, C<span class="sy1">></span><span class="br0">)</span></span></span></div>
|
|
</div>
|
|
任何构造函数初始化给定的回调到 <code>stop_callback</code> 对象中抛出的异常。</div>
|
|
<h3><span class="mw-headline" id=".E6.B3.A8.E8.A7.A3">注解</span></h3>
|
|
<p>若对传入的 <a href="cpp-thread-stop_token.html"><tt>std::stop_token</tt></a> 为 <span class="t-c"><span class="mw-geshi cpp source-cpp">st.<span class="me1">stop_requested</span><span class="br0">(</span><span class="br0">)</span> <span class="sy1">==</span> <span class="kw2">true</span></span></span> ,则在构造函数返回前于当前线程调用回调函数。</p>
|
|
</div>
|
|
<div class="visualClear"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|