std::vector apply()

in fbpcf/common/VectorUtil.h [19:35]


std::vector<T> apply(
    const std::vector<T>& a,
    const std::vector<T>& b,
    std::function<T(T, T)> f) {
  if (a.size() != b.size()) {
    throw std::invalid_argument("Size doesn't match.");
  }

  std::vector<T> res;
  res.reserve(a.size());

  for (int64_t i = 0; i < a.size(); i++) {
    res.push_back(f(a[i], b[i]));
  }

  return res;
}