tcbrindle / NanoRange

Range-based goodness for C++17
Boost Software License 1.0
358 stars 28 forks source link

split view does not work #85

Open bmanga opened 4 years ago

bmanga commented 4 years ago

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

tcbrindle commented 4 years ago

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);
bmanga commented 4 years ago

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