From 150fb80fa75c37d70c140bef409e5b58c0aa20ad Mon Sep 17 00:00:00 2001 From: Philip Trettner <Philip.Trettner@rwth-aachen.de> Date: Mon, 28 Jan 2019 14:02:34 +0100 Subject: [PATCH] assignment ops now work out-of-the-box for all tg types --- src/tg/detail/operators.hh | 2 ++ src/tg/detail/operators/common.hh | 35 +++++++++++++++++++++++++ src/tg/detail/operators/ops_pos.hh | 6 ----- src/tg/detail/operators/ops_size.hh | 6 ----- src/tg/detail/operators/ops_triangle.hh | 7 ----- src/tg/detail/operators/ops_vec.hh | 6 ----- 6 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 src/tg/detail/operators/common.hh diff --git a/src/tg/detail/operators.hh b/src/tg/detail/operators.hh index 48c49ad..554904e 100644 --- a/src/tg/detail/operators.hh +++ b/src/tg/detail/operators.hh @@ -1,5 +1,7 @@ #pragma once +#include "operators/common.hh" + #include "operators/ops_pos.hh" #include "operators/ops_vec.hh" #include "operators/ops_size.hh" diff --git a/src/tg/detail/operators/common.hh b/src/tg/detail/operators/common.hh new file mode 100644 index 0000000..9d7afe8 --- /dev/null +++ b/src/tg/detail/operators/common.hh @@ -0,0 +1,35 @@ +#pragma once + +namespace tg +{ +template <class A, class B> +constexpr auto operator+=(A& lhs, B const& rhs) -> decltype(lhs = A(lhs + rhs), lhs) +{ + lhs = A(lhs + rhs); + return lhs; +} +template <class A, class B> +constexpr auto operator-=(A& lhs, B const& rhs) -> decltype(lhs = A(lhs - rhs), lhs) +{ + lhs = A(lhs - rhs); + return lhs; +} +template <class A, class B> +constexpr auto operator*=(A& lhs, B const& rhs) -> decltype(lhs = A(lhs * rhs), lhs) +{ + lhs = A(lhs * rhs); + return lhs; +} +template <class A, class B> +constexpr auto operator/=(A& lhs, B const& rhs) -> decltype(lhs = A(lhs / rhs), lhs) +{ + lhs = A(lhs / rhs); + return lhs; +} +template <class A, class B> +constexpr auto operator%=(A& lhs, B const& rhs) -> decltype(lhs = A(lhs % rhs), lhs) +{ + lhs = A(lhs % rhs); + return lhs; +} +} // namespace tg diff --git a/src/tg/detail/operators/ops_pos.hh b/src/tg/detail/operators/ops_pos.hh index aa7c289..a8cb465 100644 --- a/src/tg/detail/operators/ops_pos.hh +++ b/src/tg/detail/operators/ops_pos.hh @@ -29,10 +29,4 @@ TG_IMPL_DEFINE_BINARY_OP_SCALAR(pos, +); TG_IMPL_DEFINE_BINARY_OP_SCALAR(pos, *); TG_IMPL_DEFINE_BINARY_OP_SCALAR_DIV(pos); -// assignment ops -TG_IMPL_DEFINE_ASSIGNMENT_OP(pos, +); -TG_IMPL_DEFINE_ASSIGNMENT_OP(pos, -); -TG_IMPL_DEFINE_ASSIGNMENT_OP(pos, *); -TG_IMPL_DEFINE_ASSIGNMENT_OP(pos, /); - } // namespace tg diff --git a/src/tg/detail/operators/ops_size.hh b/src/tg/detail/operators/ops_size.hh index ce64a22..b78e44b 100644 --- a/src/tg/detail/operators/ops_size.hh +++ b/src/tg/detail/operators/ops_size.hh @@ -23,10 +23,4 @@ TG_IMPL_DEFINE_BINARY_OP_SCALAR(size, -); TG_IMPL_DEFINE_BINARY_OP_SCALAR(size, +); TG_IMPL_DEFINE_BINARY_OP_SCALAR(size, *); TG_IMPL_DEFINE_BINARY_OP_SCALAR_DIV(size); - -// assignment ops -TG_IMPL_DEFINE_ASSIGNMENT_OP(size, +); -TG_IMPL_DEFINE_ASSIGNMENT_OP(size, -); -TG_IMPL_DEFINE_ASSIGNMENT_OP(size, *); -TG_IMPL_DEFINE_ASSIGNMENT_OP(size, /); } // namespace tg diff --git a/src/tg/detail/operators/ops_triangle.hh b/src/tg/detail/operators/ops_triangle.hh index 3662988..0080d37 100644 --- a/src/tg/detail/operators/ops_triangle.hh +++ b/src/tg/detail/operators/ops_triangle.hh @@ -90,11 +90,4 @@ constexpr triangle<D, ScalarT> operator/(triangle<D, ScalarT> const& a, size<D, r.v2 = a.v2 * inv_b; return r; } - -// assignment ops -TG_IMPL_DEFINE_ASSIGNMENT_OP(triangle, +); -TG_IMPL_DEFINE_ASSIGNMENT_OP(triangle, -); -TG_IMPL_DEFINE_ASSIGNMENT_OP(triangle, *); -TG_IMPL_DEFINE_ASSIGNMENT_OP(triangle, /); - } // namespace tg diff --git a/src/tg/detail/operators/ops_vec.hh b/src/tg/detail/operators/ops_vec.hh index 6f3574a..b8fc8f9 100644 --- a/src/tg/detail/operators/ops_vec.hh +++ b/src/tg/detail/operators/ops_vec.hh @@ -23,10 +23,4 @@ TG_IMPL_DEFINE_BINARY_OP_SCALAR(vec, -); TG_IMPL_DEFINE_BINARY_OP_SCALAR(vec, +); TG_IMPL_DEFINE_BINARY_OP_SCALAR(vec, *); TG_IMPL_DEFINE_BINARY_OP_SCALAR_DIV(vec); - -// assignment ops -TG_IMPL_DEFINE_ASSIGNMENT_OP(vec, +); -TG_IMPL_DEFINE_ASSIGNMENT_OP(vec, -); -TG_IMPL_DEFINE_ASSIGNMENT_OP(vec, *); -TG_IMPL_DEFINE_ASSIGNMENT_OP(vec, /); } // namespace tg -- GitLab