We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
constexpr bool starts_with(basic_string_view x) const noexcept; Effects: Equivalent to: return compare(0, npos, x) == 0;
compare(0, npos, x) should be: compare(0, x.size(), x)
compare(0, npos, x)
compare(0, x.size(), x)
Otherwise "Hello World"sv.starts_with("Hello"sv) would return false.
"Hello World"sv.starts_with("Hello"sv)
false
The text was updated successfully, but these errors were encountered:
This is not an editorial issue, so needs to be submitted as a defect report.
I'm pretty sure @mclow already noticed this problem, and might have opened an issue already.
Sorry, something went wrong.
I have written up the issue, but haven't added to the issues list. That will happen by Monday.
BTW, your proposed resolution is incorrect, because in the case "Hello"sv.starts_with("Hello World"sv) you would have undefined behavior.
"Hello"sv.starts_with("Hello World"sv)
You are right. I was assuming that substr(0, n) would clamp to size(), which is true for basic_string but not basic_string_view.
substr(0, n)
size()
basic_string
basic_string_view
So the proposed resolution should be return (size() >= x.size()) && (compare(0, x.size(), x) == 0).
return (size() >= x.size()) && (compare(0, x.size(), x) == 0)
Which is exactly the proposed resolution in my LWG issue, and in my patch for libc++: https://reviews.llvm.org/D40586
https://cplusplus.github.io/LWG/issue3040
basic_string_view::starts_with(basic_string_view)
No branches or pull requests
compare(0, npos, x)
should be:compare(0, x.size(), x)
Otherwise
"Hello World"sv.starts_with("Hello"sv)
would returnfalse
.The text was updated successfully, but these errors were encountered: