I'd like to call a function that takes a single range parameter, using an iterator-sentinel pair. The recommended method seems to be to call std::ranges::subrange(begin, end)
. For example, I would use the following:
#include <ranges>
#include <vector>
#include <iostream>
int main() {
std::vector<int> a{1, 2, 3};
auto r = std::ranges::subrange(a.begin(), a.end());
for (int a : r) {
std::cout << a << " ";
}
}
However this causes an error when using clang 13 (with -std=c++20
):
opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c++/11.2.0/bits/iterator_concepts.h:980:13: error: no matching function for call to '__begin'
= decltype(ranges::__cust_access::__begin(std::declval<_Tp&>()));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
See https://godbolt.org/z/cGfvxo66j . The example does compile with -stdlib=libc++
rather than the default libstdc++, but this gives other issues in my application.
I know ranges support in clang is only partial, but subrange
seems like a very basic construction. Is there any other way to convert an iterator-sentinel pair to a range?