Daily bit(e) of C++ | ranges::fold_left, ranges::fold_left_first, ranges::fold_right, ranges::fold_right_last
Daily bit(e) of C++ #124, The C++23 fold algorithms: ranges::fold_left, ranges::fold_left_first, ranges::fold_right, ranges::fold_right_last.
The C++23 introduced a set of range-enabled fold algorithms to replace the std::accumulate
numeric algorithm.
The library provides both left and right folds: std::ranges::fold_left
and std::ranges::fold_right
.
As well as variants that use the first/last elements as initializers: std::ranges::fold_left_first
and std::ranges::fold_right_last
.