|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4230" status="New"> |
| 5 | +<title><tt>simd<complex>::real/imag</tt> is overconstrained</title> |
| 6 | +<section> |
| 7 | +<sref ref="[simd.complex.access]"/> |
| 8 | +</section> |
| 9 | +<submitter>Matthias Kretz</submitter> |
| 10 | +<date>18 Mar 2025</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<p> |
| 15 | +<sref ref="[simd.complex.access]"/> overconstrains the arguments to `real` and `imag`. |
| 16 | +<tt>complex<T>::real/imag</tt> allows conversions to `T` whereas <tt>simd<complex<T>></tt> |
| 17 | +requires basically an exact match (<tt>same_as<simd<T>></tt> modulo ABI tag differences). |
| 18 | +</p> |
| 19 | +<blockquote><pre> |
| 20 | +complex<double> c = {}; |
| 21 | +c.real(1.f); // OK |
| 22 | + |
| 23 | +simd<complex<double>> sc = {}; |
| 24 | +sc.real(simd<float>(1.f)); // <span style="color:red;font-weight:bolder">ill-formed, should be allowed</span> |
| 25 | +</pre></blockquote> |
| 26 | +<p> |
| 27 | +The design intent was to match the <tt>std::complex<T></tt> interface. In which case |
| 28 | +the current wording doesn't match that intent. `complex` doesn't say <tt>real(same_as<T> auto)</tt> |
| 29 | +but 'real(T)', which allows conversions. |
| 30 | +</p> |
| 31 | +</discussion> |
| 32 | + |
| 33 | +<resolution> |
| 34 | +<p> |
| 35 | +This wording is relative to <paper num="N5008"/>. |
| 36 | +</p> |
| 37 | + |
| 38 | +<ol> |
| 39 | + |
| 40 | +<li><p>Modify <sref ref="[simd.overview]"/>, class template `basic_simd` synopsis, as indicated:</p> |
| 41 | + |
| 42 | +<blockquote> |
| 43 | +<pre> |
| 44 | +[…] |
| 45 | +<i>// <sref ref="[simd.complex.access]"/>, basic_simd complex-value accessors</i> |
| 46 | +constexpr auto real() const noexcept; |
| 47 | +constexpr auto imag() const noexcept; |
| 48 | +<del>template<<i>simd-floating-point</i> V></del> |
| 49 | + constexpr void real(<ins><i>see below</i></ins><del>const V&</del> v) noexcept; |
| 50 | +<del>template<<i>simd-floating-point</i> V></del> |
| 51 | + constexpr void imag(<ins><i>see below</i></ins><del>const V&</del> v) noexcept; |
| 52 | +[…] |
| 53 | +</pre> |
| 54 | +</blockquote> |
| 55 | +</li> |
| 56 | + |
| 57 | +<li><p>Modify <sref ref="[simd.complex.access]"/> as indicated:</p> |
| 58 | + |
| 59 | +<blockquote> |
| 60 | +<pre> |
| 61 | +<del>template<<i>simd-floating-point</i> V></del> |
| 62 | + constexpr void real(<ins><i>see below</i></ins><del>const V&</del> v) noexcept; |
| 63 | +<del>template<<i>simd-floating-point</i> V></del> |
| 64 | + constexpr void imag(<ins><i>see below</i></ins><del>const V&</del> v) noexcept; |
| 65 | +</pre> |
| 66 | +<blockquote> |
| 67 | +<p> |
| 68 | +-3- <i>Constraints</i>: |
| 69 | +</p> |
| 70 | +<ol style="list-style-type: none"> |
| 71 | +<li><p><del>(3.1) —</del> <tt><i>simd-complex</i><basic_simd></tt> is modeled<ins>.</ins><del>,</del></p></li> |
| 72 | +<li><p><del>(3.2) — <tt>same_as<typename V::value_type, typename T::value_type></tt> is modeled, and</del></p></li> |
| 73 | +<li><p><del>(3.3) — `V::size() == size()` is `true`.</del></p></li> |
| 74 | +</ol> |
| 75 | +<p> |
| 76 | +-4- <i>Effects</i>: Replaces each element of the `basic_simd` object such that the <tt><i>i</i></tt><sup>th</sup> |
| 77 | +element is replaced with <tt>value_type(v[<i>i</i>], operator[](<i>i</i>).imag())</tt> or |
| 78 | +<tt>value_type(operator[](<i>i</i>).real(), v[<i>i</i>])</tt> for `real` and `imag` respectively, |
| 79 | +for all <tt><i>i</i></tt> in the range `[0, size())`. |
| 80 | +<p/> |
| 81 | +<ins>-?- <i>Remarks</i>: The type of argument `v` is |
| 82 | +<tt>const rebind_t<typename T::value_type, basic_simd<T, Abi>>&</tt>.</ins> |
| 83 | +</p> |
| 84 | +</blockquote> |
| 85 | +</blockquote> |
| 86 | +</li> |
| 87 | + |
| 88 | +</ol> |
| 89 | +</resolution> |
| 90 | + |
| 91 | +</issue> |
0 commit comments