3953. iter_move for common_iterator and counted_iterator should return decltype(auto)

Section: 24.5.5.7 [common.iter.cust], 24.5.7.7 [counted.iter.cust] Status: WP Submitter: Hewill Kang Opened: 2023-06-30 Last modified: 2023-11-22

Priority: Not Prioritized

View all issues with WP status.

Discussion:

Although the customized iter_move of both requires the underlying iterator I to be input_iterator, they still explicitly specify the return type as iter_rvalue_reference_t<I>, which makes it always instantiated.

From the point of view that its validity is only specified in the input_iterator concept, it would be better to remove such unnecessary type instantiation, which does not make much sense for an output_iterator even if it is still valid.

[2023-10-27; Reflector poll]

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

[2023-11-11 Approved at November 2023 meeting in Kona. Status changed: Voting → WP.]

Proposed resolution:

This wording is relative to N4950.

  1. Modify 24.5.5.1 [common.iterator], class template common_iterator synopsis, as indicated:

    namespace std {
      template<input_or_output_iterator I, sentinel_for<I> S>
        requires (!same_as<I, S> && copyable<I>)
      class common_iterator {
      public:
        […]
        friend constexpr iter_rvalue_reference_t<I>decltype(auto) iter_move(const common_iterator& i)
          noexcept(noexcept(ranges::iter_move(declval<const I&>())))
            requires input_iterator<I>;
        […]
      };
      […]
    }
    
  2. Modify 24.5.5.7 [common.iter.cust] as indicated:

    friend constexpr iter_rvalue_reference_t<I>decltype(auto) iter_move(const common_iterator& i)
      noexcept(noexcept(ranges::iter_move(declval<const I&>())))
        requires input_iterator<I>;
    

    -1- Preconditions: […]

    -2- Effects: Equivalent to: return ranges::iter_move(get<I>(i.v_));

  3. Modify 24.5.7.1 [counted.iterator], class template counted_iterator synopsis, as indicated:

    namespace std {
      template<input_or_output_iterator I>
      class counted_iterator {
      public:
        […]
        friend constexpr iter_rvalue_reference_t<I>decltype(auto) iter_move(const counted_iterator& i)
          noexcept(noexcept(ranges::iter_move(i.current)))
            requires input_iterator<I>;
        […]
      };
      […]
    }
    
  4. Modify 24.5.7.7 [counted.iter.cust] as indicated:

    friend constexpr iter_rvalue_reference_t<I>decltype(auto) 
      iter_move(const counted_iterator& i)
        noexcept(noexcept(ranges::iter_move(i.current)))
        requires input_iterator<I>;
    

    -1- Preconditions: […]

    -2- Effects: Equivalent to: return ranges::iter_move(i.current);