|
| 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 <simd> |
| 22 | + |
| 23 | +struct S { |
| 24 | + operator double() const; // basic_vec(U&& value) |
| 25 | + |
| 26 | + double operator()(int) const; // basic_vec(G&& gen) |
| 27 | + |
| 28 | + double* begin() const; // basic_vec(R&& r, flags<Flags...> = {}); |
| 29 | + double* end() const; |
| 30 | + constexpr static int size() { return 2; } |
| 31 | +}; |
| 32 | + |
| 33 | +int main() { |
| 34 | + std::simd::vec<double> 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&& 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<class G> constexpr explicit basic_vec(G&& 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<<i>simd-size-type</i>, <i>i</i>>()))</code>. |
| 63 | +<p/> |
| 64 | +-9- <i>Constraints</i>: |
| 65 | +</p> |
| 66 | +<ol style="list-style-type: none"> |
| 67 | + <li><p> |
| 68 | + <ins>(9.?) — <code>constructible_from<value_type, G></code> is <code>false</code>.</ins> |
| 69 | + </p></li> |
| 70 | + <li><p> |
| 71 | + <ins>(9.?) —</ins> |
| 72 | + <tt>From<sub><i>i</i></sub></tt> satisfies <code>convertible_to<value_type></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 | +[…] |
| 80 | +<pre> |
| 81 | +template<class R, class... Flags> |
| 82 | + constexpr basic_vec(R&& r, flags<Flags...> = {}); |
| 83 | +template<class R, class... Flags> |
| 84 | + constexpr basic_vec(R&& r, const mask_type& mask, flags<Flags...> = {}); |
| 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) — `R` models `ranges::contiguous_range` and `ranges::sized_range`, |
| 95 | + </p></li> |
| 96 | + <li><p> |
| 97 | + (13.2) — `ranges::size(r)` is a constant expression, <del>and</del> |
| 98 | + </p></li> |
| 99 | + <li><p> |
| 100 | + (13.3) — `ranges::size(r)` is equal to `size()`<del>.</del><ins>,</ins> |
| 101 | + </p></li> |
| 102 | + <li><p> |
| 103 | + <ins>(13.?) — <code>constructible_from<value_type, R></code> is `false`, and</ins> |
| 104 | + </p></li> |
| 105 | + <li><p> |
| 106 | + <ins>(13.?) — <code>r(integral_constant<<i>simd-size-type</i>, 0>())</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