30#ifndef FUNCTIONAL_PROVIDED
31 #define FUNCTIONAL_IMPL 1
33 static std::string
impl_name =
"jau/functional.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().name());
93 function<int(
int)> fa1 = lambda_01();
94 fprintf(stderr,
"lambda.1: %s, signature %s\n", fa1.toString().c_str(), fa1.signature().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().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().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().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().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().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().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 {
187 function<int(
int)> fl_ = bind_free<int, int>( (cfunc) f);
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;
363 function<int(
int)> f7_o100_1 = bind_capref<int, IntOffset, int>(&offset100,
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());
371 function<int(
int)> f7_o100_2 = bind_capref<int, IntOffset, int>(&offset100,
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");
416 MyClassFunction0 f2a_1 = bind_member<int, TestFunction01, int>(
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);
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");
685 INFO(
"Test 11_member: bind_member<int, TestFunction01, int>: START");
687 MyClassFunction1 f2a_1 = bind_member<TestFunction01, int&, int>(
this, &TestFunction01::func12a_member);
689 test_function1_result_type(
"FuncPtr2a_member_11",
true, 1, 101, f2a_1, f2a_1);
690 test_function1_result_type(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_2);
694 test_function1_result_type(
"FuncPtr2b_member_11",
true, 1, 1001, f2b_1, f2b_1);
695 test_function1_result_type(
"FuncPtr2b_member_12",
true, 1, 1001, f2b_1, f2b_2);
697 test_function1_result_type(
"FuncPtr2ab_member_11",
false, 1, 0, f2a_1, f2b_1);
698 test_function1_result_type(
"FuncPtr2ab_member_22",
false, 1, 0, f2a_2, f2b_2);
699 INFO(
"Test 11_member: bind_member<int, TestFunction01, int>: END");
703 INFO(
"Test 02_free: bind_free<int, int>: START");
706 MyClassFunction0 f3a_1 = bind_free<int, int>(&TestFunction01::Func03a_static);
708 test_function0_result_type(
"FuncPtr1a_free_10",
true, 1, 101, f1a_1, f1a_1);
709 test_function0_result_type(
"FuncPtr3a_free_11",
true, 1, 101, f3a_1, f3a_1);
710 test_function0_result_type(
"FuncPtr3a_free_12",
true, 1, 101, f3a_1, f3a_2);
714 test_function0_result_type(
"FuncPtr3b_free_11",
true, 1, 1001, f3b_1, f3b_1);
715 test_function0_result_type(
"FuncPtr3b_free_12",
true, 1, 1001, f3b_1, f3b_2);
717 test_function0_result_type(
"FuncPtr1a3a_free_10",
false, 1, 0, f1a_1, f3a_1);
718 test_function0_result_type(
"FuncPtr1a3b_free_10",
false, 1, 0, f1a_1, f3b_1);
719 test_function0_result_type(
"FuncPtr3a3b_free_11",
false, 1, 0, f3a_1, f3b_1);
720 test_function0_result_type(
"FuncPtr3a3b_free_22",
false, 1, 0, f3a_2, f3b_2);
721 INFO(
"Test 02_free: bind_free<int, int>: END");
725 INFO(
"Test 12_free: bind_free<int, int>: START");
728 MyClassFunction1 f3a_1 = bind_free<int&, int>(&TestFunction01::Func13a_static);
730 test_function1_result_type(
"FuncPtr1a_free_10",
true, 1, 101, f1a_1, f1a_1);
731 test_function1_result_type(
"FuncPtr3a_free_11",
true, 1, 101, f3a_1, f3a_1);
732 test_function1_result_type(
"FuncPtr3a_free_12",
true, 1, 101, f3a_1, f3a_2);
736 test_function1_result_type(
"FuncPtr3b_free_11",
true, 1, 1001, f3b_1, f3b_1);
737 test_function1_result_type(
"FuncPtr3b_free_12",
true, 1, 1001, f3b_1, f3b_2);
739 test_function1_result_type(
"FuncPtr1a3a_free_10",
false, 1, 0, f1a_1, f3a_1);
740 test_function1_result_type(
"FuncPtr1a3b_free_10",
false, 1, 0, f1a_1, f3b_1);
741 test_function1_result_type(
"FuncPtr3a3b_free_11",
false, 1, 0, f3a_1, f3b_1);
742 test_function1_result_type(
"FuncPtr3a3b_free_22",
false, 1, 0, f3a_2, f3b_2);
743 INFO(
"Test 12_free: bind_free<int, int>: END");
747 INFO(
"Test 03_stdlambda: bind_std<int, int>: START");
749 std::function<int(
int i)> func4a_stdlambda = [](
int i)->
int {
753 jau::type_cue<std::function<int(
int i)>>
::print(
"std::function<int(int i)> type", TypeTraitGroup::ALL);
755 std::function<int(
int i)> func4b_stdlambda = [](
int i)->
int {
761 test_function0_result_type(
"FuncPtr4a_stdlambda_11",
true, 1, 101, f4a_1, f4a_1);
762 test_function0_result_type(
"FuncPtr4a_stdlambda_12",
true, 1, 101, f4a_1, f4a_2);
766 test_function0_result_type(
"FuncPtr4b_stdlambda_11",
true, 1, 1001, f4b_1, f4b_1);
767 test_function0_result_type(
"FuncPtr4b_stdlambda_12",
true, 1, 1001, f4b_1, f4b_2);
769 test_function0_result_type(
"FuncPtr4ab_stdlambda_11",
false, 1, 0, f4a_1, f4b_1);
770 test_function0_result_type(
"FuncPtr4ab_stdlambda_22",
false, 1, 0, f4a_2, f4b_2);
772 INFO(
"Test 03_stdlambda: bind_std<int, int>: END");
776 INFO(
"Test 13_stdlambda: bind_std<int, int>: START");
778 std::function<void(
int& r,
int i)> func4a_stdlambda = [](
int& r,
int i)->
void {
781 jau::type_cue<std::function<void(
int& r,
int i)>>
::print(
"std::function<int(int i)> type", TypeTraitGroup::ALL);
783 std::function<void(
int& r,
int i)> func4b_stdlambda = [](
int& r,
int i)->
void {
788 test_function1_result_type(
"FuncPtr4a_stdlambda_11",
true, 1, 101, f4a_1, f4a_1);
789 test_function1_result_type(
"FuncPtr4a_stdlambda_12",
true, 1, 101, f4a_1, f4a_2);
793 test_function1_result_type(
"FuncPtr4b_stdlambda_11",
true, 1, 1001, f4b_1, f4b_1);
794 test_function1_result_type(
"FuncPtr4b_stdlambda_12",
true, 1, 1001, f4b_1, f4b_2);
796 test_function1_result_type(
"FuncPtr4ab_stdlambda_11",
false, 1, 0, f4a_1, f4b_1);
797 test_function1_result_type(
"FuncPtr4ab_stdlambda_22",
false, 1, 0, f4a_2, f4b_2);
799 INFO(
"Test 13_stdlambda: bind_std<int, 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);
827 MyClassFunction0 f5a_o100_1 = bind_capval<int, int, int>(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);
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);
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);
870 MyClassFunction1 f5a_o100_1 = bind_capval<int, int&, int>(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);
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);
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;
909 MyClassFunction0 f6a_o100_0 = bind_capval<int, std::shared_ptr<IntOffset>,
int>(offset100,
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);
916 MyClassFunction0 f6a_o100_1 = bind_capval<int, std::shared_ptr<IntOffset>,
int>(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);
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);
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");
963 MyClassFunction0 f7a_o100_1 = bind_capval<int, IntOffset, int>(offset100, func7a_capture);
964 INFO(
"f7a_o100_1 copy_ctor done");
965 INFO(
"f7a_o100_2 move_ctor");
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);
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);
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");
1013 MyClassFunction0 f7a_o100_1 = bind_capref<int, IntOffset, int>(&offset100, func7a_capture);
1014 INFO(
"f7a_o100_1 copy_ctor done");
1015 INFO(
"f7a_o100_2 move_ctor");
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);
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);
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");
1039 volatile int i = 100;
1041 auto fa0_stub = ( [&](
int a) ->
int {
1044 typedef decltype(fa0_stub) fa0_type;
1050 fprintf(stderr,
"fa0.2: %s\n", fa0.toString().c_str());
1053 test_function0_result_type(
"lambda.2",
true, 1, 101, fa0, fa0);
1056 volatile int i = 100;
1058 auto fa0_stub = ( [i](
int a) ->
int {
1061 typedef decltype(fa0_stub) fa0_type;
1064 function<int(
int)> fa0( fa0_stub );
1066 fprintf(stderr,
"fa0.3: %s\n", fa0.toString().c_str());
1069 test_function0_result_type(
"lambda.3",
true, 1, 101, fa0, fa0);
1072 volatile int i = 100;
1074 function<int(
int)> fa0 = [i](
int a) ->
int {
1078 fprintf(stderr,
"fa0.4: %s\n", fa0.toString().c_str());
1081 test_function0_result_type(
"lambda.4",
true, 1, 101, fa0, fa0);
1084 volatile int i = 100;
1086 function<int(
int)> fa0 = [&](
int a) ->
int {
1090 fprintf(stderr,
"fa0.4: %s\n", fa0.toString().c_str());
1093 test_function0_result_type(
"lambda.4",
true, 1, 101, fa0, fa0);
1097 function<void(
int)> f0 = jau::bind_lambda( [&i](
int a) ->
void {
1103 function<int(
int)> f = jau::bind_lambda( [&i](
int a) ->
int {
1106 test_function0_result_type(
"FuncPtr1a_free_10",
true, 1, 101, f, f);
1112 volatile int i = 100;
1115 MyCFunc0 f_0 = (MyCFunc0) ( [](
int a) ->
int {
1118 const char* f0_name = jau::ctti_name<decltype(f_0)>();
1121 std::string f0_str(f0_name);
1122 fprintf(stderr,
"f_0: %s\n", f0_name);
1124 auto f_a = [&](
int a) ->
int {
1127 const char* fa_name = jau::ctti_name<decltype(f_a)>();
1129 std::string fa_str(fa_name);
1130 fprintf(stderr,
"f_a: %s\n", fa_name);
1135 fprintf(stderr,
"empty type: %s\n", f_b_type.
name());
1137 MyCFunc0 f_b = cfunction_00(f_b_type);
1143 const char* fb_name = f_b_type.
name();
1144 std::string fb_str(fb_name);
1145 fprintf(stderr,
"f_b: %s\n", fb_name);
1147#if defined(__cxx_rtti_available__)
1148 std::type_index f_0_t(
typeid(f_0));
1149 fprintf(stderr,
"f_0_t: %s\n", f_0_t.name());
1150 std::type_index f_b_t(
typeid(f_b));
1151 fprintf(stderr,
"f_b_t: %s\n", f_b_t.name());
1153 if( f_0_t == f_b_t ) {
1154 fprintf(stderr,
"INFO: RTTI limitation on functions exists: f_b_t: %s\n", f_b_t.name());
1156 fprintf(stderr,
"INFO: RTTI limitation on functions FIXED: f_b_t: %s\n", f_b_t.name());
1161 if( f0_str == fb_str ) {
1162 fprintf(stderr,
"INFO: CTTI limitation on functions exists: f_b: %s\n", fb_str.c_str());
1164 fprintf(stderr,
"INFO: CTTI limitation on functions FIXED: f_b: %s\n", fb_str.c_str());
1166 if( f_0_type == f_b_type ) {
1167 fprintf(stderr,
"INFO: CTTI limitation on functions exists: f_b_type: %s\n", f_b_type.
name());
1169 fprintf(stderr,
"INFO: CTTI limitation on functions FIXED: f_b_type: %s\n", f_b_type.
name());
1175 const char* fc_name = jau::ctti_name<decltype(f_c)>();
1177 std::string fc_str(fc_name);
1178 fprintf(stderr,
"fc_name: %s\n", fc_name);
1179 fprintf(stderr,
"fc: %s\n", f_c.toString().c_str());
1183 auto f_e = [&](
int a,
bool dummy) ->
int {
1187 const char* fe_name = jau::ctti_name<decltype(f_e)>();
1189 std::string fe_str(fe_name);
1190 fprintf(stderr,
"fe_name: %s\n", fe_name);
1192 REQUIRE(fa_str != fe_str );
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);
1522 template<
typename R,
typename L,
typename... A>
1537 return f(*
this, args...);
1540 return f(*
this, args...);
1547 auto stub = [](
auto& self,
int x) ->
int {
1551 return x * self(x-1);
1556 REQUIRE( 24 == f_1(4) );
1558#if ( FUNCTIONAL_IMPL == 1 )
1563 auto stub = [](
auto& self,
int x) ->
int {
1567 return x * self(x-1);
1570 typedef decltype(stub) stub_type;
1575 fprintf(stderr,
"ylambda 1 f_1: %s\n", f_1.toString().c_str());
1577 REQUIRE( 24 == f_1(4) );
1580 function<int(
int)> f_1 =
function<int(
int)>::bind_ylambda( [](
function<
int(
int)>::delegate_type& self,
int x) ->
int {
1584 return x * self(x-1);
1588 fprintf(stderr,
"ylambda 3 f_1: %s\n", f_1.toString().c_str());
1590 REQUIRE( 24 == f_1(4) );
1598 std::function<int(
int i)> f = [](
int i)->
int {
1603 REQUIRE(
true ==
static_cast<bool>( f ) );
1604 REQUIRE(
nullptr != f );
1605 REQUIRE( f !=
nullptr );
1608 std::function<int(
int i)> f;
1610 REQUIRE(
false ==
static_cast<bool>( f ) );
1611 REQUIRE(
nullptr == f );
1612 REQUIRE( f ==
nullptr );
1616#if ( FUNCTIONAL_IMPL == 1 )
1623 REQUIRE(
true ==
static_cast<bool>( f ) );
1624 REQUIRE(
nullptr != f );
1625 REQUIRE( f !=
nullptr );
1630 REQUIRE(
false ==
static_cast<bool>( f ) );
1631 REQUIRE(
nullptr == f );
1632 REQUIRE( f ==
nullptr );
1640 typedef int(*MyCFunc0)(int);
1641 typedef function<int(
int)> MyClassFunction0;
1643 int func02a_member(
int i) {
1647 int func02b_member(
int i)
noexcept {
1651 static int Func03a_static(
int i) {
1655 static int Func03b_static(
int i)
noexcept {
1660 typedef function<void(
int&,
int)> MyClassFunction1;
1662 void func12a_member(
int& r,
const int i) {
1665 void func12b_member(
int& r,
const int i)
noexcept {
1668 static void Func13a_static(
int& r,
const int i) {
1671 static void Func13b_static(
int& r,
const int i)
noexcept {
1675 typedef function<void()> MyClassFunction2;
1677 void func20a_member() {
1680 static void Func20a_static() {
1684 void test_function0_result_type(std::string msg,
bool expEqual,
const int value,
int expRes, MyClassFunction0& f1, MyClassFunction0& f2) {
1686 INFO(msg+
": Func0.rt Func f1p == f2p : " +
std::to_string( f1 == f2 ) +
", f1p: " + f1.toString() +
", f2 "+f2.toString() );
1687 int f1r = f1(value);
1688 int f2r = f2(value);
1691 REQUIRE(f1r == expRes);
1692 REQUIRE(f2r == expRes);
1698 void test_function0________type(std::string msg,
bool expEqual, MyClassFunction0& f1, MyClassFunction0& f2) {
1700 INFO(msg+
": Func0._t Func f1p == f2p : " +
std::to_string( f1 == f2 ) +
", f1p: " + f1.toString() +
", f2 "+f2.toString() );
1713 void test_function0_result_____(std::string msg,
const int value,
int expRes, MyClassFunction0& f1, MyClassFunction0& f2) {
1715 INFO(msg+
": Func0.ref.r_ Func f1p == f2p : " +
std::to_string( f1 == f2 ) +
", f1p: " + f1.toString() +
", f2 "+f2.toString() );
1716 int f1r = f1(value);
1717 int f2r = f2(value);
1719 REQUIRE(f1r == expRes);
1720 REQUIRE(f2r == expRes);
1722 void test_function0_result_copy(std::string msg,
const int value,
int expRes, MyClassFunction0 f1, MyClassFunction0 f2) {
1724 INFO(msg+
": Func0.cpy.r_ Func f1p == f2p : " +
std::to_string( f1 == f2 ) +
", f1p: " + f1.toString() +
", f2 "+f2.toString() );
1725 int f1r = f1(value);
1726 int f2r = f2(value);
1728 REQUIRE(f1r == expRes);
1729 REQUIRE(f2r == expRes);
1732 void test_function1_result_type(std::string msg,
bool expEqual,
const int value,
int expRes, MyClassFunction1& f1, MyClassFunction1& f2)
noexcept {
1734 INFO(msg+
": Func1.ref.rt Func f1p == f2p : " +
std::to_string( f1 == f2 ) +
", f1p: " + f1.toString() +
", f2 "+f2.toString() );
1740 REQUIRE(f1r == expRes);
1741 REQUIRE(f2r == expRes);
1747 void test_function1________type(std::string msg,
bool expEqual, MyClassFunction1& f1, MyClassFunction1& f2)
noexcept {
1749 INFO(msg+
": Func1.ref._t Func f1p == f2p : " +
std::to_string( f1 == f2 ) +
", f1p: " + f1.toString() +
", f2 "+f2.toString() );
1764 void test_function2________type(std::string msg,
bool expEqual, MyClassFunction2& f1, MyClassFunction2& f2)
noexcept {
1766 INFO(msg+
": Func2.ref._t Func f1p == f2p : " +
std::to_string( f1 == f2 ) +
", f1p: " + f1.toString() +
", f2 "+f2.toString() );
1779 MyCFunc0 f = (MyCFunc0) ( [](
int a) ->
int {
1785 static function<int(
int)> lambda_01() {
1787 function<int(
int)> f = [&](
int a) ->
int {
1792 static function<int(
int)> lambda_02() {
1794 function<int(
int)> f = [i](
int a) ->
int {
1802 IntOffset(
int v) : value(v) {}
1804 bool operator==(
const IntOffset& rhs)
const {
1805 if( &rhs ==
this ) {
1808 return value == rhs.value;
1812 {
return !( *
this == rhs ); }
1818 IntOffset2(
int v) : value(v) {}
1820 IntOffset2(
const IntOffset2 &o)
1823 INFO(
"IntOffset2::copy_ctor");
1825 IntOffset2(IntOffset2 &&o)
1828 INFO(
"IntOffset2::move_ctor");
1830 IntOffset2& operator=(
const IntOffset2 &o) {
1831 INFO(
"IntOffset2::copy_assign");
1838 IntOffset2& operator=(IntOffset2 &&o) {
1839 INFO(
"IntOffset2::move_assign");
1840 value = std::move(o.value);
1845 bool operator==(
const IntOffset2& rhs)
const {
1846 if( &rhs ==
this ) {
1849 return value == rhs.value;
1853 {
return !( *
this == rhs ); }
static constexpr y_combinator_lambda make(L func)
y_combinator_lambda(L func) noexcept
constexpr R operator()(A... args)
constexpr R operator()(A... args) const
void test09_lambda_ctti()
void test04_capval_lambda()
void test01_memberfunc_this()
void test00_usage()
Unit test covering most variants of jau::function<R(A...)
void test02_freefunc_static()
void test14_capval_lambda()
void test12_freefunc_static()
void test11_memberfunc_this()
void test06_capval_lambda()
void test13_stdfunc_lambda()
void test03_stdfunc_lambda()
void test05_capval_lambda()
void test07_capref_lambda()
func::ylambda_target_t is a Y combinator and deducing this implementation for lambda closures usable ...
Class template jau::function is a general-purpose static-polymorphic function wrapper.
Generic type information using either Runtime type information (RTTI) or Compile time type informatio...
static constexpr bool is_valid(const char *signature) noexcept
Returns true if given signature is not nullptr and has a string length > 0, otherwise false.
static constexpr const bool limited_lambda_id
Static constexpr boolean indicating whether resulting type_info uniqueness is limited for lambda func...
const char * name() const noexcept
Returns the type name, compiler implementation specific.
bool operator!=(const alphabet &lhs, const alphabet &rhs) noexcept
std::string to_string(const alphabet &v) noexcept
bool operator==(const alphabet &lhs, const alphabet &rhs) noexcept
consteval_cxx20 bool is_rtti_available() noexcept
Returns true if compiled with RTTI available.
constexpr const char * ctti_name() noexcept
Returns the type name of given type T using template Compile Time Type Information (CTTI) only with s...
jau::function< R(A...)> bind_member(C1 *base, R(C0::*mfunc)(A...)) noexcept
Bind given class instance and non-void member function to an anonymous function using func_member_tar...
jau::function< R(A...)> bind_free(R(*func)(A...)) noexcept
Bind given non-void free-function to an anonymous function using func::free_target_t.
jau::function< R(A...)> bind_std(uint64_t id, std::function< R(A...)> func) noexcept
Bind given non-void std::function to an anonymous function using func::std_target_t.
jau::function< R(A...)> bind_capval(const I &data, R(*func)(I &, A...)) noexcept
Bind given data by copying the captured value and the given non-void function to an anonymous functio...
jau::function< R(A...)> bind_capref(I *data_ptr, R(*func)(I *, A...)) noexcept
Bind given data by passing the captured reference (pointer) to the value and non-void function to an ...
@ null
Denotes a func::null_target_t.
@ lambda
Denotes a func::lambda_target_t.
@ capval
Denotes a func::capval_target_t.
@ capref
Denotes a func::capref_target_t.
@ member
Denotes a func::member_target_t.
@ free
Denotes a func::free_target_t.
@ std
Denotes a func::std_target_t.
@ ylambda
Denotes a func::ylambda_target_t.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Helper, allowing simple access to compile time typename and Type traits information,...
static void print(const std::string &typedefname, const TypeTraitGroup verbosity=TypeTraitGroup::NONE)
Print information of this type to stdout, potentially with all Type traits known.
static void print(const Value_type a)
static void Func1a_free(int &r, int i) noexcept
METHOD_AS_TEST_CASE(TestFunction01::test00_usage, "00_usage")
static std::string impl_name
static int Func0a_free(int i) noexcept
static void Func2a_free() noexcept