[llvm] [ADT] Add `sum_of` and `product_of` accumulate wrappers. (PR #162129)
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 6 11:12:07 PDT 2025
================
@@ -1692,6 +1692,28 @@ template <typename R, typename E> auto accumulate(R &&Range, E &&Init) {
std::forward<E>(Init));
}
+/// Wrapper for std::accumulate with a binary operator.
+template <typename R, typename E, typename BinaryOp>
+auto accumulate(R &&Range, E &&Init, BinaryOp &&Op) {
+ return std::accumulate(adl_begin(Range), adl_end(Range),
+ std::forward<E>(Init), std::forward<BinaryOp>(Op));
+}
+
+/// Returns the sum of all values in `Range` with `Init` initial value.
+/// The default initial value is 0.
+template <typename R, typename E = detail::ValueOfRange<R>>
+auto sum_of(R &&Range, E Init = E{0}) {
----------------
mtrofin wrote:
nit: why not just `sum` and `product`?
https://github.com/llvm/llvm-project/pull/162129
More information about the llvm-commits
mailing list