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
P1391R4 Range constructor for std::string_view #3454
Conversation
Please add "fixes" to the commit for the NB comments linked in this pull request. |
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.
Regarding the similar changes to span
in #3456.
dee969f
to
c9eee74
Compare
c9eee74
to
d7ec89c
Compare
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.
Looks good.
\pnum | ||
\effects | ||
Initializes \tcode{data_} with \tcode{to_address(begin)} and | ||
initializes \tcode{size_} with \tcode{end - begin}. |
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, but end-begin
is of type ptrdiff_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 some signed-integer-like
type (that isn't necessarily ptrdiff_t
) but must be explicitly convertible to size_t
per [iterator.concept.winc]/6. This needs to initialize size_
with static_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
with end-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:
Effects: Initializes
c
withcont
.
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:
Effects: For a non-empty range, the function creates an accumulator
acc
whose type isInputIterator
's value type, initializes it with*first
, and assigns the result to*result
.
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.
Renamed constructor parameters in description to match those in class definition. Also fixes NB US 232 and partially fixes US 272 and DE 277 (C++20 CD).
…view.deduct] Also replace commas with periods in lists of constraints.
d7ec89c
to
de25e23
Compare
Renamed constructor parameters in description to match those in class
definition.
Fixes #3415.
Fixes cplusplus/nbballot#229
Partially addresses cplusplus/nbballot#268
Partially addresses cplusplus/nbballot#284
Fixes cplusplus/papers#184