64 INFO(
"Test 00_usage: START: Implementation = functional "+std::to_string(
FUNCTIONAL_IMPL )+
".hpp");
65 fprintf(stderr,
"Implementation: functional %d, is_rtti_available %d, limited_lambda_id %d\n",
76 typedef jau::function<bool(std::vector<uint8_t>& ,
bool )> SomeFunc;
78 SomeFunc fa1 =
nullptr;
87 function<int(
int)> fa0 = [&](
int a) ->
int {
90 fprintf(stderr,
"lambda.0: %s, signature %s\n", fa0.toString().c_str(), fa0.signature().internal_name());
93 function<int(
int)> fa1 = lambda_01();
94 fprintf(stderr,
"lambda.1: %s, signature %s\n", fa1.toString().c_str(), fa1.signature().internal_name());
97 auto fa2_stub = [&](
int a) ->
int {
100 function<int(
int)> fa2_a = fa2_stub;
101 fprintf(stderr,
"lambda.2_a: %s, signature %s\n", fa2_a.toString().c_str(), fa2_a.signature().internal_name());
104 function<int(
int)> fa2_b = fa2_stub;
105 fprintf(stderr,
"lambda.2_b: %s, signature %s\n", fa2_b.toString().c_str(), fa2_b.signature().internal_name());
108 test_function0_result_____(
"lambda.0_1_", 1, 101, fa0, fa1);
109 test_function0________type(
"lambda.0_1_",
false, fa0, fa1);
110 test_function0_result_____(
"lambda.0_2a", 1, 101, fa0, fa2_a);
111 test_function0_result_____(
"lambda.0_2b", 1, 101, fa0, fa2_b);
114 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
116 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
117 test_function0________type(
"lambda.0_2a",
false, fa0, fa2_a);
120 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
122 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
123 test_function0________type(
"lambda.0_2b",
false, fa0, fa2_b);
126 fprintf(stderr,
"INFO: !limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
127 test_function0________type(
"lambda.0_2a",
false, fa0, fa2_a);
128 test_function0________type(
"lambda.0_2b",
false, fa0, fa2_b);
130 test_function0_result_____(
"lambda.2a2b", 1, 101, fa2_a, fa2_b);
131 test_function0________type(
"lambda.2a2b",
true, fa2_a, fa2_b);
134#if ( FUNCTIONAL_IMPL == 1 )
137 function<int(
int)> f_1 = [](
int a) ->
int {
140 fprintf(stderr,
"lambda.3_1 (plain) %s, signature %s\n", f_1.toString().c_str(), f_1.signature().internal_name());
142 test_function0_result_type(
"lambda.3131",
true, 1, 101, f_1, f_1);
144 function<int(
int)> f_2 =
function<int(
int)>::bind_lambda( [](
int x) ->
int {
147 fprintf(stderr,
"lambda.3_2 (plain) %s, signature %s\n", f_2.toString().c_str(), f_2.signature().internal_name());
149 test_function0_result_type(
"lambda.3232",
true, 1, 101, f_2, f_2);
153 function<int(
int)> f_1 =
function<int(
int)>::bind_ylambda( [](
auto& self,
int x) ->
int {
157 return x * self(x-1);
160 fprintf(stderr,
"ylambda.1_1 (plain) %s, signature %s\n", f_1.toString().c_str(), f_1.signature().internal_name());
162 test_function0_result_type(
"ylambda.1111",
true, 4, 24, f_1, f_1);
166 function<int(
int)> f_1 =
function<int(
int)>::bind_ylambda( [](
function<
int(
int)>::delegate_type& self,
int x) ->
int {
170 return x * self(x-1);
173 fprintf(stderr,
"ylambda.1_2 (plain) %s, signature %s\n", f_1.toString().c_str(), f_1.signature().internal_name());
175 test_function0_result_type(
"ylambda.1111",
true, 4, 24, f_1, f_1);
180 typedef int(*cfunc)(int);
181 volatile int i = 100;
183 auto f = ( [](
int a) ->
int {
188 fprintf(stderr,
"plain lambda.0 %s\n", fl_.toString().c_str());
191 test_function0_result_type(
"FuncPtr1a_free_10",
true, 1, 101, fl_, fl_);
197 typedef void(*cfunc)();
198 function<void()> fl_0 = (cfunc) ( []() ->
void {
201 fprintf(stderr,
"freeA.0 %s\n", fl_0.toString().c_str());
205 fprintf(stderr,
"freeA.1 %s\n", f2a_0.toString().c_str());
209 fprintf(stderr,
"freeA.2 %s\n", f2a_1.toString().c_str());
213 fprintf(stderr,
"freeA.3 %s\n", f20a_1.toString().c_str());
217 fprintf(stderr,
"freeA.4 %s\n", f20a_2.toString().c_str());
220 test_function2________type(
"FuncPtr1a_free_10",
true, fl_0, fl_0);
221 test_function2________type(
"FuncPtr1a_free_10",
true, f2a_0, f2a_1);
222 test_function2________type(
"FuncPtr1a_free_10",
true, f2a_1, f2a_1);
223 test_function2________type(
"FuncPtr3a_free_11",
true, f20a_1, f20a_1);
224 test_function2________type(
"FuncPtr3a_free_12",
true, f20a_1, f20a_2);
225 test_function2________type(
"FuncPtr1a_free_10",
false, f2a_1, f20a_1);
230 typedef int(*cfunc)(int);
231 function<int(
int)> fl_0 = (cfunc) ( [](
int i) ->
int {
235 fprintf(stderr,
"freeB.0 %s\n", fl_0.toString().c_str());
239 fprintf(stderr,
"freeB.1 %s\n", f1a_0.toString().c_str());
245 test_function0_result_type(
"FuncPtr1a_free_10",
true, 1, 101, fl_0, fl_0);
246 test_function0_result_type(
"FuncPtr1a_free_10",
true, 1, 101, f1a_0, f1a_1);
247 test_function0_result_type(
"FuncPtr1a_free_10",
true, 1, 101, f1a_1, f1a_1);
248 test_function0_result_type(
"FuncPtr3a_free_11",
true, 1, 101, f3a_1, f3a_1);
249 test_function0_result_type(
"FuncPtr3a_free_12",
true, 1, 101, f3a_1, f3a_2);
250 test_function0_result_type(
"FuncPtr1a_free_10",
false, 1, 101, f1a_1, f3a_1);
254 typedef void(*cfunc)(
int&, int);
255 function<void(
int&,
int)> fl_0 = (cfunc) ( [](
int& res,
int i) ->
void {
260 function<void(
int&,
int)> f3a_0 = &TestFunction01::Func13a_static;
263 test_function1_result_type(
"FuncPtr1a_free_10",
true, 1, 101, fl_0, fl_0);
264 test_function1_result_type(
"FuncPtr1a_free_10",
true, 1, 101, f1a_1, f1a_0);
265 test_function1_result_type(
"FuncPtr3a_free_11",
true, 1, 101, f3a_1, f3a_0);
266 test_function1_result_type(
"FuncPtr3a_free_11",
true, 1, 101, f3a_1, f3a_1);
267 test_function1_result_type(
"FuncPtr3a_free_12",
true, 1, 101, f3a_1, f3a_2);
268 test_function1_result_type(
"FuncPtr1a_free_10",
false, 1, 101, f1a_1, f3a_1);
272 function<int(
int)> f2a_0(
this, &TestFunction01::func02a_member);
273 fprintf(stderr,
"memberA.0 %s\n", f2a_0.toString().c_str());
277 fprintf(stderr,
"memberA.1 %s\n", f2a_1.toString().c_str());
282 test_function0_result_type(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_0);
283 test_function0_result_type(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_2);
284 test_function0_result_type(
"FuncPtr2a_member_12",
false, 1, 101, f2a_1, f2b_1);
288 function<void(
int&,
int)> f2a_0(
this, &TestFunction01::func12a_member);
292 test_function1_result_type(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_0);
293 test_function1_result_type(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_2);
294 test_function1_result_type(
"FuncPtr2a_member_12",
false, 1, 101, f2a_1, f2b_1);
300 typedef int(*cfunc)(
int&, int);
302 int(*func5a_capture)(
int&, int) = [](
int& capture,
int i)->int {
303 int res = i+10000+capture;
307 int(*func5b_capture)(
int&, int) = [](
int& capture,
int i)->int {
308 int res = i+100000+capture;
312 function<int(
int)> f5_o100_0(offset100,
313 (cfunc) ( [](
int& capture,
int i)->
int {
314 int res = i+10000+capture;
317 fprintf(stderr,
"capvalA.0 %s\n", f5_o100_0.toString().c_str());
321 (cfunc) ( [](
int& capture,
int i)->
int {
322 int res = i+10000+capture;
326 (cfunc) ( [](
int& capture,
int i)->
int {
327 int res = i+10000+capture;
330 test_function0________type(
"FuncPtr5a_o100_capture_00",
true, f5_o100_0, f5_o100_0);
331 test_function0________type(
"FuncPtr5a_o100_capture_00",
true, f5_o100_1, f5_o100_1);
332 test_function0________type(
"FuncPtr5a_o100_capture_00",
false, f5_o100_1, f5_o100_2);
334 function<int(
int)> f5a_o100_0(offset100, func5a_capture);
335 fprintf(stderr,
"capvalA.1 %s\n", f5a_o100_0.toString().c_str());
341 test_function0________type(
"FuncPtr5a_o100_capture_12",
true, f5a_o100_1, f5a_o100_0);
342 test_function0________type(
"FuncPtr5a_o100_capture_12",
true, f5a_o100_1, f5a_o100_2);
343 test_function0________type(
"FuncPtr5a_o100_capture_12",
false, f5a_o100_1, f5b_o100_1);
344 test_function0_result_type(
"FuncPtr5a_o100_capture_11",
true, 1, 10101, f5a_o100_1, f5a_o100_1);
345 test_function0_result_type(
"FuncPtr5a_o100_capture_12",
true, 1, 10101, f5a_o100_1, f5a_o100_2);
346 test_function0_result_type(
"FuncPtr5a_o100_capture_12",
false, 1, 10101, f5a_o100_1, f5b_o100_1);
350 IntOffset offset100(100);
352 typedef int(*cfunc)(IntOffset*, int);
354 int(*func7a_capture)(IntOffset*, int) = [](IntOffset* capture,
int i)->int {
355 int res = i+10000+capture->value;
358 int(*func7b_capture)(IntOffset*, int) = [](IntOffset* capture,
int i)->int {
359 int res = i+100000+capture->value;
364 (cfunc) ( [](IntOffset* capture,
int i)->
int {
365 int res = i+10000+capture->value;
368 fprintf(stderr,
"caprefA.0 %s\n", f7_o100_1.toString().c_str());
372 (cfunc) ( [](IntOffset* capture,
int i)->
int {
373 int res = i+10000+capture->value;
376 test_function0________type(
"FuncPtr7a_o100_capture_00",
true, f7_o100_1, f7_o100_1);
377 test_function0________type(
"FuncPtr7a_o100_capture_00",
false, f7_o100_1, f7_o100_2);
380 fprintf(stderr,
"caprefA.1 %s\n", f7a_o100_1.toString().c_str());
384 test_function0________type(
"FuncPtr7a_o100_capture_12",
true, f7a_o100_1, f7a_o100_2);
385 test_function0________type(
"FuncPtr7a_o100_capture_12",
false, f7a_o100_1, f7b_o100_1);
386 test_function0_result_type(
"FuncPtr7a_o100_capture_11",
true, 1, 10101, f7a_o100_1, f7a_o100_1);
387 test_function0_result_type(
"FuncPtr7a_o100_capture_12",
true, 1, 10101, f7a_o100_1, f7a_o100_2);
388 test_function0_result_type(
"FuncPtr7a_o100_capture_12",
false, 1, 10101, f7a_o100_1, f7b_o100_1);
392 std::function<int(
int i)> func4a_stdlambda = [](
int i)->
int {
396 std::function<int(
int i)> func4b_stdlambda = [](
int i)->
int {
401 fprintf(stderr,
"stdfunc.0 %s\n", f4a_1.toString().c_str());
405 test_function0_result_type(
"FuncPtr4a_stdlambda_11",
true, 1, 101, f4a_1, f4a_1);
406 test_function0_result_type(
"FuncPtr4a_stdlambda_12",
true, 1, 101, f4a_1, f4a_2);
409 INFO(
"Test 00_usage: END");
413 INFO(
"Test 01_member: bind_member<int, TestFunction01, int>: START");
417 MyClassFunction0 f2a_2 =
bind_member(
this, &TestFunction01::func02a_member);
418 test_function0_result_type(
"FuncPtr2a_member_11",
true, 1, 101, f2a_1, f2a_1);
419 test_function0_result_type(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_2);
421 MyClassFunction0 f2b_1 =
bind_member(
this, &TestFunction01::func02b_member);
422 MyClassFunction0 f2b_2 =
bind_member(
this, &TestFunction01::func02b_member);
423 test_function0_result_type(
"FuncPtr2b_member_11",
true, 1, 1001, f2b_1, f2b_1);
424 test_function0_result_type(
"FuncPtr2b_member_12",
true, 1, 1001, f2b_1, f2b_2);
426 test_function0_result_type(
"FuncPtr2ab_member_11",
false, 1, 0, f2a_1, f2b_1);
427 test_function0_result_type(
"FuncPtr2ab_member_22",
false, 1, 0, f2a_2, f2b_2);
431 std::string msg =
"member01_c1";
436 int f(
int i)
noexcept {
443 function<int(
int)> f_1a(&c_1a, &c1_t::f);
444 function<int(
int)> f_1b(&c_1b, &c1_t::f);
445 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
447 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
452 function<int(
int)> f_2a(&c_2a, &c1_t::f);
453 function<int(
int)> f_2b(&c_2b, &c1_t::f);
454 fprintf(stderr,
"%s 2a %s\n", msg.c_str(), f_2a.toString().c_str());
456 fprintf(stderr,
"%s 2b %s\n", msg.c_str(), f_2b.toString().c_str());
459 test_function0_result_____(msg+
" 1aa", 1, 101, f_1a, f_1a);
460 test_function0_result_____(msg+
" 1ab", 1, 101, f_1a, f_1b);
461 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
462 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
464 test_function0_result_____(msg+
" 2aa", 1, 1001, f_2a, f_2a);
465 test_function0_result_____(msg+
" 2ab", 1, 1001, f_2a, f_2b);
466 test_function0________type(msg+
" 2aa",
true, f_2a, f_2a);
467 test_function0________type(msg+
" 2ab",
false, f_2a, f_2b);
474 c1_t() : offset(10) {}
475 c1_t(
int v) : offset(v) {}
477 int f(
int i)
noexcept {
483 struct c2_t :
public c1_t {
485 c2_t(
int v) : c1_t(v) {}
487 int f(
int i)
noexcept {
498 std::string msg =
"member02_func_c2";
503 function<int(
int)> f_1a(&c_1a, &c2_t::f);
504 function<int(
int)> f_1b(&c_1b, &c2_t::f);
505 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
507 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
510 test_function0_result_____(msg+
" 1aa", 1, 1001, f_1a, f_1a);
511 test_function0_result_____(msg+
" 1ab", 1, 1001, f_1a, f_1b);
512 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
513 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
521 std::string msg =
"member03_func_c1_ref";
528 function<int(
int)> f_1a(&c_1a, &c1_t::f);
529 function<int(
int)> f_1b(&c_1b, &c1_t::f);
530 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
532 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
535 test_function0_result_____(msg+
" 1aa", 1, 101, f_1a, f_1a);
536 test_function0_result_____(msg+
" 1ab", 1, 101, f_1a, f_1b);
537 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
538 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
546 c1_t() : offset(10) {}
548 int f(
int i)
noexcept {
554 struct c2_t :
public c1_t {
557 c2_t() : c1_t(), offset(20) {}
558 c2_t(
int v) : c1_t(), offset(v) {}
561 struct c3_t :
public c2_t {
563 c3_t(
int v) : c2_t(v) {}
575 function<int(
int)> f_1a(&c_1a, &c1_t::f);
584 std::string msg =
"member04_field_c2";
589 REQUIRE( 1000 == c_1a.offset);
590 fprintf(stderr,
"%s offset: c2_t %d\n", msg.c_str(), c_1a.offset);
592 function<int(
int)> f_1a(&c_1a, &c1_t::f);
593 function<int(
int)> f_1b(&c_1b, &c1_t::f);
594 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
596 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
599 test_function0_result_____(msg+
" 1aa", 1, 11, f_1a, f_1a);
600 test_function0_result_____(msg+
" 1ab", 1, 11, f_1a, f_1b);
601 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
602 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
609 std::string msg =
"member05_field_c1_ref";
616 REQUIRE( 1000 == c_1a_.offset);
617 REQUIRE( 10 == c_1a.offset);
618 fprintf(stderr,
"%s offset: c2_t %d, c1_t ref %d\n", msg.c_str(), c_1a_.offset, c_1a.offset);
620 function<int(
int)> f_1a(&c_1a, &c1_t::f);
621 function<int(
int)> f_1b(&c_1b, &c1_t::f);
622 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
624 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
627 test_function0_result_____(msg+
" 1aa", 1, 11, f_1a, f_1a);
628 test_function0_result_____(msg+
" 1ab", 1, 11, f_1a, f_1b);
629 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
630 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
639 std::string msg =
"member06_vfunc_c1_ref";
644 c1_t() : offset(10) {}
645 c1_t(
int v) : offset(v) {}
647 virtual ~c1_t()
noexcept =
default;
649 virtual int f(
int i)
noexcept {
655 struct c2_t :
public c1_t {
657 c2_t(
int v) : c1_t(v) {}
659 int f(
int i)
noexcept override {
669 function<int(
int)> f_1a(&c_1a, &c1_t::f);
670 function<int(
int)> f_1b(&c_1b, &c1_t::f);
671 fprintf(stderr,
"%s 1a %s\n", msg.c_str(), f_1a.toString().c_str());
673 fprintf(stderr,
"%s 1b %s\n", msg.c_str(), f_1b.toString().c_str());
676 test_function0_result_____(msg+
" 1aa", 1, 1001, f_1a, f_1a);
677 test_function0_result_____(msg+
" 1ab", 1, 1001, f_1a, f_1b);
678 test_function0________type(msg+
" 1aa",
true, f_1a, f_1a);
679 test_function0________type(msg+
" 1ab",
false, f_1a, f_1b);
681 INFO(
"Test 01_member: bind_member<int, TestFunction01, int>: END");
803 INFO(
"Test 04_capval: bindCapture<int, int, int>: START");
807 int offset1000 = 1000;
809 typedef int(*cfunc)(
int&, int);
811 int(*func5a_capture)(
int&, int) = [](
int& capture,
int i)->int {
812 int res = i+10000+capture;
815 int(*func5b_capture)(
int&, int) = [](
int& capture,
int i)->int {
816 int res = i+100000+capture;
821 (cfunc) ( [](
int& capture,
int i)->
int {
822 int res = i+10000+capture;
825 test_function0________type(
"FuncPtr5a_o100_capture_00",
true, f5a_o100_0, f5a_o100_0);
828 MyClassFunction0 f5a_o100_2 =
bind_capval(offset100, func5a_capture);
829 test_function0________type(
"FuncPtr5a_o100_capture_12",
true, f5a_o100_1, f5a_o100_2);
830 test_function0_result_type(
"FuncPtr5a_o100_capture_11",
true, 1, 10101, f5a_o100_1, f5a_o100_1);
831 test_function0_result_type(
"FuncPtr5a_o100_capture_12",
true, 1, 10101, f5a_o100_1, f5a_o100_2);
833 MyClassFunction0 f5a_o1000_1 =
bind_capval(offset1000, func5a_capture);
834 MyClassFunction0 f5a_o1000_2 =
bind_capval(offset1000, func5a_capture);
835 test_function0________type(
"FuncPtr5a_o1000_capture_12",
true, f5a_o1000_1, f5a_o1000_2);
836 test_function0________type(
"FuncPtr5a_o100_o1000_capture_11",
false, f5a_o100_1, f5a_o1000_1);
838 MyClassFunction0 f5b_o100_1 =
bind_capval(offset100, func5b_capture);
839 MyClassFunction0 f5b_o100_2 =
bind_capval(offset100, func5b_capture);
840 test_function0_result_type(
"FuncPtr5b_o100_capture_11",
true, 1, 100101, f5b_o100_1, f5b_o100_1);
841 test_function0_result_type(
"FuncPtr5b_o100_capture_12",
true, 1, 100101, f5b_o100_1, f5b_o100_2);
843 test_function0_result_type(
"FuncPtr5ab_o100_capture_11",
false, 1, 0, f5a_o100_1, f5b_o100_1);
844 test_function0_result_type(
"FuncPtr5ab_o100_capture_22",
false, 1, 0, f5a_o100_2, f5b_o100_2);
845 INFO(
"Test 04_capval: bindCapture<int, int, int>: END");
849 INFO(
"Test 14_capval: bindCapture<int, int, int>: START");
853 int offset1000 = 1000;
855 typedef void(*cfunc)(
int&,
int&, int);
857 void(*func5a_capture)(
int&,
int&, int) = [](
int& capture,
int& res,
int i)->void {
858 res = i+10000+capture;
860 void(*func5b_capture)(
int&,
int&, int) = [](
int& capture,
int& res,
int i)->void {
861 res = i+100000+capture;
865 (cfunc) ( [](
int& capture,
int& res,
int i)->
void {
866 res = i+10000+capture;
868 test_function1________type(
"FuncPtr5a_o100_capture_00",
true, f5a_o100_0, f5a_o100_0);
871 MyClassFunction1 f5a_o100_2 =
bind_capval(offset100, func5a_capture);
872 test_function1________type(
"FuncPtr5a_o100_capture_12",
true, f5a_o100_1, f5a_o100_2);
873 test_function1_result_type(
"FuncPtr5a_o100_capture_11",
true, 1, 10101, f5a_o100_1, f5a_o100_1);
874 test_function1_result_type(
"FuncPtr5a_o100_capture_12",
true, 1, 10101, f5a_o100_1, f5a_o100_2);
876 MyClassFunction1 f5a_o1000_1 =
bind_capval(offset1000, func5a_capture);
877 MyClassFunction1 f5a_o1000_2 =
bind_capval(offset1000, func5a_capture);
878 test_function1________type(
"FuncPtr5a_o1000_capture_12",
true, f5a_o1000_1, f5a_o1000_2);
879 test_function1________type(
"FuncPtr5a_o100_o1000_capture_11",
false, f5a_o100_1, f5a_o1000_1);
881 MyClassFunction1 f5b_o100_1 =
bind_capval(offset100, func5b_capture);
882 MyClassFunction1 f5b_o100_2 =
bind_capval(offset100, func5b_capture);
883 test_function1_result_type(
"FuncPtr5b_o100_capture_11",
true, 1, 100101, f5b_o100_1, f5b_o100_1);
884 test_function1_result_type(
"FuncPtr5b_o100_capture_12",
true, 1, 100101, f5b_o100_1, f5b_o100_2);
886 test_function1_result_type(
"FuncPtr5ab_o100_capture_11",
false, 1, 0, f5a_o100_1, f5b_o100_1);
887 test_function1_result_type(
"FuncPtr5ab_o100_capture_22",
false, 1, 0, f5a_o100_2, f5b_o100_2);
888 INFO(
"Test 14_capval: bindCapture<int, int, int>: END");
892 INFO(
"Test 05_capval: bindCapture<int, std::shared_ptr<IntOffset>, int>: START");
895 std::shared_ptr<IntOffset> offset100(
new IntOffset(100));
896 std::shared_ptr<IntOffset> offset1000(
new IntOffset(1000));
898 typedef int(*cfunc)(std::shared_ptr<IntOffset>&, int);
900 int(*func6a_capture)(std::shared_ptr<IntOffset>&, int) = [](std::shared_ptr<IntOffset>& capture,
int i)->int {
901 int res = i+10000+capture->value;
904 int(*func6b_capture)(std::shared_ptr<IntOffset>&, int) = [](std::shared_ptr<IntOffset>& capture,
int i)->int {
905 int res = i+100000+capture->value;
910 (cfunc) ( [](std::shared_ptr<IntOffset>& sharedOffset,
int i)->int {
911 int res = i+10000+sharedOffset->value;
914 test_function0________type(
"FuncPtr6a_o100_capture_00",
true, f6a_o100_0, f6a_o100_0);
917 MyClassFunction0 f6a_o100_2 =
bind_capval(offset100, func6a_capture);
918 test_function0________type(
"FuncPtr6a_o100_capture_12",
true, f6a_o100_1, f6a_o100_2);
919 test_function0_result_type(
"FuncPtr6a_o100_capture_11",
true, 1, 10101, f6a_o100_1, f6a_o100_1);
920 test_function0_result_type(
"FuncPtr6a_o100_capture_12",
true, 1, 10101, f6a_o100_1, f6a_o100_2);
922 MyClassFunction0 f6a_o1000_1 =
bind_capval(offset1000, func6a_capture);
923 MyClassFunction0 f6a_o1000_2 =
bind_capval(offset1000, func6a_capture);
924 test_function0________type(
"FuncPtr6a_o1000_capture_12",
true, f6a_o1000_1, f6a_o1000_2);
925 test_function0________type(
"FuncPtr6a_o100_o1000_capture_11",
false, f6a_o100_1, f6a_o1000_1);
927 MyClassFunction0 f6b_o100_1 =
bind_capval(offset100, func6b_capture);
928 MyClassFunction0 f6b_o100_2 =
bind_capval(offset100, func6b_capture);
929 test_function0_result_type(
"FuncPtr6b_o100_capture_11",
true, 1, 100101, f6b_o100_1, f6b_o100_1);
930 test_function0_result_type(
"FuncPtr6b_o100_capture_12",
true, 1, 100101, f6b_o100_1, f6b_o100_2);
932 test_function0_result_type(
"FuncPtr6ab_o100_capture_11",
false, 1, 0, f6a_o100_1, f6b_o100_1);
933 test_function0_result_type(
"FuncPtr6ab_o100_capture_22",
false, 1, 0, f6a_o100_2, f6b_o100_2);
934 INFO(
"Test 05_capval: bindCapture<int, std::shared_ptr<IntOffset>, int>: END");
938 INFO(
"Test 06_capval: bindCapture<int, IntOffset, int>: START");
941 IntOffset offset100(100);
942 IntOffset offset1000(1000);
944 typedef int(*cfunc)(IntOffset&, int);
946 int(*func7a_capture)(IntOffset&, int) = [](IntOffset& capture,
int i)->int {
947 int res = i+10000+capture.value;
950 int(*func7b_capture)(IntOffset&, int) = [](IntOffset& capture,
int i)->int {
951 int res = i+100000+capture.value;
956 (cfunc) ( [](IntOffset& capture,
int i)->
int {
957 int res = i+10000+capture.value;
960 test_function0________type(
"FuncPtr7a_o100_capture_00",
true, f7a_o100_0, f7a_o100_0);
962 INFO(
"f7a_o100_1 copy_ctor");
964 INFO(
"f7a_o100_1 copy_ctor done");
965 INFO(
"f7a_o100_2 move_ctor");
966 MyClassFunction0 f7a_o100_2 =
bind_capval(IntOffset(100), func7a_capture);
967 INFO(
"f7a_o100_2 move_ctor done");
968 test_function0________type(
"FuncPtr7a_o100_capture_12",
true, f7a_o100_1, f7a_o100_2);
969 test_function0_result_type(
"FuncPtr7a_o100_capture_11",
true, 1, 10101, f7a_o100_1, f7a_o100_1);
970 test_function0_result_type(
"FuncPtr7a_o100_capture_12",
true, 1, 10101, f7a_o100_1, f7a_o100_2);
972 MyClassFunction0 f7a_o1000_1 =
bind_capval(offset1000, func7a_capture);
973 MyClassFunction0 f7a_o1000_2 =
bind_capval(offset1000, func7a_capture);
974 test_function0________type(
"FuncPtr7a_o1000_capture_12",
true, f7a_o1000_1, f7a_o1000_2);
975 test_function0________type(
"FuncPtr7a_o100_o1000_capture_11",
false, f7a_o100_1, f7a_o1000_1);
977 MyClassFunction0 f7b_o100_1 =
bind_capval(offset100, func7b_capture);
978 MyClassFunction0 f7b_o100_2 =
bind_capval(offset100, func7b_capture);
979 test_function0_result_type(
"FuncPtr7b_o100_capture_11",
true, 1, 100101, f7b_o100_1, f7b_o100_1);
980 test_function0_result_type(
"FuncPtr7b_o100_capture_12",
true, 1, 100101, f7b_o100_1, f7b_o100_2);
982 test_function0_result_type(
"FuncPtr7ab_o100_capture_11",
false, 1, 0, f7a_o100_1, f7b_o100_1);
983 test_function0_result_type(
"FuncPtr7ab_o100_capture_22",
false, 1, 0, f7a_o100_2, f7b_o100_2);
984 INFO(
"Test 06_capval: bindCapture<int, IntOffset, int>: END");
988 INFO(
"Test 07_capref: bindCapture<int, IntOffset, int>: START");
991 IntOffset offset100(100);
992 IntOffset offset1000(1000);
994 typedef int(*cfunc)(IntOffset*, int);
996 int(*func7a_capture)(IntOffset*, int) = [](IntOffset* capture,
int i)->int {
997 int res = i+10000+capture->value;
1000 int(*func7b_capture)(IntOffset*, int) = [](IntOffset* capture,
int i)->int {
1001 int res = i+100000+capture->value;
1006 (cfunc) ( [](IntOffset* capture,
int i)->
int {
1007 int res = i+10000+capture->value;
1010 test_function0________type(
"FuncPtr7a_o100_capture_00",
true, f7a_o100_0, f7a_o100_0);
1012 INFO(
"f7a_o100_1 copy_ctor");
1014 INFO(
"f7a_o100_1 copy_ctor done");
1015 INFO(
"f7a_o100_2 move_ctor");
1016 MyClassFunction0 f7a_o100_2 =
bind_capref(&offset100, func7a_capture);
1017 INFO(
"f7a_o100_2 move_ctor done");
1018 test_function0________type(
"FuncPtr7a_o100_capture_12",
true, f7a_o100_1, f7a_o100_2);
1019 test_function0_result_type(
"FuncPtr7a_o100_capture_11",
true, 1, 10101, f7a_o100_1, f7a_o100_1);
1020 test_function0_result_type(
"FuncPtr7a_o100_capture_12",
true, 1, 10101, f7a_o100_1, f7a_o100_2);
1022 MyClassFunction0 f7a_o1000_1 =
bind_capref(&offset1000, func7a_capture);
1023 MyClassFunction0 f7a_o1000_2 =
bind_capref(&offset1000, func7a_capture);
1024 test_function0________type(
"FuncPtr7a_o1000_capture_12",
true, f7a_o1000_1, f7a_o1000_2);
1025 test_function0________type(
"FuncPtr7a_o100_o1000_capture_11",
false, f7a_o100_1, f7a_o1000_1);
1027 MyClassFunction0 f7b_o100_1 =
bind_capref(&offset100, func7b_capture);
1028 MyClassFunction0 f7b_o100_2 =
bind_capref(&offset100, func7b_capture);
1029 test_function0_result_type(
"FuncPtr7b_o100_capture_11",
true, 1, 100101, f7b_o100_1, f7b_o100_1);
1030 test_function0_result_type(
"FuncPtr7b_o100_capture_12",
true, 1, 100101, f7b_o100_1, f7b_o100_2);
1032 test_function0_result_type(
"FuncPtr7ab_o100_capture_11",
false, 1, 0, f7a_o100_1, f7b_o100_1);
1033 test_function0_result_type(
"FuncPtr7ab_o100_capture_22",
false, 1, 0, f7a_o100_2, f7b_o100_2);
1034 INFO(
"Test 07_capref: bindCapture<int, IntOffset, int>: END");
1198 volatile int i = 100;
1199 volatile int j = 100;
1201 auto fa0_stub = ( [&](
int a) ->
int {
1205 function<int(
int)> fa0_a( fa0_stub );
1206 fprintf(stderr,
"fa0_a: %s\n", fa0_a.toString().c_str());
1209 auto fa0c_stub = ( [&](
int a) ->
int {
1212 function<int(
int)> fa0_c( fa0c_stub );
1213 fprintf(stderr,
"fa0_c: %s\n", fa0_c.toString().c_str());
1214 fprintf(stderr,
"fa0_stub is_same fa0c_stub: %d\n",
1215 std::is_same_v<
decltype(fa0_stub),
decltype(fa0c_stub)> );
1216 fprintf(stderr,
"fa0_a == fa0_c: %d\n",
1221 function<int(
int)> fa0_b( fa0_stub );
1222 fprintf(stderr,
"fa1: %s\n", fa0_b.toString().c_str());
1225 function<int(
int)> fa2_1 = [&](
int a) ->
int {
1228 fprintf(stderr,
"fa2_1: %s\n", fa2_1.toString().c_str());
1232 function<int(
int)> fa2_2 = lambda_01();
1233 fprintf(stderr,
"fa2_2: %s\n", fa2_2.toString().c_str());
1239 function<int(
int)> fa2_3 = [&](
int a) ->
int {
1242 fprintf(stderr,
"fa2_3: %s\n", fa2_3.toString().c_str());
1246 function<int(
int)> fa2_4 = [i](
int a) ->
int {
1249 fprintf(stderr,
"fa2_4: %s\n", fa2_4.toString().c_str());
1254 function<int(
int)> f_b = [&](
int a) ->
int {
1257 fprintf(stderr,
"f_b: %s\n", f_b.toString().c_str());
1262 function<int(
int)> f_c = [&](
int a) ->
int {
1263 return 2 * ( j + a );
1265 fprintf(stderr,
"f_c: %s\n", f_c.toString().c_str());
1270 function<int(
int)> f_d = [&](
int a) ->
int {
1271 return 2 * ( i + a );
1273 fprintf(stderr,
"f_d: %s\n", f_d.toString().c_str());
1277 function<int(
int,
bool)> f_e = [&](
int a,
bool dummy) ->
int {
1281 fprintf(stderr,
"f_e: %s\n", f_e.toString().c_str());
1284 test_function0_result_type(
"lambda.5b",
true, 1, 101, fa2_1, fa2_1);
1285 test_function0_result_type(
"lambda.5a",
true, 1, 101, fa0_a, fa0_b);
1287 test_function0_result_____(
"lambda.5c", 1, 101, fa2_1, fa2_2);
1288 test_function0________type(
"lambda.5c",
false, fa2_1, fa2_2);
1289 test_function0_result_____(
"lambda.5e", 1, 101, fa2_1, fa2_4);
1290 test_function0________type(
"lambda.5e",
false, fa2_1, fa2_4);
1292 test_function0________type(
"lambda.5B",
false, fa2_1, f_b);
1293 test_function0________type(
"lambda.5C",
false, fa2_1, f_c);
1295 test_function0_result_____(
"lambda.5d", 1, 101, fa2_1, fa2_3);
1297 if( fa2_1 == fa2_3 ) {
1298 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1300 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
1301 test_function0________type(
"lambda.5d",
false, fa2_1, fa2_3);
1303 if( fa2_1 == f_d ) {
1304 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1306 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
1307 test_function0________type(
"lambda.5D",
false, fa2_1, f_d);
1310 fprintf(stderr,
"INFO: !limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1311 test_function0________type(
"lambda.5d",
false, fa2_1, fa2_3);
1312 test_function0________type(
"lambda.5D",
false, fa2_1, f_d);
1314 CHECK(fa2_1 != f_e);
1320 function<int(
int)> f_1 = [&i](
int a) ->
int {
1323 fprintf(stderr,
"l6 f_1 ref: %s\n", f_1.toString().c_str());
1328 function<int(
int)> f_2 = [&j](
int a) ->
int {
1331 fprintf(stderr,
"l6 f_2 ref: %s\n", f_2.toString().c_str());
1334 test_function0_result_____(
"lambda.6", 1, 101, f_1, f_2);
1335 test_function0________type(
"lambda.6",
false, f_1, f_2);
1336 test_function0________type(
"lambda.6",
true, f_1, f_1);
1342 function<int(
int)> f_1 = [&i](
int a) ->
int {
1347 fprintf(stderr,
"l7 f_1 ref: %s\n", f_1.toString().c_str());
1352 function<int(
int)> f_2 = [&j](
int a) ->
int {
1357 fprintf(stderr,
"l7 f_2 ref: %s\n", f_2.toString().c_str());
1360 test_function0_result_copy(
"lambda.7.1a", 1, 101, f_1, f_2);
1361 test_function0_result_copy(
"lambda.7.1b", 1, 102, f_1, f_2);
1362 test_function0_result_copy(
"lambda.7.1c", 1, 103, f_1, f_2);
1364 test_function0_result_____(
"lambda.7.2a", 1, 104, f_1, f_2);
1365 test_function0_result_____(
"lambda.7.2b", 1, 105, f_1, f_2);
1366 test_function0_result_____(
"lambda.7.2c", 1, 106, f_1, f_2);
1368 test_function0________type(
"lambda.7.5",
false, f_1, f_2);
1369 test_function0________type(
"lambda.7.5",
true, f_1, f_1);
1375 function<int(
int)> f_1 = [i](
int a) ->
int {
1378 fprintf(stderr,
"l8 f_1 cpy: %s\n", f_1.toString().c_str());
1383 function<int(
int)> f_2 = [j](
int a) ->
int {
1386 fprintf(stderr,
"l8 f_2 cpy: %s\n", f_2.toString().c_str());
1389 test_function0_result_____(
"lambda.8.1", 1, 101, f_1, f_2);
1391 test_function0________type(
"lambda.8.2",
false, f_1, f_2);
1394 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1396 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
1397 test_function0________type(
"lambda.8.2",
false, f_1, f_2);
1400 test_function0________type(
"lambda.8.3",
true, f_1, f_1);
1406 function<int(
int)> f_1 = [i](
int a) ->
int {
1407 static int store = i;
1408 int res = store + a;
1412 fprintf(stderr,
"l9 f_1 cpy: %s\n", f_1.toString().c_str());
1417 function<int(
int)> f_2 = [j](
int a) ->
int {
1418 static int store = j;
1419 int res = store + a;
1423 fprintf(stderr,
"l9 f_2 cpy: %s\n", f_2.toString().c_str());
1426 test_function0_result_copy(
"lambda.9.1a", 1, 101, f_1, f_2);
1427 test_function0_result_copy(
"lambda.9.1b", 1, 102, f_1, f_2);
1428 test_function0_result_copy(
"lambda.9.1c", 1, 103, f_1, f_2);
1430 test_function0_result_____(
"lambda.9.2a", 1, 104, f_1, f_2);
1431 test_function0_result_____(
"lambda.9.2b", 1, 105, f_1, f_2);
1432 test_function0_result_____(
"lambda.9.2c", 1, 106, f_1, f_2);
1435 test_function0________type(
"lambda.9.5",
false, f_1, f_2);
1438 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1440 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
1441 test_function0________type(
"lambda.9.5",
false, f_1, f_2);
1444 test_function0________type(
"lambda.9.5",
true, f_1, f_1);
1453 function<int(
int)> f_1 = [i](
int a)
mutable ->
int {
1458 fprintf(stderr,
"l10 f_1 cpy: %s\n", f_1.toString().c_str());
1463 function<int(
int)> f_2 = [j](
int a)
mutable ->
int {
1468 fprintf(stderr,
"l10 f_2 cpy: %s\n", f_2.toString().c_str());
1471#if FUNCTIONAL_IMPL == 1
1472 test_function0_result_copy(
"lambda.10.1a", 1, 101, f_1, f_2);
1473 test_function0_result_copy(
"lambda.10.1b", 1, 101, f_1, f_2);
1474 test_function0_result_copy(
"lambda.10.1c", 1, 101, f_1, f_2);
1476 fprintf(stderr,
"l10 f_2 cpy: FUNCTIONAL_BROKEN_COPY_WITH_MUTABLE_LAMBDA\n");
1479 test_function0_result_____(
"lambda.10.2a", 1, 101, f_1, f_2);
1480 test_function0_result_____(
"lambda.10.2b", 1, 102, f_1, f_2);
1481 test_function0_result_____(
"lambda.10.2c", 1, 103, f_1, f_2);
1484 test_function0________type(
"lambda.10.5",
false, f_1, f_2);
1487 fprintf(stderr,
"INFO: limited_lambda_id: %s:%d\n", __FILE__, __LINE__);
1489 fprintf(stderr,
"INFO: limited_lambda_id FIXED: %s:%d\n", __FILE__, __LINE__);
1490 test_function0________type(
"lambda.10.5",
false, f_1, f_2);
1493 test_function0________type(
"lambda.10.5",
true, f_1, f_1);
1495#if ( FUNCTIONAL_IMPL == 1 )
1497 function<int(
int)> f_1 =
function<int(
int)>::bind_ylambda( [](
auto& self,
int x) ->
int {
1501 return x * self(x-1);
1504 fprintf(stderr,
"ylambda 1 f_1: %s\n", f_1.toString().c_str());
1506 REQUIRE( 24 == f_1(4) );
1509 function<int(
int)> f_2 =
function<int(
int)>::bind_ylambda( [](
auto& self,
int x) ->
int {
1513 return x * self(x-1);
1516 test_function0________type(
"ylambda.1.1",
true, f_1, f_1);
1517 test_function0________type(
"ylambda.1.2",
false, f_1, f_2);