aboutsummaryrefslogtreecommitdiff
path: root/src/list/operation/higher/fold.h
blob: 38c3554be205e1e9757cd03a87d3cc82530df02e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FOLD_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FOLD_H_

namespace tav {

namespace detail {

template <
	template<typename, typename> class Function,
	typename                           Initial,
	typename                           Pair
>
struct fold_pair {
	typedef Function<
		Car<Pair>,
		Eval<fold_pair<Function, Initial, Cdr<Pair>>>
	> type;
};

template <
	template<typename, typename> class Function,
	typename                           Initial
>
struct fold_pair<Function, Initial, void> {
	typedef Initial type;
};

}

template <
	template<typename, typename> class Function,
	typename                           Initial,
	typename                           List
>
using Fold = Eval<detail::fold_pair<Function, Initial, List>>;

}

#endif  // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FOLD_H_