Title
reverse_iterator::operator-> should not use prev for non-pointer iterators
Status
new
Section
[reverse.iter.elem]
Submitter
Hewill Kang

Created on 2022-06-26.00:00:00 last changed 6 months ago

Messages

Date: 2024-06-18.11:49:41

Proposed resolution:

This wording is relative to N4910.

  1. Modify [reverse.iter.elem] as indicated:

    constexpr pointer operator->() const
      requires (is_pointer_v<Iterator> ||
                requires(const Iterator i) { i.operator->(); });
    

    -2- Effects:

    1. (2.1) — If Iterator is a pointer type, equivalent to: return prev(current);

    2. (2.2) — Otherwise, equivalent to: return prev(current).operator->();

      Iterator tmp = current;
      --tmp;
      return tmp.operator->();
      
Date: 2024-06-15.00:00:00

[ 2024-06-18; Jonathan adds a comment ]

It's not clear that `std::prev` requires Cpp17InputIterator, that's the subject of LWG 3197.

Date: 2022-07-15.00:00:00

[ 2022-07-08; Reflector poll ]

Set priority to 3 after reflector poll. Suggested to use ranges::prev instead.

Date: 2022-06-26.00:00:00

When the underlying iterator is not a pointer type, reverse_iterator::operator-> returns prev(current).operator->(). However, prev only works with Cpp17BidirectionalIterator, given that C++20 bidirectional_iterator may just be Cpp17InputIterator, we shouldn't use prev here.

History
Date User Action Args
2024-06-18 11:49:41adminsetmessages: + msg14169
2022-07-08 20:04:38adminsetmessages: + msg12565
2022-06-26 09:41:14adminsetmessages: + msg12539
2022-06-26 00:00:00admincreate