This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
simd::basic_vec
constructorSection: 29.10.7.2 [simd.ctor] Status: New Submitter: Hewill Kang Opened: 2025-09-29 Last modified: 2025-10-03
Priority: Not Prioritized
View other active issues in [simd.ctor].
View all other issues in [simd.ctor].
View all issues with New status.
Discussion:
The broadcasting, generator-based, and range constructors of simd::basic_vec
all take a single
argument, and their constraints are not mutually exclusive.
value_type
, this will lead to ambiguity:
#include <simd>
struct S {
operator double() const; // basic_vec(U&& value)
double operator()(int) const; // basic_vec(G&& gen)
double* begin() const; // basic_vec(R&& r, flags<Flags...> = {});
double* end() const;
constexpr static int size() { return 2; }
};
int main() {
std::simd::vec<double> simd(S{}); // error: call of overloaded 'basic_simd(S)' is ambiguous
}
Do we need more constraints, similar to the one in string_view(R&& r)
that requires
R
not to be convertible to const char*
, to make the above work, i.e., only invoke the
broadcasting constructor?
Proposed resolution:
This wording is relative to N5014.
Modify 29.10.7.2 [simd.ctor] as indicated:
template<class G> constexpr explicit basic_vec(G&& gen);[…]-8- Let
-9- Constraints:Fromi
denote the typedecltype(gen(integral_constant<simd-size-type, i>()))
.
(9.?) —
constructible_from<value_type, G>
isfalse
.(9.?) —
Fromi
satisfiesconvertible_to<value_type>
for alli
in the range of [0, size()
). In addition, for all i in the range of [0, size()
), ifFromi
is an arithmetic type, conversion fromFromi
tovalue_type
is value-preserving.template<class R, class... Flags> constexpr basic_vec(R&& r, flags<Flags...> = {}); template<class R, class... Flags> constexpr basic_vec(R&& r, const mask_type& mask, flags<Flags...> = {});-12- Let mask be
-13- Constraints:mask_type(true)
for the overload with nomask
parameter.
(13.1) —
R
modelsranges::contiguous_range
andranges::sized_range
,(13.2) —
ranges::size(r)
is a constant expression,and(13.3) —
ranges::size(r)
is equal tosize()
.,(13.?) —
constructible_from<value_type, R>
isfalse
, and(13.?) —
r(integral_constant<simd-size-type, 0>())
is not a valid expression.