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

[range.split] The example does not work after P2499R0 #6017

Closed
dangelog opened this issue Dec 14, 2022 · 1 comment · Fixed by #6041
Closed

[range.split] The example does not work after P2499R0 #6017

dangelog opened this issue Dec 14, 2022 · 1 comment · Fixed by #6041

Comments

@dangelog
Copy link
Contributor

https://eel.is/c++draft/range.split.overview#3 has this example:

string str{"the quick brown fox"};
for (string_view word : views::split(str, ' ')) {
  cout << word << '*';
}
// The above prints the*quick*brown*fox*

This implicitly constructs a std::string_view out of each subrange obtained by split. This does not compile any more because the corresponding constructor has been made explicit by P2499R0, and split doesn't seem to have the same shortcuts that other views have (e.g. take out of string_view yields another string_view).

Possible solution: make the construction explicit:

string str{"the quick brown fox"};
for (const auto& word : views::split(str, ' ')) {
  cout << string_view(word) << '*';
}
// The above prints the*quick*brown*fox*
@jwakely
Copy link
Member

jwakely commented Dec 14, 2022

Possible solution: make the construction explicit:

Yeah, this looks good to me.

dangelog added a commit to dangelog/cplusplusdraft that referenced this issue Dec 30, 2022
After P2499R0 it is no longer possible to implicitly construct a
string_view out of a range (like the ones produced by views::split).
Use explicit construction instead.

Fixes cplusplus#6017
dangelog added a commit to dangelog/cplusplusdraft that referenced this issue Dec 30, 2022
After P2499R0 it is no longer possible to implicitly construct a
string_view out of a range (like the ones produced by views::split).
Use explicit construction instead.

Fixes cplusplus#6017
dangelog added a commit to dangelog/cplusplusdraft that referenced this issue Jan 19, 2023
…ng_view in the example

After P2499R0 it is no longer possible to implicitly construct a
string_view out of a range (like the ones produced by views::split).
As a solution, use explicit construction instead.

This is purely editorial, as it affects only the example code.

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

Successfully merging a pull request may close this issue.

2 participants