-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Folding algorithms #3099
Folding algorithms #3099
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment was marked as resolved.
This comment was marked as resolved.
Thanks, this looks great! 😻 I exhaustively compared this to the Standard, and checked all of the |
|
||
template <input_range _Rng, class _Ty, _Indirectly_binary_left_foldable<_Ty, iterator_t<_Rng>> _Fn> | ||
_NODISCARD constexpr auto operator()(_Rng&& _Range, _Ty _Init, _Fn _Func) const { | ||
return _RANGES fold_left_with_iter(_STD forward<_Rng>(_Range), _STD move(_Init), _Pass_fn(_Func)).value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd want this to avoid the extra move into the in_value_result
and back out. (This is why the wording uses Returns: instead of "Effects: Equivalent to return ...;
")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do RVO or deferred temporary materialization help with that?
I think this would be reasonable to address in a followup PR.
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
I've pushed a merge with |
Thanks for implementing this C++23 feature! ⚙️ 🎉 😻 |
This PR implements P2322R6 (
ranges::fold
) and closes #2922.Changes:
<algorithm>
header includes<optional>
in C++23 mode,ranges::fold_left
andranges::fold_left_with_iter
- both invoke_Fold_left_with_iter_fn::_Fold_left_with_iter_impl
,ranges::fold_left_first
andranges::fold_left_first_with_iter
- both invoke_Fold_left_first_with_iter_fn::_Fold_left_first_with_iter_impl
,ranges::fold_right
- invokes_Fold_right_unchecked
ranges::fold_right_last
- invokes private function_Fold_right_last_unchecked