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
[iterator.operations] Clarify the observable side-effects of distance
.
#2813
Conversation
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 don't think it's an oversight, I think the implication is already there.
Why introduce i
instead of incrementing first
directly?
@jwakely Sure, no good reason to introduce a separate I don't see how the implication is clear? It seems to say that Let's say I make an iterator that has some side-effect like printing hello world every time it's incremented. And let's say it does not expose the interface of a random-access iterator, but the compiler and/or stdlib are able to figure out that it does in fact point into a random-access structure, and optimize away the increments to return the correct value from distance but avoid printing hello world. Is that conforming? I think according to the standard as currently written, it is: the standard just says |
But the standard doesn't say that magic, impossible optimisation happens, so you can't assume it does, and have to assume the increments happen, and so other copies of input iterators can be affected. Saying "no impossible magic happens" doesn't seem necessary to me. A note stating that input iterators might become non-dereferenceable might be reasonable, but specifying the function using code isn't an improvement IMHO. |
Right, but it also doesn't state that the increments do happen, as far as I can tell. |
I'm not convinced the rewrite as code is a net improvement. I do sympathize with the sentiment that "needed to get" is sloppy wording of sorts; is there maybe a small prose adjustment that helps here? "increments first until last is reached and returns the number of increments" or so? |
Editorial meeting: Go with Jens' suggestion. |
Please be sure to keep the wording style consistent in |
The standard claims that for non-Random-Access iterators,
distance
"uses ++". I guess the reader is supposed to infer from this that you can't continue using an iterator that doesn't have a multi-pass guarantee after passing it todistance
, but it could be more clear. Especially sincedistance(a, a)
won't actually invalidate anything (at any rate, not in libc++ and I'd be quite surprised if it did in any standard library implementation)I believe that this lack of clarity in the standard is an editorial oversight, and that the committee's intended meaning is that
distance(first, last)
has the same observable side-effects as calling pre-increment++
on first until it equals last.Fixes #2807.