Debian Codegraph @

yo/advancedtemplates/examples/typeat.h

raw
1 #ifndef INCLUDED_TYPEAT_H_
2 #define INCLUDED_TYPEAT_H_
3
4 #include "typelist.h"
5
6 //TYPEAT
7 template <size_t index, typename Typelist>
8 struct TypeAt;
9 //=
10
11 //INVALID
12 template <size_t index>
13 struct TypeAt<index, TypeList<>>
14 {
15 static_assert(index < 0, "TypeAt index out of bounds");
16 using Type = TypeAt;
17 };
18 //=
19
20 //ZERO
21 template <typename Head, typename ...Tail>
22 struct TypeAt<0, TypeList<Head, Tail...>>
23 {
24 using Type = Head;
25 };
26 //=
27
28 //TYPELIST
29 template <size_t index, typename Head, typename ...Tail>
30 struct TypeAt<index, TypeList<Head, Tail...>>
31 {
32 using Type = typename TypeAt<index - 1, TypeList<Tail...>>::Type;
33 };
34 //=
35
36 #endif