Use std::accumulate

This commit is contained in:
Chip Hogg
2022-03-11 03:48:57 +00:00
parent 73a56115a1
commit bfa8db6139

View File

@@ -25,6 +25,7 @@
#include <array>
#include <cassert>
#include <cstddef>
#include <numeric>
#include <optional>
#include <tuple>
@@ -88,9 +89,7 @@ constexpr auto coprimes_up_to(std::size_t n, const std::array<std::size_t, N> &b
template<std::size_t N>
constexpr std::size_t product(const std::array<std::size_t, N> &values) {
std::size_t product = 1;
for (const auto &v : values) { product *= v; }
return product;
return std::accumulate(std::begin(values), std::end(values), std::size_t{1u}, std::multiplies{});
}
// A configurable instantiation of the "wheel factorization" algorithm [1] for prime numbers.