I tried a small example to get used to the GSL and range-v3 libraries, and I thought how they could work together. I have this toy example
#include <iostream> #include <range/v3/all.hpp> using namespace std; using namespace ranges; void example_vector(vector<int> const& v) { ranges::for_each(view::tail(v), [](int x){ cout << x << ' '; }); cout << '\n'; } int main() { auto seq = vector<int> { 2,2,2,0,0,2,1,2 }; example_vector(seq); }
which is working. But if I try to use gsl::span<int>
as a range, this will result in an error message. The compiler tells me that span
does not populate the concept of presentation.
#include <gsl.h> // ... void example_span(gsl::span<const int> v) { ranges::for_each(view::tail(v), [](int x){ cout << x << ' '; }); cout << '\n'; }
Compiler Message:
note: candidate template ignored: disabled by 'enable_if' [with Rng = gsl::span<const int, -1> &, Rest = <>, _concept_requires_123 = 42] CONCEPT_REQUIRES_(ViewConcept<Rng, Rest...>())>
But in my understanding, this should be, because span
is a specific view and even has iterators begin()
and end()
(of the same type).
- Would it be great if they worked together, being composed, or are there any reasons for both of them to be incompatible?
- I think this is a problem that comes from using a strong โconceptโ in the -3 range. Does this happen automatically if any other kind of feature feature is supported by the language?
- I assume that
span
currently needs some adaptation if I want to use both libraries in some piece of (non-industrial) software. What should I change so that they work together? (if it's a good idea at all) - It also leads me ultimately to the question, โWhat does the class have for fullfill to work with
range-v3
?โ Is it inherited from facades, adapters, or is that the only way to tell the compiler about these conceptual requirements?
source share