<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2690: invoke&lt;R&gt;</title>
<meta property="og:title" content="Issue 2690: invoke&lt;R&gt;">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2690.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#Resolved">Resolved</a> status.</em></p>
<h3 id="2690"><a href="lwg-defects.html#2690">2690</a>. <code>invoke&lt;R&gt;</code></h3>
<p><b>Section:</b> 22.10.5 <a href="https://wg21.link/func.invoke">[func.invoke]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Zhihao Yuan <b>Opened:</b> 2016-03-25 <b>Last modified:</b> 2021-06-12</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#func.invoke">issues</a> in [func.invoke].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In <a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4169.html">N4169</a>
the author dropped the <code>invoke&lt;R&gt;</code> support by claiming
that it's an unnecessary cruft in TR1, obsoleted by C++11
type inference.  But now we have some new business went
to *<code><i>INVOKE</i></code>*<code>(f, t1, t2, ..., tN, R)</code>, that is to discard the
return type when <code>R</code> is <code>void</code>. This form is very useful, or
possible even more useful than the basic form when
implementing a call wrapper. Also note that the optional
<code>R</code> support is already in <code>std::is_callable</code> and
<code>std::is_nothrow_callable</code>.
</p>

<p><i>[2016-07-31, Tomasz Kami&nacute;ski comments]</i></p>

<p>
The lack of <code>invoke&lt;R&gt;</code> was basically a result of the concurrent publication of the never revision 
of the paper and additional special semantics of <code><i>INVOKE</i>(f, args..., void)</code>.
<p/>
In contrast to existing <code>std::invoke</code> function, the proposed <code>invoke&lt;R&gt;</code> version is not 
SFINAE friendly, as elimination of the standard version of invoke is guaranteed by <code>std::result_of_t</code> 
in the result type that is missing for proposed <code>invoke&lt;R&gt;</code> version. To provide this guarantee, 
following remarks shall be added to the specification:
</p>
<blockquote>
<p>
<i>Remarks:</i> This function shall not participate in overload resolution unless 
<code>is_callable_v&lt;F(Args...), R&gt;</code> is <code>true</code>.
</p>
</blockquote>

<p><i>[2016-08-01, Tomasz Kami&nacute;ski and Zhihao Yuan update the proposed wording]</i></p>


<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to N4606.
</p>
<ol>
<li><p>Modify 22.10 <a href="https://wg21.link/function.objects">[function.objects]</a>/2, header <code>&lt;functional&gt;</code> synopsis, as indicated:</p>

<blockquote>
<pre>
namespace std {
  <i>// 20.12.3, invoke:</i>
  template &lt;class F, class... Args&gt; result_of_t&lt;F&amp;&amp;(Args&amp;&amp;...)&gt; invoke(F&amp;&amp; f, Args&amp;&amp;... args);
  <ins>template &lt;class R, class F, class... Args&gt; R invoke(F&amp;&amp; f, Args&amp;&amp;... args);</ins>
</pre>
</blockquote>
</li>

<li><p>Add the following sequence of paragraphs after 22.10.5 <a href="https://wg21.link/func.invoke">[func.invoke]</a>/1 as indicated:</p>

<blockquote>
<pre>
<ins>template &lt;class R, class F, class... Args&gt; R invoke(F&amp;&amp; f, Args&amp;&amp;... args);</ins>
</pre>
<blockquote>
<p>
<ins>-?- <i>Returns</i>: <code><i>INVOKE</i>(std::forward&lt;F&gt;(f), std::forward&lt;Args&gt;(args)..., R)</code> 
(22.10.4 <a href="https://wg21.link/func.require">[func.require]</a>).</ins>
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless 
<code>is_callable_v&lt;F(Args...), R&gt;</code> is <code>true</code>.</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2016-09-04, Tomasz Kami&nacute;ski comments and improves wording]</i></p>

<p>
The usage of <code>is_callable_v&lt;F(Args...), R&gt;</code> causes problem in situation when either <code>F</code> or <code>Args</code> 
is an abstract type and the function type <code>F(Args...)</code> cannot be formed or when one of the args is <i>cv</i>-qualified, 
as top-level <i>cv</i>-qualification for function parameters is dropped by language rules. It should use 
<code>is_callable_v&lt;F&amp;&amp;(Args&amp;&amp;...), R&gt;</code> instead.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to N4606.
</p>
<ol>
<li><p>Modify 22.10 <a href="https://wg21.link/function.objects">[function.objects]</a>/2, header <code>&lt;functional&gt;</code> synopsis, as indicated:</p>

<blockquote>
<pre>
namespace std {
  <i>// 20.12.3, invoke:</i>
  template &lt;class F, class... Args&gt; result_of_t&lt;F&amp;&amp;(Args&amp;&amp;...)&gt; invoke(F&amp;&amp; f, Args&amp;&amp;... args);
  <ins>template &lt;class R, class F, class... Args&gt; R invoke(F&amp;&amp; f, Args&amp;&amp;... args);</ins>
</pre>
</blockquote>
</li>

<li><p>Add the following sequence of paragraphs after 22.10.5 <a href="https://wg21.link/func.invoke">[func.invoke]</a>/1 as indicated:</p>

<blockquote>
<pre>
<ins>template &lt;class R, class F, class... Args&gt; R invoke(F&amp;&amp; f, Args&amp;&amp;... args);</ins>
</pre>
<blockquote>
<p>
<ins>-?- <i>Returns</i>: <code><i>INVOKE</i>(std::forward&lt;F&gt;(f), std::forward&lt;Args&gt;(args)..., R)</code> 
(22.10.4 <a href="https://wg21.link/func.require">[func.require]</a>).</ins>
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless 
<code>is_callable_v&lt;F&amp;&amp;(Args&amp;&amp;...), R&gt;</code> is <code>true</code>.</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2018-08-22, Zhihao Yuan provides improved wording]</i></p>


<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
<p>This wording is relative to <a href="https://wg21.link/n4762">N4762</a>.</p>
</p>

<ol>
<li><p>Modify 22.10.2 <a href="https://wg21.link/functional.syn">[functional.syn]</a>, header <code>&lt;functional&gt;</code> synopsis, as indicated:</p>

<blockquote>
<pre>
namespace std {
  <i>// 22.10.5 <a href="https://wg21.link/func.invoke">[func.invoke]</a>, invoke</i>
  template&lt;class F, class... Args&gt;
    invoke_result_t&lt;F, Args...&gt; invoke(F&amp;&amp; f, Args&amp;&amp;... args)
      noexcept(is_nothrow_invocable_v&lt;F, Args...&gt;);
  <ins>template &lt;class R, class F, class... Args&gt;
    R invoke(F&amp;&amp; f, Args&amp;&amp;... args)
      noexcept(is_nothrow_invocable_r_v&lt;R, F, Args...&gt;);</ins>
</pre>
</blockquote>
</li>

<li><p>Add the following sequence of paragraphs after 22.10.5 <a href="https://wg21.link/func.invoke">[func.invoke]</a>/1 as indicated:</p>

<blockquote>
<pre>
<ins>template &lt;class R, class F, class... Args&gt;
  R invoke(F&amp;&amp; f, Args&amp;&amp;... args)
    noexcept(is_nothrow_invocable_r_v&lt;R, F, Args...&gt;);</ins>
</pre>
<blockquote>
<p>
<ins>-?- <i>Constraints</i>: <code>is_invocable_r_v&lt;R, F, Args...&gt;</code>.</ins>
<p/>
<ins>-?- <i>Returns:</i> <code><i>INVOKE</i>&lt;R&gt;(std::forward&lt;F&gt;(f), std::forward&lt;Args&gt;(args)...)</code> 
(22.10.4 <a href="https://wg21.link/func.require">[func.require]</a>).</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2021-06-12; Resolved by accepting <a href="https://wg21.link/P2136R3" title=" invoke_r">P2136R3</a>.]</i></p>



<p id="res-2690"><b>Proposed resolution:</b></p>
<p>
<p>This wording is relative to <a href="https://wg21.link/n4849">N4849</a>.</p>
</p>

<ol>
<li><p>Modify 22.10.2 <a href="https://wg21.link/functional.syn">[functional.syn]</a>, header <code>&lt;functional&gt;</code> synopsis, as indicated:</p>

<blockquote>
<pre>
namespace std {
  <i>// 22.10.5 <a href="https://wg21.link/func.invoke">[func.invoke]</a>, invoke</i>
  template&lt;class F, class... Args&gt;
    constexpr invoke_result_t&lt;F, Args...&gt; invoke(F&amp;&amp; f, Args&amp;&amp;... args)
      noexcept(is_nothrow_invocable_v&lt;F, Args...&gt;);
  <ins>template &lt;class R, class F, class... Args&gt;
    constexpr R invoke(F&amp;&amp; f, Args&amp;&amp;... args)
      noexcept(is_nothrow_invocable_r_v&lt;R, F, Args...&gt;);</ins>
</pre>
</blockquote>
</li>

<li><p>Add the following sequence of paragraphs after 22.10.5 <a href="https://wg21.link/func.invoke">[func.invoke]</a>/1 as indicated:</p>

<blockquote>
<pre>
<ins>template &lt;class R, class F, class... Args&gt;
  constexpr R invoke(F&amp;&amp; f, Args&amp;&amp;... args)
    noexcept(is_nothrow_invocable_r_v&lt;R, F, Args...&gt;);</ins>
</pre>
<blockquote>
<p>
<ins>-?- <i>Constraints</i>: <code>is_invocable_r_v&lt;R, F, Args...&gt;</code>.</ins>
<p/>
<ins>-?- <i>Returns:</i> <code><i>INVOKE</i>&lt;R&gt;(std::forward&lt;F&gt;(f), std::forward&lt;Args&gt;(args)...)</code> 
(22.10.4 <a href="https://wg21.link/func.require">[func.require]</a>).</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
