This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++23 status.

3580. iota_view's iterator's binary operator+ should be improved

Section: 25.6.4.3 [range.iota.iterator] Status: C++23 Submitter: Zoe Carver Opened: 2021-08-14 Last modified: 2023-11-22

Priority: Not Prioritized

View other active issues in [range.iota.iterator].

View all other issues in [range.iota.iterator].

View all issues with C++23 status.

Discussion:

iota_view's iterator's operator+ could avoid a copy construct by doing "i += n; return i" rather than "return i += n;" as seen in 25.6.4.3 [range.iota.iterator].

This is what libc++ has implemented and shipped, even though it may not technically be conforming (if a program asserted the number of copies, for example).

It might be good to update this operator and the minus operator accordingly.

[2021-08-20; Reflector poll]

Set status to Tentatively Ready after six votes in favour during reflector poll.

[2021-10-14 Approved at October 2021 virtual plenary. Status changed: Voting → WP.]

Proposed resolution:

This wording is relative to N4892.

  1. Modify 25.6.4.3 [range.iota.iterator] as indicated:

    friend constexpr iterator operator+(iterator i, difference_type n)
      requires advanceable<W>;
    

    -20- Effects: Equivalent to:

    return i += n; 
    return i;
    
    friend constexpr iterator operator+(difference_type n, iterator i)
      requires advanceable<W>;
    

    -21- Effects: Equivalent to: return i + n;

    friend constexpr iterator operator-(iterator i, difference_type n)
      requires advanceable<W>;
    

    -22- Effects: Equivalent to:

    return i -= n;
    return i;