-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
basic_string_view's non-member begin/end should take basic_string_view by value #119
Conversation
…w by value ... as the working draft requires. Test coverage failed to detect this issue due to [an overload resolution bug in MSVC](https://developercommunity.visualstudio.com/content/problem/739010/overload-resolution-fails-to-select-deleted-overlo.html). Drive-by: Remove the "accepts rvalues" bit from the comment in `begin` which caused the confusion that gave rise to microsoft#104. Hopefully it is now glaringly obvious that `begin` and `end` accept both lvalues and rvalues. Resolves microsoft#104.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could pass by const value, as other functions in this file do. OK to merge as-is.
Out of curiosity why take it by value and not rvalue_reference? The lvalue_reference case is already covered by the classical |
As I understand, it's just a performance optimization. In case of (const-)reference you'll do dereference twice while accessing to the underlying c-string's character - the first dereference of 'reference' itself (because references are implemented as pointers), the second is dereference of the c-string. If you pass string_view by value, one avoids the first dereference. |
@shuffle-c That overload is not about performance but to provide a specialization for That specialization is required to opt-in the forwarding-range concept. |
These non-member |
Description
... as the working draft requires. Test coverage failed to detect this issue due to an overload resolution bug in MSVC.
Drive-by: Remove the "accepts rvalues" bit from the comment in
begin
which caused the confusion that gave rise to #104. Hopefully it is now glaringly obvious thatbegin
andend
accept both lvalues and rvalues.Resolves #104.
[This is a replay of Microsoft-internal PR 203374.]
Checklist:
Working Draft. (N/A)
(The version is important because clang-format's behavior sometimes changes.)
_Ugly
as perhttps://eel.is/c++draft/lex.name#3.1 .
_Ugly
.what happens to compile.
by an STL maintainer before CI is online, leave this unchecked for initial
submission).
members, adding virtual functions, changing whether a type is an aggregate or
trivially copyable, etc.). If unsure, leave this box unchecked and ask a
maintainer for help.