Closed AnthonyVH closed 1 week ago
You can't convert a const vector<T>
into the const span<T>
no matter what type T
is. A proper solution is to convert it to span<const T>
if that is your intent.
Ugh, of course. Well, that was certainly the blooper of the day. Sorry to have wasted your time with this.
Conversion of an
std::vector<mp_units::...>
tostd::span<mp_units::...>
doesn't work. I've tried with bothquantity
andquantity_point
and neither work.I haven't figured out the exact reason yet, but somehow such a vector doesn't satisfy (clang's)
Range
concept.Both implicit conversion as well as a bunch of explicit constructors (e.g.
std::span<unit_t>(v.begin(), v.size())
orstd::span<unit_t>(v.begin(), v.end())
) fail.Here is a Godbolt link of the failure: https://godbolt.org/z/7oKq8h398. Only the clang output is actually useful, since msvc has an issue finding
mp_units
, and the GCC output shows no info whatsoever.Minimal example to reproduce:
Note that implicit conversion using CTAD (i.e.
std::span(v)
) works. However, the resulting type however is notstd::span<unit_t>
, and passing it to a function expecting anstd::span<unit_t>
results in the following clang output:Clang 18.1.0 error messages for the minimal example code above: