ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.06k stars 437 forks source link

Subrange next() fails to compile with unsized ranges. #1718

Closed maxrossi91 closed 2 years ago

maxrossi91 commented 2 years ago

Hi,

First of all thank you very much for this amazing library.

I encountered a compile error on the call of a next() on an unsized subrange, namely

/opt/compiler-explorer/libs/rangesv3/0.11.0/include/range/v3/view/subrange.hpp:307:32: error: no matching function for call to 'ranges::subrange<Integers::Iterator>::get_size_()'

This is reported on both v0.11.0 and v0.12.0. This error is not present when using std::ranges.

I reproduced the error on Compiler Explorer here.

Please let me know if you need any additional information.

brevzin commented 2 years ago

Simpler example:

#include <range/v3/view/subrange.hpp>
#include <list>

int main() {
    std::list<int> x = {1, 2, 3};
    auto r = ranges::subrange(x.begin(), x.end());
    (void)r.next();
}

subrange::next() should work for forward ranges, but the implementation right now erroneously requires that either the subrange stores the size or the sentinel is a sized sentinel for the iterator.

maxrossi91 commented 2 years ago

Thank you very much for the fast handling of this.