我正在探索gcc中的实验范围库实现。 将无限iota范围与滤镜视图结合使用时, 我遇到了令人惊讶的编译错误 ({live example,使用GCC 9.0 HEAD 201812):
#include <iostream>
#include <vector>
#include <experimental/ranges/range>
int main()
{
using namespace std::experimental::ranges;
auto odds = view::filter([](int x){ return x%2 != 0; });
// auto v = std::vector{0,1,2,3,4,5};
// auto x = v | odds; // (1) ok
// auto x = view::iota(0,6) | odds; // (2) ok
// auto x = view::iota(0) | view::take(6); // (3) ok
auto x = view::iota(0) | view::take(6) | odds; // (4) error: sentinel?
for (auto e : x) std::cout << e << ' ';
}
这是怎么了?
答案 0 :(得分:2)
这只是cmcstl2中的错误。简短的复制示例:
auto yes = [](int){ return true; };
// this works
view::filter(view::iota(0), yes);
view::iota(0,10) | view::filter(yes);
// this doesn't
view::iota(0) | view::filter(yes);
Casey已在this PR(特别是this commit)中对其进行了修复。