aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-01-20 16:55:07 +0100
committerAdrian Kummerlaender2015-01-20 16:55:07 +0100
commitb5fc92b5377e3effe4410348f4199316b88fba7f (patch)
tree62e52de144b612b81540e47ba4047c2a9f8c6b16
parent78df97907e9e5758b03fb11f556f24ebb12a740c (diff)
downloadTypeAsValue-b5fc92b5377e3effe4410348f4199316b88fba7f.tar
TypeAsValue-b5fc92b5377e3effe4410348f4199316b88fba7f.tar.gz
TypeAsValue-b5fc92b5377e3effe4410348f4199316b88fba7f.tar.bz2
TypeAsValue-b5fc92b5377e3effe4410348f4199316b88fba7f.tar.lz
TypeAsValue-b5fc92b5377e3effe4410348f4199316b88fba7f.tar.xz
TypeAsValue-b5fc92b5377e3effe4410348f4199316b88fba7f.tar.zst
TypeAsValue-b5fc92b5377e3effe4410348f4199316b88fba7f.zip
Added basic boolean logic operations
-rw-r--r--src/operation/logic.h28
-rw-r--r--test.cc67
2 files changed, 91 insertions, 4 deletions
diff --git a/src/operation/logic.h b/src/operation/logic.h
new file mode 100644
index 0000000..23393b2
--- /dev/null
+++ b/src/operation/logic.h
@@ -0,0 +1,28 @@
+#ifndef TYPEASVALUE_SRC_OPERATION_LOGIC_H_
+#define TYPEASVALUE_SRC_OPERATION_LOGIC_H_
+
+#include "type.h"
+
+namespace tav {
+
+template <
+ typename X,
+ typename Y
+>
+using And = Boolean<X::value && Y::value>;
+
+template <
+ typename X,
+ typename Y
+>
+using Or = Boolean<X::value || Y::value>;
+
+template <
+ typename X,
+ typename Y
+>
+using Xor = Boolean<X::value ^ Y::value>;
+
+}
+
+#endif // TYPEASVALUE_SRC_OPERATION_LOGIC_H_
diff --git a/test.cc b/test.cc
index 19c279c..37f83b7 100644
--- a/test.cc
+++ b/test.cc
@@ -1,5 +1,6 @@
#include "type.h"
#include "operation/math.h"
+#include "operation/logic.h"
#include "conditional/if.h"
#include "list/cons.h"
@@ -48,7 +49,7 @@ static_assert(
static_assert(
std::is_same<
tav::Int<3>,
- tav::Add<tav::Int<1>, tav::Int<2>>
+ tav::Add<tav::Int<1>, tav::Int<2>>::type
>::value,
"(+ 1 2) != 3"
);
@@ -56,7 +57,7 @@ static_assert(
static_assert(
std::is_same<
tav::Int<4>,
- tav::Substract<tav::Int<10>, tav::Int<6>>
+ tav::Substract<tav::Int<10>, tav::Int<6>>::type
>::value,
"(- 10 6) != 4"
);
@@ -64,7 +65,7 @@ static_assert(
static_assert(
std::is_same<
tav::Int<42>,
- tav::Multiply<tav::Int<2>, tav::Int<21>>
+ tav::Multiply<tav::Int<2>, tav::Int<21>>::type
>::value,
"(* 2 21) != 42"
);
@@ -72,11 +73,69 @@ static_assert(
static_assert(
std::is_same<
tav::Int<5>,
- tav::Divide<tav::Int<10>, tav::Int<2>>
+ tav::Divide<tav::Int<10>, tav::Int<2>>::type
>::value,
"(/ 10 2) != 42"
);
+// logic
+
+static_assert(
+ std::is_same<
+ tav::Boolean<true>,
+ tav::And<tav::Boolean<true>, tav::Boolean<true>>::type
+ >::value,
+ "(and #t #t) != #t"
+);
+
+static_assert(
+ std::is_same<
+ tav::Boolean<false>,
+ tav::And<tav::Boolean<false>, tav::Boolean<true>>::type
+ >::value,
+ "(and #f #t) != #f"
+);
+
+static_assert(
+ std::is_same<
+ tav::Boolean<true>,
+ tav::Or<tav::Boolean<true>, tav::Boolean<true>>::type
+ >::value,
+ "(or #t #t) != #t"
+);
+
+static_assert(
+ std::is_same<
+ tav::Boolean<true>,
+ tav::Or<tav::Boolean<false>, tav::Boolean<true>>::type
+ >::value,
+ "(or #f #t) != #t"
+);
+
+static_assert(
+ std::is_same<
+ tav::Boolean<false>,
+ tav::Or<tav::Boolean<false>, tav::Boolean<false>>::type
+ >::value,
+ "(or #f #f) != #f"
+);
+
+static_assert(
+ std::is_same<
+ tav::Boolean<true>,
+ tav::Xor<tav::Boolean<false>, tav::Boolean<true>>::type
+ >::value,
+ "(xor #f #t) != #t"
+);
+
+static_assert(
+ std::is_same<
+ tav::Boolean<false>,
+ tav::Xor<tav::Boolean<true>, tav::Boolean<true>>::type
+ >::value,
+ "(xor #t #t) != #f"
+);
+
// conditionals
static_assert(