aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/operation.h42
-rw-r--r--src/type.h9
2 files changed, 49 insertions, 2 deletions
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<X::value + Y::value> 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<X::value - Y::value> 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<X, Y>::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<X, Y>::value,
+ "only values of the same type may be divided"
+ );
+
+ typedef std::integral_constant<
+ decltype(X::value / Y::value),
+ X::value / Y::value
+ > type;
};
}
diff --git a/src/type.h b/src/type.h
index 1149520..304bff4 100644
--- a/src/type.h
+++ b/src/type.h
@@ -20,6 +20,15 @@ using equal_type = typename std::integral_constant<
std::is_same<typename X::value_type, typename Y::value_type>::value
>::type;
+template <
+ typename X,
+ typename Y
+>
+using equal_value = typename std::integral_constant<
+ bool,
+ X::value == Y::value
+>::type;
+
}
#endif // TYPEASVALUE_SRC_TYPE_H_