aboutsummaryrefslogtreecommitdiff
path: root/src/list/operation/higher/fold.h
blob: 3f39b40be21c97a3cd32707ee580a7c46262415a (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                           Current
>
struct fold_pair {
	typedef Function<
		Head<Current>,
		Eval<fold_pair<Function, Initial, Tail<Current>>>
	> 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                           Current
>
using Fold = Eval<detail::fold_pair<Function, Initial, Current>>;

}

#endif  // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FOLD_H_