4
4
*/
5
5
6
6
#include " Foo.h"
7
+ #ifndef NODELEGATE
7
8
#include < Delegate.h>
9
+ #else
10
+ #include < functional>
11
+ #endif
8
12
#include < memory>
9
13
10
14
extern void stopwatch ();
11
15
12
16
std::shared_ptr<Foo> oPtr (new Foo());
13
- bool inline cbCPtr (int result) { return oPtr->cb (result); }
17
+ bool inline cbCPtr (int result) {
18
+ return oPtr->cb (result);
19
+ }
14
20
15
21
16
22
extern void set_f0 (bool (*_f)(Foo*, int ), Foo* _o);
@@ -21,6 +27,7 @@ extern void set_f3(bool(*)(int result));
21
27
extern void set_f4 (const std::function<bool (int )>& f);
22
28
extern void set_f5 (const std::function<bool (int )>& f);
23
29
30
+ #ifndef NODELEGATE
24
31
extern void set_f6 (const Delegate<bool (int )>&);
25
32
extern void set_f7 (const Delegate<bool (int )>&);
26
33
@@ -31,25 +38,48 @@ extern void set_f10(const Delegate<bool(int), Foo*>& f);
31
38
32
39
extern void set_f11 (const Delegate<bool (int ), Foo*>& f);
33
40
extern void set_f12 (const Delegate<bool (int ), Foo*>& f);
41
+ #else
42
+ extern void set_f6 (const std::function<bool (int )>&);
43
+ extern void set_f7 (const std::function<bool (int )>&);
34
44
35
- void testPrep () {
36
- std::shared_ptr<Foo> o (oPtr);
37
- set_f0 (Foo::cbwObj, o.get ());
38
- set_f1 ([](Foo* o, int result) -> bool { return o->cb (result); }, o.get ());
39
- set_f2 (cbCPtr);
40
- set_f3 (cbCPtr);
41
-
42
- set_f4 ([o](int result) -> bool { return o->cb (result); });
43
- set_f5 (std::bind (Foo::cbwObj, o.get (), std::placeholders::_1));
45
+ extern void set_f8 (const std::function<bool (int )>&);
44
46
45
- set_f6 ([o]( int result) -> bool { return o-> cb (result); } );
46
- set_f7 ( std::bind (Foo::cbwObj, o. get (), std::placeholders::_1) );
47
+ extern void set_f9 ( const std::function< bool ( int )>& f );
48
+ extern void set_f10 ( const std::function< bool ( int )>& f );
47
49
48
- set_f8 ([](int result) -> bool { return cbCPtr (result); });
50
+ extern void set_f11 (const std::function<bool (int )>& f);
51
+ extern void set_f12 (const std::function<bool (int )>& f);
52
+ #endif
49
53
50
- set_f9 ([o](int result) -> bool { return o->cb (result); });
51
- set_f10 (std::bind (Foo::cbwObj, o.get (), std::placeholders::_1));
52
-
53
- set_f11 ({ [](Foo* o, int result) -> bool { return o->cb (result); }, o.get () }); // fast calling!
54
- set_f12 ({ Foo::cbwObj, o.get () }); // fast calling!
54
+ void testPrep () {
55
+ std::shared_ptr<Foo> o (oPtr);
56
+ set_f0 (Foo::cbwObj, o.get ());
57
+ set_f1 ([](Foo * o, int result) -> bool { return o->cb (result); }, o.get ());
58
+ set_f2 (cbCPtr);
59
+ set_f3 (cbCPtr);
60
+
61
+ set_f4 ([o](int result) -> bool { return o->cb (result); });
62
+ set_f5 (std::bind (Foo::cbwObj, o.get (), std::placeholders::_1));
63
+
64
+ set_f6 ([o](int result) -> bool { return o->cb (result); });
65
+ set_f7 (std::bind (Foo::cbwObj, o.get (), std::placeholders::_1));
66
+
67
+ #ifndef NODELEGATE
68
+ // hint to compiler to generate Delegate constructor for simple fp instead of functional
69
+ using Fp2 = bool (*)(int );
70
+ set_f8 (static_cast <Fp2>([](int result) -> bool { return cbCPtr (result); }));
71
+ #else
72
+ set_f8 ([](int result) -> bool { return cbCPtr (result); });
73
+ #endif
74
+
75
+ set_f9 ([o](int result) -> bool { return o->cb (result); });
76
+ set_f10 (std::bind (Foo::cbwObj, o.get (), std::placeholders::_1));
77
+
78
+ #ifndef NODELEGATE
79
+ set_f11 ({ [](Foo * o, int result) -> bool { return o->cb (result); }, o.get () }); // fast calling!
80
+ set_f12 ({ Foo::cbwObj, o.get () }); // fast calling!
81
+ #else
82
+ set_f11 ([o](int result) -> bool { return o->cb (result); });
83
+ set_f12 (std::bind (Foo::cbwObj, o.get (), std::placeholders::_1));
84
+ #endif
55
85
}
0 commit comments