Title
transform_view::iterator<true>::value_type and iterator_category should use const F&
Status
c++23
Section
[range.transform.iterator]
Submitter
Tim Song

Created on 2021-06-06.00:00:00 last changed 13 months ago

Messages

Date: 2022-07-25.20:32:58

Proposed resolution:

This wording is relative to N4885.

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

    namespace std::ranges {
      template<input_range V, copy_constructible F>
        requires view<V> && is_object_v<F> &&
                 regular_invocable<F&, range_reference_t<V>> &&
                 can-reference<invoke_result_t<F&, range_reference_t<V>>>
      template<bool Const>
      class transform_view<V, F>::iterator {
      private:
        […]
      public:
        using iterator_concept = see below;
        using iterator_category = see below; // not always present
        using value_type =
          remove_cvref_t<invoke_result_t<maybe-const<Const, F>&, 
          range_reference_t<Base>>>;
        using difference_type = range_difference_t<Base>;  
        […]
      };
    }
    

    -1- […]

    -2- The member typedef-name iterator_category is defined if and only if Base models forward_range. In that case, iterator::iterator_category is defined as follows: Let C denote the type iterator_traits<iterator_t<Base>>::iterator_category.

    1. (2.1) — If is_lvalue_reference_v<invoke_result_t<maybe-const<Const, F>&, range_reference_t<Base>>> is true, then

      1. (2.1.1) — […]

      2. (2.1.2) — […]

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

Date: 2022-07-25.00:00:00

[ 2022-07-25 Approved at July 2022 virtual plenary. Status changed: Ready → WP. ]

Date: 2022-07-15.00:00:00

[ 2022-07-15; LWG telecon: move to Ready ]

Date: 2022-07-15.00:00:00

[ 2022-07-08; Reflector poll ]

SG9 has decided to proceed with this PR in its 2021-09-13 telecon and not block the issue for a paper on the more general const/non-const problem.

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

Date: 2021-06-15.00:00:00

[ 2021-06-14; Reflector poll ]

Set priority to 2 after reflector poll, send to SG9 for design clarification. Should r and as_const(r) guarantee same elements?

Date: 2021-06-06.00:00:00

Iterators obtained from a const transform_view invoke the transformation function as const, but the value_type and iterator_category determination uses plain F&, i.e., non-const.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-07-25 20:32:58adminsetmessages: + msg12633
2022-07-25 20:32:58adminsetstatus: ready -> wp
2022-07-25 20:28:19adminsetmessages: + msg12607
2022-07-08 19:58:56adminsetmessages: + msg12559
2022-07-08 19:58:56adminsetstatus: open -> ready
2021-06-14 14:09:34adminsetmessages: + msg11932
2021-06-14 14:09:34adminsetstatus: new -> open
2021-06-06 16:05:01adminsetmessages: + msg11877
2021-06-06 00:00:00admincreate