为什么ranges :: split_view不是双向范围

Why is ranges::split_view not a Bidirectional Range?

本文关键字:范围 view ranges split 为什么      更新时间:2023-10-16

我正在使用cmcstl2库,其中c 提出的范围为gcc 8

std::string text = "Let me split this into words";
std::string pattern = " ";
auto splitText = text | ranges::view::split(pattern) | 
        ranges::view::reverse;

,但这不起作用,因为该视图只是一个向前范围而不是范围要求的双向范围(我认为这是发生的)。为什么?如果

text | ranges::view::split(pattern)

输出子弹视图。那视图不能逆转吗?

也必须在CMCSTL2中进行以下操作才能将其打印出来。

for (auto x : splitText)
{
    for (auto m : x)
        std::cout << m;
    std::cout << " ";
}

,但在范围V3/0.4.0版本中我可以做:

    for (auto x : splitText)
       std::cout << x << 'n';

为什么?X的类型是什么?

编写的方式仅支持向前。

,您当然可以尝试制作双向Alange版本,尽管我怀疑这很难或不到一般。

考虑如何指定pattern的所有选项,以便它也可以向后匹配。