From b5fc92b5377e3effe4410348f4199316b88fba7f Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 20 Jan 2015 16:55:07 +0100 Subject: Added basic boolean logic operations --- src/operation/logic.h | 28 +++++++++++++++++++++ test.cc | 67 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 src/operation/logic.h 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; + +template < + typename X, + typename Y +> +using Or = Boolean; + +template < + typename X, + typename Y +> +using Xor = Boolean; + +} + +#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<2>> + tav::Add, 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<6>> + tav::Substract, 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<21>> + tav::Multiply, 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<2>> + tav::Divide, tav::Int<2>>::type >::value, "(/ 10 2) != 42" ); +// logic + +static_assert( + std::is_same< + tav::Boolean, + tav::And, tav::Boolean>::type + >::value, + "(and #t #t) != #t" +); + +static_assert( + std::is_same< + tav::Boolean, + tav::And, tav::Boolean>::type + >::value, + "(and #f #t) != #f" +); + +static_assert( + std::is_same< + tav::Boolean, + tav::Or, tav::Boolean>::type + >::value, + "(or #t #t) != #t" +); + +static_assert( + std::is_same< + tav::Boolean, + tav::Or, tav::Boolean>::type + >::value, + "(or #f #t) != #t" +); + +static_assert( + std::is_same< + tav::Boolean, + tav::Or, tav::Boolean>::type + >::value, + "(or #f #f) != #f" +); + +static_assert( + std::is_same< + tav::Boolean, + tav::Xor, tav::Boolean>::type + >::value, + "(xor #f #t) != #t" +); + +static_assert( + std::is_same< + tav::Boolean, + tav::Xor, tav::Boolean>::type + >::value, + "(xor #t #t) != #f" +); + // conditionals static_assert( -- cgit v1.2.3