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

3618. Unnecessary iter_move for transform_view::iterator

Section: 24.7.7.3 [range.transform.iterator] Status: New Submitter: Barry Revzin Opened: 2021-10-12 Last modified: 2021-10-17

Priority: Not Prioritized

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

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

View all issues with New status.

Discussion:

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 24.7.7.3 [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;
}

Proposed resolution:

This wording is relative to N4892.

  1. Modify 24.7.7.3 [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;
    }
    […]