I used to work with gsl::span from the Guidelines Support Library for some time. With gsl::span, is was possible to define a function taking a static extent and calling it with a gsl::span of dynamic extent, e.g.
void f(gsl::span<int, 5> s) { }
...
std::vector<int> v(100);
f(gsl::make_span(v).subspan(42, 5)); // Works
After porting the code to std::span, I noticed that this is no longer possible:
void f(std::span<int, 5> s) { }
...
std::vector<int> v(100);
f(std::span(v).subspan(42, 5)); // Does not work
Is there any reason for this difference? Is there any recommended way to convert a std::span with dynamic extent to a std::span with fixed extent? Of course, it is possible to create a new span with fixed extent when calling the function:
f(std::span<int, 5>(&v[42], 5));
However, I think that the "subspan" variant is much better readable, it expresses the intention in a better way, and it allows appropriate range checking in a debug build.