aboutsummaryrefslogtreecommitdiff
path: root/src/function/apply.h
blob: 8e780e044c609989f740068a2a5bd53601e2b400 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef TYPEASVALUE_SRC_FUNCTION_APPLY_H_
#define TYPEASVALUE_SRC_FUNCTION_APPLY_H_

#include <type_traits>

#include "list/list.h"
#include "list/operation/nth.h"

namespace tav {

namespace detail {

struct placeholder_tag { };

template <typename Type>
using is_placeholder = tav::Boolean<
	std::is_base_of<placeholder_tag, Type>::value
>;

template <int Index>
struct placeholder : placeholder_tag { };

template <
	typename Partials,
	typename Argument
>
struct resolve_placeholder {
	typedef Argument type;
};

template <
	typename Partials,
	int      Index
>
struct resolve_placeholder<Partials, placeholder<Index>> {
	typedef typename Nth<Size<Index>, Partials>::type type;
};

}

typedef detail::placeholder<0> _0;
typedef detail::placeholder<1> _1;
typedef detail::placeholder<2> _2;
typedef detail::placeholder<3> _3;

template <
	template<typename...> class Function,
	typename...                 Arguments
>
struct Apply {
	template <typename... Partials>
	using variadic_type = Function<
		typename detail::resolve_placeholder<
			typename tav::List<Partials...>::type,
			Arguments
		>::type...
	>;

	template <typename Partial>
	using single_type = variadic_type<Partial>;

	template <typename Partial0, typename Partial1>
	using pair_type = variadic_type<Partial0, Partial1>;

	template <typename Partial0, typename Partial1, typename Partial2>
	using triple_type = variadic_type<Partial0, Partial1, Partial2>;
};

}

#endif  // TYPEASVALUE_SRC_FUNCTION_APPLY_H_