Title
reverse_iterator's converting assignment is overconstrained
Status
new
Section
[reverse.iter.cons][move.iter.cons]
Submitter
Hewill Kang

Created on 2021-09-26.00:00:00 last changed 37 months ago

Messages

Date: 2021-10-14.11:35:36

Proposed resolution:

This wording is relative to N4892.

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

    template<class U>
      constexpr reverse_iterator&
        operator=(const reverse_iterator<U>& u);
    

    -5- Constraints: is_same_v<U, Iterator> is false, const U& models convertible_to<Iterator>, and assignable_from<Iterator&, const U&> is modeled.

    -6- Effects: Assigns u.current to current.

    -7- Returns: *this.

  2. Modify [move.iter.cons] as indicated:

    [Drafting note: As drive-by fix a missing "Returns: *this" has been added as well.]

    template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
    

    -5- Constraints: is_same_v<U, Iterator> is false, const U& models convertible_to<Iterator>, and assignable_from<Iterator&, const U&> is modeled.

    -6- Effects: Assigns u.current to current.

    -?- Returns: *this.

Date: 2021-10-14.12:55:25

[ Tomasz Kamiński commented ]

The move_iterator/reverse_iterator were present before C++20, and this change restores their compatibility with C++17 code, where only assignment was required. They are materially different from adapters introduced with C++20, and I believe we should put more weight into backward compatibility than consistency with newer iterator wrappers.

Date: 2021-10-14.11:35:36

[ Tim Song commented: ]

This was intentional, but I think we missed the fact that counted_iterator did something else already. These should probably be made consistent one way or another.

Date: 2021-10-15.00:00:00

[ 2021-10-14; Reflector poll ]

Set priority to 3 after reflector poll.

Date: 2021-09-26.00:00:00

In order to remove the incorrect bi-convertibility of reverse_iterator<int*> and reverse_iterator<const int*>, LWG 3435 adds two constraints to reverse_iterator's converting assignment, namely convertible_to<const U&, Iterator> and assignable_from<Iterator&, const U&>, but since this function only assigns u.current to current, there is no need to require convertible_to<const U&, Iterator> — the latter is sufficient.

We should remove this constraint and be consistent with the move_sentinel and counted_iterator' converting assignment.

History
Date User Action Args
2021-10-14 11:35:36adminsetmessages: + msg12159
2021-10-14 11:35:36adminsetmessages: + msg12158
2021-10-14 11:35:36adminsetmessages: + msg12157
2021-10-02 15:36:25adminsetmessages: + msg12081
2021-09-26 00:00:00admincreate