|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4209" status="New"> |
| 5 | +<title><tt>default_domain::transform_env</tt> should be returning <tt><i>FWD-ENV</i>(env)</tt></title> |
| 6 | +<section><sref ref="[exec.domain.default]"/></section> |
| 7 | +<submitter>Eric Niebler</submitter> |
| 8 | +<date>07 Feb 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +Imported from <a href="https://github.com/cplusplus/sender-receiver/issues/168">cplusplus/sender-receiver #168</a>. |
| 14 | +</p> |
| 15 | +<p> |
| 16 | +When writing a generic recursive sender transform, you need to ability to unpack an unknown sender |
| 17 | +`S` and recursively transform the children. |
| 18 | +<p/> |
| 19 | +For that, it can be useful to know the type of the environment that `S` will use when connecting its |
| 20 | +child senders, which is why `transform_env` exists. |
| 21 | +<p/> |
| 22 | +For an environment `E` and a sender `S` with tag `T` child `C`, the expression |
| 23 | +`default_domain().transform_env(S, E)` should return an environment `E2` that is identical to the |
| 24 | +environment of the receiver that `S` uses to connect `C`. |
| 25 | +<p/> |
| 26 | +`default_domain().transform_env(S, E)` will first check whether `T().transform_env(S, E)` is |
| 27 | +well-formed. If so, it will return that (e.g. `when_all_t` has a `transform_env` that adds a stop token |
| 28 | +to the environment). |
| 29 | +<p/> |
| 30 | +If `T().transform_env(S, E)` is not well-formed, what should `default_domain::transform_env` do? At |
| 31 | +present, it returns `E` unmodified. |
| 32 | +<p/> |
| 33 | +But <sref ref="[exec.adapt.general]"/> has this: |
| 34 | +</p> |
| 35 | +<blockquote style="border-left: 3px solid #ccc;padding-left: 15px;"> |
| 36 | +<p> |
| 37 | +[unless otherwise specified, when] a parent sender is connected to a receiver `rcvr`, any receiver used |
| 38 | +to connect a child sender has an associated environment equal to <tt><i>FWD-ENV</i>(get_env(rcvr))</tt>. |
| 39 | +</p> |
| 40 | +</blockquote> |
| 41 | +<p> |
| 42 | +So the correct thing for `default_domain::transform_env` to do is to return <tt><i>FWD-ENV</i>(get_env(rcvr))</tt>. |
| 43 | +</p> |
| 44 | +</discussion> |
| 45 | + |
| 46 | +<resolution> |
| 47 | +<p> |
| 48 | +This wording is relative to <paper num="N5001"/>. |
| 49 | +</p> |
| 50 | + |
| 51 | +<ol> |
| 52 | +<li> |
| 53 | +<p>Modify <sref ref="[exec.domain.default]"/> as indicated:</p> |
| 54 | + |
| 55 | +<blockquote> |
| 56 | +<pre> |
| 57 | +template<sender Sndr, <i>queryable</i> Env> |
| 58 | + constexpr <i>queryable</i> decltype(auto) transform_env(Sndr&& sndr, Env&& env) noexcept; |
| 59 | +</pre> |
| 60 | +<blockquote> |
| 61 | +<p> |
| 62 | +-5- Let `e` be the expression |
| 63 | +</p> |
| 64 | +<blockquote><pre> |
| 65 | +tag_of_t<Sndr>().transform_env(std::forward<Sndr>(sndr), std::forward<Env>(env)) |
| 66 | +</pre></blockquote> |
| 67 | +<p> |
| 68 | +if that expression is well-formed; otherwise, <tt><del>static_cast<Env></del><ins><i>FWD-ENV</i></ins>(std::forward<Env>(env))</tt>. |
| 69 | +<p/> |
| 70 | +-6- <i>Mandates</i>: `noexcept(e)` is `true`. |
| 71 | +<p/> |
| 72 | +-7- <i>Returns</i>: `e`. |
| 73 | +</p> |
| 74 | +</blockquote> |
| 75 | +</blockquote> |
| 76 | +</li> |
| 77 | +</ol> |
| 78 | + |
| 79 | +</resolution> |
| 80 | + |
| 81 | +</issue> |
0 commit comments