forked from TartanLlama/expected
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bases.cpp
191 lines (170 loc) · 7.24 KB
/
bases.cpp
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <catch2/catch.hpp>
#include <tl/expected.hpp>
#include <string>
// Old versions of GCC don't have the correct trait names. Could fix them up if needs be.
#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \
!defined(__clang__))
// nothing for now
#else
TEST_CASE("Triviality", "[bases.triviality]") {
REQUIRE(std::is_trivially_copy_constructible<tl::expected<int,int>>::value);
REQUIRE(std::is_trivially_copy_assignable<tl::expected<int,int>>::value);
REQUIRE(std::is_trivially_move_constructible<tl::expected<int,int>>::value);
REQUIRE(std::is_trivially_move_assignable<tl::expected<int,int>>::value);
REQUIRE(std::is_trivially_destructible<tl::expected<int,int>>::value);
REQUIRE(std::is_trivially_copy_constructible<tl::expected<void,int>>::value);
REQUIRE(std::is_trivially_move_constructible<tl::expected<void,int>>::value);
REQUIRE(std::is_trivially_destructible<tl::expected<void,int>>::value);
{
struct T {
T(const T&) = default;
T(T&&) = default;
T& operator=(const T&) = default;
T& operator=(T&&) = default;
~T() = default;
};
REQUIRE(std::is_trivially_copy_constructible<tl::expected<T,int>>::value);
REQUIRE(std::is_trivially_copy_assignable<tl::expected<T,int>>::value);
REQUIRE(std::is_trivially_move_constructible<tl::expected<T,int>>::value);
REQUIRE(std::is_trivially_move_assignable<tl::expected<T,int>>::value);
REQUIRE(std::is_trivially_destructible<tl::expected<T,int>>::value);
}
{
struct T {
T(const T&){}
T(T&&) {}
T& operator=(const T&) { return *this; }
T& operator=(T&&) { return *this; }
~T(){}
};
REQUIRE(!std::is_trivially_copy_constructible<tl::expected<T,int>>::value);
REQUIRE(!std::is_trivially_copy_assignable<tl::expected<T,int>>::value);
REQUIRE(!std::is_trivially_move_constructible<tl::expected<T,int>>::value);
REQUIRE(!std::is_trivially_move_assignable<tl::expected<T,int>>::value);
REQUIRE(!std::is_trivially_destructible<tl::expected<T,int>>::value);
}
}
TEST_CASE("Deletion", "[bases.deletion]") {
REQUIRE(std::is_copy_constructible<tl::expected<int,int>>::value);
REQUIRE(std::is_copy_assignable<tl::expected<int,int>>::value);
REQUIRE(std::is_move_constructible<tl::expected<int,int>>::value);
REQUIRE(std::is_move_assignable<tl::expected<int,int>>::value);
REQUIRE(std::is_destructible<tl::expected<int,int>>::value);
{
struct T {
T()=default;
};
REQUIRE(std::is_default_constructible<tl::expected<T,int>>::value);
}
{
struct T {
T(int){}
};
REQUIRE(!std::is_default_constructible<tl::expected<T,int>>::value);
}
{
struct T {
T(const T&) = default;
T(T&&) = default;
T& operator=(const T&) = default;
T& operator=(T&&) = default;
~T() = default;
};
REQUIRE(std::is_copy_constructible<tl::expected<T,int>>::value);
REQUIRE(std::is_copy_assignable<tl::expected<T,int>>::value);
REQUIRE(std::is_move_constructible<tl::expected<T,int>>::value);
REQUIRE(std::is_move_assignable<tl::expected<T,int>>::value);
REQUIRE(std::is_destructible<tl::expected<T,int>>::value);
}
{
struct T {
T(const T&)=delete;
T(T&&)=delete;
T& operator=(const T&)=delete;
T& operator=(T&&)=delete;
};
REQUIRE(!std::is_copy_constructible<tl::expected<T,int>>::value);
REQUIRE(!std::is_copy_assignable<tl::expected<T,int>>::value);
REQUIRE(!std::is_move_constructible<tl::expected<T,int>>::value);
REQUIRE(!std::is_move_assignable<tl::expected<T,int>>::value);
}
{
struct T {
T(const T&)=delete;
T(T&&)=default;
T& operator=(const T&)=delete;
T& operator=(T&&)=default;
};
REQUIRE(!std::is_copy_constructible<tl::expected<T,int>>::value);
REQUIRE(!std::is_copy_assignable<tl::expected<T,int>>::value);
REQUIRE(std::is_move_constructible<tl::expected<T,int>>::value);
REQUIRE(std::is_move_assignable<tl::expected<T,int>>::value);
}
{
struct T {
T(const T&)=default;
T(T&&)=delete;
T& operator=(const T&)=default;
T& operator=(T&&)=delete;
};
REQUIRE(std::is_copy_constructible<tl::expected<T,int>>::value);
REQUIRE(std::is_copy_assignable<tl::expected<T,int>>::value);
}
{
tl::expected<int, int> e;
REQUIRE(std::is_default_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_constructible<decltype(e)>::value);
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(std::is_trivially_move_assignable<decltype(e)>::value);
# endif
}
{
tl::expected<int, std::string> e;
REQUIRE(std::is_default_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_constructible<decltype(e)>::value);
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
# endif
}
{
tl::expected<std::string, int> e;
REQUIRE(std::is_default_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_constructible<decltype(e)>::value);
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
# endif
}
{
tl::expected<std::string, std::string> e;
REQUIRE(std::is_default_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_constructible<decltype(e)>::value);
REQUIRE(std::is_move_constructible<decltype(e)>::value);
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
REQUIRE(std::is_move_assignable<decltype(e)>::value);
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
# if !defined(TL_EXPECTED_GCC49)
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
# endif
}
}
#endif