aboutsummaryrefslogtreecommitdiff
path: root/src/list/list.h
blob: f21d0fcc6a45edcd787ce8011a91d17547df08b9 (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
#ifndef TYPEASVALUE_SRC_LIST_LIST_H_
#define TYPEASVALUE_SRC_LIST_LIST_H_

#include "cons.h"

namespace tav {

template <
	typename    Head,
	typename... Tail
>
struct List {
	typedef Cons<
		Head,
		typename List<Tail...>::type
	> type;
};

template <typename Head>
struct List<Head> {
	typedef Cons<Head, void> type;
};

template <typename Cons>
using Head = Car<Cons>;

template <typename Cons>
using Tail = Cdr<Cons>;

template <typename Cons>
struct Length {
	typedef Add<Size<1>, typename Length<Cdr<Cons>>::type> type;
};

template <>
struct Length<void> {
	typedef Size<0> type;
};

template <
	typename Primary,
	typename Secondary
>
struct Concatenate {
	typedef Cons<
		Head<Primary>,
		typename Concatenate<
			Tail<Primary>,
			Secondary
		>::type
	> type;
};

template <typename Secondary>
struct Concatenate<void, Secondary> {
	typedef Secondary type;
};

}

#endif  // TYPEASVALUE_SRC_LIST_LIST_H_