|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4299" status="New"> |
| 5 | +<title>Missing <i>Mandates:</i> part in <tt>optional<T&>::transform</tt></title> |
| 6 | +<section><sref ref="[optional.ref.monadic]"/></section> |
| 7 | +<submitter>Giuseppe D'Angelo</submitter> |
| 8 | +<date>15 Jul 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +In <sref ref="[optional.ref.monadic]"/> the specification of <tt>optional<T&>::transform</tt> |
| 14 | +is missing an additional part of the <i>Mandates:</i> element compared to the primary template's |
| 15 | +`transform` (in <sref ref="[optional.monadic]"/> p8; that is, is missing to enforce that |
| 16 | +the `U` type is a valid contained type for `optional`. |
| 17 | +<p/> |
| 18 | +The definition of "valid contained type" comes from <paper num="P2988R12"/>. The paper |
| 19 | +amended the <i>Mandates:</i> element of the primary template's `transform` to |
| 20 | +use this definition. The fact that the same wording has not been applied to |
| 21 | +<tt>optional<T&>::transform</tt> as well looks like an oversight. I would |
| 22 | +suggest to apply it. |
| 23 | +</p> |
| 24 | +</discussion> |
| 25 | + |
| 26 | +<resolution> |
| 27 | +<p> |
| 28 | +This wording is relative to this |
| 29 | +<a href="https://github.com/cplusplus/draft/actions/runs/16433597877/artifacts/3583518547">CD preview draft</a>. |
| 30 | +</p> |
| 31 | + |
| 32 | +<ol> |
| 33 | + |
| 34 | +<li><p>Modify <sref ref="[optional.ref.monadic]"/> as indicated:</p> |
| 35 | + |
| 36 | +<blockquote> |
| 37 | +<pre> |
| 38 | +template<class F> |
| 39 | + constexpr optional<remove_cv_t<invoke_result_t<F, T&>>> transform(F&& f) const; |
| 40 | +</pre> |
| 41 | +<blockquote> |
| 42 | +<p> |
| 43 | +-4- Let `U` be <tt>remove_cv_t<invoke_result_t<F, T&>></tt>. |
| 44 | +<p/> |
| 45 | +-5- <i>Mandates</i>: <ins>`U` is a valid contained type for `optional`.</ins> The declaration |
| 46 | +</p> |
| 47 | +<blockquote><pre> |
| 48 | +U u(invoke(std::forward<F>(f), *val )); |
| 49 | +</pre></blockquote> |
| 50 | +<p> |
| 51 | +is well-formed for some invented variable `u`. |
| 52 | +</p> |
| 53 | +</blockquote> |
| 54 | +</blockquote> |
| 55 | +</li> |
| 56 | + |
| 57 | +</ol> |
| 58 | +</resolution> |
| 59 | + |
| 60 | +</issue> |
0 commit comments