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

Connector Switch via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 5 03:02:06 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);
----------------
c8ef wrote:

Indeed we can. Previously we use `__iter_ref` because `auto&&` is not available in c++14. In ranges we can use this.

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


More information about the libcxx-commits mailing list