Title
Clarify operator+= complexity for {chunk,stride}_view::iterator
Status
c++23
Section
[range.chunk.fwd.iter][range.stride.iterator]
Submitter
Tim Song

Created on 2023-02-09.00:00:00 last changed 12 months ago

Messages

Date: 2023-02-13.11:31:32

Proposed resolution:

This wording is relative to n4928.

  1. Modify [range.chunk.fwd.iter] p13 as indicated:

    constexpr iterator& operator+=(difference_type x)
      requires random_access_range<Base>;
    

    -12- Preconditions: If x is positive, ranges::distance(current_, end_) > n_ * (x - 1) is true.

    [Note 1: If x is negative, the Effects paragraph implies a precondition. — end note]

    -13- Effects: Equivalent to:

    if (x > 0) {
      ranges::advance(current_, n_ * (x - 1));
      missing_ = ranges::advance(current_, n_ * x, end_);
    } else if (x < 0) {
      ranges::advance(current_, n_ * x + missing_);
      missing_ = 0;
    }
    return *this;
    
  2. Modify [range.stride.iterator] p14 as indicated:

    constexpr iterator& operator+=(difference_type n) requires random_access_range<Base>;
    

    -13- 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]

    -14- Effects: Equivalent to:

    if (n > 0) {
      ranges::advance(current_, stride_ * (n - 1));
      missing_ = ranges::advance(current_, stride_ * n, end_);
    } else if (n < 0) {
      ranges::advance(current_, stride_ * n + missing_);
      missing_ = 0;
    }
    return *this;
    
Date: 2023-02-13.00:00:00

[ 2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Immediate → WP. ]

Date: 2023-02-10.18:26:23

[ Issaquah 2023-02-10; LWG issue processing ]

Move to Immediate for C++23

Date: 2023-02-09.00:00:00

The intent was that the precondition allows the call to ranges::advance, which otherwise would have time linear in the argument of operator+=, to actually be implemented using operator+= or equivalent for all but the last step. This is at best very non-obvious and should be clarified.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2023-02-13 11:31:32adminsetmessages: + msg13405
2023-02-13 11:31:32adminsetstatus: immediate -> wp
2023-02-10 18:26:23adminsetmessages: + msg13341
2023-02-10 18:26:23adminsetstatus: new -> immediate
2023-02-10 15:46:58adminsetmessages: + msg13334
2023-02-09 00:00:00admincreate