diff --git a/coord/ops.hpp b/coord/ops.hpp index 10822a5b..8eda8684 100644 --- a/coord/ops.hpp +++ b/coord/ops.hpp @@ -23,8 +23,8 @@ #include "../maths.hpp" #include "../types/bits.hpp" -#include #include +#include namespace util { /////////////////////////////////////////////////////////////////////// @@ -625,7 +625,24 @@ namespace util { } - //------------------------------------------------------------------------- + /////////////////////////////////////////////////////////////////////////// + template < + size_t S, + typename T, + template class K, + typename = std::enable_if_t< + is_coord_v, void + > + > + constexpr + T + sum (const K k) + { + return sum (std::cbegin (k), std::cend (k)); + } + + + /////////////////////////////////////////////////////////////////////////// #define VECTOR_OP(OP) \ template < \ size_t S, \ diff --git a/test/coord.cpp b/test/coord.cpp index efef4064..1b7c7b70 100644 --- a/test/coord.cpp +++ b/test/coord.cpp @@ -34,5 +34,7 @@ main (void) auto vec = util::vector4f (0.5f); t.expect_eq (vec, util::normalised (vec), "normalisation of normalised vector"); + t.expect_eq (sum (util::vector4f::ONES), 4.f, "elementwise summation"); + return t.status (); }