aboutsummaryrefslogtreecommitdiff
path: root/src/conditional/cond.h
blob: 4def6118c79d928451640d1a86d35732270ec3d1 (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
#ifndef TYPEASVALUE_SRC_CONDITIONAL_COND_H_
#define TYPEASVALUE_SRC_CONDITIONAL_COND_H_

#include "type.h"
#include "list/cons.h"
#include "list/detail/find_variadic.h"

namespace tav {

namespace detail {

template <typename... Branches>
class select_cond_branch {
	private:
		template <typename Pair>
		using predicate = IsTrue<Car<Pair>>;

	public:
		using type = Eval<detail::find_variadic<predicate, Branches...>>;

	static_assert(
		IsPair<type>::value,
		"all branch conditions resolve to false"
	);
};

}

template <typename... Branches>
using Cond = Cdr<Eval<detail::select_cond_branch<Branches...>>>;

template <
	typename Condition,
	typename Result
>
using Branch = Pair<Condition, Result>;

template <typename Result>
using Else = Branch<Boolean<true>, Result>;

}

#endif  // TYPEASVALUE_SRC_CONDITIONAL_COND_H_