63 INFO(
"Test 00_usage: START: Implementation = functional "+std::to_string(
FUNCTIONAL_IMPL )+
".hpp");
64 fprintf(stderr,
"Implementation: functional %d, is_rtti_available %d, limited_lambda_id %d\n",
75 typedef jau::function<bool(std::vector<uint8_t>& ,
bool )> SomeFunc;
77 SomeFunc fa1 =
nullptr;
86 function<int(
int)> fa0 = [&](
int a) ->
int {
89 fprintf(stderr,
"lambda.0: %s, signature %s\n", fa0.toString().c_str(), fa0.signature().internal_name());
92 function<int(
int)> fa1 = lambda_01();
93 fprintf(stderr,
"lambda.1: %s, signature %s\n", fa1.toString().c_str(), fa1.signature().internal_name());
96 auto fa2_stub = [&](
int a) ->
int {
100 fprintf(stderr,
"lambda.2_a: %s, signature %s\n", fa2_a.toString().c_str(), fa2_a.signature().internal_name());
103 function<int(
int)> fa2_b = fa2_stub;
104 fprintf(stderr,
"lambda.2_b: %s, signature %s\n", fa2_b.toString().c_str(), fa2_b.signature().internal_name());
107 test_function0_result_____(
"lambda.0_1_", 1, 101, fa0, fa1);
108 test_function0________type(
"lambda.0_1_",
false, fa0, fa1);
109 test_function0_result_____(
"lambda.0_2a", 1, 101, fa0, fa2_a);
110 test_function0_result_____(
"lambda.0_2b", 1, 101, fa0, fa2_b);
113 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
115 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
116 test_function0________type(
"lambda.0_2a",
false, fa0, fa2_a);
119 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
121 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
122 test_function0________type(
"lambda.0_2b",
false, fa0, fa2_b);
125 fprintf(stderr,
"INFO: !limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
126 test_function0________type(
"lambda.0_2a",
false, fa0, fa2_a);
127 test_function0________type(
"lambda.0_2b",
false, fa0, fa2_b);
129 test_function0_result_____(
"lambda.2a2b", 1, 101, fa2_a, fa2_b);
130 test_function0________type(
"lambda.2a2b",
true, fa2_a, fa2_b);
133#if ( FUNCTIONAL_IMPL == 1 )
136 function<int(
int)> f_1 = [](
int a) ->
int {
139 fprintf(stderr,
"lambda.3_1 (plain) %s, signature %s\n", f_1.toString().c_str(), f_1.signature().internal_name());
141 test_function0_result_type(
"lambda.3131",
true, 1, 101, f_1, f_1);
143 function<int(
int)> f_2 =
function<int(
int)>::bind_lambda( [](
int x) ->
int {
146 fprintf(stderr,
"lambda.3_2 (plain) %s, signature %s\n", f_2.toString().c_str(), f_2.signature().internal_name());
148 test_function0_result_type(
"lambda.3232",
true, 1, 101, f_2, f_2);
152 function<int(
int)> f_1 =
function<int(
int)>::bind_ylambda( [](
auto& self,
int x) ->
int {
156 return x * self(x-1);
159 fprintf(stderr,
"ylambda.1_1 (plain) %s, signature %s\n", f_1.toString().c_str(), f_1.signature().internal_name());
161 test_function0_result_type(
"ylambda.1111",
true, 4, 24, f_1, f_1);
165 function<int(
int)> f_1 =
function<int(
int)>::bind_ylambda( [](
function<
int(
int)>::delegate_type& self,
int x) ->
int {
169 return x * self(x-1);
172 fprintf(stderr,
"ylambda.1_2 (plain) %s, signature %s\n", f_1.toString().c_str(), f_1.signature().internal_name());
174 test_function0_result_type(
"ylambda.1111",
true, 4, 24, f_1, f_1);
179 typedef int(*cfunc)(int);
180 volatile int i = 100;
182 auto f = ( [](
int a) ->
int {
187 fprintf(stderr,
"plain lambda.0 %s\n", fl_.toString().c_str());
190 test_function0_result_type(
"FuncPtr1a_free_10",
true, 1, 101, fl_, fl_);
196 typedef void(*cfunc)();
197 function<void()> fl_0 = (cfunc) ( []() ->
void {
200 fprintf(stderr,
"freeA.0 %s\n", fl_0.toString().c_str());
204 fprintf(stderr,
"freeA.1 %s\n", f2a_0.toString().c_str());
208 fprintf(stderr,
"freeA.2 %s\n", f2a_1.toString().c_str());
212 fprintf(stderr,
"freeA.3 %s\n", f20a_1.toString().c_str());
216 fprintf(stderr,
"freeA.4 %s\n", f20a_2.toString().c_str());
219 test_function2________type(
"FuncPtr1a_free_10",
true, fl_0, fl_0);
220 test_function2________type(
"FuncPtr1a_free_10",
true, f2a_0, f2a_1);
221 test_function2________type(
"FuncPtr1a_free_10",
true, f2a_1, f2a_1);
222 test_function2________type(
"FuncPtr3a_free_11",
true, f20a_1, f20a_1);
223 test_function2________type(
"FuncPtr3a_free_12",
true, f20a_1, f20a_2);
224 test_function2________type(
"FuncPtr1a_free_10",
false, f2a_1, f20a_1);
229 typedef int(*cfunc)(int);
230 function<int(
int)> fl_0 = (cfunc) ( [](
int i) ->
int {
234 fprintf(stderr,
"freeB.0 %s\n", fl_0.toString().c_str());
238 fprintf(stderr,
"freeB.1 %s\n", f1a_0.toString().c_str());
244 test_function0_result_type(
"FuncPtr1a_free_10",
true, 1, 101, fl_0, fl_0);
245 test_function0_result_type(
"FuncPtr1a_free_10",
true, 1, 101, f1a_0, f1a_1);
246 test_function0_result_type(
"FuncPtr1a_free_10",
true, 1, 101, f1a_1, f1a_1);
247 test_function0_result_type(
"FuncPtr3a_free_11",
true, 1, 101, f3a_1, f3a_1);
248 test_function0_result_type(
"FuncPtr3a_free_12",
true, 1, 101, f3a_1, f3a_2);
249 test_function0_result_type(
"FuncPtr1a_free_10",
false, 1, 101, f1a_1, f3a_1);
253 typedef void(*cfunc)(
int&, int);
254 function<void(
int&,
int)> fl_0 = (cfunc) ( [](
int& res,
int i) ->
void {
259 function<void(
int&,
int)> f3a_0 = &TestFunction01::Func13a_static;
262 test_function1_result_type(
"FuncPtr1a_free_10",
true, 1, 101, fl_0, fl_0);
263 test_function1_result_type(
"FuncPtr1a_free_10",
true, 1, 101, f1a_1, f1a_0);
264 test_function1_result_type(
"FuncPtr3a_free_11",
true, 1, 101, f3a_1, f3a_0);
265 test_function1_result_type(
"FuncPtr3a_free_11",
true, 1, 101, f3a_1, f3a_1);
266 test_function1_result_type(
"FuncPtr3a_free_12",
true, 1, 101, f3a_1, f3a_2);
267 test_function1_result_type(
"FuncPtr1a_free_10",
false, 1, 101, f1a_1, f3a_1);
271 function<int(
int)> f2a_0(
this, &TestFunction01::func02a_member);
272 fprintf(stderr,
"memberA.0 %s\n", f2a_0.toString().c_str());
276 fprintf(stderr,
"memberA.1 %s\n", f2a_1.toString().c_str());
281 test_function0_result_type(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_0);
282 test_function0_result_type(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_2);
283 test_function0_result_type(
"FuncPtr2a_member_12",
false, 1, 101, f2a_1, f2b_1);
287 function<void(
int&,
int)> f2a_0(
this, &TestFunction01::func12a_member);
291 test_function1_result_type(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_0);
292 test_function1_result_type(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_2);
293 test_function1_result_type(
"FuncPtr2a_member_12",
false, 1, 101, f2a_1, f2b_1);
299 typedef int(*cfunc)(
int&, int);
301 int(*func5a_capture)(
int&, int) = [](
int& capture,
int i)->int {
302 int res = i+10000+capture;
306 int(*func5b_capture)(
int&, int) = [](
int& capture,
int i)->int {
307 int res = i+100000+capture;
311 function<int(
int)> f5_o100_0(offset100,
312 (cfunc) ( [](
int& capture,
int i)->
int {
313 int res = i+10000+capture;
316 fprintf(stderr,
"capvalA.0 %s\n", f5_o100_0.toString().c_str());
320 (cfunc) ( [](
int& capture,
int i)->
int {
321 int res = i+10000+capture;
325 (cfunc) ( [](
int& capture,
int i)->
int {
326 int res = i+10000+capture;
329 test_function0________type(
"FuncPtr5a_o100_capture_00",
true, f5_o100_0, f5_o100_0);
330 test_function0________type(
"FuncPtr5a_o100_capture_00",
true, f5_o100_1, f5_o100_1);
331 test_function0________type(
"FuncPtr5a_o100_capture_00",
false, f5_o100_1, f5_o100_2);
333 function<int(
int)> f5a_o100_0(offset100, func5a_capture);
334 fprintf(stderr,
"capvalA.1 %s\n", f5a_o100_0.toString().c_str());
340 test_function0________type(
"FuncPtr5a_o100_capture_12",
true, f5a_o100_1, f5a_o100_0);
341 test_function0________type(
"FuncPtr5a_o100_capture_12",
true, f5a_o100_1, f5a_o100_2);
342 test_function0________type(
"FuncPtr5a_o100_capture_12",
false, f5a_o100_1, f5b_o100_1);
343 test_function0_result_type(
"FuncPtr5a_o100_capture_11",
true, 1, 10101, f5a_o100_1, f5a_o100_1);
344 test_function0_result_type(
"FuncPtr5a_o100_capture_12",
true, 1, 10101, f5a_o100_1, f5a_o100_2);
345 test_function0_result_type(
"FuncPtr5a_o100_capture_12",
false, 1, 10101, f5a_o100_1, f5b_o100_1);
349 IntOffset offset100(100);
351 typedef int(*cfunc)(IntOffset*, int);
353 int(*func7a_capture)(IntOffset*, int) = [](IntOffset* capture,
int i)->int {
354 int res = i+10000+capture->value;
357 int(*func7b_capture)(IntOffset*, int) = [](IntOffset* capture,
int i)->int {
358 int res = i+100000+capture->value;
363 (cfunc) ( [](IntOffset* capture,
int i)->
int {
364 int res = i+10000+capture->value;
367 fprintf(stderr,
"caprefA.0 %s\n", f7_o100_1.toString().c_str());
371 (cfunc) ( [](IntOffset* capture,
int i)->
int {
372 int res = i+10000+capture->value;
375 test_function0________type(
"FuncPtr7a_o100_capture_00",
true, f7_o100_1, f7_o100_1);
376 test_function0________type(
"FuncPtr7a_o100_capture_00",
false, f7_o100_1, f7_o100_2);
379 fprintf(stderr,
"caprefA.1 %s\n", f7a_o100_1.toString().c_str());
383 test_function0________type(
"FuncPtr7a_o100_capture_12",
true, f7a_o100_1, f7a_o100_2);
384 test_function0________type(
"FuncPtr7a_o100_capture_12",
false, f7a_o100_1, f7b_o100_1);
385 test_function0_result_type(
"FuncPtr7a_o100_capture_11",
true, 1, 10101, f7a_o100_1, f7a_o100_1);
386 test_function0_result_type(
"FuncPtr7a_o100_capture_12",
true, 1, 10101, f7a_o100_1, f7a_o100_2);
387 test_function0_result_type(
"FuncPtr7a_o100_capture_12",
false, 1, 10101, f7a_o100_1, f7b_o100_1);
391 std::function<int(
int i)> func4a_stdlambda = [](
int i)->
int {
395 std::function<int(
int i)> func4b_stdlambda = [](
int i)->
int {
400 fprintf(stderr,
"stdfunc.0 %s\n", f4a_1.toString().c_str());
404 test_function0_result_type(
"FuncPtr4a_stdlambda_11",
true, 1, 101, f4a_1, f4a_1);
405 test_function0_result_type(
"FuncPtr4a_stdlambda_12",
true, 1, 101, f4a_1, f4a_2);
408 INFO(
"Test 00_usage: END");
412 INFO(
"Test 01_member: bind_member<int, TestFunction01, int>: START");
416 MyClassFunction0 f2a_2 =
bind_member(
this, &TestFunction01::func02a_member);
417 test_function0_result_type(
"FuncPtr2a_member_11",
true, 1, 101, f2a_1, f2a_1);
418 test_function0_result_type(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_2);
420 MyClassFunction0 f2b_1 =
bind_member(
this, &TestFunction01::func02b_member);
421 MyClassFunction0 f2b_2 =
bind_member(
this, &TestFunction01::func02b_member);
422 test_function0_result_type(
"FuncPtr2b_member_11",
true, 1, 1001, f2b_1, f2b_1);
423 test_function0_result_type(
"FuncPtr2b_member_12",
true, 1, 1001, f2b_1, f2b_2);
425 test_function0_result_type(
"FuncPtr2ab_member_11",
false, 1, 0, f2a_1, f2b_1);
426 test_function0_result_type(
"FuncPtr2ab_member_22",
false, 1, 0, f2a_2, f2b_2);
430 std::string msg =
"member01_c1";
435 int f(
int i)
noexcept {
442 function<int(
int)> f_1a(&c_1a, &c1_t::f);
443 function<int(
int)> f_1b(&c_1b, &c1_t::f);
444 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
446 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
451 function<int(
int)> f_2a(&c_2a, &c1_t::f);
452 function<int(
int)> f_2b(&c_2b, &c1_t::f);
453 fprintf(stderr,
"%s 2a %s\n", msg.c_str(), f_2a.toString().c_str());
455 fprintf(stderr,
"%s 2b %s\n", msg.c_str(), f_2b.toString().c_str());
458 test_function0_result_____(msg+
" 1aa", 1, 101, f_1a, f_1a);
459 test_function0_result_____(msg+
" 1ab", 1, 101, f_1a, f_1b);
460 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
461 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
463 test_function0_result_____(msg+
" 2aa", 1, 1001, f_2a, f_2a);
464 test_function0_result_____(msg+
" 2ab", 1, 1001, f_2a, f_2b);
465 test_function0________type(msg+
" 2aa",
true, f_2a, f_2a);
466 test_function0________type(msg+
" 2ab",
false, f_2a, f_2b);
473 c1_t() : offset(10) {}
474 c1_t(
int v) : offset(v) {}
476 int f(
int i)
noexcept {
482 struct c2_t :
public c1_t {
484 c2_t(
int v) : c1_t(v) {}
486 int f(
int i)
noexcept {
497 std::string msg =
"member02_func_c2";
502 function<int(
int)> f_1a(&c_1a, &c2_t::f);
503 function<int(
int)> f_1b(&c_1b, &c2_t::f);
504 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
506 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
509 test_function0_result_____(msg+
" 1aa", 1, 1001, f_1a, f_1a);
510 test_function0_result_____(msg+
" 1ab", 1, 1001, f_1a, f_1b);
511 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
512 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
520 std::string msg =
"member03_func_c1_ref";
527 function<int(
int)> f_1a(&c_1a, &c1_t::f);
528 function<int(
int)> f_1b(&c_1b, &c1_t::f);
529 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
531 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
534 test_function0_result_____(msg+
" 1aa", 1, 101, f_1a, f_1a);
535 test_function0_result_____(msg+
" 1ab", 1, 101, f_1a, f_1b);
536 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
537 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
545 c1_t() : offset(10) {}
547 int f(
int i)
noexcept {
553 struct c2_t :
public c1_t {
556 c2_t() : c1_t(), offset(20) {}
557 c2_t(
int v) : c1_t(), offset(v) {}
560 struct c3_t :
public c2_t {
562 c3_t(
int v) : c2_t(v) {}
574 function<int(
int)> f_1a(&c_1a, &c1_t::f);
583 std::string msg =
"member04_field_c2";
588 REQUIRE( 1000 == c_1a.offset);
589 fprintf(stderr,
"%s offset: c2_t %d\n", msg.c_str(), c_1a.offset);
591 function<int(
int)> f_1a(&c_1a, &c1_t::f);
592 function<int(
int)> f_1b(&c_1b, &c1_t::f);
593 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
595 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
598 test_function0_result_____(msg+
" 1aa", 1, 11, f_1a, f_1a);
599 test_function0_result_____(msg+
" 1ab", 1, 11, f_1a, f_1b);
600 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
601 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
608 std::string msg =
"member05_field_c1_ref";
615 REQUIRE( 1000 == c_1a_.offset);
616 REQUIRE( 10 == c_1a.offset);
617 fprintf(stderr,
"%s offset: c2_t %d, c1_t ref %d\n", msg.c_str(), c_1a_.offset, c_1a.offset);
619 function<int(
int)> f_1a(&c_1a, &c1_t::f);
620 function<int(
int)> f_1b(&c_1b, &c1_t::f);
621 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
623 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
626 test_function0_result_____(msg+
" 1aa", 1, 11, f_1a, f_1a);
627 test_function0_result_____(msg+
" 1ab", 1, 11, f_1a, f_1b);
628 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
629 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
638 std::string msg =
"member06_vfunc_c1_ref";
643 c1_t() : offset(10) {}
644 c1_t(
int v) : offset(v) {}
646 virtual ~c1_t()
noexcept =
default;
648 virtual int f(
int i)
noexcept {
654 struct c2_t :
public c1_t {
656 c2_t(
int v) : c1_t(v) {}
658 int f(
int i)
noexcept override {
668 function<int(
int)> f_1a(&c_1a, &c1_t::f);
669 function<int(
int)> f_1b(&c_1b, &c1_t::f);
670 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
672 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
675 test_function0_result_____(msg+
" 1aa", 1, 1001, f_1a, f_1a);
676 test_function0_result_____(msg+
" 1ab", 1, 1001, f_1a, f_1b);
677 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
678 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
680 INFO(
"Test 01_member: bind_member<int, TestFunction01, int>: END");
802 INFO(
"Test 04_capval: bindCapture<int, int, int>: START");
806 int offset1000 = 1000;
808 typedef int(*cfunc)(
int&, int);
810 int(*func5a_capture)(
int&, int) = [](
int& capture,
int i)->int {
811 int res = i+10000+capture;
814 int(*func5b_capture)(
int&, int) = [](
int& capture,
int i)->int {
815 int res = i+100000+capture;
820 (cfunc) ( [](
int& capture,
int i)->
int {
821 int res = i+10000+capture;
824 test_function0________type(
"FuncPtr5a_o100_capture_00",
true, f5a_o100_0, f5a_o100_0);
827 MyClassFunction0 f5a_o100_2 =
bind_capval(offset100, func5a_capture);
828 test_function0________type(
"FuncPtr5a_o100_capture_12",
true, f5a_o100_1, f5a_o100_2);
829 test_function0_result_type(
"FuncPtr5a_o100_capture_11",
true, 1, 10101, f5a_o100_1, f5a_o100_1);
830 test_function0_result_type(
"FuncPtr5a_o100_capture_12",
true, 1, 10101, f5a_o100_1, f5a_o100_2);
832 MyClassFunction0 f5a_o1000_1 =
bind_capval(offset1000, func5a_capture);
833 MyClassFunction0 f5a_o1000_2 =
bind_capval(offset1000, func5a_capture);
834 test_function0________type(
"FuncPtr5a_o1000_capture_12",
true, f5a_o1000_1, f5a_o1000_2);
835 test_function0________type(
"FuncPtr5a_o100_o1000_capture_11",
false, f5a_o100_1, f5a_o1000_1);
837 MyClassFunction0 f5b_o100_1 =
bind_capval(offset100, func5b_capture);
838 MyClassFunction0 f5b_o100_2 =
bind_capval(offset100, func5b_capture);
839 test_function0_result_type(
"FuncPtr5b_o100_capture_11",
true, 1, 100101, f5b_o100_1, f5b_o100_1);
840 test_function0_result_type(
"FuncPtr5b_o100_capture_12",
true, 1, 100101, f5b_o100_1, f5b_o100_2);
842 test_function0_result_type(
"FuncPtr5ab_o100_capture_11",
false, 1, 0, f5a_o100_1, f5b_o100_1);
843 test_function0_result_type(
"FuncPtr5ab_o100_capture_22",
false, 1, 0, f5a_o100_2, f5b_o100_2);
844 INFO(
"Test 04_capval: bindCapture<int, int, int>: END");
848 INFO(
"Test 14_capval: bindCapture<int, int, int>: START");
852 int offset1000 = 1000;
854 typedef void(*cfunc)(
int&,
int&, int);
856 void(*func5a_capture)(
int&,
int&, int) = [](
int& capture,
int& res,
int i)->void {
857 res = i+10000+capture;
859 void(*func5b_capture)(
int&,
int&, int) = [](
int& capture,
int& res,
int i)->void {
860 res = i+100000+capture;
864 (cfunc) ( [](
int& capture,
int& res,
int i)->
void {
865 res = i+10000+capture;
867 test_function1________type(
"FuncPtr5a_o100_capture_00",
true, f5a_o100_0, f5a_o100_0);
870 MyClassFunction1 f5a_o100_2 =
bind_capval(offset100, func5a_capture);
871 test_function1________type(
"FuncPtr5a_o100_capture_12",
true, f5a_o100_1, f5a_o100_2);
872 test_function1_result_type(
"FuncPtr5a_o100_capture_11",
true, 1, 10101, f5a_o100_1, f5a_o100_1);
873 test_function1_result_type(
"FuncPtr5a_o100_capture_12",
true, 1, 10101, f5a_o100_1, f5a_o100_2);
875 MyClassFunction1 f5a_o1000_1 =
bind_capval(offset1000, func5a_capture);
876 MyClassFunction1 f5a_o1000_2 =
bind_capval(offset1000, func5a_capture);
877 test_function1________type(
"FuncPtr5a_o1000_capture_12",
true, f5a_o1000_1, f5a_o1000_2);
878 test_function1________type(
"FuncPtr5a_o100_o1000_capture_11",
false, f5a_o100_1, f5a_o1000_1);
880 MyClassFunction1 f5b_o100_1 =
bind_capval(offset100, func5b_capture);
881 MyClassFunction1 f5b_o100_2 =
bind_capval(offset100, func5b_capture);
882 test_function1_result_type(
"FuncPtr5b_o100_capture_11",
true, 1, 100101, f5b_o100_1, f5b_o100_1);
883 test_function1_result_type(
"FuncPtr5b_o100_capture_12",
true, 1, 100101, f5b_o100_1, f5b_o100_2);
885 test_function1_result_type(
"FuncPtr5ab_o100_capture_11",
false, 1, 0, f5a_o100_1, f5b_o100_1);
886 test_function1_result_type(
"FuncPtr5ab_o100_capture_22",
false, 1, 0, f5a_o100_2, f5b_o100_2);
887 INFO(
"Test 14_capval: bindCapture<int, int, int>: END");
891 INFO(
"Test 05_capval: bindCapture<int, std::shared_ptr<IntOffset>, int>: START");
894 std::shared_ptr<IntOffset> offset100(
new IntOffset(100));
895 std::shared_ptr<IntOffset> offset1000(
new IntOffset(1000));
897 typedef int(*cfunc)(std::shared_ptr<IntOffset>&, int);
899 int(*func6a_capture)(std::shared_ptr<IntOffset>&, int) = [](std::shared_ptr<IntOffset>& capture,
int i)->int {
900 int res = i+10000+capture->value;
903 int(*func6b_capture)(std::shared_ptr<IntOffset>&, int) = [](std::shared_ptr<IntOffset>& capture,
int i)->int {
904 int res = i+100000+capture->value;
909 (cfunc) ( [](std::shared_ptr<IntOffset>& sharedOffset,
int i)->int {
910 int res = i+10000+sharedOffset->value;
913 test_function0________type(
"FuncPtr6a_o100_capture_00",
true, f6a_o100_0, f6a_o100_0);
916 MyClassFunction0 f6a_o100_2 =
bind_capval(offset100, func6a_capture);
917 test_function0________type(
"FuncPtr6a_o100_capture_12",
true, f6a_o100_1, f6a_o100_2);
918 test_function0_result_type(
"FuncPtr6a_o100_capture_11",
true, 1, 10101, f6a_o100_1, f6a_o100_1);
919 test_function0_result_type(
"FuncPtr6a_o100_capture_12",
true, 1, 10101, f6a_o100_1, f6a_o100_2);
921 MyClassFunction0 f6a_o1000_1 =
bind_capval(offset1000, func6a_capture);
922 MyClassFunction0 f6a_o1000_2 =
bind_capval(offset1000, func6a_capture);
923 test_function0________type(
"FuncPtr6a_o1000_capture_12",
true, f6a_o1000_1, f6a_o1000_2);
924 test_function0________type(
"FuncPtr6a_o100_o1000_capture_11",
false, f6a_o100_1, f6a_o1000_1);
926 MyClassFunction0 f6b_o100_1 =
bind_capval(offset100, func6b_capture);
927 MyClassFunction0 f6b_o100_2 =
bind_capval(offset100, func6b_capture);
928 test_function0_result_type(
"FuncPtr6b_o100_capture_11",
true, 1, 100101, f6b_o100_1, f6b_o100_1);
929 test_function0_result_type(
"FuncPtr6b_o100_capture_12",
true, 1, 100101, f6b_o100_1, f6b_o100_2);
931 test_function0_result_type(
"FuncPtr6ab_o100_capture_11",
false, 1, 0, f6a_o100_1, f6b_o100_1);
932 test_function0_result_type(
"FuncPtr6ab_o100_capture_22",
false, 1, 0, f6a_o100_2, f6b_o100_2);
933 INFO(
"Test 05_capval: bindCapture<int, std::shared_ptr<IntOffset>, int>: END");
937 INFO(
"Test 06_capval: bindCapture<int, IntOffset, int>: START");
940 IntOffset offset100(100);
941 IntOffset offset1000(1000);
943 typedef int(*cfunc)(IntOffset&, int);
945 int(*func7a_capture)(IntOffset&, int) = [](IntOffset& capture,
int i)->int {
946 int res = i+10000+capture.value;
949 int(*func7b_capture)(IntOffset&, int) = [](IntOffset& capture,
int i)->int {
950 int res = i+100000+capture.value;
955 (cfunc) ( [](IntOffset& capture,
int i)->
int {
956 int res = i+10000+capture.value;
959 test_function0________type(
"FuncPtr7a_o100_capture_00",
true, f7a_o100_0, f7a_o100_0);
961 INFO(
"f7a_o100_1 copy_ctor");
963 INFO(
"f7a_o100_1 copy_ctor done");
964 INFO(
"f7a_o100_2 move_ctor");
965 MyClassFunction0 f7a_o100_2 =
bind_capval(IntOffset(100), func7a_capture);
966 INFO(
"f7a_o100_2 move_ctor done");
967 test_function0________type(
"FuncPtr7a_o100_capture_12",
true, f7a_o100_1, f7a_o100_2);
968 test_function0_result_type(
"FuncPtr7a_o100_capture_11",
true, 1, 10101, f7a_o100_1, f7a_o100_1);
969 test_function0_result_type(
"FuncPtr7a_o100_capture_12",
true, 1, 10101, f7a_o100_1, f7a_o100_2);
971 MyClassFunction0 f7a_o1000_1 =
bind_capval(offset1000, func7a_capture);
972 MyClassFunction0 f7a_o1000_2 =
bind_capval(offset1000, func7a_capture);
973 test_function0________type(
"FuncPtr7a_o1000_capture_12",
true, f7a_o1000_1, f7a_o1000_2);
974 test_function0________type(
"FuncPtr7a_o100_o1000_capture_11",
false, f7a_o100_1, f7a_o1000_1);
976 MyClassFunction0 f7b_o100_1 =
bind_capval(offset100, func7b_capture);
977 MyClassFunction0 f7b_o100_2 =
bind_capval(offset100, func7b_capture);
978 test_function0_result_type(
"FuncPtr7b_o100_capture_11",
true, 1, 100101, f7b_o100_1, f7b_o100_1);
979 test_function0_result_type(
"FuncPtr7b_o100_capture_12",
true, 1, 100101, f7b_o100_1, f7b_o100_2);
981 test_function0_result_type(
"FuncPtr7ab_o100_capture_11",
false, 1, 0, f7a_o100_1, f7b_o100_1);
982 test_function0_result_type(
"FuncPtr7ab_o100_capture_22",
false, 1, 0, f7a_o100_2, f7b_o100_2);
983 INFO(
"Test 06_capval: bindCapture<int, IntOffset, int>: END");
987 INFO(
"Test 07_capref: bindCapture<int, IntOffset, int>: START");
990 IntOffset offset100(100);
991 IntOffset offset1000(1000);
993 typedef int(*cfunc)(IntOffset*, int);
995 int(*func7a_capture)(IntOffset*, int) = [](IntOffset* capture,
int i)->int {
996 int res = i+10000+capture->value;
999 int(*func7b_capture)(IntOffset*, int) = [](IntOffset* capture,
int i)->int {
1000 int res = i+100000+capture->value;
1005 (cfunc) ( [](IntOffset* capture,
int i)->
int {
1006 int res = i+10000+capture->value;
1009 test_function0________type(
"FuncPtr7a_o100_capture_00",
true, f7a_o100_0, f7a_o100_0);
1011 INFO(
"f7a_o100_1 copy_ctor");
1013 INFO(
"f7a_o100_1 copy_ctor done");
1014 INFO(
"f7a_o100_2 move_ctor");
1015 MyClassFunction0 f7a_o100_2 =
bind_capref(&offset100, func7a_capture);
1016 INFO(
"f7a_o100_2 move_ctor done");
1017 test_function0________type(
"FuncPtr7a_o100_capture_12",
true, f7a_o100_1, f7a_o100_2);
1018 test_function0_result_type(
"FuncPtr7a_o100_capture_11",
true, 1, 10101, f7a_o100_1, f7a_o100_1);
1019 test_function0_result_type(
"FuncPtr7a_o100_capture_12",
true, 1, 10101, f7a_o100_1, f7a_o100_2);
1021 MyClassFunction0 f7a_o1000_1 =
bind_capref(&offset1000, func7a_capture);
1022 MyClassFunction0 f7a_o1000_2 =
bind_capref(&offset1000, func7a_capture);
1023 test_function0________type(
"FuncPtr7a_o1000_capture_12",
true, f7a_o1000_1, f7a_o1000_2);
1024 test_function0________type(
"FuncPtr7a_o100_o1000_capture_11",
false, f7a_o100_1, f7a_o1000_1);
1026 MyClassFunction0 f7b_o100_1 =
bind_capref(&offset100, func7b_capture);
1027 MyClassFunction0 f7b_o100_2 =
bind_capref(&offset100, func7b_capture);
1028 test_function0_result_type(
"FuncPtr7b_o100_capture_11",
true, 1, 100101, f7b_o100_1, f7b_o100_1);
1029 test_function0_result_type(
"FuncPtr7b_o100_capture_12",
true, 1, 100101, f7b_o100_1, f7b_o100_2);
1031 test_function0_result_type(
"FuncPtr7ab_o100_capture_11",
false, 1, 0, f7a_o100_1, f7b_o100_1);
1032 test_function0_result_type(
"FuncPtr7ab_o100_capture_22",
false, 1, 0, f7a_o100_2, f7b_o100_2);
1033 INFO(
"Test 07_capref: bindCapture<int, IntOffset, int>: END");
1197 volatile int i = 100;
1198 volatile int j = 100;
1200 auto fa0_stub = ( [&](
int a) ->
int {
1204 function<int(
int)> fa0_a( fa0_stub );
1205 fprintf(stderr,
"fa0_a: %s\n", fa0_a.toString().c_str());
1208 auto fa0c_stub = ( [&](
int a) ->
int {
1211 function<int(
int)> fa0_c( fa0c_stub );
1212 fprintf(stderr,
"fa0_c: %s\n", fa0_c.toString().c_str());
1213 fprintf(stderr,
"fa0_stub is_same fa0c_stub: %d\n",
1214 std::is_same_v<
decltype(fa0_stub),
decltype(fa0c_stub)> );
1215 fprintf(stderr,
"fa0_a == fa0_c: %d\n",
1220 function<int(
int)> fa0_b( fa0_stub );
1221 fprintf(stderr,
"fa1: %s\n", fa0_b.toString().c_str());
1224 function<int(
int)> fa2_1 = [&](
int a) ->
int {
1227 fprintf(stderr,
"fa2_1: %s\n", fa2_1.toString().c_str());
1231 function<int(
int)> fa2_2 = lambda_01();
1232 fprintf(stderr,
"fa2_2: %s\n", fa2_2.toString().c_str());
1238 function<int(
int)> fa2_3 = [&](
int a) ->
int {
1241 fprintf(stderr,
"fa2_3: %s\n", fa2_3.toString().c_str());
1245 function<int(
int)> fa2_4 = [i](
int a) ->
int {
1248 fprintf(stderr,
"fa2_4: %s\n", fa2_4.toString().c_str());
1253 function<int(
int)> f_b = [&](
int a) ->
int {
1256 fprintf(stderr,
"f_b: %s\n", f_b.toString().c_str());
1261 function<int(
int)> f_c = [&](
int a) ->
int {
1262 return 2 * ( j + a );
1264 fprintf(stderr,
"f_c: %s\n", f_c.toString().c_str());
1269 function<int(
int)> f_d = [&](
int a) ->
int {
1270 return 2 * ( i + a );
1272 fprintf(stderr,
"f_d: %s\n", f_d.toString().c_str());
1276 function<int(
int,
bool)> f_e = [&](
int a,
bool dummy) ->
int {
1280 fprintf(stderr,
"f_e: %s\n", f_e.toString().c_str());
1283 test_function0_result_type(
"lambda.5b",
true, 1, 101, fa2_1, fa2_1);
1284 test_function0_result_type(
"lambda.5a",
true, 1, 101, fa0_a, fa0_b);
1286 test_function0_result_____(
"lambda.5c", 1, 101, fa2_1, fa2_2);
1287 test_function0________type(
"lambda.5c",
false, fa2_1, fa2_2);
1288 test_function0_result_____(
"lambda.5e", 1, 101, fa2_1, fa2_4);
1289 test_function0________type(
"lambda.5e",
false, fa2_1, fa2_4);
1291 test_function0________type(
"lambda.5B",
false, fa2_1, f_b);
1292 test_function0________type(
"lambda.5C",
false, fa2_1, f_c);
1294 test_function0_result_____(
"lambda.5d", 1, 101, fa2_1, fa2_3);
1296 if( fa2_1 == fa2_3 ) {
1297 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1299 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
1300 test_function0________type(
"lambda.5d",
false, fa2_1, fa2_3);
1302 if( fa2_1 == f_d ) {
1303 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1305 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
1306 test_function0________type(
"lambda.5D",
false, fa2_1, f_d);
1309 fprintf(stderr,
"INFO: !limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1310 test_function0________type(
"lambda.5d",
false, fa2_1, fa2_3);
1311 test_function0________type(
"lambda.5D",
false, fa2_1, f_d);
1313 CHECK(fa2_1 != f_e);
1319 function<int(
int)> f_1 = [&i](
int a) ->
int {
1322 fprintf(stderr,
"l6 f_1 ref: %s\n", f_1.toString().c_str());
1327 function<int(
int)> f_2 = [&j](
int a) ->
int {
1330 fprintf(stderr,
"l6 f_2 ref: %s\n", f_2.toString().c_str());
1333 test_function0_result_____(
"lambda.6", 1, 101, f_1, f_2);
1334 test_function0________type(
"lambda.6",
false, f_1, f_2);
1335 test_function0________type(
"lambda.6",
true, f_1, f_1);
1341 function<int(
int)> f_1 = [&i](
int a) ->
int {
1346 fprintf(stderr,
"l7 f_1 ref: %s\n", f_1.toString().c_str());
1351 function<int(
int)> f_2 = [&j](
int a) ->
int {
1356 fprintf(stderr,
"l7 f_2 ref: %s\n", f_2.toString().c_str());
1359 test_function0_result_copy(
"lambda.7.1a", 1, 101, f_1, f_2);
1360 test_function0_result_copy(
"lambda.7.1b", 1, 102, f_1, f_2);
1361 test_function0_result_copy(
"lambda.7.1c", 1, 103, f_1, f_2);
1363 test_function0_result_____(
"lambda.7.2a", 1, 104, f_1, f_2);
1364 test_function0_result_____(
"lambda.7.2b", 1, 105, f_1, f_2);
1365 test_function0_result_____(
"lambda.7.2c", 1, 106, f_1, f_2);
1367 test_function0________type(
"lambda.7.5",
false, f_1, f_2);
1368 test_function0________type(
"lambda.7.5",
true, f_1, f_1);
1374 function<int(
int)> f_1 = [i](
int a) ->
int {
1377 fprintf(stderr,
"l8 f_1 cpy: %s\n", f_1.toString().c_str());
1382 function<int(
int)> f_2 = [j](
int a) ->
int {
1385 fprintf(stderr,
"l8 f_2 cpy: %s\n", f_2.toString().c_str());
1388 test_function0_result_____(
"lambda.8.1", 1, 101, f_1, f_2);
1390 test_function0________type(
"lambda.8.2",
false, f_1, f_2);
1393 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1395 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
1396 test_function0________type(
"lambda.8.2",
false, f_1, f_2);
1399 test_function0________type(
"lambda.8.3",
true, f_1, f_1);
1405 function<int(
int)> f_1 = [i](
int a) ->
int {
1406 static int store = i;
1407 int res = store + a;
1411 fprintf(stderr,
"l9 f_1 cpy: %s\n", f_1.toString().c_str());
1416 function<int(
int)> f_2 = [j](
int a) ->
int {
1417 static int store = j;
1418 int res = store + a;
1422 fprintf(stderr,
"l9 f_2 cpy: %s\n", f_2.toString().c_str());
1425 test_function0_result_copy(
"lambda.9.1a", 1, 101, f_1, f_2);
1426 test_function0_result_copy(
"lambda.9.1b", 1, 102, f_1, f_2);
1427 test_function0_result_copy(
"lambda.9.1c", 1, 103, f_1, f_2);
1429 test_function0_result_____(
"lambda.9.2a", 1, 104, f_1, f_2);
1430 test_function0_result_____(
"lambda.9.2b", 1, 105, f_1, f_2);
1431 test_function0_result_____(
"lambda.9.2c", 1, 106, f_1, f_2);
1434 test_function0________type(
"lambda.9.5",
false, f_1, f_2);
1437 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1439 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
1440 test_function0________type(
"lambda.9.5",
false, f_1, f_2);
1443 test_function0________type(
"lambda.9.5",
true, f_1, f_1);
1452 function<int(
int)> f_1 = [i](
int a)
mutable ->
int {
1457 fprintf(stderr,
"l10 f_1 cpy: %s\n", f_1.toString().c_str());
1462 function<int(
int)> f_2 = [j](
int a)
mutable ->
int {
1467 fprintf(stderr,
"l10 f_2 cpy: %s\n", f_2.toString().c_str());
1470#if FUNCTIONAL_IMPL == 1
1471 test_function0_result_copy(
"lambda.10.1a", 1, 101, f_1, f_2);
1472 test_function0_result_copy(
"lambda.10.1b", 1, 101, f_1, f_2);
1473 test_function0_result_copy(
"lambda.10.1c", 1, 101, f_1, f_2);
1475 fprintf(stderr,
"l10 f_2 cpy: FUNCTIONAL_BROKEN_COPY_WITH_MUTABLE_LAMBDA\n");
1478 test_function0_result_____(
"lambda.10.2a", 1, 101, f_1, f_2);
1479 test_function0_result_____(
"lambda.10.2b", 1, 102, f_1, f_2);
1480 test_function0_result_____(
"lambda.10.2c", 1, 103, f_1, f_2);
1483 test_function0________type(
"lambda.10.5",
false, f_1, f_2);
1486 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1488 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
1489 test_function0________type(
"lambda.10.5",
false, f_1, f_2);
1492 test_function0________type(
"lambda.10.5",
true, f_1, f_1);
1494#if ( FUNCTIONAL_IMPL == 1 )
1496 function<int(
int)> f_1 =
function<int(
int)>::bind_ylambda( [](
auto& self,
int x) ->
int {
1500 return x * self(x-1);
1503 fprintf(stderr,
"ylambda 1 f_1: %s\n", f_1.toString().c_str());
1505 REQUIRE( 24 == f_1(4) );
1508 function<int(
int)> f_2 =
function<int(
int)>::bind_ylambda( [](
auto& self,
int x) ->
int {
1512 return x * self(x-1);
1515 test_function0________type(
"ylambda.1.1",
true, f_1, f_1);
1516 test_function0________type(
"ylambda.1.2",
false, f_1, f_2);