Can't create a std::span from a gsl::span anymore after implementing P1394r4
ldionne opened this issue · comments
Since P1394r4, std::span
changed the following constructors:
template<class Container> constexpr span(Container&);
template<class Container> constexpr span(const Container&);
into the following constructor:
template <class R> constexpr span(R&&);
where R
must be a std::contiguous_range
. However, as it happens, gsl::span
does not qualify as a contiguous_range
because its iterators are not contiguous_iterator
s. As a result, the following code starts failing when a Standard Library implements the resolution of P1394r4:
cat <<EOF | clang++ -xc++ - -std=c++20 -fsyntax-only
#include <gsl/span>
#include <span>
gsl::span<int> gsl_span;
std::span<int> std_span = gsl_span;
EOF
Here is a reproducer on Godbolt: https://godbolt.org/z/c1b686vjh. This worked previously with libc++ before we implemented P1394r4.
I would suggest that gsl::span
's iterators be made contiguous_iterator
s in C++20, which would improve its interoperability with standard library types.
Note that this issue was found while building a large code base with the latest version of libc++ -- I suspect this issue is going to hit a decent number of people when LLVM 14 is released.
Hi @ldionne, thanks for finding this. Will investigate.
Related to #982