<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4208: Wording needs to ensure that in connect(sndr, rcvr) that rcvr expression is only evaluated once</title>
<meta property="og:title" content="Issue 4208: Wording needs to ensure that in connect(sndr, rcvr) that rcvr expression is only evaluated once">
<meta property="og:description" content="C++ library issue. Status: WP">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4208.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#WP">WP</a> status.</em></p>
<h3 id="4208"><a href="lwg-defects.html#4208">4208</a>. Wording needs to ensure that in <code class='backtick'>connect(sndr, rcvr)</code> that <code class='backtick'>rcvr</code> expression is only evaluated once</h3>
<p><b>Section:</b> 33.9.10 <a href="https://wg21.link/exec.connect">[exec.connect]</a> <b>Status:</b> <a href="lwg-active.html#WP">WP</a>
 <b>Submitter:</b> Eric Niebler <b>Opened:</b> 2025-02-07 <b>Last modified:</b> 2025-06-23</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#exec.connect">active issues</a> in [exec.connect].</p>
<p><b>View all other</b> <a href="lwg-index.html#exec.connect">issues</a> in [exec.connect].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#WP">WP</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Imported from <a href="https://github.com/cplusplus/sender-receiver/issues/325">cplusplus/sender-receiver #325</a>.
</p>
<p>
The current wording of <code class='backtick'>connect(sndr, rcvr)</code> defines the <code class='backtick'>new_sndr</code> expression as 
<code>transform_sender(decltype(<i>get-domain-late</i>(sndr, get_env(rcvr))){}, sndr, get_env(rcvr))</code>.
<p/>
It then defines <code class='backtick'>connect(sndr, rcvr)</code> as expression equivalent to <code class='backtick'>new_sndr.connect(rcvr)</code>.
<p/>
As currently worded, this requires evaluating the <code class='backtick'>rcvr</code> expression twice. Note that the first
usage in the <code class='backtick'>new_sndr</code> expression is unevaluated, but the second usage in <code class='backtick'>get_env(rcvr)</code> is evaluated.
<p/>
I think we need to add an extra sentence at the end of this section saying "Where the expression 
<code class='backtick'>rcvr</code> is only evaluated once." or similar.
</p>

<p><i>[Hagenberg 2025-02-11; move to Ready]</i></p>


<p><i>[Sofia 2025-06-21; Status changed: Voting &rarr; WP.]</i></p>



<p id="res-4208"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N5001" title=" Working Draft, Programming Languages — C++">N5001</a>.
</p>

<ol>
<li>
<p>Modify 33.9.10 <a href="https://wg21.link/exec.connect">[exec.connect]</a> as indicated:</p>

<blockquote>
<p>
-6- The expression <code class='backtick'>connect(sndr, rcvr)</code> is expression-equivalent to:
</p>
<ol style="list-style-type: none">
<li><p>(6.1) &mdash; <code class='backtick'>new_sndr.connect(rcvr)</code> if that expression is well-formed.
<p/>
<i>Mandates</i>: The type of the expression above satisfies <code class='backtick'>operation_state</code>.
</p>
</li>
<li><p>(6.2) &mdash; Otherwise, <code><i>connect-awaitable</i>(new_sndr, rcvr)</code>.</p></li>
</ol>
<p>
<ins>except that <code class='backtick'>rcvr</code> is evaluated only once.</ins>
<p/>
<i>Mandates</i>: <code>sender&lt;Sndr&gt; &amp;&amp; receiver&lt;Rcvr&gt;</code> is <code>true</code>.
<p/>
</p>
</blockquote>
</li>
</ol>






</body>
</html>
