Wayverb
sum_ranges.h
1 #pragma once
2 
3 #include "utilities/foldl.h"
4 #include "utilities/for_each.h"
5 
6 namespace wayverb {
7 namespace core {
8 
9 template <typename... Ts>
10 auto sum_params(Ts&&... ts) {
11  return util::foldl_params(std::plus<>{}, std::forward<Ts>(ts)...);
12 }
13 
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));
19  while (b != e) {
20  ret.emplace_back(sum_params(*b++, (*its++)...));
21  }
22  return ret;
23 }
24 
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()); },
29  t,
30  ts...);
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)...);
34 }
35 
36 } // namespace core
37 } // namespace wayverb
Definition: traits.cpp:2
Definition: capsule_base.h:9