aboutsummaryrefslogtreecommitdiff
path: root/src/list/operation/section.h
blob: 214c9fdf0df438f58ca83ce4141ee68d30b266f1 (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
72
73
74
75
76
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_SECTION_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_SECTION_H_

#include "operation/math.h"

namespace tav {

namespace detail {

template <
	typename Index,
	typename Count,
	typename List
>
struct take_count_at {
	typedef Eval<take_count_at<
		Substract<Index, Size<1>>,
		Count,
		Tail<List>
	>> type;
};

template <
	typename Count,
	typename List
>
struct take_count_at<Size<0>, Count, List> {
	typedef Cons<
		Head<List>,
		Eval<take_count_at<
			Size<0>,
			Substract<Count, Size<1>>,
			Tail<List>
		>>
	> type;
};

template <
	typename Index,
	typename Count
>
struct take_count_at<Index, Count, void> {
	typedef void type;
};

template <typename Count>
struct take_count_at<Size<0>, Count, void> {
	typedef void type;
};

template <typename List>
struct take_count_at<Size<0>, Size<0>, List> {
	typedef void type;
};

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

}

template <
	typename Start,
	typename End,
	typename List
>
using Section = Eval<detail::take_count_at<
	Start,
	Substract<Add<End, Size<1>>, Start>,
	List
>>;

}

#endif  // TYPEASVALUE_SRC_LIST_OPERATION_SECTION_H_