aboutsummaryrefslogtreecommitdiff
path: root/src/list/operation/higher/filter.h
blob: 9dcdf37870c864a6e70d6e7341c4cd8d32757f38 (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
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FILTER_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FILTER_H_

#include "fold.h"
#include "conditional/if.h"

namespace tav {

namespace detail {

template <template<typename> class Predicate>
struct filter_predicate {
	template <
		typename Current,
		typename Previous
	>
	using function = If<
		Eval<Predicate<Current>>,
		Cons<Current, Previous>,
		Previous
	>;
};

}

template <
	template<typename> class Predicate,
	typename                 List
>
using Filter = Fold<
	detail::filter_predicate<Predicate>::template function,
	void,
	List
>;

}

#endif  // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FILTER_H_