[libcxx-commits] [libcxx] [libc++][NFC] Update implementation strategy of the `operator()(I&& first, S last)` for `std::ranges::distance` (PR #215994)
Lucas Mellone via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 13 02:55:50 PDT 2026
https://github.com/lknknm updated https://github.com/llvm/llvm-project/pull/215994
>From fc9037a24279718d0d21dbb57919ef2708aa52b4 Mon Sep 17 00:00:00 2001
From: Lucas Mellone <github.snugness349 at passinbox.com>
Date: Thu, 13 Aug 2026 11:19:08 +0200
Subject: [PATCH 1/2] nfc: change impl strategy for operator()
---
libcxx/include/__iterator/distance.h | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/libcxx/include/__iterator/distance.h b/libcxx/include/__iterator/distance.h
index c7c4ff22d6e9f..20f186bc89c8a 100644
--- a/libcxx/include/__iterator/distance.h
+++ b/libcxx/include/__iterator/distance.h
@@ -22,7 +22,8 @@
#include <__ranges/size.h>
#include <__type_traits/decay.h>
#include <__type_traits/enable_if.h>
-#include <__type_traits/remove_cvref.h>
+#include <__type_traits/is_array.h>
+#include <__type_traits/remove_reference.h>
#include <__utility/move.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -87,10 +88,10 @@ struct __distance {
template <class _Ip, sized_sentinel_for<decay_t<_Ip>> _Sp>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> operator()(_Ip&& __first, _Sp __last) const {
- if constexpr (sized_sentinel_for<_Sp, __remove_cvref_t<_Ip>>) {
+ if constexpr (!is_array_v<remove_reference_t<_Ip>>) {
return __last - __first;
} else {
- return __last - decay_t<_Ip>(__first);
+ return __last - static_cast<decay_t<_Ip>>(__first);
}
}
>From 75ffd15d7f204bfa2d27f1e7352d9ba8a8d02e86 Mon Sep 17 00:00:00 2001
From: Lucas Mellone <github.snugness349 at passinbox.com>
Date: Thu, 13 Aug 2026 11:55:41 +0200
Subject: [PATCH 2/2] Update libcxx/include/__iterator/distance.h
Co-authored-by: A. Jiang <de34 at live.cn>
---
libcxx/include/__iterator/distance.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/__iterator/distance.h b/libcxx/include/__iterator/distance.h
index 20f186bc89c8a..1d1b37b7b662d 100644
--- a/libcxx/include/__iterator/distance.h
+++ b/libcxx/include/__iterator/distance.h
@@ -87,7 +87,8 @@ struct __distance {
}
template <class _Ip, sized_sentinel_for<decay_t<_Ip>> _Sp>
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> operator()(_Ip&& __first, _Sp __last) const {
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<decay_t<_Ip>>
+ operator()(_Ip&& __first, _Sp __last) const {
if constexpr (!is_array_v<remove_reference_t<_Ip>>) {
return __last - __first;
} else {
More information about the libcxx-commits
mailing list