Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is ranges::split_view not a Bidirectional Range?

Tags:

c++

range-v3

I am using the cmcstl2 library with the C++ proposed Ranges with gcc 8

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

But this does not work since the view is only a Forward Range not a Bidirectional Range which required by range (which is what I think is going on). Why? if

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

outputs a view of subranges. Can't that view be reversed?

Also in cmcstl2 I must do the following to print it out.

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

But in range-v3/0.4.0 version I can do:

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

Why? What is the type of x?

like image 508
tcw321 Avatar asked Nov 24 '25 19:11

tcw321


1 Answers

The way it's been written only supports ForwardRange.

You can certainly try to make a BidirectionalRange version, although I suspect that is either hard or less general.

Consider how to specify all the options for pattern such that it can also match backwards.

like image 97
Caleth Avatar answered Nov 26 '25 08:11

Caleth