[libcxx-commits] [libcxx] [libc++] Simplify the implementation of ranges::iter_move a bit (PR #198081)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sat May 16 03:20:19 PDT 2026
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/198081
None
>From 517cb8f1ce9a8c07adbea056c555179c7a4f5b29 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sat, 16 May 2026 12:19:54 +0200
Subject: [PATCH] [libc++] Simplify the implementation of ranges::iter_move a
bit
---
libcxx/include/__iterator/iter_move.h | 31 +++++++--------------------
1 file changed, 8 insertions(+), 23 deletions(-)
diff --git a/libcxx/include/__iterator/iter_move.h b/libcxx/include/__iterator/iter_move.h
index a726b6e329e90..528ed600ce8cd 100644
--- a/libcxx/include/__iterator/iter_move.h
+++ b/libcxx/include/__iterator/iter_move.h
@@ -44,18 +44,6 @@ concept __unqualified_iter_move = __class_or_enum<remove_cvref_t<_Tp>> && requir
iter_move(std::forward<_Tp>(__t));
};
-template <class _Tp>
-concept __move_deref = !__unqualified_iter_move<_Tp> && requires(_Tp&& __t) {
- *__t;
- requires is_lvalue_reference_v<decltype(*__t)>;
-};
-
-template <class _Tp>
-concept __just_deref = !__unqualified_iter_move<_Tp> && !__move_deref<_Tp> && requires(_Tp&& __t) {
- *__t;
- requires(!is_lvalue_reference_v<decltype(*__t)>);
-};
-
// [iterator.cust.move]
struct __fn {
@@ -69,17 +57,14 @@ struct __fn {
// NOLINTEND(libcpp-robust-against-adl)
template <class _Ip>
- requires __move_deref<_Ip>
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Ip&& __i) const
- noexcept(noexcept(std::move(*std::forward<_Ip>(__i)))) -> decltype(std::move(*std::forward<_Ip>(__i))) {
- return std::move(*std::forward<_Ip>(__i));
- }
-
- template <class _Ip>
- requires __just_deref<_Ip>
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Ip&& __i) const
- noexcept(noexcept(*std::forward<_Ip>(__i))) -> decltype(*std::forward<_Ip>(__i)) {
- return *std::forward<_Ip>(__i);
+ requires (!__unqualified_iter_move<_Ip> && requires(_Ip&& __t) { *__t; })
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Ip&& __i) const
+ noexcept(noexcept(*std::forward<_Ip>(__i))) {
+ if constexpr (is_lvalue_reference_v<decltype(*__i)>) {
+ return std::move(*std::forward<_Ip>(__i));
+ } else {
+ return *std::forward<_Ip>(__i);
+ }
}
};
} // namespace __iter_move
More information about the libcxx-commits
mailing list