Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f2dc665

Browse files
committedMar 22, 2025·
New issue from Matthias Kretz: "simd<complex>::real/imag is overconstrained"
1 parent 337bd66 commit f2dc665

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
 

‎xml/issue4230.xml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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&lt;complex&gt;::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&lt;T&gt;::real/imag</tt> allows conversions to `T` whereas <tt>simd&lt;complex&lt;T&gt;&gt;</tt>
17+
requires basically an exact match (<tt>same_as&lt;simd&lt;T&gt;&gt;</tt> modulo ABI tag differences).
18+
</p>
19+
<blockquote><pre>
20+
complex&lt;double&gt; c = {};
21+
c.real(1.f); // OK
22+
23+
simd&lt;complex&lt;double&gt;&gt; sc = {};
24+
sc.real(simd&lt;float&gt;(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&lt;T&gt;</tt> interface. In which case
28+
the current wording doesn't match that intent. `complex` doesn't say <tt>real(same_as&lt;T&gt; 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+
[&hellip;]
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&lt;<i>simd-floating-point</i> V&gt;</del>
49+
constexpr void real(<ins><i>see below</i></ins><del>const V&amp;</del> v) noexcept;
50+
<del>template&lt;<i>simd-floating-point</i> V&gt;</del>
51+
constexpr void imag(<ins><i>see below</i></ins><del>const V&amp;</del> v) noexcept;
52+
[&hellip;]
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&lt;<i>simd-floating-point</i> V&gt;</del>
62+
constexpr void real(<ins><i>see below</i></ins><del>const V&amp;</del> v) noexcept;
63+
<del>template&lt;<i>simd-floating-point</i> V&gt;</del>
64+
constexpr void imag(<ins><i>see below</i></ins><del>const V&amp;</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) &mdash;</del> <tt><i>simd-complex</i>&lt;basic_simd&gt;</tt> is modeled<ins>.</ins><del>,</del></p></li>
72+
<li><p><del>(3.2) &mdash; <tt>same_as&lt;typename V::value_type, typename T::value_type&gt;</tt> is modeled, and</del></p></li>
73+
<li><p><del>(3.3) &mdash; `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&lt;typename T::value_type, basic_simd&lt;T, Abi&gt;&gt;&amp;</tt>.</ins>
83+
</p>
84+
</blockquote>
85+
</blockquote>
86+
</li>
87+
88+
</ol>
89+
</resolution>
90+
91+
</issue>

0 commit comments

Comments
 (0)
Please sign in to comment.