Skip to content

[libc++][ranges] LWG3618: Unnecessary iter_move for transform_view::iterator #91809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2024

Conversation

xiaoyang-sde
Copy link
Member

Introduction

This patch implements LWG3618: Unnecessary iter_move for transform_view::iterator.

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, but its sole purpose is to ensure the appropriate conditional noexcept specification.

Reference

@xiaoyang-sde xiaoyang-sde requested a review from a team as a code owner May 10, 2024 21:03
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label May 10, 2024
@llvmbot
Copy link
Member

llvmbot commented May 10, 2024

@llvm/pr-subscribers-libcxx

Author: Xiaoyang Liu (xiaoyang-sde)

Changes

Introduction

This patch implements LWG3618: Unnecessary iter_move for transform_view::iterator.

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, but its sole purpose is to ensure the appropriate conditional noexcept specification.

Reference


Full diff: https://github.com/llvm/llvm-project/pull/91809.diff

2 Files Affected:

  • (modified) libcxx/docs/Status/Cxx23Issues.csv (+1-1)
  • (modified) libcxx/include/__ranges/transform_view.h (-7)
diff --git a/libcxx/docs/Status/Cxx23Issues.csv b/libcxx/docs/Status/Cxx23Issues.csv
index 04f6e23375acd..55db4d209a407 100644
--- a/libcxx/docs/Status/Cxx23Issues.csv
+++ b/libcxx/docs/Status/Cxx23Issues.csv
@@ -146,7 +146,7 @@
 "`3610 <https://wg21.link/LWG3610>`__","``iota_view::size`` sometimes rejects integer-class types","February 2022","","","|ranges|"
 "`3612 <https://wg21.link/LWG3612>`__","Inconsistent pointer alignment in ``std::format`` ","February 2022","|Complete|","14.0","|format|"
 "`3616 <https://wg21.link/LWG3616>`__","LWG 3498 seems to miss the non-member ``swap`` for ``basic_syncbuf`` ","February 2022","",""
-"`3618 <https://wg21.link/LWG3618>`__","Unnecessary ``iter_move`` for ``transform_view::iterator`` ","February 2022","","","|ranges|"
+"`3618 <https://wg21.link/LWG3618>`__","Unnecessary ``iter_move`` for ``transform_view::iterator`` ","February 2022","|Complete|","19.0","|ranges|"
 "`3619 <https://wg21.link/LWG3619>`__","Specification of ``vformat_to`` contains ill-formed ``formatted_size`` calls","February 2022","|Nothing to do|","","|format|"
 "`3621 <https://wg21.link/LWG3621>`__","Remove feature-test macro ``__cpp_lib_monadic_optional`` ","February 2022","|Complete|","15.0"
 "`3632 <https://wg21.link/LWG3632>`__","``unique_ptr`` ""Mandates: This constructor is not selected by class template argument deduction""","February 2022","|Nothing to do|",""
diff --git a/libcxx/include/__ranges/transform_view.h b/libcxx/include/__ranges/transform_view.h
index dc3aaa59ed8c3..bcce389c0e680 100644
--- a/libcxx/include/__ranges/transform_view.h
+++ b/libcxx/include/__ranges/transform_view.h
@@ -326,13 +326,6 @@ class transform_view<_View, _Fn>::__iterator : public __transform_view_iterator_
   {
     return __x.__current_ - __y.__current_;
   }
-
-  _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) iter_move(const __iterator& __i) noexcept(noexcept(*__i)) {
-    if constexpr (is_lvalue_reference_v<decltype(*__i)>)
-      return std::move(*__i);
-    else
-      return *__i;
-  }
 };
 
 #  if _LIBCPP_STD_VER >= 23

@xiaoyang-sde xiaoyang-sde added the ranges Issues related to `<ranges>` label May 10, 2024
@@ -146,7 +146,7 @@
"`3610 <https://wg21.link/LWG3610>`__","``iota_view::size`` sometimes rejects integer-class types","February 2022","","","|ranges|"
"`3612 <https://wg21.link/LWG3612>`__","Inconsistent pointer alignment in ``std::format`` ","February 2022","|Complete|","14.0","|format|"
"`3616 <https://wg21.link/LWG3616>`__","LWG 3498 seems to miss the non-member ``swap`` for ``basic_syncbuf`` ","February 2022","",""
"`3618 <https://wg21.link/LWG3618>`__","Unnecessary ``iter_move`` for ``transform_view::iterator`` ","February 2022","","","|ranges|"
"`3618 <https://wg21.link/LWG3618>`__","Unnecessary ``iter_move`` for ``transform_view::iterator`` ","February 2022","|Complete|","19.0","|ranges|"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LWG-issues adds a noexcept. This is not tested in libcxx/test/std/ranges/range.adaptors/range.transform/iterator/deref.pass.cpp. Please update this test.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gentle ping, it looks like there is outstanding feedback that needs to be addressed.

@@ -37,7 +37,7 @@ int main(int, char**) {
using View = std::ranges::transform_view<MoveOnlyView, PlusOneNoexcept>;
View transformView(MoveOnlyView{buff}, PlusOneNoexcept{});
assert(*transformView.begin() == 1);
LIBCPP_ASSERT_NOEXCEPT(*std::declval<std::ranges::iterator_t<View>>());
ASSERT_NOEXCEPT(*std::declval<std::ranges::iterator_t<View>>());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The operator* previously provided a noexcept specifier as a libc++ extension. Following the adoption of this LWG issue, the noexcept specifier is now standard behavior.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying with your comment. LGTM!

@xiaoyang-sde
Copy link
Member Author

Thanks for clarifying with your comment. LGTM!

Could you please merge this patch? Thank you!

@mordante mordante merged commit 3d7622e into llvm:main Jul 22, 2024
55 checks passed
@xiaoyang-sde xiaoyang-sde deleted the lwg3618 branch July 22, 2024 20:31
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
…::iterator` (#91809)

Summary:
## Introduction

This patch implements LWG3618: Unnecessary `iter_move` for
`transform_view::iterator`.

`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, but its sole purpose is to ensure the
appropriate conditional `noexcept` specification.

## Reference

-
[[range.transform.iterator]](https://eel.is/c++draft/range.transform.iterator)
- [LWG3618](https://cplusplus.github.io/LWG/issue3618)

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251361
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants