aboutsummaryrefslogtreecommitdiff
path: root/src/list/operation/higher/list_index.h
blob: d665b82a242ad12d8a2d769b1fd9f6ec05475304 (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
40
41
42
43
44
45
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_LIST_INDEX_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_LIST_INDEX_H_

#include "operation/math.h"

namespace tav {

namespace detail {

template <
	template<typename> class Predicate,
	typename                 List,
	typename                 Index = Size<0>
>
struct index_of_first {
	typedef If<
		Eval<Predicate<Head<List>>>,
		Index,
		Eval<index_of_first<
			Predicate,
			Tail<List>,
			Add<Index, Size<1>>
		>>
	> type;
};

template <
	template<typename> class Predicate,
	typename                 Index
>
struct index_of_first<Predicate, void, Index> {
	typedef Boolean<false> type;
};

}

template <
	template<typename> class Predicate,
	typename                 List
>
using ListIndex = Eval<detail::index_of_first<Predicate, List>>;

}

#endif  // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_LIST_INDEX_H_