I'm wondering why this code doesn't compile with clang 15, even though the ranges library is marked as fully supported in clang 15 on the compiler support page? It does compile with g++12, even if the support is marked only as partial, and it compiles with clang trunk.
#include <ranges>
#include <vector>
int main() {
std::vector x{1,2,3,4};
auto y = x | std::views::filter([](auto i){ return i <2;});
}
Is the code incorrect? And if it is, is there a way to work around the bug until clang 16 gets released. I guess ranges-v3 would work, but perhaps someone knows how to fix it using only the standard library.
Interestingly, I get different errors when using -stdlib=libstdc++
and -stdlib=libc++
:
- libstdc++:
error: invalid operands to binary expression ('std::vector<int>' and '_Partial<std::ranges::views::_Filter, decay_t<(lambda at <source>:7:37)>>' (aka '_Partial<std::ranges::views::_Filter, (lambda at <source>:7:37)>'))
- libc++:
error: no member named 'views' in namespace 'std'