Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split view does not work #85

Open
bmanga opened this issue Feb 26, 2020 · 2 comments
Open

split view does not work #85

bmanga opened this issue Feb 26, 2020 · 2 comments
Labels

Comments

@bmanga
Copy link

bmanga commented Feb 26, 2020

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

@bmanga bmanga changed the title nano split view does not work split view does not work Feb 26, 2020
@tcbrindle tcbrindle added the bug label Feb 26, 2020
@tcbrindle
Copy link
Owner

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
Copy link
Author

bmanga commented Feb 26, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants