3 #include "utilities/foldl.h" 4 #include "utilities/for_each.h" 9 template <
typename... Ts>
10 auto sum_params(Ts&&... ts) {
11 return util::foldl_params(std::plus<>{}, std::forward<Ts>(ts)...);
14 template <
typename It,
typename... Its>
15 auto sum_ranges(It b, It e, Its... its) {
16 using value_type = decltype(sum_params(*b, *its...));
17 util::aligned::vector<value_type> ret;
18 ret.reserve(std::distance(b, e));
20 ret.emplace_back(sum_params(*b++, (*its++)...));
25 template <
typename T,
typename... Ts>
26 auto sum_vectors(T t, Ts... ts) {
27 const auto max_len = util::foldl_params(
28 [](
auto a,
auto b) {
return std::max(a.size(), b.size()); },
31 util::for_each_params(
32 [&](
auto& vec) { vec.resize(max_len, 0.0); }, t, ts...);
33 return sum_ranges(begin(t), end(t), begin(ts)...);
Definition: capsule_base.h:9