coord/ops: add element sum overload

This commit is contained in:
Danny Robson 2016-08-15 18:46:04 +10:00
parent 1f86925237
commit f6ceb5cdee
2 changed files with 21 additions and 2 deletions

View File

@ -23,8 +23,8 @@
#include "../maths.hpp"
#include "../types/bits.hpp"
#include <cstdlib>
#include <cmath>
#include <cstdlib>
namespace util {
///////////////////////////////////////////////////////////////////////
@ -625,7 +625,24 @@ namespace util {
}
//-------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////
template <
size_t S,
typename T,
template <size_t,typename> class K,
typename = std::enable_if_t<
is_coord_v<K>, void
>
>
constexpr
T
sum (const K<S,T> k)
{
return sum (std::cbegin (k), std::cend (k));
}
///////////////////////////////////////////////////////////////////////////
#define VECTOR_OP(OP) \
template < \
size_t S, \

View File

@ -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 ();
}