|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4373" status="New"> |
| 5 | +<title>`function_ref` should provide `result_type`</title> |
| 6 | +<section> |
| 7 | +<sref ref="[func.wrap.ref.class]"/> |
| 8 | +</section> |
| 9 | +<submitter>Hewill Kang</submitter> |
| 10 | +<date>12 Sep 2025</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<p> |
| 15 | +Currently, `function`, `move_only_function`, and `copyable_function` all have a |
| 16 | +type member `result_type`, but `function_ref` does not: |
| 17 | +</p> |
| 18 | +<blockquote> |
| 19 | +<pre> |
| 20 | +static_assert(is_same_v< function <int(int)>::result_type, int>); |
| 21 | +static_assert(is_same_v<move_only_function <int(int)>::result_type, int>); |
| 22 | +static_assert(is_same_v< copyable_function <int(int)>::result_type, int>); |
| 23 | +static_assert(is_same_v< function_ref<int(int)>::result_type, int>); // <span style="color:#C80000;font-weight:bold">error</span> |
| 24 | +</pre> |
| 25 | +</blockquote> |
| 26 | +<p> |
| 27 | +It seems worthwhile to also provide it for the latter, as it is consistent with the other |
| 28 | +wrappers and allows the user to easily extract the return type. |
| 29 | +</p> |
| 30 | +</discussion> |
| 31 | + |
| 32 | +<resolution> |
| 33 | +<p> |
| 34 | +This wording is relative to <paper num="N5014"/>. |
| 35 | +</p> |
| 36 | + |
| 37 | +<ol> |
| 38 | + |
| 39 | +<li><p>Modify <sref ref="[func.wrap.ref.class]"/> as indicated:</p> |
| 40 | + |
| 41 | +<blockquote> |
| 42 | +<pre> |
| 43 | +namespace std { |
| 44 | + template<class R, class... ArgTypes> |
| 45 | + class function_ref<R(ArgTypes...) <i>cv</i> noexcept(<i>noex</i>)> { |
| 46 | + public: |
| 47 | + <ins>using result_type = R;</ins> |
| 48 | + |
| 49 | + // <i><sref ref="[func.wrap.ref.ctor]"/>, constructors and assignment operators</i> |
| 50 | + template<class F> function_ref(F*) noexcept; |
| 51 | + […] |
| 52 | + }; |
| 53 | + |
| 54 | +} |
| 55 | +</pre> |
| 56 | +</blockquote> |
| 57 | + |
| 58 | +</li> |
| 59 | + |
| 60 | +</ol></resolution> |
| 61 | + |
| 62 | +</issue> |
0 commit comments