diff options
-rw-r--r-- | src/operation/math.h | 37 | ||||
-rw-r--r-- | src/type.h | 6 | ||||
-rw-r--r-- | 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 <typename Base> -using Square = Multiply<Base, Base>; +template < + typename X, + typename Y +> +using Modulo = std::integral_constant< + decltype(X::value % Y::value), + X::value % Y::value +>; template <typename X> -using Even = Boolean<(X::value % 2 == 0)>; +using Even = EqualValue< + Modulo<X, Size<2>>, + Size<0> +>; template <typename X> -using Odd = Boolean<!Even<X>::value>; +using Odd = Not<Even<X>>; + +template <typename Base> +using Square = Multiply<Base, Base>; } @@ -6,13 +6,13 @@ namespace tav { template <int Value> -using Int = typename std::integral_constant<int, Value>::type; +using Int = std::integral_constant<int, Value>; template <std::size_t Value> -using Size = typename std::integral_constant<std::size_t, Value>::type; +using Size = std::integral_constant<std::size_t, Value>; template <bool Value> -using Boolean = typename std::integral_constant<bool, Value>::type; +using Boolean = std::integral_constant<bool, Value>; template < typename X, @@ -84,6 +84,22 @@ static_assert( "(/ 10 2) != 42" ); +static_assert( + std::is_same< + tav::Int<1>, + tav::Modulo<tav::Int<10>, tav::Int<3>>::type + >::value, + "(modulo 10 3) != 1" +); + +static_assert( + std::is_same< + tav::Int<4096>, + tav::Square<tav::Int<64>>::type + >::value, + "(square 64) != 4096" +); + // logic static_assert( |