-
Notifications
You must be signed in to change notification settings - Fork 781
P1391R4 Range constructor for std::string_view #3454
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
size_t
is of type size_type, butend-begin
is of typeptrdiff_t
. The conversion will "just work" even for the overflow case, but it's a bit odd.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.
Bug:
end - begin
has somesigned-integer-like
type (that isn't necessarilyptrdiff_t
) but must be explicitly convertible tosize_t
per [iterator.concept.winc]/6. This needs to initializesize_
withstatic_cast<size_t>(end - begin)
.As always, let-me-know-if-this-isn't-editorial-and-I'll-file-an-LWG-issue.
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.
We could simply say "direct-initializes
size_t
withend-begin
", but that's a bit subtle.@zygoloid , your call. (This also affects the similar text in the corresponding
span
changes.)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.
Sorry, my "bug" cry here was a bit of an overreaction - I (and apparently all of LWG) am still not used to non-integral difference types. Either "direct-initializes" or
static_cast<size_t>
would be great here, or we could clean it up post-merge via LWG issue. This certainly doesn't rise to the level of refusing to apply the proposal and sending it back to LWG, which "bug" would seem to imply.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.
It seems to me that this is just one instance of a systemic problem in the library wording. This phrasing "initializes x with y" is common, but underspecified (and formally meaningless) -- the library wording either needs to say what kind of initialization is performed, or specify an initializer (not an expression) with which to initialize. We should ask LWG to think about this; for each "initializes x with y" utterance, the reader should know what kind of initialization we mean.
Looking at random through the library wording, the first case I found: [queue.cons]/1:
The meaning of this depends on whether this is direct- or copy-initialization. (It's obscure, but if
T
is not Cpp17CopyInsertable into the container, it could be the case that one form of initialization works and the other does not, or that they both work and do different things.)Another random sample: [partial.sum]/2:
Again the difference between direct- and copy-initialization is observable here.
Perhaps the library should have blanket wording that when it says "initializes", it means by direct- or copy-initialization, and that it's unspecified which one you get (or something like that) -- and someone should go through all the instances and check if any of them mean something else (I doubt this is the only case that does). I'm not convinced that this particular instance of the problem needs to be dealt with while applying the motions.
@CaseyCarter Can you file an LWG issue, please?
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.
I've mailed lwgchair to ask for an issue.