aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-14 10:43:49 +0100
committerAdrian Kummerlaender2015-02-14 10:43:49 +0100
commite24f25ada7e8f48dc35cb235e045a4324bccb4f2 (patch)
tree3b6c409c7d336557163dcb25e4b11fdef82a3a79
parent73680466149c7aad21de558b7acc11dfa05183d2 (diff)
downloadTypeAsValue-e24f25ada7e8f48dc35cb235e045a4324bccb4f2.tar
TypeAsValue-e24f25ada7e8f48dc35cb235e045a4324bccb4f2.tar.gz
TypeAsValue-e24f25ada7e8f48dc35cb235e045a4324bccb4f2.tar.bz2
TypeAsValue-e24f25ada7e8f48dc35cb235e045a4324bccb4f2.tar.lz
TypeAsValue-e24f25ada7e8f48dc35cb235e045a4324bccb4f2.tar.xz
TypeAsValue-e24f25ada7e8f48dc35cb235e045a4324bccb4f2.tar.zst
TypeAsValue-e24f25ada7e8f48dc35cb235e045a4324bccb4f2.zip
Introduced `Eval` function evaluation helper
* replaces `typename *::type` constructs with `Eval` applications * aims to further unify function evaluation
-rw-r--r--example/prime/prime.cc16
-rw-r--r--src/conditional/cond.h12
-rw-r--r--src/conditional/if.h4
-rw-r--r--src/function/apply.h6
-rw-r--r--src/function/detail/apply.h10
-rw-r--r--src/list/cons.h4
-rw-r--r--src/list/generator/higher/list_tabulate.h2
-rw-r--r--src/list/generator/iota.h10
-rw-r--r--src/list/generator/make_list.h10
-rw-r--r--src/list/list.h16
-rw-r--r--src/list/operation/append.h8
-rw-r--r--src/list/operation/basic.h4
-rw-r--r--src/list/operation/delete_nth.h4
-rw-r--r--src/list/operation/drop.h4
-rw-r--r--src/list/operation/higher/drop_while.h8
-rw-r--r--src/list/operation/higher/filter.h8
-rw-r--r--src/list/operation/higher/find.h8
-rw-r--r--src/list/operation/higher/fold.h6
-rw-r--r--src/list/operation/higher/map.h4
-rw-r--r--src/list/operation/higher/partition.h4
-rw-r--r--src/list/operation/higher/query.h8
-rw-r--r--src/list/operation/higher/sort.h28
-rw-r--r--src/list/operation/higher/take_while.h12
-rw-r--r--src/list/operation/nth.h10
-rw-r--r--src/list/operation/reverse.h14
-rw-r--r--src/list/operation/take.h8
-rw-r--r--src/type.h7
-rw-r--r--test.cc4
28 files changed, 120 insertions, 119 deletions
diff --git a/example/prime/prime.cc b/example/prime/prime.cc
index e89d2a4..b826a72 100644
--- a/example/prime/prime.cc
+++ b/example/prime/prime.cc
@@ -11,7 +11,7 @@
#include "runtime/list/for_each.h"
// (define candidates (iota 1000 2 1))
-using candidates = tav::Iota<tav::Size<1000>, tav::Int<2>, tav::Int<1>>::type;
+using candidates = tav::Eval<tav::Iota<tav::Size<1000>, tav::Int<2>, tav::Int<1>>>;
// (define (isMultipleOf candidate base) (= (modulo candidate base) 0))
template <
@@ -42,15 +42,15 @@ using removeMultiplesOf = tav::Remove<
// (car candidates)))))))
template <typename Candidates>
struct Sieve {
- typedef typename tav::Cons<
+ typedef tav::Eval<tav::Cons<
tav::Head<Candidates>,
- typename Sieve<
- typename removeMultiplesOf<
+ tav::Eval<Sieve<
+ tav::Eval<removeMultiplesOf<
tav::Tail<Candidates>,
tav::Head<Candidates>
- >::type
- >::type
- >::type type;
+ >>
+ >>
+ >> type;
};
template <>
@@ -59,7 +59,7 @@ struct Sieve<void> {
};
// (define primes (sieve candidates))
-using primes = Sieve<candidates>::type;
+using primes = tav::Eval<Sieve<candidates>>;
int main(int, char **) {
tav::runtime::for_each<primes>([](const int x) {
diff --git a/src/conditional/cond.h b/src/conditional/cond.h
index 0c2b1a8..2d6a415 100644
--- a/src/conditional/cond.h
+++ b/src/conditional/cond.h
@@ -12,15 +12,15 @@ template <typename... Branches>
class Cond {
private:
template <typename Pair>
- using predicate = IsTrue<typename Car<Pair>::type::type>;
+ using predicate = IsTrue<Eval<Eval<Car<Pair>>>>;
public:
- typedef typename Cdr<
- typename Find<
+ typedef Eval<Cdr<
+ Eval<Find<
predicate,
- typename List<Branches...>::type
- >::type
- >::type type;
+ Eval<List<Branches...>>
+ >>
+ >> type;
};
diff --git a/src/conditional/if.h b/src/conditional/if.h
index b019674..b99f399 100644
--- a/src/conditional/if.h
+++ b/src/conditional/if.h
@@ -6,12 +6,12 @@
namespace tav {
template <
- bool Condition,
+ typename Condition,
typename TrueBranch,
typename FalseBranch
>
using If = std::conditional<
- Condition,
+ Condition::value,
TrueBranch,
FalseBranch
>;
diff --git a/src/function/apply.h b/src/function/apply.h
index 5a2105c..f4de292 100644
--- a/src/function/apply.h
+++ b/src/function/apply.h
@@ -19,15 +19,15 @@ template <
>
struct Apply : Cond<
Pair<
- GreaterThan<typename detail::count_placeholders<Arguments...>::type, Size<2>>,
+ GreaterThan<Eval<detail::count_placeholders<Arguments...>>, Size<2>>,
detail::apply_variadic<Function, Arguments...>
>,
Pair<
- IsEqualValue<typename detail::count_placeholders<Arguments...>::type, Size<2>>,
+ IsEqualValue<Eval<detail::count_placeholders<Arguments...>>, Size<2>>,
detail::apply_pair<Function, Arguments...>
>,
Pair<
- IsEqualValue<typename detail::count_placeholders<Arguments...>::type, Size<1>>,
+ IsEqualValue<Eval<detail::count_placeholders<Arguments...>>, Size<1>>,
detail::apply_single<Function, Arguments...>
>,
Pair<
diff --git a/src/function/detail/apply.h b/src/function/detail/apply.h
index b4b70bf..da347f7 100644
--- a/src/function/detail/apply.h
+++ b/src/function/detail/apply.h
@@ -33,13 +33,13 @@ template <
int Index
>
struct resolve_placeholder<Partials, placeholder<Index>> {
- typedef typename Nth<Size<Index>, Partials>::type type;
+ typedef Eval<Nth<Size<Index>, Partials>> type;
};
template <typename... Arguments>
using count_placeholders = Count<
is_placeholder,
- typename List<Arguments...>::type
+ Eval<List<Arguments...>>
>;
template <
@@ -57,10 +57,10 @@ template <
struct apply_variadic {
template <typename... Partials>
using function = Function<
- typename resolve_placeholder<
- typename tav::List<Partials...>::type,
+ Eval<resolve_placeholder<
+ Eval<List<Partials...>>,
Arguments
- >::type...
+ >>...
>;
};
diff --git a/src/list/cons.h b/src/list/cons.h
index 7f54eb5..8efca67 100644
--- a/src/list/cons.h
+++ b/src/list/cons.h
@@ -16,7 +16,7 @@ struct Cons {
template <typename Pair>
struct Car {
static_assert(
- IsPair<Pair>::type::value,
+ Eval<IsPair<Pair>>::value,
"Pair type required"
);
@@ -26,7 +26,7 @@ struct Car {
template <typename Pair>
struct Cdr {
static_assert(
- IsPair<Pair>::type::value,
+ Eval<IsPair<Pair>>::value,
"Pair type required"
);
diff --git a/src/list/generator/higher/list_tabulate.h b/src/list/generator/higher/list_tabulate.h
index dd2914a..856ed11 100644
--- a/src/list/generator/higher/list_tabulate.h
+++ b/src/list/generator/higher/list_tabulate.h
@@ -12,7 +12,7 @@ template <
>
using ListTabulate = Map<
Initializer,
- typename Iota<Count, Size<0>, Size<1>>::type
+ Eval<Iota<Count, Size<0>, Size<1>>>
>;
}
diff --git a/src/list/generator/iota.h b/src/list/generator/iota.h
index 2d5b506..56ebeca 100644
--- a/src/list/generator/iota.h
+++ b/src/list/generator/iota.h
@@ -11,14 +11,14 @@ template <
typename Step
>
struct Iota {
- typedef typename Cons<
+ typedef Eval<Cons<
Initial,
- typename Iota<
+ Eval<Iota<
Substract<Count, Size<1>>,
Add<Initial, Step>,
Step
- >::type
- >::type type;
+ >>
+ >> type;
};
template <
@@ -26,7 +26,7 @@ template <
typename Step
>
struct Iota<Size<1>, Initial, Step> {
- typedef typename Cons<Initial, void>::type type;
+ typedef Eval<Cons<Initial, void>> type;
};
}
diff --git a/src/list/generator/make_list.h b/src/list/generator/make_list.h
index 33419cb..d927905 100644
--- a/src/list/generator/make_list.h
+++ b/src/list/generator/make_list.h
@@ -11,18 +11,18 @@ template <
typename Element
>
struct MakeList {
- typedef typename Cons<
+ typedef Eval<Cons<
Element,
- typename MakeList<
+ Eval<MakeList<
Substract<Count, Size<1>>,
Element
- >::type
- >::type type;
+ >>
+ >> type;
};
template <typename Element>
struct MakeList<Size<1>, Element> {
- typedef typename Cons<Element, void>::type type;
+ typedef Eval<Cons<Element, void>> type;
};
}
diff --git a/src/list/list.h b/src/list/list.h
index 658ac31..e369739 100644
--- a/src/list/list.h
+++ b/src/list/list.h
@@ -10,25 +10,25 @@ template <
typename... Tail
>
struct List {
- typedef typename Cons<
+ typedef Eval<Cons<
Head,
- typename List<Tail...>::type
- >::type type;
+ Eval<List<Tail...>>
+ >> type;
};
template <typename Head>
struct List<Head> {
- typedef typename Cons<Head, void>::type type;
+ typedef Eval<Cons<Head, void>> type;
};
template <typename Head>
struct List<Head, void> {
- typedef typename List<Head>::type type;
+ typedef Eval<List<Head>> type;
};
template <typename... Tail>
struct List<void, Tail...> {
- typedef typename List<Tail...>::type type;
+ typedef Eval<List<Tail...>> type;
};
template <>
@@ -45,10 +45,10 @@ using ListOfType = List<
>;
template <typename Cons>
-using Head = typename Car<Cons>::type;
+using Head = Eval<Car<Cons>>;
template <typename Cons>
-using Tail = typename Cdr<Cons>::type;
+using Tail = Eval<Cdr<Cons>>;
}
diff --git a/src/list/operation/append.h b/src/list/operation/append.h
index 6cf15f0..28c9adf 100644
--- a/src/list/operation/append.h
+++ b/src/list/operation/append.h
@@ -8,13 +8,13 @@ template <
typename Secondary
>
struct Append {
- typedef typename Cons<
+ typedef Eval<Cons<
Head<Primary>,
- typename Append<
+ Eval<Append<
Tail<Primary>,
Secondary
- >::type
- >::type type;
+ >>
+ >> type;
};
template <typename Secondary>
diff --git a/src/list/operation/basic.h b/src/list/operation/basic.h
index b4aa35a..5f9a3f9 100644
--- a/src/list/operation/basic.h
+++ b/src/list/operation/basic.h
@@ -13,11 +13,11 @@ class Length {
using accumulate = Add<Size<1>, Accumulated>;
public:
- typedef typename Fold<
+ typedef Eval<Fold<
accumulate,
Size<0>,
Cons
- >::type type;
+ >> type;
};
diff --git a/src/list/operation/delete_nth.h b/src/list/operation/delete_nth.h
index 03df12a..6127ade 100644
--- a/src/list/operation/delete_nth.h
+++ b/src/list/operation/delete_nth.h
@@ -12,8 +12,8 @@ template <
typename List
>
using DeleteNth = Append<
- typename Take<Index, List>::type,
- typename Drop<Add<Index, Size<1>>, List>::type
+ Eval<Take<Index, List>>,
+ Eval<Drop<Add<Index, Size<1>>, List>>
>;
}
diff --git a/src/list/operation/drop.h b/src/list/operation/drop.h
index 651dad5..c61983b 100644
--- a/src/list/operation/drop.h
+++ b/src/list/operation/drop.h
@@ -10,10 +10,10 @@ template <
typename Current
>
struct Drop {
- typedef typename Drop<
+ typedef Eval<Drop<
Substract<Count, Size<1>>,
Tail<Current>
- >::type type;
+ >> type;
};
template <typename Current>
diff --git a/src/list/operation/higher/drop_while.h b/src/list/operation/higher/drop_while.h
index ad1553f..8ba2664 100644
--- a/src/list/operation/higher/drop_while.h
+++ b/src/list/operation/higher/drop_while.h
@@ -10,11 +10,11 @@ template <
typename Current
>
struct DropWhile {
- typedef typename If<
- Predicate<Head<Current>>::type::value,
- typename DropWhile<Predicate, Tail<Current>>::type,
+ typedef Eval<If<
+ Eval<Predicate<Head<Current>>>,
+ Eval<DropWhile<Predicate, Tail<Current>>>,
Current
- >::type type;
+ >> type;
};
template <
diff --git a/src/list/operation/higher/filter.h b/src/list/operation/higher/filter.h
index acc1422..3588400 100644
--- a/src/list/operation/higher/filter.h
+++ b/src/list/operation/higher/filter.h
@@ -17,13 +17,13 @@ class Filter {
typename Previous
>
using predicate_wrapper = If<
- Predicate<Current>::type::value,
- typename Cons<Current, Previous>::type,
+ Eval<Predicate<Current>>,
+ Eval<Cons<Current, Previous>>,
Previous
>;
public:
- typedef typename Fold<predicate_wrapper, void, List>::type type;
+ typedef Eval<Fold<predicate_wrapper, void, List>> type;
};
@@ -37,7 +37,7 @@ class Remove {
using predicate_negator = Not<Predicate<Element>>;
public:
- typedef typename Filter<predicate_negator, List>::type type;
+ typedef Eval<Filter<predicate_negator, List>> type;
};
diff --git a/src/list/operation/higher/find.h b/src/list/operation/higher/find.h
index bf9d04f..abc3199 100644
--- a/src/list/operation/higher/find.h
+++ b/src/list/operation/higher/find.h
@@ -11,11 +11,11 @@ template <
typename Current
>
struct Find {
- typedef typename If<
- Predicate<Head<Current>>::type::value,
+ typedef Eval<If<
+ Eval<Predicate<Head<Current>>>,
Head<Current>,
- typename Find<Predicate, Tail<Current>>::type
- >::type type;
+ Eval<Find<Predicate, Tail<Current>>>
+ >> type;
};
template <
diff --git a/src/list/operation/higher/fold.h b/src/list/operation/higher/fold.h
index 6ad4bd7..3ed0a42 100644
--- a/src/list/operation/higher/fold.h
+++ b/src/list/operation/higher/fold.h
@@ -9,10 +9,10 @@ template <
typename Current
>
struct Fold {
- typedef typename Function<
+ typedef Eval<Function<
Head<Current>,
- typename Fold<Function, Initial, Tail<Current>>::type
- >::type type;
+ Eval<Fold<Function, Initial, Tail<Current>>>
+ >> type;
};
template <
diff --git a/src/list/operation/higher/map.h b/src/list/operation/higher/map.h
index 9cb6524..ac214b7 100644
--- a/src/list/operation/higher/map.h
+++ b/src/list/operation/higher/map.h
@@ -16,12 +16,12 @@ class Map {
typename Previous
>
using function_wrapper = Cons<
- typename Function<Current>::type,
+ Eval<Function<Current>>,
Previous
>;
public:
- typedef typename Fold<function_wrapper, void, List>::type type;
+ typedef Eval<Fold<function_wrapper, void, List>> type;
};
diff --git a/src/list/operation/higher/partition.h b/src/list/operation/higher/partition.h
index aed0ea6..eedeb91 100644
--- a/src/list/operation/higher/partition.h
+++ b/src/list/operation/higher/partition.h
@@ -10,8 +10,8 @@ template <
typename Elements
>
using Partition = Cons<
- typename Filter<Predicate, Elements>::type,
- typename Remove<Predicate, Elements>::type
+ Eval<Filter<Predicate, Elements>>,
+ Eval<Remove<Predicate, Elements>>
>;
}
diff --git a/src/list/operation/higher/query.h b/src/list/operation/higher/query.h
index d2b8e76..1d00267 100644
--- a/src/list/operation/higher/query.h
+++ b/src/list/operation/higher/query.h
@@ -15,7 +15,7 @@ template <
using Any = Fold<
Or,
Boolean<false>,
- typename Map<Predicate, List>::type
+ Eval<Map<Predicate, List>>
>;
template <
@@ -25,7 +25,7 @@ template <
using All = Fold<
And,
Boolean<true>,
- typename Map<Predicate, List>::type
+ Eval<Map<Predicate, List>>
>;
template <
@@ -33,7 +33,7 @@ template <
typename List
>
using None = Not<
- typename Any<Predicate, List>::type
+ Eval<Any<Predicate, List>>
>;
template <
@@ -43,7 +43,7 @@ template <
using Count = Fold<
Add,
tav::Size<0>,
- typename Map<Predicate, List>::type
+ Eval<Map<Predicate, List>>
>;
}
diff --git a/src/list/operation/higher/sort.h b/src/list/operation/higher/sort.h
index 5a4009c..cf86e9b 100644
--- a/src/list/operation/higher/sort.h
+++ b/src/list/operation/higher/sort.h
@@ -14,25 +14,25 @@ template <
>
class Sort {
private:
- using index = Divide<typename Length<Sequence>::type, Size<2>>;
- using pivot = typename Nth<index, Sequence>::type;
+ using index = Divide<Eval<Length<Sequence>>, Size<2>>;
+ using pivot = Eval<Nth<index, Sequence>>;
- using partitions = typename Partition<
+ using partitions = Eval<Partition<
Apply<Comparator, pivot, _0>::template function,
- typename DeleteNth<index, Sequence>::type
- >::type;
+ Eval<DeleteNth<index, Sequence>>
+ >>;
- using lhs = typename Car<partitions>::type;
- using rhs = typename Cdr<partitions>::type;
+ using lhs = Eval<Car<partitions>>;
+ using rhs = Eval<Cdr<partitions>>;
public:
- typedef typename Concatenate<
- typename List<
- typename Sort<Comparator, lhs>::type,
- typename List<pivot>::type,
- typename Sort<Comparator, rhs>::type
- >::type
- >::type type;
+ typedef Eval<Concatenate<
+ Eval<List<
+ Eval<Sort<Comparator, lhs>>,
+ Eval<List<pivot>>,
+ Eval<Sort<Comparator, rhs>>
+ >>
+ >> type;
};
template <template<typename, typename> class Comparator>
diff --git a/src/list/operation/higher/take_while.h b/src/list/operation/higher/take_while.h
index d04dc2d..8e61c45 100644
--- a/src/list/operation/higher/take_while.h
+++ b/src/list/operation/higher/take_while.h
@@ -10,14 +10,14 @@ template <
typename Current
>
struct TakeWhile {
- typedef typename If<
- Predicate<Head<Current>>::type::value,
- typename Cons<
+ typedef Eval<If<
+ Eval<Predicate<Head<Current>>>,
+ Eval<Cons<
Head<Current>,
- typename TakeWhile<Predicate, Tail<Current>>::type
- >::type,
+ Eval<TakeWhile<Predicate, Tail<Current>>>
+ >>,
void
- >::type type;
+ >> type;
};
template <
diff --git a/src/list/operation/nth.h b/src/list/operation/nth.h
index 076add4..08e60cc 100644
--- a/src/list/operation/nth.h
+++ b/src/list/operation/nth.h
@@ -10,10 +10,10 @@ template <
typename Pair
>
struct Nth {
- typedef typename Nth<
+ typedef Eval<Nth<
Substract<Index, Size<1>>,
Tail<Pair>
- >::type type;
+ >> type;
};
template <typename Pair>
@@ -32,13 +32,13 @@ struct Nth<Size<0>, void> {
};
template <typename List>
-using First = typename Nth<Size<0>, List>::type;
+using First = Eval<Nth<Size<0>, List>>;
template <typename List>
-using Second = typename Nth<Size<1>, List>::type;
+using Second = Eval<Nth<Size<1>, List>>;
template <typename List>
-using Third = typename Nth<Size<2>, List>::type;
+using Third = Eval<Nth<Size<2>, List>>;
}
diff --git a/src/list/operation/reverse.h b/src/list/operation/reverse.h
index 83691f8..d4b2be9 100644
--- a/src/list/operation/reverse.h
+++ b/src/list/operation/reverse.h
@@ -6,22 +6,20 @@
namespace tav {
-template <typename List>
+template <typename Sequence>
class Reverse {
private:
template <
typename Current,
typename Previous
>
- struct reversed_append {
- typedef typename Append<
- Previous,
- typename Cons<Current, void>::type
- >::type type;
- };
+ using reversed_append = Append<
+ Previous,
+ Eval<List<Current>>
+ >;
public:
- typedef typename Fold<reversed_append, void, List>::type type;
+ typedef Eval<Fold<reversed_append, void, Sequence>> type;
};
diff --git a/src/list/operation/take.h b/src/list/operation/take.h
index c396c28..fdff123 100644
--- a/src/list/operation/take.h
+++ b/src/list/operation/take.h
@@ -10,13 +10,13 @@ template <
typename Current
>
struct Take {
- typedef typename Cons<
+ typedef Eval<Cons<
Head<Current>,
- typename Take<
+ Eval<Take<
Substract<Count, Size<1>>,
Tail<Current>
- >::type
- >::type type;
+ >>
+ >> type;
};
template <typename Current>
diff --git a/src/type.h b/src/type.h
index 15ba2f8..508e22f 100644
--- a/src/type.h
+++ b/src/type.h
@@ -17,14 +17,17 @@ using Boolean = std::integral_constant<bool, Value>;
template <char Value>
using Char = std::integral_constant<char, Value>;
+template <typename Function>
+using Eval = typename Function::type;
+
template <
typename X,
typename Y
>
-using IsEqualType = typename std::is_same<
+using IsEqualType = Eval<std::is_same<
typename X::value_type,
typename Y::value_type
->::type;
+>>;
template <
typename X,
diff --git a/test.cc b/test.cc
index 11b870f..39d5349 100644
--- a/test.cc
+++ b/test.cc
@@ -220,7 +220,7 @@ static_assert(
static_assert(
std::is_same<
tav::Int<1>,
- tav::If<true, tav::Int<1>, tav::Int<2>>::type
+ tav::If<tav::Boolean<true>, tav::Int<1>, tav::Int<2>>::type
>::value,
"(if #t 1 2) != 1"
);
@@ -228,7 +228,7 @@ static_assert(
static_assert(
std::is_same<
tav::Int<2>,
- tav::If<false, tav::Int<1>, tav::Int<2>>::type
+ tav::If<tav::Boolean<false>, tav::Int<1>, tav::Int<2>>::type
>::value,
"(if #f 1 2) != 2"
);