Skip to content

Can't create a std::span from a gsl::span anymore after implementing P1394r4 #1016

@ldionne

Description

@ldionne

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_iterators. 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_iterators 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions