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

3301. transform_view::iterator has incorrect iterator_category

Section: 25.7.9.3 [range.transform.iterator] Status: C++20 Submitter: Michel Morin Opened: 2019-10-03 Last modified: 2021-02-25

Priority: 1

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

View all issues with C++20 status.

Discussion:

When the transformation function returns an rvalue, transform_view::iterator cannot model cpp17-forward-iterator. However, similar to LWG 3291(i), the current wording on transform_view::iterator::iterator_category does not consider this.

As Casey Carter pointed out here, the proposed wording below does not consider input_iterator that is not cpp17-input-iterator (this problem is not specific to the PR; it's pervasive in adapted iterators) and concepts-based determination would be a better fix for issues around iterator_category. But anyway, I consider this PR as a minimal fix at the moment.

[2019-10-31 Issue Prioritization]

Priority to 1 after reflector discussion.

Previous resolution [SUPERSEDED]:

This wording is relative to N4830.

  1. Modify 25.7.9.3 [range.transform.iterator] as indicated:

    -2- iterator::iterator_category is defined as follows: Let C denote the type iterator_traits<iterator_t<Base>>::iterator_category.

    1. (2.?) — If is_lvalue_reference_v<iter_reference_t<iterator_t<Base>>> is true,

      1. (2.?.?) — If C models derived_from<contiguous_iterator_tag>, then iterator_category denotes random_access_iterator_tag;

      2. (2.?.?) — Ootherwise, iterator_category denotes C.

    2. (2.?) — Otherwise, iterator_category denotes input_iterator_tag.

[2019-11-06, Tim updates P/R based on Belfast LWG evening session discussion]

The check in the original P/R is incorrect; we want to check the transformation's result, not the base iterator.

[2020-02-10 Move to Immediate Monday afternoon in Prague]

Proposed resolution:

This wording is relative to N4830.

  1. Modify 25.7.9.3 [range.transform.iterator] as indicated:

    -2- iterator::iterator_category is defined as follows: Let C denote the type iterator_traits<iterator_t<Base>>::iterator_category.

    1. (2.?) — If is_lvalue_reference_v<invoke_result_t<F&, range_reference_t<Base>>> is true,

      1. (2.?.?) — If C models derived_from<contiguous_iterator_tag>, then iterator_category denotes random_access_iterator_tag;

      2. (2.?.?) — Ootherwise, iterator_category denotes C.

    2. (2.?) — Otherwise, iterator_category denotes input_iterator_tag.