aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--src/conditional/cond.h9
-rw-r--r--src/function/apply.h9
-rw-r--r--test.cc14
4 files changed, 21 insertions, 13 deletions
diff --git a/README.md b/README.md
index ba07515..92a1c35 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ This library is a expanded reimplementation of my previous attempt at this probl
* guaranteed evaluation during compile time
* basic math and logic operations
-* conditionals
+* conditionals such as `If` and `Cond`
* `Cons` constructor for `Pair` type
* `List` function as helper for `Pair` based list construction
* basic list operators such as `Nth`, `Length`, `Take` and `Append`
diff --git a/src/conditional/cond.h b/src/conditional/cond.h
index c543449..5f8014f 100644
--- a/src/conditional/cond.h
+++ b/src/conditional/cond.h
@@ -19,6 +19,15 @@ using Cond = Cdr<Eval<
detail::find_variadic<detail::cond_predicate, Branches...>
>>;
+template <
+ typename Condition,
+ typename Result
+>
+using Branch = Pair<Condition, Result>;
+
+template <typename Result>
+using Else = Branch<Boolean<true>, Result>;
+
}
#endif // TYPEASVALUE_SRC_CONDITIONAL_COND_H_
diff --git a/src/function/apply.h b/src/function/apply.h
index 591fa8a..553ae7f 100644
--- a/src/function/apply.h
+++ b/src/function/apply.h
@@ -18,20 +18,19 @@ template <
typename... Arguments
>
struct Apply : Cond<
- Pair<
+ Branch<
GreaterThan<detail::count_placeholders<Arguments...>, Size<2>>,
detail::apply_variadic<Function, Arguments...>
>,
- Pair<
+ Branch<
IsEqualValue<detail::count_placeholders<Arguments...>, Size<2>>,
detail::apply_pair<Function, Arguments...>
>,
- Pair<
+ Branch<
IsEqualValue<detail::count_placeholders<Arguments...>, Size<1>>,
detail::apply_single<Function, Arguments...>
>,
- Pair<
- Boolean<true>,
+ Else<
detail::apply_none<Function, Arguments...>
>
> { };
diff --git a/test.cc b/test.cc
index 5742fb2..7a2e963 100644
--- a/test.cc
+++ b/test.cc
@@ -239,9 +239,9 @@ static_assert(
std::is_same<
tav::Int<2>,
tav::Cond<
- tav::Pair<tav::IsEqualValue<tav::Int<1>, tav::Int<2>>, tav::Int<1>>,
- tav::Pair<tav::IsEqualValue<tav::Int<2>, tav::Int<2>>, tav::Int<2>>,
- tav::Pair<tav::IsEqualValue<tav::Int<3>, tav::Int<2>>, tav::Int<3>>
+ tav::Branch<tav::IsEqualValue<tav::Int<1>, tav::Int<2>>, tav::Int<1>>,
+ tav::Branch<tav::IsEqualValue<tav::Int<2>, tav::Int<2>>, tav::Int<2>>,
+ tav::Branch<tav::IsEqualValue<tav::Int<3>, tav::Int<2>>, tav::Int<3>>
>
>::value,
"(cond ((= 1 2) 1) ((= 2 2) 2) ((= 3 2) 3)) != 2"
@@ -251,10 +251,10 @@ static_assert(
std::is_same<
tav::Int<-1>,
tav::Cond<
- tav::Pair<tav::IsEqualValue<tav::Int<1>, tav::Int<2>>, tav::Int< 1>>,
- tav::Pair<tav::IsEqualValue<tav::Int<2>, tav::Int<3>>, tav::Int< 2>>,
- tav::Pair<tav::IsEqualValue<tav::Int<3>, tav::Int<4>>, tav::Int< 3>>,
- tav::Pair<tav::Boolean<true>, tav::Int<-1>>
+ tav::Branch<tav::IsEqualValue<tav::Int<1>, tav::Int<2>>, tav::Int< 1>>,
+ tav::Branch<tav::IsEqualValue<tav::Int<2>, tav::Int<3>>, tav::Int< 2>>,
+ tav::Branch<tav::IsEqualValue<tav::Int<3>, tav::Int<4>>, tav::Int< 3>>,
+ tav::Else<tav::Int<-1>>
>
>::value,
"(cond ((= 1 2) 1) ((= 2 3) 2) ((= 3 4) 3) (else -1)) != -1"