-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeListTest.cpp
More file actions
113 lines (91 loc) · 3.38 KB
/
Copy pathTypeListTest.cpp
File metadata and controls
113 lines (91 loc) · 3.38 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "TypeList.hpp" //includes TypeList.hpp
#include <type_traits> // static testing
#include <UnitTest++/UnitTest++.h> // dynamic testing
using namespace vmp;
using namespace std;
SUITE(TypeList) {
TEST(Size) {
static_assert(3 == typelist<short, int, long>::size(),
"TypeList size must equal number of constituent types");
}
TEST(Part) {
static_assert(is_same<short, typelist<short, int, long>::part<0>>::value,
"0 should yield first type");
static_assert(is_same<int, typelist<short, int, long>::part<1>>::value,
"1 should yield second type");
static_assert(is_same<long, typelist<short, int, long>::part<2>>::value,
"2 should yield third type");
}
TEST(AtHead) {
static_assert(is_same<typelist<float, double, short, int, long>,
typelist<short, int, long>::athead<float, double>>::value,
"AtHead type must have types prepended");
}
TEST(AtTail) {
static_assert(is_same<typelist<short, int, long, float, double>,
typelist<short, int, long>::attail<float, double>>::value,
"AtTail type must have types appended");
}
// Type alias as a function of types
template <typename type> using add_int = typelist<type, int>;
TEST(ForAll) {
static_assert(is_same<typelist<typelist<short, int>, typelist<int, int>, typelist<long, int>>,
typelist<short, int, long>::forall<add_int>>::value,
"ForAll type should be defined by mapping of type alias");
}
TEST(ReBind) {
static_assert(
is_same<tuple<short, int, long>, typelist<short, int, long>::rebind<tuple>>::value,
"Rebind type must be defined by pack");
}
template<typename t_type>
struct wrapint {};
template<typename t_type>
struct wraplong {};
TEST(ReWrap) {
static_assert(is_same<
typelist<wrapint<int>, wraplong<long>>,
typelist<int, long>::template rewrap<wrapint, wraplong>
>::value, "Wrap should be applied to each element");
}
short function(int, long) { return 0; }
TEST(FunPtr) {
static_assert(
is_same<decltype(&function),
typelist<int, long>::template funptr<short>
>::value, "FunPtr type should have typelist parts as args, with template arg returned");
}
struct method {
short call (int, long) const { return 0; }
};
TEST(MetPtr) {
static_assert(
is_same<decltype(&method::call),
typelist<int, long>::template metptr<short, method>
>::value, "MetPtr type should have typelist parts as args, with template arg returned");
}
template<typename t_list, typename t_tail>
using maptail = typename t_list::template attail<t_tail>;
TEST(Paired) {
static_assert(is_same<
typelist<
typelist<char, short>,
typelist<int, long>
>,
typelist<
typelist<char>,
typelist<int>
>::paired<maptail, short, long>
>::value, "Paired should use yield a typelist of aliased type");
}
TEST(Is_Typelist) {
static_assert(is_typelist<typelist<>>::value, "empty typelist should be identified");
static_assert(is_typelist<typelist<int, long>>::value, "typelist should be identified");
static_assert(!is_typelist<int>::value, "only typelist should be identified");
}
TEST(TypeOnly) {
static_assert(is_same<typelist<sizetype, sizetype, sizetype>,
typeonly<sizetype, 3>>::value,
"typeonly of sizetype must yield a typelist of only the specified type");
}
}