Title
Unnecessary iter_move for transform_view::iterator
Status
c++23
Section
[range.transform.iterator]
Submitter
Barry Revzin

Created on 2021-10-12.00:00:00 last changed 5 months ago

Messages

Date: 2022-02-10.12:58:57

Proposed resolution:

This wording is relative to N4892.

  1. Modify [range.transform.iterator], class template transform_view::iterator, as indicated:

    […]
    constexpr decltype(auto) operator*() const noexcept(noexcept(invoke(*parent_->fun_, *current_))) {
      return invoke(*parent_->fun_, *current_);
    }
    […]
    friend constexpr decltype(auto) iter_move(const iterator& i)
      noexcept(noexcept(invoke(*i.parent_->fun_, *i.current_))) {
      if constexpr (is_lvalue_reference_v<decltype(*i)>)
        return std::move(*i);
      else
        return *i;
    }
    […]
    
Date: 2022-02-10.00:00:00

[ 2022-02-10 Approved at February 2022 virtual plenary. Status changed: Tentatively Ready → WP. ]

Date: 2022-01-15.00:00:00

[ 2022-01-29; Reflector poll ]

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

Date: 2021-10-12.00:00:00

transform_view's iterator currently specifies a customization point for iter_move. This customization point does the same thing that the default implementation would do — std::move(*E) if *E is an lvalue, else *E — except that it is only there to provide the correct conditional noexcept specification. But for iota_view, we instead provide a noexcept-specifier on the iterator's operator*. We should do the same thing for both, and the simplest thing would be:

Change [range.transform.iterator] to put the whole body into noexcept:

constexpr decltype(auto) operator*() const noexcept(noexcept(invoke(*parent_->fun_, *current_))) {
  return invoke(*parent_->fun_, *current_);
} 

And to remove this:

friend constexpr decltype(auto) iter_move(const iterator& i)
  noexcept(noexcept(invoke(*i.parent_->fun_, *i.current_))) {
  if constexpr (is_lvalue_reference_v<decltype(*i)>)
    return std::move(*i);
  else
    return *i;
}
History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-02-10 12:58:57adminsetmessages: + msg12354
2022-02-10 12:58:57adminsetstatus: ready -> wp
2022-01-29 22:29:12adminsetmessages: + msg12286
2022-01-29 22:29:12adminsetstatus: new -> ready
2021-10-17 10:48:28adminsetmessages: + msg12173
2021-10-12 00:00:00admincreate