From f63675d062156627dc23aa74d51356a7ab77c914 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Thu, 15 Jan 2015 20:06:41 +0100 Subject: Completed basic math operators and fixed their result type * the result type now depends on the `decltype` of the performed operation --- src/operation.h | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/operation.h') diff --git a/src/operation.h b/src/operation.h index c906b55..66dbc41 100644 --- a/src/operation.h +++ b/src/operation.h @@ -15,7 +15,10 @@ struct add { "only values of the same type may be added" ); - typedef Int type; + typedef std::integral_constant< + decltype(X::value + Y::value), + X::value + Y::value + > type; }; template < @@ -28,7 +31,42 @@ struct substract { "only values of the same type may be substracted" ); - typedef Int type; + typedef std::integral_constant< + decltype(X::value - Y::value), + X::value - Y::value + > type; +}; + +template < + typename X, + typename Y +> +struct multiply { + static_assert( + equal_type::value, + "only values of the same type may be multiplied" + ); + + typedef std::integral_constant< + decltype(X::value * Y::value), + X::value * Y::value + > type; +}; + +template < + typename X, + typename Y +> +struct divide { + static_assert( + equal_type::value, + "only values of the same type may be divided" + ); + + typedef std::integral_constant< + decltype(X::value / Y::value), + X::value / Y::value + > type; }; } -- cgit v1.2.3