diff --git a/coord/ops.hpp b/coord/ops.hpp index f7b24fce..fa83152f 100644 --- a/coord/ops.hpp +++ b/coord/ops.hpp @@ -71,12 +71,13 @@ namespace util { void \ >::type \ > \ + constexpr \ auto \ operator OP (A a, B b) \ { \ typename coord::traits::template result< \ S,typename std::common_type::type \ - > out; \ + > out {}; \ for (size_t i = 0; i < S; ++i) \ out[i] = a[i] OP b[i]; \ return out; \ @@ -125,10 +126,11 @@ namespace util { is_coord::value,void \ >::type \ > \ + constexpr \ auto \ operator OP (U u, K k) \ { \ - K::type> out; \ + K::type> out{};\ \ for (size_t i = 0; i < S; ++i) \ out[i] = u OP k[i]; \ @@ -144,10 +146,11 @@ namespace util { is_coord::value,void \ >::type \ > \ + constexpr \ auto \ operator OP (K k, U u) \ { \ - K::type> out; \ + K::type> out{};\ \ for (size_t i = 0; i < S; ++i) \ out[i] = k[i] OP u; \ @@ -210,10 +213,11 @@ namespace util { typename T, \ template class K \ > \ + constexpr \ auto \ operator OP (K k) \ { \ - K ())> out; \ + K ())> out{}; \ \ for (size_t i = 0; i < S; ++i) \ out[i] = OP k[i]; \ @@ -238,6 +242,7 @@ namespace util { typename T, template class K > + constexpr bool operator== (K a, K b) { @@ -256,6 +261,7 @@ namespace util { typename T, template class K > + constexpr bool operator!= (K a, K b) { @@ -272,10 +278,11 @@ namespace util { typename T, typename U > + constexpr vector::type> operator- (point a, point b) { - vector::type> out; + vector::type> out {}; for (size_t i = 0; i < S; ++i) out[i] = a[i] - b[i]; return out; @@ -288,6 +295,7 @@ namespace util { typename T, typename U > + constexpr vector::type> operator- (U u, point p) { @@ -300,7 +308,9 @@ namespace util { size_t S, typename T > - T dot (const T (&a)[S], const T (&b)[S]) + constexpr + T + dot (const T (&a)[S], const T (&b)[S]) { T sum = 0; for (size_t i = 0; i < S; ++i) @@ -314,6 +324,7 @@ namespace util { template class A, template class B > + constexpr typename std::enable_if< is_coord::value && is_coord::value, T @@ -329,17 +340,20 @@ namespace util { typename T, template class K > + constexpr typename std::enable_if::value,T>::type dot (K a, const T (&b)[S]) { return dot (a.data, b); } + template < size_t S, typename T, template class K > + constexpr typename std::enable_if< is_coord::value, T @@ -356,6 +370,7 @@ namespace util { typename T, template class K > + constexpr K abs (K k) { @@ -370,6 +385,7 @@ namespace util { typename T, template class K > + constexpr K pow (K k) { @@ -379,7 +395,6 @@ namespace util { } - /////////////////////////////////////////////////////////////////////////// // logical element operators @@ -389,10 +404,11 @@ namespace util { typename T, template class K > + constexpr K min (K a, K b) { - K out; + K out {}; for (size_t i = 0; i < S; ++i) out[i] = min (a[i], b[i]); return out; @@ -406,10 +422,11 @@ namespace util { typename T, template class K > + constexpr K max (K a, K b) { - K out; + K out {}; for (size_t i = 0; i < S; ++i) out[i] = max (a[i], b[i]); return out; @@ -418,12 +435,14 @@ namespace util { ///------------------------------------------------------------------------ template class K> + constexpr T min (K k) { return *std::min_element (k.begin (), k.end ()); } template class K> + constexpr T max (K k) { return *std::max_element (k.begin (), k.end ()); } @@ -438,10 +457,11 @@ namespace util { template class A, \ template class B \ > \ + constexpr \ vector \ operator OP (const A a, const B b) \ { \ - vector out; \ + vector out {}; \ for (size_t i = 0; i < S; ++i) \ out[i] = a[i] OP b[i]; \ return out; \ @@ -462,10 +482,11 @@ namespace util { typename U, \ template class K \ > \ + constexpr \ vector \ operator OP (const K k, const U u) \ { \ - vector out; \ + vector out {}; \ for (size_t i = 0; i < S; ++i) \ out[i] = k[i] OP u; \ return out; \ @@ -481,34 +502,40 @@ namespace util { //------------------------------------------------------------------------- template class K> + constexpr bool any (const K k) { - return std::any_of (k.begin (), k.end (), identity); + return std::any_of (std::cbegin (k), std::cbegin (k), identity); } //------------------------------------------------------------------------- template class K> + constexpr bool all (const K k) { - return std::all_of (k.begin (), k.end (), identity); + return std::all_of (std::cbegin (k), std::cbegin (k), identity); } /////////////////////////////////////////////////////////////////////////// template class K> + constexpr typename std::enable_if< std::is_floating_point::value, K >::type - floor (K k) + floor (const K k) { T (*floor_func)(T) = std::floor; - K v; - std::transform (k.begin (), k.end (), v.begin (), floor_func); - return v; + K out {}; + std::transform (std::cbegin (k), + std::cend (k), + std::begin (out), + floor_func); + return out; } }