aboutsummaryrefslogtreecommitdiff
path: root/src/list/operation/nth.h
blob: 5a604f4183a1e3bec6f1f00b3cae9230a3f88e06 (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
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_NTH_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_NTH_H_

#include "operation/math.h"

namespace tav {

namespace detail {

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

template <typename List>
struct Nth<Size<0>, List> {
	typedef Head<List> type;
};

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

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

}

template <
	typename Index,
	typename List
>
using Nth = Eval<detail::Nth<Index, List>>;

template <typename List>
using First  = Nth<Size<0>, List>;

template <typename List>
using Second = Nth<Size<1>, List>;

template <typename List>
using Third  = Nth<Size<2>, List>;

}

#endif  // TYPEASVALUE_SRC_LIST_OPERATION_NTH_H_