Skip to content

Commit fd74a9f

Browse files
committed
New issue from Hewill: "Ambiguities of simd::basic_vec constructor"
1 parent 5e4e2c4 commit fd74a9f

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

xml/issue4391.xml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4391" status="New">
5+
<title>Ambiguities of `simd::basic_vec` constructor</title>
6+
<section><sref ref="[simd.ctor]"/></section>
7+
<submitter>Hewill Kang</submitter>
8+
<date>29 Sep 2025</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
The broadcasting, generator-based, and range constructors of `simd::basic_vec` all take a single
14+
argument, and their constraints are not mutually exclusive.
15+
<p/>
16+
This means that when a type satisfies both characteristics, such as a range that can be converted to a
17+
`value_type`, this will lead to ambiguity:
18+
</p>
19+
<blockquote>
20+
<pre>
21+
#include &lt;simd&gt;
22+
23+
struct S {
24+
operator double() const; // basic_vec(U&amp;&amp; value)
25+
26+
double operator()(int) const; // basic_vec(G&amp;&amp; gen)
27+
28+
double* begin() const; // basic_vec(R&amp;&amp; r, flags&lt;Flags...&gt; = {});
29+
double* end() const;
30+
constexpr static int size() { return 2; }
31+
};
32+
33+
int main() {
34+
std::simd::vec&lt;double&gt; simd(S{}); // <span style="color:#C80000;font-weight:bold">error: call of overloaded 'basic_simd(S)' is ambiguous</span>
35+
}
36+
</pre>
37+
</blockquote>
38+
<p>
39+
Do we need more constraints, similar to the one in <code>string_view(R&amp;&amp; r)</code> that requires
40+
`R` not to be convertible to `const char*`, to make the above work, i.e., only invoke the
41+
broadcasting constructor?
42+
</p>
43+
</discussion>
44+
45+
<resolution>
46+
<p>
47+
This wording is relative to <paper num="N5014"/>.
48+
</p>
49+
50+
<ol>
51+
52+
53+
<li><p>Modify <sref ref="[simd.ctor]"/> as indicated:</p>
54+
55+
<blockquote>
56+
<pre>
57+
template&lt;class G&gt; constexpr explicit basic_vec(G&amp;&amp; gen);
58+
</pre>
59+
<blockquote>
60+
<p>
61+
-8- Let <tt>From<sub><i>i</i></sub></tt> denote the type
62+
<code>decltype(gen(integral_constant&lt;<i>simd-size-type</i>, <i>i</i>&gt;()))</code>.
63+
<p/>
64+
-9- <i>Constraints</i>:
65+
</p>
66+
<ol style="list-style-type: none">
67+
<li><p>
68+
<ins>(9.?) &mdash; <code>constructible_from&lt;value_type, G&gt;</code> is <code>false</code>.</ins>
69+
</p></li>
70+
<li><p>
71+
<ins>(9.?) &mdash;</ins>
72+
<tt>From<sub><i>i</i></sub></tt> satisfies <code>convertible_to&lt;value_type&gt;</code> for all
73+
<tt><i>i</i></tt> in the range of [<code>0, size()</code>). In addition, for all <i>i</i> in the range of
74+
[<code>0, size()</code>), if <tt>From<sub><i>i</i></sub></tt> is an arithmetic type, conversion from
75+
<tt>From<sub><i>i</i></sub></tt> to <code>value_type</code> is value-preserving.</p>
76+
</li>
77+
</ol>
78+
</blockquote>
79+
[&hellip;]
80+
<pre>
81+
template&lt;class R, class... Flags&gt;
82+
constexpr basic_vec(R&amp;&amp; r, flags&lt;Flags...&gt; = {});
83+
template&lt;class R, class... Flags&gt;
84+
constexpr basic_vec(R&amp;&amp; r, const mask_type&amp; mask, flags&lt;Flags...&gt; = {});
85+
</pre>
86+
<blockquote>
87+
<p>
88+
-12- Let mask be `mask_type(true)` for the overload with no `mask` parameter.
89+
<p/>
90+
-13- <i>Constraints</i>:
91+
</p>
92+
<ol style="list-style-type: none">
93+
<li><p>
94+
(13.1) &mdash; `R` models `ranges::contiguous_range` and `ranges::sized_range`,
95+
</p></li>
96+
<li><p>
97+
(13.2) &mdash; `ranges::size(r)` is a constant expression, <del>and</del>
98+
</p></li>
99+
<li><p>
100+
(13.3) &mdash; `ranges::size(r)` is equal to `size()`<del>.</del><ins>,</ins>
101+
</p></li>
102+
<li><p>
103+
<ins>(13.?) &mdash; <code>constructible_from&lt;value_type, R&gt;</code> is `false`, and</ins>
104+
</p></li>
105+
<li><p>
106+
<ins>(13.?) &mdash; <code>r(integral_constant&lt;<i>simd-size-type</i>, 0&gt;())</code> is not a valid
107+
expression.</ins>
108+
</p></li>
109+
</ol>
110+
</blockquote>
111+
</blockquote>
112+
</li>
113+
</ol>
114+
115+
</resolution>
116+
117+
</issue>

0 commit comments

Comments
 (0)