-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_gl_function.cpp
177 lines (155 loc) · 2.97 KB
/
test_gl_function.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "function.hpp"
#include "reference_wrapper.hpp"
#include <iostream>
using namespace std;
void foo0() {
cout << "foo0()" << endl;
}
void foo1(int) {
cout << "foo1()" << endl;
}
void foo2(int, int) {
cout << "foo2()" << endl;
}
struct bar0 {
void operator()() {
cout << "bar0()" << endl;
}
};
struct bar1 {
void operator()(int) {
cout << "bar1()" << endl;
}
};
struct bar2 {
void operator()(int, int) {
cout << "bar2()" << endl;
}
};
struct egg0 {
void operator()() {
cout << "egg0()" << endl;
}
egg0() { }
private:
egg0(const egg0 &);
};
struct egg1 {
void operator()(int) {
cout << "egg1()" << endl;
}
egg1() { }
private:
egg1(const egg1 &);
};
struct egg2 {
void operator()(int, int) {
cout << "egg2()" << endl;
}
egg2() { }
private:
egg2(const egg2 &);
};
struct spam0 {
void print() {
cout << "spam0()" << endl;
}
};
struct spam1 {
void print(int) {
cout << "spam1()" << endl;
}
};
struct spam2 {
void print(int, int) {
cout << "spam2()" << endl;
}
};
void test_function_ptr() {
#if 1
gl::function<void()> f0 = foo0;
f0();
gl::function<void(int)> f1 = foo1;
f1(1);
gl::function<void(int,int)> f2 = foo2;
f2(1, 2);
gl::function<void()> ff0 = foo0;
ff0();
gl::function<void(int)> ff1 = foo1;
ff1(1);
gl::function<void(int,int)> ff2 = foo2;
ff2(1, 2);
/* leak? */
f0 = ff0;
f1 = ff1;
f2 = ff2;
#endif
}
void test_function_obj() {
#if 1
gl::function<void()> f0 = bar0();
f0();
gl::function<void(int)> f1 = bar1();
f1(1);
gl::function<void(int,int)> f2 = bar2();
f2(1, 2);
gl::function<void()> ff0 = bar0();
ff0();
gl::function<void(int)> ff1 = bar1();
ff1(1);
gl::function<void(int,int)> ff2 = bar2();
ff2(1, 2);
/* leak? */
f0 = ff0;
f1 = ff1;
f2 = ff2;
#endif
}
void test_function_obj_ref() {
#if 1
egg0 e0;
egg1 e1;
egg2 e2;
gl::function<void()> f0 = gl::ref(e0);
f0();
gl::function<void(int)> f1 = gl::ref(e1);
f1(1);
gl::function<void(int,int)> f2 = gl::ref(e2);
f2(1, 2);
gl::function<void()> ff0 = gl::ref(e0);
ff0();
gl::function<void(int)> ff1 = gl::ref(e1);
ff1(1);
gl::function<void(int,int)> ff2 = gl::ref(e2);
ff2(1, 2);
/* leak? */
f0 = ff0;
f1 = ff1;
f2 = ff2;
#endif
}
void test_member_funciton_ptr() {
#if 1
spam0 sp0;
gl::function<void(spam0*)> f1 = &spam0::print;
f1(&sp0);
spam1 sp1;
gl::function<void(spam1*,int)> f2 = &spam1::print;
f2(&sp1, 1);
gl::function<void(spam0*)> ff1 = &spam0::print;
ff1(&sp0);
gl::function<void(spam1*,int)> ff2 = &spam1::print;
ff2(&sp1, 1);
/* leak? */
f1 = ff1;
f2 = ff2;
#endif
}
int main()
{
test_function_ptr();
test_function_obj();
test_function_obj_ref();
test_member_funciton_ptr();
return 0;
}