Daily bit(e) of C++ | std::transform_reduce
Daily bit(e) of C++ ♻️68, The C++17 algorithm that combines a single and two-range transformation with a reduction: std::transform_reduce.
Transform-reduce is a common operation, notably in distributed systems. C++ offers a C++17 standard algorithm with the same name.
The algorithm requires a commutative and associative reduction but offers single and two-range variants, a parallel (C++17) and constexpr (C++20) version.
There is no direct range alternative; however, similar behaviour can be obtained using the std::ranges::fold_left (C++23) in combination with a std::views::zip (C++23).