[libcxx-commits] [libcxx] [libc++] Add `ranges::fold_left_first` and ranges::`fold_left_first_with_iter` (PR #121558)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jan 6 11:15:09 PST 2025
================
@@ -118,6 +121,55 @@ struct __fold_left {
};
inline constexpr auto fold_left = __fold_left();
+
+struct __fold_left_first_with_iter {
+ template <input_iterator _Ip, sentinel_for<_Ip> _Sp, __indirectly_binary_left_foldable<iter_value_t<_Ip>, _Ip> _Fp>
+ requires constructible_from<iter_value_t<_Ip>, iter_reference_t<_Ip>>
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(_Ip __first, _Sp __last, _Fp __f) {
+ using _Up = decltype(fold_left(std::move(__first), __last, iter_value_t<_Ip>(*__first), __f));
+
+ // case of empty range
+ if (__first == __last) {
+ return fold_left_first_with_iter_result<_Ip, optional<_Up>>{std::move(__first), optional<_Up>()};
----------------
JCGoran wrote:
Done.
https://github.com/llvm/llvm-project/pull/121558
More information about the libcxx-commits
mailing list