diff options
Diffstat (limited to 'src/ipa/libipa/vector.h')
-rw-r--r-- | src/ipa/libipa/vector.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h index 937a28e9..9bdd54b6 100644 --- a/src/ipa/libipa/vector.h +++ b/src/ipa/libipa/vector.h @@ -10,6 +10,7 @@ #include <array> #include <cmath> #include <functional> +#include <numeric> #include <optional> #include <ostream> @@ -239,6 +240,12 @@ public: return std::sqrt(length2()); } + template<typename R = T> + constexpr R sum() const + { + return std::accumulate(data_.begin(), data_.end(), R{}); + } + private: template<class BinaryOp> static constexpr Vector apply(const Vector &lhs, const Vector &rhs, BinaryOp op) |