tcbrindle / NanoRange

Range-based goodness for C++17

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

split view does not work

bmanga opened this issue · comments

Hi, it seems that nano::split_view does not work as expected for a simple case (at least on gcc 8-9-trunk):

int main()
{   
  std::string words = "hello;world";
  std::string delimiter = ";";
  auto foo = words | rng::views::split(delimiter);
}

Godbolt link

Thanks for the bug report. This doesn't seem to be specific to GCC, but occurs with Clang as well. I think the problem is that the views::split adaptor should be wrapping the passed-in ranges with views::all, but isn't doing so right now.

In the mean time, there are a couple of workarounds. You can either manually wrap the delimiter with views::all yourself:

 auto foo = words | rng::views::split(rng::views::all(delimiter));

or alternatively, use a char as the delimiter rather than a string:

char delimiter = ';';
auto foo = words | rng::views::split(delimiter);

Thanks for the suggestions!
Funnily enough, using std::string_view for delimiter also seems to work.