|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4362" status="New"> |
| 5 | +<title>Inconsistent usage of `constexpr` for `inplace_stop_token` and `inplace_stop_source`</title> |
| 6 | +<section> |
| 7 | +<sref ref="[stoptoken.inplace]"/> |
| 8 | +</section> |
| 9 | +<submitter>Lewis Baker</submitter> |
| 10 | +<date>28 Aug 2025</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<p> |
| 15 | +The `inplace_stop_source::get_token()` member function is declared `constexpr`, |
| 16 | +but there are no `constexpr` member-functions declared on `inplace_stop_token`, |
| 17 | +making the utility of being able to call this member function during constant |
| 18 | +evaluation limited. |
| 19 | +<p/> |
| 20 | +Should the member functions of `inplace_stop_token` also be declared `constexpr`? |
| 21 | +i.e. `operator==`, `swap()`, `stop_possible()` and `stop_requested()`. |
| 22 | +<p/> |
| 23 | +The `operator==` and `stop_possible()` and `swap()` member functions should be |
| 24 | +able to be made `constexpr` trivially as they are just required to compare/modify |
| 25 | +pointers to the associated stop source. |
| 26 | +<p/> |
| 27 | +The `stop_requested()` member function is specified to be equivalent to calling |
| 28 | +`stop_requested()` on the associated `inplace_stop_source` (if any), which is not |
| 29 | +currently declared `constexpr` primarily because its implementation requires |
| 30 | +synchronisation/atomic operations. |
| 31 | +<p/> |
| 32 | +Now that `std::atomic` operations are now `constexpr`, it may be possible/appropriate |
| 33 | +for `stop_requested()` on both `inplace_stop_source` and `inplace_stop_token` to also |
| 34 | +be declared `constexpr`. |
| 35 | +</p> |
| 36 | +</discussion> |
| 37 | + |
| 38 | +<resolution> |
| 39 | +<p> |
| 40 | +This wording is relative to <paper num="N5014"/>. |
| 41 | +</p> |
| 42 | + |
| 43 | +<blockquote class="note"> |
| 44 | +<p> |
| 45 | +[<i>Drafting note:</i>: This is the minimum proposed wording change. Additionally, consider adding |
| 46 | +`constexpr` to the declaration of `inplace_stop_token::stop_requested()` (in |
| 47 | +<sref ref="[stoptoken.inplace.general]"/> and <sref ref="[stoptoken.inplace.mem]"/>) and to |
| 48 | +`inplace_stop_source::stop_requested()` (in <sref ref="[stopsource.inplace.general]"/> and |
| 49 | +<sref ref="[stopsource.inplace.mem]"/>)] |
| 50 | +</p> |
| 51 | +</blockquote> |
| 52 | + |
| 53 | +<ol> |
| 54 | + |
| 55 | +<li><p>Modify <sref ref="[stoptoken.inplace.general]"/>, class `inplace_stop_token` synopsis, as indicated:</p> |
| 56 | + |
| 57 | +<blockquote><pre> |
| 58 | +namespace std { |
| 59 | + class inplace_stop_token { |
| 60 | + public: |
| 61 | + template<class CallbackFn> |
| 62 | + using callback_type = inplace_stop_callback<CallbackFn>; |
| 63 | + |
| 64 | + <ins>constexpr</ins> inplace_stop_token() = default; |
| 65 | + <ins>constexpr</ins> bool operator==(const inplace_stop_token&) const = default; |
| 66 | + |
| 67 | + // <i><sref ref="[stoptoken.inplace.mem]"/>, member functions</i> |
| 68 | + bool stop_requested() const noexcept; |
| 69 | + <ins>constexpr</ins> bool stop_possible() const noexcept; |
| 70 | + <ins>constexpr</ins> void swap(inplace_stop_token&) noexcept; |
| 71 | + |
| 72 | + private: |
| 73 | + const inplace_stop_source* <i>stop-source</i> = nullptr; // <i>exposition only</i> |
| 74 | + }; |
| 75 | +} |
| 76 | +</pre></blockquote> |
| 77 | + |
| 78 | +</li> |
| 79 | + |
| 80 | + |
| 81 | +<li><p>Modify <sref ref="[stoptoken.inplace.mem]"/> as indicated:</p> |
| 82 | + |
| 83 | +<blockquote class="note"> |
| 84 | +<p> |
| 85 | +[<i>Drafting note:</i>: As a drive-by fix this adds the missing return type `bool` to the |
| 86 | +`stop_possible()` prototype] |
| 87 | +</p> |
| 88 | +</blockquote> |
| 89 | + |
| 90 | +<blockquote> |
| 91 | +<pre> |
| 92 | +<ins>constexpr</ins> void swap(inplace_stop_token& rhs) noexcept; |
| 93 | +</pre> |
| 94 | +<blockquote> |
| 95 | +<p> |
| 96 | +-1- <i>Effects</i>: Exchanges the values of <tt><i>stop-source</i></tt> and <tt>rhs.<i>stop-source</i></tt>. |
| 97 | +</p> |
| 98 | +</blockquote> |
| 99 | +[…] |
| 100 | +<pre> |
| 101 | +<ins>constexpr bool</ins> stop_possible() const noexcept; |
| 102 | +</pre> |
| 103 | +<blockquote> |
| 104 | +<p> |
| 105 | +-4- <i>Returns</i>: <tt><i>stop-source</i> != nullptr</tt>. |
| 106 | +</p> |
| 107 | +</blockquote> |
| 108 | + |
| 109 | +</blockquote> |
| 110 | + |
| 111 | +</li> |
| 112 | + |
| 113 | +</ol> |
| 114 | +</resolution> |
| 115 | + |
| 116 | +</issue> |
0 commit comments