From 2a19b789eb761bfc85bf3b92fc205c0f9df11433 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 21 Feb 2021 01:27:12 +0700 Subject: [PATCH] operators non-arithmetic T support --- README.md | 144 ++++++++++++++-------------- headers/vmath.hpp/vmath_mat_fun.hpp | 62 ++++++------ headers/vmath.hpp/vmath_qua_fun.hpp | 24 ++--- headers/vmath.hpp/vmath_vec_fun.hpp | 62 ++++++------ 4 files changed, 146 insertions(+), 146 deletions(-) diff --git a/README.md b/README.md index bb08b23..43cfac7 100644 --- a/README.md +++ b/README.md @@ -460,33 +460,33 @@ using qdouble = qua; // +operator template < typename T, size_t Size > -constexpr vec operator+(const vec& xs); +constexpr auto operator+(const vec& xs); // -operator template < typename T, size_t Size > -constexpr vec operator-(const vec& xs); +constexpr auto operator-(const vec& xs); // ~operator template < typename T, size_t Size > -constexpr vec operator~(const vec& xs); +constexpr auto operator~(const vec& xs); // !operator template < typename T, size_t Size > -constexpr vec operator!(const vec& xs); +constexpr auto operator!(const vec& xs); // operator+ template < typename T, size_t Size > -constexpr vec operator+(const vec& xs, T y); +constexpr auto operator+(const vec& xs, T y); template < typename T, size_t Size > -constexpr vec operator+(T x, const vec& ys); +constexpr auto operator+(T x, const vec& ys); template < typename T, size_t Size > -constexpr vec operator+(const vec& xs, const vec& ys); +constexpr auto operator+(const vec& xs, const vec& ys); // operator+= @@ -499,13 +499,13 @@ constexpr vec& operator+=(vec& xs, const vec& ys); // operator- template < typename T, size_t Size > -constexpr vec operator-(const vec& xs, T y); +constexpr auto operator-(const vec& xs, T y); template < typename T, size_t Size > -constexpr vec operator-(T x, const vec& ys); +constexpr auto operator-(T x, const vec& ys); template < typename T, size_t Size > -constexpr vec operator-(const vec& xs, const vec& ys); +constexpr auto operator-(const vec& xs, const vec& ys); // operator-= @@ -518,13 +518,13 @@ constexpr vec& operator-=(vec& xs, const vec& ys); // operator* template < typename T, size_t Size > -constexpr vec operator*(const vec& xs, T y); +constexpr auto operator*(const vec& xs, T y); template < typename T, size_t Size > -constexpr vec operator*(T x, const vec& ys); +constexpr auto operator*(T x, const vec& ys); template < typename T, size_t Size > -constexpr vec operator*(const vec& xs, const vec& ys); +constexpr auto operator*(const vec& xs, const vec& ys); // operator*= @@ -537,13 +537,13 @@ constexpr vec& operator*=(vec& xs, const vec& ys); // operator/ template < typename T, size_t Size > -constexpr vec operator/(const vec& xs, T y); +constexpr auto operator/(const vec& xs, T y); template < typename T, size_t Size > -constexpr vec operator/(T x, const vec& ys); +constexpr auto operator/(T x, const vec& ys); template < typename T, size_t Size > -constexpr vec operator/(const vec& xs, const vec& ys); +constexpr auto operator/(const vec& xs, const vec& ys); // operator/= @@ -556,13 +556,13 @@ constexpr vec& operator/=(vec& xs, const vec& ys); // operator& template < typename T, size_t Size > -constexpr vec operator&(const vec& xs, T y); +constexpr auto operator&(const vec& xs, T y); template < typename T, size_t Size > -constexpr vec operator&(T x, const vec& ys); +constexpr auto operator&(T x, const vec& ys); template < typename T, size_t Size > -constexpr vec operator&(const vec& xs, const vec& ys); +constexpr auto operator&(const vec& xs, const vec& ys); // operator&= @@ -575,13 +575,13 @@ constexpr vec& operator&=(vec& xs, const vec& ys); // operator| template < typename T, size_t Size > -constexpr vec operator|(const vec& xs, T y); +constexpr auto operator|(const vec& xs, T y); template < typename T, size_t Size > -constexpr vec operator|(T x, const vec& ys); +constexpr auto operator|(T x, const vec& ys); template < typename T, size_t Size > -constexpr vec operator|(const vec& xs, const vec& ys); +constexpr auto operator|(const vec& xs, const vec& ys); // operator|= @@ -594,13 +594,13 @@ constexpr vec& operator|=(vec& xs, const vec& ys); // operator^ template < typename T, size_t Size > -constexpr vec operator^(const vec& xs, T y); +constexpr auto operator^(const vec& xs, T y); template < typename T, size_t Size > -constexpr vec operator^(T x, const vec& ys); +constexpr auto operator^(T x, const vec& ys); template < typename T, size_t Size > -constexpr vec operator^(const vec& xs, const vec& ys); +constexpr auto operator^(const vec& xs, const vec& ys); // operator^= @@ -613,24 +613,24 @@ constexpr vec& operator^=(vec& xs, const vec& ys); // operator&& template < typename T, size_t Size > -constexpr vec operator&&(const vec& xs, T y); +constexpr auto operator&&(const vec& xs, T y); template < typename T, size_t Size > -constexpr vec operator&&(T x, const vec& ys); +constexpr auto operator&&(T x, const vec& ys); template < typename T, size_t Size > -constexpr vec operator&&(const vec& xs, const vec& ys); +constexpr auto operator&&(const vec& xs, const vec& ys); // operator|| template < typename T, size_t Size > -constexpr vec operator||(const vec& xs, T y); +constexpr auto operator||(const vec& xs, T y); template < typename T, size_t Size > -constexpr vec operator||(T x, const vec& ys); +constexpr auto operator||(T x, const vec& ys); template < typename T, size_t Size > -constexpr vec operator||(const vec& xs, const vec& ys); +constexpr auto operator||(const vec& xs, const vec& ys); // operator== @@ -654,33 +654,33 @@ constexpr bool operator<(const vec& xs, const vec& ys); // +operator template < typename T, size_t Size > -constexpr mat operator+(const mat& xs); +constexpr auto operator+(const mat& xs); // -operator template < typename T, size_t Size > -constexpr mat operator-(const mat& xs); +constexpr auto operator-(const mat& xs); // ~operator template < typename T, size_t Size > -constexpr mat operator~(const mat& xs); +constexpr auto operator~(const mat& xs); // !operator template < typename T, size_t Size > -constexpr mat operator!(const mat& xs); +constexpr auto operator!(const mat& xs); // operator+ template < typename T, size_t Size > -constexpr mat operator+(const mat& xs, T y); +constexpr auto operator+(const mat& xs, T y); template < typename T, size_t Size > -constexpr mat operator+(T x, const mat& ys); +constexpr auto operator+(T x, const mat& ys); template < typename T, size_t Size > -constexpr mat operator+(const mat& xs, const mat& ys); +constexpr auto operator+(const mat& xs, const mat& ys); // operator+= @@ -693,13 +693,13 @@ constexpr mat& operator+=(mat& xs, const mat& ys); // operator- template < typename T, size_t Size > -constexpr mat operator-(const mat& xs, T y); +constexpr auto operator-(const mat& xs, T y); template < typename T, size_t Size > -constexpr mat operator-(T x, const mat& ys); +constexpr auto operator-(T x, const mat& ys); template < typename T, size_t Size > -constexpr mat operator-(const mat& xs, const mat& ys); +constexpr auto operator-(const mat& xs, const mat& ys); // operator-= @@ -712,16 +712,16 @@ constexpr mat& operator-=(mat& xs, const mat& ys); // operator* template < typename T, size_t Size > -constexpr mat operator*(const mat& xs, T y); +constexpr auto operator*(const mat& xs, T y); template < typename T, size_t Size > -constexpr mat operator*(T x, const mat& ys); +constexpr auto operator*(T x, const mat& ys); template < typename T, size_t Size > -constexpr vec operator*(const vec& xs, const mat& ys); +constexpr auto operator*(const vec& xs, const mat& ys); template < typename T, size_t Size > -constexpr mat operator*(const mat& xs, const mat& ys); +constexpr auto operator*(const mat& xs, const mat& ys); // operator*= @@ -737,10 +737,10 @@ constexpr mat& operator*=(mat& xs, const mat& ys); // operator/ template < typename T, size_t Size > -constexpr mat operator/(const mat& xs, T y); +constexpr auto operator/(const mat& xs, T y); template < typename T, size_t Size > -constexpr mat operator/(T x, const mat& ys); +constexpr auto operator/(T x, const mat& ys); // operator/= @@ -750,13 +750,13 @@ constexpr mat& operator/=(mat& xs, T y); // operator& template < typename T, size_t Size > -constexpr mat operator&(const mat& xs, T y); +constexpr auto operator&(const mat& xs, T y); template < typename T, size_t Size > -constexpr mat operator&(T x, const mat& ys); +constexpr auto operator&(T x, const mat& ys); template < typename T, size_t Size > -constexpr mat operator&(const mat& xs, const mat& ys); +constexpr auto operator&(const mat& xs, const mat& ys); // operator&= @@ -769,13 +769,13 @@ constexpr mat& operator&=(mat& xs, const mat& ys); // operator| template < typename T, size_t Size > -constexpr mat operator|(const mat& xs, T y); +constexpr auto operator|(const mat& xs, T y); template < typename T, size_t Size > -constexpr mat operator|(T x, const mat& ys); +constexpr auto operator|(T x, const mat& ys); template < typename T, size_t Size > -constexpr mat operator|(const mat& xs, const mat& ys); +constexpr auto operator|(const mat& xs, const mat& ys); // operator|= @@ -788,13 +788,13 @@ constexpr mat& operator|=(mat& xs, const mat& ys); // operator^ template < typename T, size_t Size > -constexpr mat operator^(const mat& xs, T y); +constexpr auto operator^(const mat& xs, T y); template < typename T, size_t Size > -constexpr mat operator^(T x, const mat& ys); +constexpr auto operator^(T x, const mat& ys); template < typename T, size_t Size > -constexpr mat operator^(const mat& xs, const mat& ys); +constexpr auto operator^(const mat& xs, const mat& ys); // operator^= @@ -807,24 +807,24 @@ constexpr mat& operator^=(mat& xs, const mat& ys); // operator&& template < typename T, size_t Size > -constexpr mat operator&&(const mat& xs, T y); +constexpr auto operator&&(const mat& xs, T y); template < typename T, size_t Size > -constexpr mat operator&&(T x, const mat& ys); +constexpr auto operator&&(T x, const mat& ys); template < typename T, size_t Size > -constexpr mat operator&&(const mat& xs, const mat& ys); +constexpr auto operator&&(const mat& xs, const mat& ys); // operator|| template < typename T, size_t Size > -constexpr mat operator||(const mat& xs, T y); +constexpr auto operator||(const mat& xs, T y); template < typename T, size_t Size > -constexpr mat operator||(T x, const mat& ys); +constexpr auto operator||(T x, const mat& ys); template < typename T, size_t Size > -constexpr mat operator||(const mat& xs, const mat& ys); +constexpr auto operator||(const mat& xs, const mat& ys); // operator== @@ -848,17 +848,17 @@ constexpr bool operator<(const mat& xs, const mat& ys); // +operator template < typename T > -constexpr qua operator+(const qua& xs); +constexpr auto operator+(const qua& xs); // -operator template < typename T > -constexpr qua operator-(const qua& xs); +constexpr auto operator-(const qua& xs); // operator+ template < typename T > -constexpr qua operator+(const qua& xs, const qua& ys); +constexpr auto operator+(const qua& xs, const qua& ys); // operator+= @@ -868,7 +868,7 @@ constexpr qua& operator+=(qua& xs, const qua& ys); // operator- template < typename T > -constexpr qua operator-(const qua& xs, const qua& ys); +constexpr auto operator-(const qua& xs, const qua& ys); // operator-= @@ -878,16 +878,16 @@ constexpr qua& operator-=(qua& xs, const qua& ys); // operator* template < typename T > -constexpr qua operator*(const qua& xs, T y); +constexpr auto operator*(const qua& xs, T y); template < typename T > -constexpr qua operator*(T x, const qua& ys); +constexpr auto operator*(T x, const qua& ys); template < typename T > -constexpr vec operator*(const vec& xs, const qua& ys); +constexpr auto operator*(const vec& xs, const qua& ys); template < typename T > -constexpr qua operator*(const qua& xs, const qua& ys); +constexpr auto operator*(const qua& xs, const qua& ys); // operator*= @@ -903,10 +903,10 @@ constexpr qua& operator*=(qua& xs, const qua& ys); // operator/ template < typename T > -constexpr qua operator/(const qua& xs, T y); +constexpr auto operator/(const qua& xs, T y); template < typename T > -constexpr qua operator/(T x, const qua& ys); +constexpr auto operator/(T x, const qua& ys); // operator/= diff --git a/headers/vmath.hpp/vmath_mat_fun.hpp b/headers/vmath.hpp/vmath_mat_fun.hpp index 3dc1eda..704f850 100644 --- a/headers/vmath.hpp/vmath_mat_fun.hpp +++ b/headers/vmath.hpp/vmath_mat_fun.hpp @@ -195,45 +195,45 @@ namespace vmath_hpp // +operator template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator+(const mat& xs) { + [[nodiscard]] constexpr auto operator+(const mat& xs) { return xs; } // -operator template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator-(const mat& xs) { + [[nodiscard]] constexpr auto operator-(const mat& xs) { return map_join([](const vec& x){ return -x; }, xs); } // ~operator template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator~(const mat& xs) { + [[nodiscard]] constexpr auto operator~(const mat& xs) { return map_join([](const vec& x){ return ~x; }, xs); } // !operator template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator!(const mat& xs) { + [[nodiscard]] constexpr auto operator!(const mat& xs) { return map_join([](const vec& x){ return !x; }, xs); } // operator+ template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator+(const mat& xs, T y) { + [[nodiscard]] constexpr auto operator+(const mat& xs, T y) { return map_join([y](const vec& x){ return x + y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator+(T x, const mat& ys) { + [[nodiscard]] constexpr auto operator+(T x, const mat& ys) { return map_join([x](const vec& y){ return x + y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator+(const mat& xs, const mat& ys) { + [[nodiscard]] constexpr auto operator+(const mat& xs, const mat& ys) { return map_join([](const vec& x, const vec& y){ return x + y; }, xs, ys); } @@ -252,17 +252,17 @@ namespace vmath_hpp // operator- template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator-(const mat& xs, T y) { + [[nodiscard]] constexpr auto operator-(const mat& xs, T y) { return map_join([y](const vec& x){ return x - y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator-(T x, const mat& ys) { + [[nodiscard]] constexpr auto operator-(T x, const mat& ys) { return map_join([x](const vec& y){ return x - y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator-(const mat& xs, const mat& ys) { + [[nodiscard]] constexpr auto operator-(const mat& xs, const mat& ys) { return map_join([](const vec& x, const vec& y){ return x - y; }, xs, ys); } @@ -281,24 +281,24 @@ namespace vmath_hpp // operator* template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator*(const mat& xs, T y) { + [[nodiscard]] constexpr auto operator*(const mat& xs, T y) { return map_join([y](const vec& x){ return x * y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator*(T x, const mat& ys) { + [[nodiscard]] constexpr auto operator*(T x, const mat& ys) { return map_join([x](const vec& y){ return x * y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator*(const vec& xs, const mat& ys) { + [[nodiscard]] constexpr auto operator*(const vec& xs, const mat& ys) { return fold_join([](const vec& acc, T x, const vec& y){ return acc + x * y; }, vec{}, xs, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator*(const mat& xs, const mat& ys) { + [[nodiscard]] constexpr auto operator*(const mat& xs, const mat& ys) { return map_join([&ys](const vec& x){ return x * ys; }, xs); @@ -324,12 +324,12 @@ namespace vmath_hpp // operator/ template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator/(const mat& xs, T y) { + [[nodiscard]] constexpr auto operator/(const mat& xs, T y) { return map_join([y](const vec& x){ return x / y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator/(T x, const mat& ys) { + [[nodiscard]] constexpr auto operator/(T x, const mat& ys) { return map_join([x](const vec& y){ return x / y; }, ys); } @@ -343,17 +343,17 @@ namespace vmath_hpp // operator& template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator&(const mat& xs, T y) { + [[nodiscard]] constexpr auto operator&(const mat& xs, T y) { return map_join([y](const vec& x){ return x & y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator&(T x, const mat& ys) { + [[nodiscard]] constexpr auto operator&(T x, const mat& ys) { return map_join([x](const vec& y){ return x & y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator&(const mat& xs, const mat& ys) { + [[nodiscard]] constexpr auto operator&(const mat& xs, const mat& ys) { return map_join([](const vec& x, const vec& y){ return x & y; }, xs, ys); } @@ -372,17 +372,17 @@ namespace vmath_hpp // operator| template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator|(const mat& xs, T y) { + [[nodiscard]] constexpr auto operator|(const mat& xs, T y) { return map_join([y](const vec& x){ return x | y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator|(T x, const mat& ys) { + [[nodiscard]] constexpr auto operator|(T x, const mat& ys) { return map_join([x](const vec& y){ return x | y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator|(const mat& xs, const mat& ys) { + [[nodiscard]] constexpr auto operator|(const mat& xs, const mat& ys) { return map_join([](const vec& x, const vec& y){ return x | y; }, xs, ys); } @@ -401,17 +401,17 @@ namespace vmath_hpp // operator^ template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator^(const mat& xs, T y) { + [[nodiscard]] constexpr auto operator^(const mat& xs, T y) { return map_join([y](const vec& x){ return x ^ y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator^(T x, const mat& ys) { + [[nodiscard]] constexpr auto operator^(T x, const mat& ys) { return map_join([x](const vec& y){ return x ^ y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator^(const mat& xs, const mat& ys) { + [[nodiscard]] constexpr auto operator^(const mat& xs, const mat& ys) { return map_join([](const vec& x, const vec& y){ return x ^ y; }, xs, ys); } @@ -430,34 +430,34 @@ namespace vmath_hpp // operator&& template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator&&(const mat& xs, T y) { + [[nodiscard]] constexpr auto operator&&(const mat& xs, T y) { return map_join([y](const vec& x){ return x && y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator&&(T x, const mat& ys) { + [[nodiscard]] constexpr auto operator&&(T x, const mat& ys) { return map_join([x](const vec& y){ return x && y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator&&(const mat& xs, const mat& ys) { + [[nodiscard]] constexpr auto operator&&(const mat& xs, const mat& ys) { return map_join([](const vec& x, const vec& y){ return x && y; }, xs, ys); } // operator|| template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator||(const mat& xs, T y) { + [[nodiscard]] constexpr auto operator||(const mat& xs, T y) { return map_join([y](const vec& x){ return x || y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator||(T x, const mat& ys) { + [[nodiscard]] constexpr auto operator||(T x, const mat& ys) { return map_join([x](const vec& y){ return x || y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator||(const mat& xs, const mat& ys) { + [[nodiscard]] constexpr auto operator||(const mat& xs, const mat& ys) { return map_join([](const vec& x, const vec& y){ return x || y; }, xs, ys); } diff --git a/headers/vmath.hpp/vmath_qua_fun.hpp b/headers/vmath.hpp/vmath_qua_fun.hpp index 59d1624..3c5d574 100644 --- a/headers/vmath.hpp/vmath_qua_fun.hpp +++ b/headers/vmath.hpp/vmath_qua_fun.hpp @@ -23,21 +23,21 @@ namespace vmath_hpp // +operator template < typename T > - [[nodiscard]] constexpr qua operator+(const qua& xs) { + [[nodiscard]] constexpr auto operator+(const qua& xs) { return xs; } // -operator template < typename T > - [[nodiscard]] constexpr qua operator-(const qua& xs) { + [[nodiscard]] constexpr auto operator-(const qua& xs) { return qua(-vec{xs}); } // operator+ template < typename T > - [[nodiscard]] constexpr qua operator+(const qua& xs, const qua& ys) { + [[nodiscard]] constexpr auto operator+(const qua& xs, const qua& ys) { return qua(vec{xs} + vec{ys}); } @@ -51,7 +51,7 @@ namespace vmath_hpp // operator- template < typename T > - [[nodiscard]] constexpr qua operator-(const qua& xs, const qua& ys) { + [[nodiscard]] constexpr auto operator-(const qua& xs, const qua& ys) { return qua(vec{xs} - vec{ys}); } @@ -65,30 +65,30 @@ namespace vmath_hpp // operator* template < typename T > - [[nodiscard]] constexpr qua operator*(const qua& xs, T y) { + [[nodiscard]] constexpr auto operator*(const qua& xs, T y) { return qua(vec{xs} * y); } template < typename T > - [[nodiscard]] constexpr qua operator*(T x, const qua& ys) { + [[nodiscard]] constexpr auto operator*(T x, const qua& ys) { return qua(x * vec{ys}); } template < typename T > - [[nodiscard]] constexpr vec operator*(const vec& xs, const qua& ys) { + [[nodiscard]] constexpr auto operator*(const vec& xs, const qua& ys) { /// REFERENCE: /// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/ - const vec qv2 = cross(ys.v, xs) * T(2); + const vec qv2 = cross(ys.v, xs) * T{2}; return xs + qv2 * ys.s + cross(ys.v, qv2); } template < typename T > - [[nodiscard]] constexpr qua operator*(const qua& xs, const qua& ys) { + [[nodiscard]] constexpr auto operator*(const qua& xs, const qua& ys) { /// REFERENCE: /// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/arithmetic/ - return { + return qua{ cross(ys.v, xs.v) + ys.s * xs.v + xs.s * ys.v, ys.s * xs.s - dot(ys.v, xs.v)}; } @@ -113,12 +113,12 @@ namespace vmath_hpp // operator/ template < typename T > - [[nodiscard]] constexpr qua operator/(const qua& xs, T y) { + [[nodiscard]] constexpr auto operator/(const qua& xs, T y) { return qua(vec{xs} / y); } template < typename T > - [[nodiscard]] constexpr qua operator/(T x, const qua& ys) { + [[nodiscard]] constexpr auto operator/(T x, const qua& ys) { return qua(x / vec{ys}); } diff --git a/headers/vmath.hpp/vmath_vec_fun.hpp b/headers/vmath.hpp/vmath_vec_fun.hpp index 979a3ec..017f940 100644 --- a/headers/vmath.hpp/vmath_vec_fun.hpp +++ b/headers/vmath.hpp/vmath_vec_fun.hpp @@ -199,45 +199,45 @@ namespace vmath_hpp // +operator template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator+(const vec& xs) { + [[nodiscard]] constexpr auto operator+(const vec& xs) { return xs; } // -operator template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator-(const vec& xs) { + [[nodiscard]] constexpr auto operator-(const vec& xs) { return map_join([](T x){ return -x; }, xs); } // ~operator template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator~(const vec& xs) { + [[nodiscard]] constexpr auto operator~(const vec& xs) { return map_join([](T x){ return ~x; }, xs); } // !operator template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator!(const vec& xs) { + [[nodiscard]] constexpr auto operator!(const vec& xs) { return map_join([](T x){ return !x; }, xs); } // operator+ template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator+(const vec& xs, T y) { + [[nodiscard]] constexpr auto operator+(const vec& xs, T y) { return map_join([y](T x){ return x + y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator+(T x, const vec& ys) { + [[nodiscard]] constexpr auto operator+(T x, const vec& ys) { return map_join([x](T y){ return x + y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator+(const vec& xs, const vec& ys) { + [[nodiscard]] constexpr auto operator+(const vec& xs, const vec& ys) { return map_join([](T x, T y){ return x + y; }, xs, ys); } @@ -256,17 +256,17 @@ namespace vmath_hpp // operator- template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator-(const vec& xs, T y) { + [[nodiscard]] constexpr auto operator-(const vec& xs, T y) { return map_join([y](T x){ return x - y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator-(T x, const vec& ys) { + [[nodiscard]] constexpr auto operator-(T x, const vec& ys) { return map_join([x](T y){ return x - y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator-(const vec& xs, const vec& ys) { + [[nodiscard]] constexpr auto operator-(const vec& xs, const vec& ys) { return map_join([](T x, T y){ return x - y; }, xs, ys); } @@ -285,17 +285,17 @@ namespace vmath_hpp // operator* template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator*(const vec& xs, T y) { + [[nodiscard]] constexpr auto operator*(const vec& xs, T y) { return map_join([y](T x){ return x * y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator*(T x, const vec& ys) { + [[nodiscard]] constexpr auto operator*(T x, const vec& ys) { return map_join([x](T y){ return x * y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator*(const vec& xs, const vec& ys) { + [[nodiscard]] constexpr auto operator*(const vec& xs, const vec& ys) { return map_join([](T x, T y){ return x * y; }, xs, ys); } @@ -314,17 +314,17 @@ namespace vmath_hpp // operator/ template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator/(const vec& xs, T y) { + [[nodiscard]] constexpr auto operator/(const vec& xs, T y) { return map_join([y](T x){ return x / y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator/(T x, const vec& ys) { + [[nodiscard]] constexpr auto operator/(T x, const vec& ys) { return map_join([x](T y){ return x / y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator/(const vec& xs, const vec& ys) { + [[nodiscard]] constexpr auto operator/(const vec& xs, const vec& ys) { return map_join([](T x, T y){ return x / y; }, xs, ys); } @@ -343,17 +343,17 @@ namespace vmath_hpp // operator& template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator&(const vec& xs, T y) { + [[nodiscard]] constexpr auto operator&(const vec& xs, T y) { return map_join([y](T x){ return x & y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator&(T x, const vec& ys) { + [[nodiscard]] constexpr auto operator&(T x, const vec& ys) { return map_join([x](T y){ return x & y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator&(const vec& xs, const vec& ys) { + [[nodiscard]] constexpr auto operator&(const vec& xs, const vec& ys) { return map_join([](T x, T y){ return x & y; }, xs, ys); } @@ -372,17 +372,17 @@ namespace vmath_hpp // operator| template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator|(const vec& xs, T y) { + [[nodiscard]] constexpr auto operator|(const vec& xs, T y) { return map_join([y](T x){ return x | y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator|(T x, const vec& ys) { + [[nodiscard]] constexpr auto operator|(T x, const vec& ys) { return map_join([x](T y){ return x | y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator|(const vec& xs, const vec& ys) { + [[nodiscard]] constexpr auto operator|(const vec& xs, const vec& ys) { return map_join([](T x, T y){ return x | y; }, xs, ys); } @@ -401,17 +401,17 @@ namespace vmath_hpp // operator^ template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator^(const vec& xs, T y) { + [[nodiscard]] constexpr auto operator^(const vec& xs, T y) { return map_join([y](T x){ return x ^ y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator^(T x, const vec& ys) { + [[nodiscard]] constexpr auto operator^(T x, const vec& ys) { return map_join([x](T y){ return x ^ y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator^(const vec& xs, const vec& ys) { + [[nodiscard]] constexpr auto operator^(const vec& xs, const vec& ys) { return map_join([](T x, T y){ return x ^ y; }, xs, ys); } @@ -430,34 +430,34 @@ namespace vmath_hpp // operator&& template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator&&(const vec& xs, T y) { + [[nodiscard]] constexpr auto operator&&(const vec& xs, T y) { return map_join([y](T x){ return x && y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator&&(T x, const vec& ys) { + [[nodiscard]] constexpr auto operator&&(T x, const vec& ys) { return map_join([x](T y){ return x && y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator&&(const vec& xs, const vec& ys) { + [[nodiscard]] constexpr auto operator&&(const vec& xs, const vec& ys) { return map_join([](T x, T y){ return x && y; }, xs, ys); } // operator|| template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator||(const vec& xs, T y) { + [[nodiscard]] constexpr auto operator||(const vec& xs, T y) { return map_join([y](T x){ return x || y; }, xs); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator||(T x, const vec& ys) { + [[nodiscard]] constexpr auto operator||(T x, const vec& ys) { return map_join([x](T y){ return x || y; }, ys); } template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator||(const vec& xs, const vec& ys) { + [[nodiscard]] constexpr auto operator||(const vec& xs, const vec& ys) { return map_join([](T x, T y){ return x || y; }, xs, ys); }