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

4120. move_iterator should provide iterator_category only when it models forward_iterator

Section: 25.5.4.2 [move.iterator] Status: New Submitter: Hewill Kang Opened: 2024-07-12 Last modified: 2024-08-31

Priority: 3

View other active issues in [move.iterator].

View all other issues in [move.iterator].

View all issues with New status.

Discussion:

Following up LWG 4116, when the underlying iterator does not satisfy forward_iterator, move_iterator::operator++(int) will return void, which fails to meet the C++17 iterator requirements, which should not provide iterator_category.

[2024-08-02; Reflector poll]

Set priority to 3 after reflector poll.

"NAD, would be a major breaking change to something present since C++11."

"We're knowingly breaking the rules here for backwards compatibility. Should have a note here indicating that the rule is broken for good reason, and that you should do as the Standard says and not as the Standard does."

Proposed resolution:

This wording is relative to N4986.

  1. Modify 25.5.4.2 [move.iterator] as indicated:

    [Drafting note: Iterator that models forward_iterator implies that iterator_traits<Iterator>::iterator_category is always valid as it satisfies the exposition-only concept cpp17-iterator.]

    -2- The member typedef-name iterator_category is defined if and only if the qualified-id iterator_traits<Iterator>::iterator_category is valid and denotes a typeIterator models forward_iterator. In that case, iterator_category denotes

    1. (2.1) — random_access_iterator_tag if the type iterator_traits<Iterator>::iterator_category models derived_from<random_access_iterator_tag>, and

    2. (2.2) — iterator_traits<Iterator>::iterator_category otherwise.