-
-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathfunction_static_tests.cpp
More file actions
569 lines (465 loc) · 27.9 KB
/
function_static_tests.cpp
File metadata and controls
569 lines (465 loc) · 27.9 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
#include <sqlite_orm/sqlite_orm.h>
#include <catch2/catch_all.hpp>
#include <type_traits> // std::is_same
using namespace sqlite_orm;
using internal::callable_arguments;
using internal::function;
using internal::function_call;
using internal::is_aggregate_udf_v;
using internal::is_scalar_udf_v;
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
using internal::quoted_scalar_function;
#endif
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
template<class S, auto f>
concept storage_scalar_callable = requires(S& storage) {
{ storage.template create_scalar_function<f>() };
{ storage.template delete_scalar_function<f>() };
};
template<class S, auto f>
concept storage_aggregate_callable = requires(S& storage) {
{ storage.template create_aggregate_function<f>() };
{ storage.template delete_aggregate_function<f>() };
};
constexpr auto clamp_int_ptr = &std::clamp<int>;
#endif
TEST_CASE("function static") {
SECTION("scalar") {
SECTION("variadic") {
struct FirstFunction {
std::string operator()(const arg_values& args) const {
std::string res;
res.reserve(args.size());
for (auto value: args) {
auto stringValue = value.get<std::string>();
if (!stringValue.empty()) {
res += stringValue.front();
}
}
return res;
}
static const char* name() {
return "FIRST";
}
};
}
SECTION("non variadic") {
SECTION("double(double) const") {
struct Function {
double operator()(double arg) const {
return std::sqrt(arg);
}
};
STATIC_REQUIRE(is_scalar_udf_v<Function>);
STATIC_REQUIRE_FALSE(is_aggregate_udf_v<Function>);
using RunMemberFunctionPointer = internal::scalar_call_function_t<Function>;
using ExpectedType = double (Function::*)(double) const;
STATIC_REQUIRE(std::is_same<RunMemberFunctionPointer, ExpectedType>::value);
using ArgumentsTuple = internal::function_arguments<RunMemberFunctionPointer, std::tuple, std::decay_t>;
using ExpectedArgumentsTuple = std::tuple<double>;
STATIC_REQUIRE(std::is_same<ArgumentsTuple, ExpectedArgumentsTuple>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::return_type, double>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::args_tuple, std::tuple<double>>::value);
}
SECTION("double(double)") {
struct Function {
double operator()(double arg) {
return std::sqrt(arg);
}
};
STATIC_REQUIRE(is_scalar_udf_v<Function>);
STATIC_REQUIRE_FALSE(is_aggregate_udf_v<Function>);
using RunMemberFunctionPointer = internal::scalar_call_function_t<Function>;
using ExpectedType = double (Function::*)(double);
STATIC_REQUIRE(std::is_same<RunMemberFunctionPointer, ExpectedType>::value);
using ArgumentsTuple = internal::function_arguments<RunMemberFunctionPointer, std::tuple, std::decay_t>;
using ExpectedArgumentsTuple = std::tuple<double>;
STATIC_REQUIRE(std::is_same<ArgumentsTuple, ExpectedArgumentsTuple>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::return_type, double>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::args_tuple, std::tuple<double>>::value);
}
SECTION("int(std::string) const") {
struct Function {
int operator()(std::string arg) const {
return int(arg.length());
}
};
STATIC_REQUIRE(is_scalar_udf_v<Function>);
STATIC_REQUIRE_FALSE(is_aggregate_udf_v<Function>);
using RunMemberFunctionPointer = internal::scalar_call_function_t<Function>;
using ExpectedType = int (Function::*)(std::string) const;
STATIC_REQUIRE(std::is_same<RunMemberFunctionPointer, ExpectedType>::value);
using ArgumentsTuple = internal::function_arguments<RunMemberFunctionPointer, std::tuple, std::decay_t>;
using ExpectedArgumentsTuple = std::tuple<std::string>;
STATIC_REQUIRE(std::is_same<ArgumentsTuple, ExpectedArgumentsTuple>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::return_type, int>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::args_tuple, std::tuple<std::string>>::value);
}
SECTION("int(std::string)") {
struct Function {
int operator()(std::string arg) {
return int(arg.length());
}
};
STATIC_REQUIRE(is_scalar_udf_v<Function>);
STATIC_REQUIRE_FALSE(is_aggregate_udf_v<Function>);
using RunMemberFunctionPointer = internal::scalar_call_function_t<Function>;
using ExpectedType = int (Function::*)(std::string);
STATIC_REQUIRE(std::is_same<RunMemberFunctionPointer, ExpectedType>::value);
using ArgumentsTuple = internal::function_arguments<RunMemberFunctionPointer, std::tuple, std::decay_t>;
using ExpectedArgumentsTuple = std::tuple<std::string>;
STATIC_REQUIRE(std::is_same<ArgumentsTuple, ExpectedArgumentsTuple>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::return_type, int>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::args_tuple, std::tuple<std::string>>::value);
}
SECTION("std::string(const std::string &, const std::string &) const") {
struct Function {
std::string operator()(const std::string& arg1, const std::string& arg2) const {
return arg1 + arg2;
}
};
STATIC_REQUIRE(is_scalar_udf_v<Function>);
STATIC_REQUIRE_FALSE(is_aggregate_udf_v<Function>);
using RunMemberFunctionPointer = internal::scalar_call_function_t<Function>;
using ExpectedType = std::string (Function::*)(const std::string&, const std::string&) const;
STATIC_REQUIRE(std::is_same<RunMemberFunctionPointer, ExpectedType>::value);
using ArgumentsTuple = internal::function_arguments<RunMemberFunctionPointer, std::tuple, std::decay_t>;
using ExpectedArgumentsTuple = std::tuple<std::string, std::string>;
STATIC_REQUIRE(std::is_same<ArgumentsTuple, ExpectedArgumentsTuple>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::return_type, std::string>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::args_tuple,
std::tuple<std::string, std::string>>::value);
}
SECTION("std::string(const std::string &, const std::string &)") {
struct Function {
std::string operator()(const std::string& arg1, const std::string& arg2) {
return arg1 + arg2;
}
};
STATIC_REQUIRE(is_scalar_udf_v<Function>);
STATIC_REQUIRE_FALSE(is_aggregate_udf_v<Function>);
using RunMemberFunctionPointer = internal::scalar_call_function_t<Function>;
using ExpectedType = std::string (Function::*)(const std::string&, const std::string&);
STATIC_REQUIRE(std::is_same<RunMemberFunctionPointer, ExpectedType>::value);
using ArgumentsTuple = internal::function_arguments<RunMemberFunctionPointer, std::tuple, std::decay_t>;
using ExpectedArgumentsTuple = std::tuple<std::string, std::string>;
STATIC_REQUIRE(std::is_same<ArgumentsTuple, ExpectedArgumentsTuple>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::return_type, std::string>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::args_tuple,
std::tuple<std::string, std::string>>::value);
}
}
}
SECTION("aggregate") {
SECTION("void(int) & int() const") {
struct Function {
int total = 0;
int count = 0;
void step(int value) {
++count;
total += value;
}
int fin() const {
return total;
}
};
STATIC_REQUIRE(is_aggregate_udf_v<Function>);
STATIC_REQUIRE_FALSE(is_scalar_udf_v<Function>);
using StepMemberFunctionPointer = internal::aggregate_step_function_t<Function>;
using ExpectedStepType = void (Function::*)(int);
STATIC_REQUIRE(std::is_same<StepMemberFunctionPointer, ExpectedStepType>::value);
using FinMemberFunctionPointer = internal::aggregate_fin_function_t<Function>;
using ExpectedFinType = int (Function::*)() const;
STATIC_REQUIRE(std::is_same<FinMemberFunctionPointer, ExpectedFinType>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::return_type, int>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::args_tuple, std::tuple<int>>::value);
}
SECTION("void(std::string) const & std::string()") {
struct Function {
mutable std::string result;
void step(std::string value) const {
result += value[0];
}
std::string fin() {
return std::move(result);
}
};
STATIC_REQUIRE(is_aggregate_udf_v<Function>);
STATIC_REQUIRE_FALSE(is_scalar_udf_v<Function>);
using StepMemberFunctionPointer = internal::aggregate_step_function_t<Function>;
using ExpectedStepType = void (Function::*)(std::string) const;
STATIC_REQUIRE(std::is_same<StepMemberFunctionPointer, ExpectedStepType>::value);
using FinMemberFunctionPointer = internal::aggregate_fin_function_t<Function>;
using ExpectedFinType = std::string (Function::*)();
STATIC_REQUIRE(std::is_same<FinMemberFunctionPointer, ExpectedFinType>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::return_type, std::string>::value);
STATIC_REQUIRE(std::is_same<callable_arguments<Function>::args_tuple, std::tuple<std::string>>::value);
}
}
SECTION("function call expressions") {
struct SFunction {
static const char* name() {
return "";
}
int operator()(int) const;
};
#ifdef SQLITE_ORM_STATIC_CALL_OPERATOR_SUPPORTED
struct SFunction2 {
static const char* name() {
return "";
}
static int operator()(int);
};
#endif
struct AFunction {
static const char* name() {
return "";
}
void step(int);
int fin() const;
};
constexpr auto scalar = func<SFunction>;
constexpr auto aggregate = func<AFunction>;
STATIC_REQUIRE(std::is_same<decltype(scalar), const function<SFunction>>::value);
STATIC_REQUIRE(std::is_same<decltype(scalar(42)), function_call<SFunction, int>>::value);
STATIC_REQUIRE(std::is_same<decltype(aggregate), const function<AFunction>>::value);
STATIC_REQUIRE(std::is_same<decltype(aggregate(42)), function_call<AFunction, int>>::value);
STATIC_REQUIRE(std::is_same<function<SFunction>::callable_type, SFunction>::value);
STATIC_REQUIRE(std::is_same<function<SFunction>::udf_type, SFunction>::value);
#ifdef SQLITE_ORM_STATIC_CALL_OPERATOR_SUPPORTED
constexpr auto scalar2 = func<SFunction2>;
STATIC_REQUIRE(std::is_same<decltype(scalar2), const function<SFunction2>>::value);
STATIC_REQUIRE(std::is_same<decltype(scalar2(42)), function_call<SFunction2, int>>::value);
STATIC_REQUIRE(std::is_same<function<SFunction2>::callable_type, SFunction2>::value);
STATIC_REQUIRE(std::is_same<function<SFunction2>::udf_type, SFunction2>::value);
#endif
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
STATIC_REQUIRE(orm_scalar_function<decltype(scalar)>);
STATIC_REQUIRE_FALSE(orm_aggregate_function<decltype(scalar)>);
STATIC_REQUIRE(orm_aggregate_function<decltype(aggregate)>);
STATIC_REQUIRE_FALSE(orm_scalar_function<decltype(aggregate)>);
using storage_type = decltype(make_storage(""));
STATIC_REQUIRE(storage_scalar_callable<storage_type, scalar>);
STATIC_REQUIRE_FALSE(storage_aggregate_callable<storage_type, scalar>);
STATIC_REQUIRE(storage_aggregate_callable<storage_type, aggregate>);
STATIC_REQUIRE_FALSE(storage_scalar_callable<storage_type, aggregate>);
#ifdef SQLITE_ORM_STATIC_CALL_OPERATOR_SUPPORTED
STATIC_REQUIRE(orm_scalar_function<decltype(scalar2)>);
STATIC_REQUIRE_FALSE(orm_aggregate_function<decltype(scalar2)>);
STATIC_REQUIRE(storage_scalar_callable<storage_type, scalar2>);
STATIC_REQUIRE_FALSE(storage_aggregate_callable<storage_type, scalar2>);
#endif
#endif
}
#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
SECTION("quoted") {
struct functor {
bool operator()(int&, int&) const = delete;
bool operator()(const int&, const int&) const {
return true;
}
#ifdef SQLITE_ORM_STATIC_CALL_OPERATOR_SUPPORTED
static bool operator()(int, int) {
return true;
}
#endif
};
#ifdef SQLITE_ORM_STATIC_CALL_OPERATOR_SUPPORTED
// note: this static lambda lives up here because of GCC 13.2 and mangling issues
constexpr auto lambda_static_dummy = [](unsigned long errcode) static {
return errcode != 0;
};
#endif
SECTION("detect overloaded call operator") {
constexpr auto lambda = [](unsigned long) {};
using lambda_type = std::remove_const_t<decltype(lambda)>;
STATIC_REQUIRE(
polyfill::is_detected_v<internal::overloaded_callop_t, void(unsigned long) const, lambda_type>);
STATIC_REQUIRE_FALSE(
polyfill::is_detected_v<internal::overloaded_static_callop_t, void(unsigned long) const, lambda_type>);
}
#ifdef SQLITE_ORM_STATIC_CALL_OPERATOR_SUPPORTED
SECTION("detect overloaded static call operator") {
constexpr auto lambda = [](unsigned long) static {};
using lambda_type = std::remove_const_t<decltype(lambda)>;
STATIC_REQUIRE_FALSE(
polyfill::is_detected_v<internal::overloaded_callop_t, void(unsigned long), lambda_type>);
STATIC_REQUIRE(
polyfill::is_detected_v<internal::overloaded_static_callop_t, void(unsigned long), lambda_type>);
}
#endif
SECTION("freestanding function") {
#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ < 12)
SKIP("GCC < 12 cannot use this function pointer as NTTP in this test.");
#else
constexpr auto quotedScalar = "f"_scalar.quote(clamp_int_ptr);
using quoted_type = decltype("f"_scalar.quote(clamp_int_ptr));
using expected_callable_type = std::remove_cv_t<decltype(clamp_int_ptr)>;
STATIC_REQUIRE(quotedScalar._nme[0] == 'f' && quotedScalar._nme[1] == '\0');
STATIC_REQUIRE(std::is_same_v<decltype(quotedScalar),
const quoted_scalar_function<expected_callable_type,
const int&(const int&, const int&, const int&),
2>>);
STATIC_REQUIRE(std::is_same_v<quoted_type::callable_type, expected_callable_type>);
STATIC_REQUIRE(std::is_same_v<quoted_type::udf_type, const int&(const int&, const int&, const int&)>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::return_type, int>);
STATIC_REQUIRE(
std::is_same_v<callable_arguments<quoted_type::udf_type>::args_tuple, std::tuple<int, int, int>>);
STATIC_REQUIRE(orm_quoted_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE_FALSE(orm_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE(
std::is_same_v<decltype(quotedScalar(0, 1, 1)),
function_call<const int&(const int&, const int&, const int&), int, int, int>>);
using storage_type = decltype(make_storage(""));
STATIC_REQUIRE(storage_scalar_callable<storage_type, quotedScalar>);
#endif
}
SECTION("template function") {
#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ < 12)
SKIP("GCC < 12 cannot use this function pointer as NTTP in this test.");
#else
constexpr auto quotedScalar =
"f"_scalar.quote<const int&(const int&, const int&, const int&)>(clamp_int_ptr);
using quoted_type =
decltype("f"_scalar.quote<const int&(const int&, const int&, const int&)>(clamp_int_ptr));
using expected_callable_type = std::remove_cv_t<decltype(clamp_int_ptr)>;
STATIC_REQUIRE(quotedScalar._nme[0] == 'f' && quotedScalar._nme[1] == '\0');
STATIC_REQUIRE(std::is_same_v<decltype(quotedScalar),
const quoted_scalar_function<expected_callable_type,
const int&(const int&, const int&, const int&),
2>>);
STATIC_REQUIRE(std::is_same_v<quoted_type::callable_type, expected_callable_type>);
STATIC_REQUIRE(std::is_same_v<quoted_type::udf_type, const int&(const int&, const int&, const int&)>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::return_type, int>);
STATIC_REQUIRE(
std::is_same_v<callable_arguments<quoted_type::udf_type>::args_tuple, std::tuple<int, int, int>>);
STATIC_REQUIRE(orm_quoted_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE_FALSE(orm_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE(
std::is_same_v<decltype(quotedScalar(0, 1, 1)),
function_call<const int&(const int&, const int&, const int&), int, int, int>>);
using storage_type = decltype(make_storage(""));
STATIC_REQUIRE(storage_scalar_callable<storage_type, quotedScalar>);
#endif
}
SECTION("lambda") {
constexpr auto lambda = [](unsigned long errcode) {
return errcode != 0;
};
using lambda_type = std::remove_const_t<decltype(lambda)>;
constexpr auto quotedScalar = "f"_scalar.quote(lambda);
using quoted_type = std::remove_const_t<decltype(quotedScalar)>;
STATIC_REQUIRE(quotedScalar._nme[0] == 'f' && quotedScalar._nme[1] == '\0');
STATIC_REQUIRE(std::is_same_v<decltype(quotedScalar),
const quoted_scalar_function<lambda_type, bool(unsigned long) const, 2>>);
STATIC_REQUIRE(std::is_same_v<quoted_type::callable_type, lambda_type>);
STATIC_REQUIRE(std::is_same_v<quoted_type::udf_type, bool(unsigned long) const>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::return_type, bool>);
STATIC_REQUIRE(
std::is_same_v<callable_arguments<quoted_type::udf_type>::args_tuple, std::tuple<unsigned long>>);
STATIC_REQUIRE(orm_quoted_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE_FALSE(orm_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE(
std::is_same_v<decltype(quotedScalar(1ul)), function_call<bool(unsigned long) const, unsigned long>>);
using storage_type = decltype(make_storage(""));
STATIC_REQUIRE(storage_scalar_callable<storage_type, quotedScalar>);
}
#ifdef SQLITE_ORM_STATIC_CALL_OPERATOR_SUPPORTED
SECTION("static lambda") {
constexpr auto lambda = [](unsigned long errcode) static {
return errcode != 0;
};
using lambda_type = std::remove_const_t<decltype(lambda)>;
constexpr auto quotedScalar = "f"_scalar.quote(lambda);
using quoted_type = std::remove_const_t<decltype(quotedScalar)>;
STATIC_REQUIRE(quotedScalar._nme[0] == 'f' && quotedScalar._nme[1] == '\0');
STATIC_REQUIRE(std::is_same_v<decltype(quotedScalar),
const quoted_scalar_function<lambda_type, bool(unsigned long), 2>>);
STATIC_REQUIRE(std::is_same_v<quoted_type::callable_type, lambda_type>);
STATIC_REQUIRE(std::is_same_v<quoted_type::udf_type, bool(unsigned long)>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::return_type, bool>);
STATIC_REQUIRE(
std::is_same_v<callable_arguments<quoted_type::udf_type>::args_tuple, std::tuple<unsigned long>>);
STATIC_REQUIRE(orm_quoted_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE_FALSE(orm_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE(
std::is_same_v<decltype(quotedScalar(1ul)), function_call<bool(unsigned long), unsigned long>>);
using storage_type = decltype(make_storage(""));
STATIC_REQUIRE(storage_scalar_callable<storage_type, quotedScalar>);
}
#endif
SECTION("classic function object") {
constexpr auto quotedScalar = "f"_scalar.quote<bool(const int&, const int&) const>(std::equal_to<int>{});
using quoted_type = decltype("f"_scalar.quote<bool(const int&, const int&) const>(std::equal_to<int>{}));
STATIC_REQUIRE(quotedScalar._nme[0] == 'f' && quotedScalar._nme[1] == '\0');
STATIC_REQUIRE(std::is_same_v<
decltype(quotedScalar),
const quoted_scalar_function<std::equal_to<int>, bool(const int&, const int&) const, 2>>);
STATIC_REQUIRE(std::is_same_v<quoted_type::callable_type, std::equal_to<int>>);
STATIC_REQUIRE(std::is_same_v<quoted_type::udf_type, bool(const int&, const int&) const>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::return_type, bool>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::args_tuple, std::tuple<int, int>>);
STATIC_REQUIRE(orm_quoted_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE_FALSE(orm_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE(std::is_same_v<decltype(quotedScalar(1, 1)),
function_call<bool(const int&, const int&) const, int, int>>);
using storage_type = decltype(make_storage(""));
STATIC_REQUIRE(storage_scalar_callable<storage_type, quotedScalar>);
}
SECTION("transparent function object") {
constexpr auto quotedScalar = "f"_scalar.quote<bool(const int&, const int&) const>(std::equal_to<void>{});
using quoted_type = decltype("f"_scalar.quote<bool(const int&, const int&) const>(std::equal_to<void>{}));
STATIC_REQUIRE(quotedScalar._nme[0] == 'f' && quotedScalar._nme[1] == '\0');
STATIC_REQUIRE(std::is_same_v<
decltype(quotedScalar),
const quoted_scalar_function<std::equal_to<void>, bool(const int&, const int&) const, 2>>);
STATIC_REQUIRE(std::is_same_v<quoted_type::callable_type, std::equal_to<void>>);
STATIC_REQUIRE(std::is_same_v<quoted_type::udf_type, bool(const int&, const int&) const>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::return_type, bool>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::args_tuple, std::tuple<int, int>>);
STATIC_REQUIRE(orm_quoted_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE_FALSE(orm_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE(std::is_same_v<decltype(quotedScalar(1, 1)),
function_call<bool(const int&, const int&) const, int, int>>);
using storage_type = decltype(make_storage(""));
STATIC_REQUIRE(storage_scalar_callable<storage_type, quotedScalar>);
}
SECTION("function object overloaded call operator") {
constexpr auto quotedScalar = "f"_scalar.quote<bool(const int&, const int&) const>(functor{});
using quoted_type = decltype("f"_scalar.quote<bool(const int&, const int&) const>(functor{}));
STATIC_REQUIRE(quotedScalar._nme[0] == 'f' && quotedScalar._nme[1] == '\0');
STATIC_REQUIRE(
std::is_same_v<decltype(quotedScalar),
const quoted_scalar_function<functor, bool(const int&, const int&) const, 2>>);
STATIC_REQUIRE(std::is_same_v<quoted_type::callable_type, functor>);
STATIC_REQUIRE(std::is_same_v<quoted_type::udf_type, bool(const int&, const int&) const>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::return_type, bool>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::args_tuple, std::tuple<int, int>>);
STATIC_REQUIRE(orm_quoted_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE_FALSE(orm_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE(std::is_same_v<decltype(quotedScalar(1, 1)),
function_call<bool(const int&, const int&) const, int, int>>);
using storage_type = decltype(make_storage(""));
STATIC_REQUIRE(storage_scalar_callable<storage_type, quotedScalar>);
}
#ifdef SQLITE_ORM_STATIC_CALL_OPERATOR_SUPPORTED
SECTION("function object with static call operator") {
constexpr auto quotedScalar = "f"_scalar.quote<bool(int, int)>(functor{});
using quoted_type = decltype("f"_scalar.quote<bool(int, int)>(functor{}));
STATIC_REQUIRE(quotedScalar._nme[0] == 'f' && quotedScalar._nme[1] == '\0');
STATIC_REQUIRE(
std::is_same_v<decltype(quotedScalar), const quoted_scalar_function<functor, bool(int, int), 2>>);
STATIC_REQUIRE(std::is_same_v<quoted_type::callable_type, functor>);
STATIC_REQUIRE(std::is_same_v<quoted_type::udf_type, bool(int, int)>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::return_type, bool>);
STATIC_REQUIRE(std::is_same_v<callable_arguments<quoted_type::udf_type>::args_tuple, std::tuple<int, int>>);
STATIC_REQUIRE(orm_quoted_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE_FALSE(orm_scalar_function<decltype(quotedScalar)>);
STATIC_REQUIRE(std::is_same_v<decltype(quotedScalar(1, 1)), function_call<bool(int, int), int, int>>);
using storage_type = decltype(make_storage(""));
STATIC_REQUIRE(storage_scalar_callable<storage_type, quotedScalar>);
}
#endif
}
#endif
}