-
-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathfunction_traits_test.cpp
More file actions
295 lines (266 loc) · 11 KB
/
Copy pathfunction_traits_test.cpp
File metadata and controls
295 lines (266 loc) · 11 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
// Copyright 2015, Tobias Hermann and the FunctionalPlus contributors.
// https://github.com/Dobiasd/FunctionalPlus
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <doctest/doctest.h>
#include <fplus/fplus.hpp>
#include <vector>
namespace {
typedef std::deque<int> IntDeq;
typedef std::deque<IntDeq> IntContCont;
typedef IntDeq IntCont;
typedef IntCont Row;
}
std::string CcI2SFree(const std::string& str, int x)
{
return str + std::to_string(x);
}
std::string CcI2SFreeNoexcept(const std::string& str, int x) noexcept
{
return str + std::to_string(x);
}
auto CcI2SLambda = [](const std::string& str, int x) { return CcI2SFree(str, x); };
auto CcI2SLambdaNoexcept = [](const std::string& str, int x) noexcept { return CcI2SFree(str, x); };
std::function<std::string(const std::string&, int)>
CcI2SStdFunction = CcI2SLambda;
std::function<std::string(const std::string&, int)>
CcI2SStdFunctionNoexcept = CcI2SLambdaNoexcept;
std::string (*CcI2SFunctionPointer)(const std::string&, int) = &CcI2SFree;
std::string (*CcI2SFunctionPointerNoexcept)(const std::string&, int) noexcept = &CcI2SFreeNoexcept;
struct CcI2SStrct {
std::string operator()(const std::string& str, int x)
{
return CcI2SFree(str, x);
}
std::string nonCMemF(const std::string& str, int x)
{
return CcI2SFree(str, x);
}
std::string cnstMemF(const std::string& str, int x) const
{
return CcI2SFree(str, x);
}
static std::string sttcMemF(const std::string& str, int x)
{
return CcI2SFree(str, x);
}
};
struct CcI2SStrctNoexcept {
std::string operator()(const std::string& str, int x) noexcept
{
return CcI2SFreeNoexcept(str, x);
}
std::string nonCMemF(const std::string& str, int x) noexcept
{
return CcI2SFreeNoexcept(str, x);
}
std::string cnstMemF(const std::string& str, int x) const noexcept
{
return CcI2SFreeNoexcept(str, x);
}
static std::string sttcMemF(const std::string& str, int x) noexcept
{
return CcI2SFreeNoexcept(str, x);
}
};
TEST_CASE("function_traits_test - static_asserts")
{
using namespace fplus;
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFree)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFree)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFree)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SLambda)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SLambda)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SLambda)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SStdFunction)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SStdFunction)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SStdFunction)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFunctionPointer)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFunctionPointer)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFunctionPointer)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFreeNoexcept)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFreeNoexcept)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFreeNoexcept)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SLambdaNoexcept)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SLambdaNoexcept)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SLambdaNoexcept)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SStdFunctionNoexcept)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SStdFunctionNoexcept)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SStdFunctionNoexcept)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFunctionPointerNoexcept)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFunctionPointerNoexcept)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(CcI2SFunctionPointerNoexcept)>::result_type,
std::string>::value,
"No.");
CcI2SStrct ccI2SStrct;
ccI2SStrct("dummy call to avoid unused variable warnings", 0);
static_assert(std::is_same<
utils::function_traits<decltype(ccI2SStrct)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(ccI2SStrct)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(ccI2SStrct)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrct::nonCMemF)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrct::nonCMemF)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrct::nonCMemF)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrct::cnstMemF)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrct::cnstMemF)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrct::cnstMemF)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrct::sttcMemF)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrct::sttcMemF)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrct::sttcMemF)>::result_type,
std::string>::value,
"No.");
CcI2SStrctNoexcept ccI2SStrctNoexcept;
ccI2SStrctNoexcept("dummy call to avoid unused variable warnings", 0);
static_assert(std::is_same<
utils::function_traits<decltype(ccI2SStrctNoexcept)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(ccI2SStrctNoexcept)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(ccI2SStrctNoexcept)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrctNoexcept::nonCMemF)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrctNoexcept::nonCMemF)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrctNoexcept::nonCMemF)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrctNoexcept::cnstMemF)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrctNoexcept::cnstMemF)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrctNoexcept::cnstMemF)>::result_type,
std::string>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrctNoexcept::sttcMemF)>::arg<0>::type,
const std::string&>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrctNoexcept::sttcMemF)>::arg<1>::type,
int>::value,
"No.");
static_assert(std::is_same<
utils::function_traits<decltype(&CcI2SStrctNoexcept::sttcMemF)>::result_type,
std::string>::value,
"No.");
}