Files
hustoj/web/cppreference-zh/chmhelp/cpp-concepts-invocable.html
2025-08-01 12:57:54 +08:00

78 lines
7.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>std::invocable, std::regular_invocable</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_concepts_invocable 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::</span>invocable, <span style="font-size:0.7em; line-height:130%">std::</span>regular_invocable</h1>
<div id="bodyContent">
<div id="contentSub"><span class="subpages">&lt; <a href="cpp.html">cpp</a>&lrm; | <a href="cpp-concepts.html">concepts</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-dsc-header">
<td>
<div>&#23450;&#20041;&#20110;&#22836;&#25991;&#20214; <code><a href="cpp-header-concepts.html">&lt;concepts&gt;</a></code></div>
</td>
<td></td>
<td></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">&lt;</span> <span class="kw1">class</span> F, <span class="kw1">class</span>... <span class="me1">Args</span> <span class="sy1">&gt;</span><br /></span>
<p>concept invocable <span class="sy1">=</span><br />
&nbsp; requires<span class="br0">(</span>F<span class="sy3">&amp;&amp;</span> f, Args<span class="sy3">&amp;&amp;</span>... <span class="me1">args</span><span class="br0">)</span> <span class="br0">{</span><br />
&nbsp; &nbsp; <a href="cpp-utility-functional-invoke.html"><span class="kw1058">std::<span class="me2">invoke</span></span></a><span class="br0">(</span><a href="cpp-utility-forward.html"><span class="kw1117">std::<span class="me2">forward</span></span></a><span class="sy1">&lt;</span>F<span class="sy1">&gt;</span><span class="br0">(</span>f<span class="br0">)</span>, <a href="cpp-utility-forward.html"><span class="kw1117">std::<span class="me2">forward</span></span></a><span class="sy1">&lt;</span>Args<span class="sy1">&gt;</span><span class="br0">(</span>args<span class="br0">)</span>...<span class="br0">)</span><span class="sy4">;</span><br />
&nbsp; &nbsp; &nbsp; <span class="coMULTI">/* &#19981;&#35201;&#27714;&#20445;&#25345;&#30456;&#31561;&#24615; */</span><br /></p>
&nbsp; <span class="br0">}</span><span class="sy4">;</span></div>
</td>
<td class="t-dcl-nopad"></td>
<td><span class="t-mark-rev t-since-cxx20">(C++20 &#36215;)</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">&lt;</span> <span class="kw1">class</span> F, <span class="kw1">class</span>... <span class="me1">Args</span> <span class="sy1">&gt;</span><br />
concept regular_invocable <span class="sy1">=</span> std<span class="sy4">::</span><span class="me2">invocable</span><span class="sy1">&lt;</span>F, Args...<span class="sy1">&gt;</span><span class="sy4">;</span></span></div>
</td>
<td class="t-dcl-nopad"></td>
<td><span class="t-mark-rev t-since-cxx20">(C++20 &#36215;)</span></td>
</tr>
<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p><code>invocable</code> &#27010;&#24565;&#25351;&#23450;&#33021;&#29992;&#20989;&#25968;&#27169;&#26495; <span class="t-lc"><a href="cpp-utility-functional-invoke.html">std::invoke</a></span> &#20197;&#21442;&#25968;&#38598; <code>Args...</code> &#35843;&#29992;&#21487;&#35843;&#29992;&#31867;&#22411; <code>F</code> &#12290;</p>
<p><code>regular_invocable</code> &#27010;&#24565;&#23545; <code>invocable</code> &#27010;&#24565;&#22686;&#21152; <code>invoke</code> &#24517;&#39035;&#20445;&#25345;&#30456;&#31561;&#24615;&#19988;&#19981;&#20462;&#25913;&#21487;&#35843;&#29992;&#23545;&#35937;&#25110;&#21442;&#25968;&#12290;</p>
<h3><span class="mw-headline" id=".E7.9B.B8.E7.AD.89.E6.80.A7.E4.BF.9D.E6.8C.81">&#30456;&#31561;&#24615;&#20445;&#25345;</span></h3>
<p>&#33509;&#34920;&#36798;&#24335;&#23545;&#32473;&#23450;&#30340;&#30456;&#31561;&#36755;&#20837;&#20135;&#29983;&#30456;&#31561;&#36755;&#20986;&#65292;&#21017;&#23427;<i>&#20445;&#25345;&#30456;&#31561;&#24615;</i>&#12290;</p>
<ul>
<li>&#34920;&#36798;&#24335;&#30340;&#36755;&#20837;&#30001;&#20854;&#25805;&#20316;&#25968;&#32452;&#25104;&#12290;</li>
<li>&#34920;&#36798;&#24335;&#30340;&#36755;&#20986;&#30001;&#20854;&#32467;&#26524;&#21644;&#34920;&#36798;&#24335;&#25152;&#20462;&#25913;&#30340;&#25152;&#26377;&#25805;&#20316;&#25968;&#65288;&#33509;&#23384;&#22312;&#65289;&#32452;&#25104;&#12290;</li>
</ul>
<p>&#22312;&#26631;&#20934;&#27010;&#24565;&#30340;&#35268;&#33539;&#20013;&#65292;&#25805;&#20316;&#25968;&#23450;&#20041;&#20026;&#20165;&#21253;&#21547;&#19979;&#21015;&#20869;&#23481;&#30340;&#26368;&#22823;&#23376;&#34920;&#36798;&#24335;&#65306;</p>
<ul>
<li><a href="cpp-language-expressions.html#.E5.88.9D.E7.AD.89.E8.A1.A8.E8.BE.BE.E5.BC.8F">&#26631;&#35782;&#34920;&#36798;&#24335;</a>&#65292;&#21450;</li>
<li>&#23545; <a href="cpp-utility-move.html"><tt>std::move</tt></a> &#12289; <span class="t-lc"><a href="cpp-utility-forward.html">std::forward</a></span> &#19982; <span class="t-lc"><a href="cpp-utility-declval.html">std::declval</a></span> &#30340;&#35843;&#29992;&#12290;</li>
</ul>
<p>&#27599;&#20010;&#25805;&#20316;&#25968;&#30340; cv &#38480;&#23450;&#19982;&#20540;&#31867;&#21035;&#65292;&#26159;&#36890;&#36807;&#20551;&#35774;&#27599;&#20010;&#27169;&#26495;&#31867;&#22411;&#24418;&#21442;&#20195;&#34920;&#19968;&#20010; cv &#26080;&#38480;&#23450;&#30340;&#38750;&#25968;&#32452;&#23545;&#35937;&#31867;&#22411;&#30830;&#23450;&#30340;&#12290;</p>
<p>&#36827;&#19968;&#27493;&#35201;&#27714;&#27599;&#20010;&#35201;&#27714;&#20445;&#25345;&#30456;&#31561;&#24615;&#30340;&#34920;&#36798;&#24335;&#37117;<i>&#31283;&#23450;</i>&#65306;&#36825;&#31181;&#34920;&#36798;&#24335;&#24102;&#30456;&#21516;&#36755;&#20837;&#23545;&#35937;&#30340;&#20108;&#27425;&#27714;&#20540;&#24517;&#39035;&#25317;&#26377;&#30456;&#31561;&#30340;&#36755;&#20986;&#65292;&#32780;&#26080;&#20219;&#20309;&#23545;&#36825;&#20123;&#36755;&#20837;&#23545;&#35937;&#30340;&#26174;&#24335;&#20013;&#38388;&#20462;&#25913;&#12290;</p>
<p>&#38500;&#38750;&#21478;&#22806;&#25552;&#37266;&#65292;&#27599;&#20010;&#29992;&#20110; <i>requires &#34920;&#36798;&#24335;</i>&#20013;&#30340;&#34920;&#36798;&#24335;&#37117;&#35201;&#27714;&#20445;&#25345;&#30456;&#31561;&#24615;&#19988;&#31283;&#23450;&#65292;&#32780;&#34920;&#36798;&#24335;&#30340;&#27714;&#20540;&#24517;&#39035;&#21482;&#20462;&#25913;&#20854;&#38750;&#24120;&#25805;&#20316;&#25968;&#12290;&#24517;&#39035;&#19981;&#20462;&#25913;&#24120;&#25805;&#20316;&#25968;&#12290;</p>
<h3><span class="mw-headline" id=".E6.B3.A8.E6.84.8F">&#27880;&#24847;</span></h3>
<p><code>invocable</code> &#19982; <code>regular_invocable</code> &#38388;&#30340;&#21306;&#21035;&#26159;&#32431;&#35821;&#20041;&#19978;&#30340;&#12290;</p>
<p>&#38543;&#26426;&#25968;&#29983;&#25104;&#22120;&#21487;&#28385;&#36275; <code>invocable</code> &#20294;&#19981;&#33021;&#28385;&#36275; <code>regular_invocable</code> &#65288;&#38500;&#20102;<a rel="nofollow" class="external text" href="https://xkcd.com/221/">&#25630;&#31505;</a><a rel="nofollow" class="external text" href="http://dilbert.com/strip/2001-10-25">&#30340;</a>&#65289;&#12290;</p>
</div>
<div class="visualClear"></div>
</div>
</div>
</div>
</body>
</html>