From 8b0d1c5296c22ce28fd0c8f9b251308b7bbf3090 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 24 Jan 2015 15:24:19 +0100 Subject: Added `Modulo` math operator * redefined `Even` in terms of `Modulo` and removed unnecessary dependent name declarators * added appropriate test case, also for `Square` --- src/operation/math.h | 37 +++++++++++++++++++++++++------------ src/type.h | 6 +++--- test.cc | 16 ++++++++++++++++ 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/operation/math.h b/src/operation/math.h index 0ede3f5..28a6832 100644 --- a/src/operation/math.h +++ b/src/operation/math.h @@ -2,6 +2,7 @@ #define TYPEASVALUE_SRC_OPERATION_MATH_H_ #include "type.h" +#include "logic.h" namespace tav { @@ -9,46 +10,58 @@ template < typename X, typename Y > -using Add = typename std::integral_constant< +using Add = std::integral_constant< decltype(X::value + Y::value), X::value + Y::value ->::type; +>; template < typename X, typename Y > -using Substract = typename std::integral_constant< +using Substract = std::integral_constant< decltype(X::value - Y::value), X::value - Y::value ->::type; +>; template < typename X, typename Y > -using Multiply = typename std::integral_constant< +using Multiply = std::integral_constant< decltype(X::value * Y::value), X::value * Y::value ->::type; +>; template < typename X, typename Y > -using Divide = typename std::integral_constant< +using Divide = std::integral_constant< decltype(X::value / Y::value), X::value / Y::value ->::type; +>; -template -using Square = Multiply; +template < + typename X, + typename Y +> +using Modulo = std::integral_constant< + decltype(X::value % Y::value), + X::value % Y::value +>; template -using Even = Boolean<(X::value % 2 == 0)>; +using Even = EqualValue< + Modulo>, + Size<0> +>; template -using Odd = Boolean::value>; +using Odd = Not>; + +template +using Square = Multiply; } diff --git a/src/type.h b/src/type.h index 0bcf272..76a1aae 100644 --- a/src/type.h +++ b/src/type.h @@ -6,13 +6,13 @@ namespace tav { template -using Int = typename std::integral_constant::type; +using Int = std::integral_constant; template -using Size = typename std::integral_constant::type; +using Size = std::integral_constant; template -using Boolean = typename std::integral_constant::type; +using Boolean = std::integral_constant; template < typename X, diff --git a/test.cc b/test.cc index 1a20a74..6476bb8 100644 --- a/test.cc +++ b/test.cc @@ -84,6 +84,22 @@ static_assert( "(/ 10 2) != 42" ); +static_assert( + std::is_same< + tav::Int<1>, + tav::Modulo, tav::Int<3>>::type + >::value, + "(modulo 10 3) != 1" +); + +static_assert( + std::is_same< + tav::Int<4096>, + tav::Square>::type + >::value, + "(square 64) != 4096" +); + // logic static_assert( -- cgit v1.2.3