Skip to content
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

[range.chunk.fwd.iter, range.stride.iterator] What precondition is implied here? #5730

Open
hewillk opened this issue Aug 16, 2022 · 4 comments

Comments

@hewillk
Copy link
Contributor

hewillk commented Aug 16, 2022

From [range.chunk.fwd.iter-12] / [range.stride.iterator-13]:

constexpr iterator& operator+=(difference_type n) requires random_­access_­range<Base>;

Preconditions: If n is positive, ranges​::​distance(current_­, end_­) > stride_­ * (n - 1) is true.
[Note 1: If n is negative, the Effects paragraph implies a precondition. — end note]

Effects: Equivalent to:

if (x > 0) {
  missing_ = ranges::advance(current_, n_ * x, end_);
} else if (x < 0) {
  ranges::advance(current_, n_ * x + missing_);
  missing_ = 0;
}
return *this;

Maybe it's my English comprehension issue, "If x is negative, the Effects paragraph implies a precondition." What does this mean? What precondition is implied here?

@JohelEGP
Copy link
Contributor

According to https://eel.is/c++draft/description#structure.specifications-4, that'd be the Preconditions of the call(s) to ranges::advance.

@hewillk
Copy link
Contributor Author

hewillk commented Aug 16, 2022

Thanks for the clarification.
However, according to the description of ranges::advance in [range.iter.op.advance]:

template<input_­or_­output_­iterator I>
  constexpr void ranges::advance(I& i, iter_difference_t<I> n);

Preconditions: If I does not model bidirectional_­iterator, n is not negative.
Effects:

  • If I models random_­access_­iterator, equivalent to i += n.
  • Otherwise, if n is non-negative, increments i by n.
  • Otherwise, decrements i by -n.

There are no Preconditions for random_access_iterator, that is to say, the Precondition of calling ranges::advance here has already been satisfied, isn't it? so I don't see why need to take a Note here again.

@JohelEGP
Copy link
Contributor

So, according to that, that'd be the Preconditions on i += n.
The original call ranges::advance(current_, n_ * x + missing_); is equivalent to current_ += n_ * x + missing_. The note must be referring to a precondition on the evaluation of this latter +=.

@tkoeppe
Copy link
Contributor

tkoeppe commented Sep 16, 2022

Is there an editorial issue here? The wording is as requested in https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1899r3.html. Do you have an improvement in mind? @cjdb, @timsong-cpp, any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants