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

Created on 2021-10-12.00:00:00 last changed 1 month ago

Messages

Date: 2021-10-17.10:48:28

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: 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
2021-10-17 10:48:28adminsetmessages: + msg12173
2021-10-12 00:00:00admincreate