aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-01-15 19:50:40 +0100
committerAdrian Kummerlaender2015-01-15 19:50:40 +0100
commit5415ecfbdc5078826e09cf6525ff5c0289cedfd4 (patch)
tree6b07b7f2a4cf6ff6e30b865cb14ebcb059be2a40 /src
parentf32004323eae427cba2d25d01836367b291e522d (diff)
downloadTypeAsValue-5415ecfbdc5078826e09cf6525ff5c0289cedfd4.tar
TypeAsValue-5415ecfbdc5078826e09cf6525ff5c0289cedfd4.tar.gz
TypeAsValue-5415ecfbdc5078826e09cf6525ff5c0289cedfd4.tar.bz2
TypeAsValue-5415ecfbdc5078826e09cf6525ff5c0289cedfd4.tar.lz
TypeAsValue-5415ecfbdc5078826e09cf6525ff5c0289cedfd4.tar.xz
TypeAsValue-5415ecfbdc5078826e09cf6525ff5c0289cedfd4.tar.zst
TypeAsValue-5415ecfbdc5078826e09cf6525ff5c0289cedfd4.zip
Added basic value type alias and math operations
Diffstat (limited to 'src')
-rw-r--r--src/operation.h36
-rw-r--r--src/type.h25
2 files changed, 61 insertions, 0 deletions
diff --git a/src/operation.h b/src/operation.h
new file mode 100644
index 0000000..c906b55
--- /dev/null
+++ b/src/operation.h
@@ -0,0 +1,36 @@
+#ifndef TYPEASVALUE_SRC_OPERATION_H_
+#define TYPEASVALUE_SRC_OPERATION_H_
+
+#include "type.h"
+
+namespace tav {
+
+template <
+ typename X,
+ typename Y
+>
+struct add {
+ static_assert(
+ equal_type<X, Y>::value,
+ "only values of the same type may be added"
+ );
+
+ typedef Int<X::value + Y::value> type;
+};
+
+template <
+ typename X,
+ typename Y
+>
+struct substract {
+ static_assert(
+ equal_type<X, Y>::value,
+ "only values of the same type may be substracted"
+ );
+
+ typedef Int<X::value - Y::value> type;
+};
+
+}
+
+#endif // TYPEASVALUE_SRC_OPERATION_H_
diff --git a/src/type.h b/src/type.h
new file mode 100644
index 0000000..1149520
--- /dev/null
+++ b/src/type.h
@@ -0,0 +1,25 @@
+#ifndef TYPEASVALUE_SRC_TYPE_H_
+#define TYPEASVALUE_SRC_TYPE_H_
+
+#include <type_traits>
+
+namespace tav {
+
+template <int Value>
+using Int = typename std::integral_constant<int, Value>::type;
+
+template <bool Value>
+using Boolean = typename std::integral_constant<bool, Value>::type;
+
+template <
+ typename X,
+ typename Y
+>
+using equal_type = typename std::integral_constant<
+ bool,
+ std::is_same<typename X::value_type, typename Y::value_type>::value
+>::type;
+
+}
+
+#endif // TYPEASVALUE_SRC_TYPE_H_