[libcxx-commits] [libcxx] [libcxx] Optimize `ranges::fold_left_with_iter` for segmented iterators (PR #177853)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 5 00:52:49 PST 2026


================
@@ -80,18 +82,25 @@ concept __indirectly_binary_left_foldable =
 struct __fold_left_with_iter {
   template <input_iterator _Ip, sentinel_for<_Ip> _Sp, class _Tp, __indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
-    using _Up = decay_t<invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
+    using _Up        = decay_t<invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
+    using __iter_ref = decltype(*__first);
----------------
philnik777 wrote:

Do we need this? Can't we just `auto&&` and `std::forward<decltype(__element)>` below?

https://github.com/llvm/llvm-project/pull/177853


More information about the libcxx-commits mailing list