1 #include <boost/config.hpp>
2
3 #if defined(BOOST_MSVC)
4 #pragma warning(disable: 4786) // identifier truncated in debug info
5 #pragma warning(disable: 4710) // function not inlined
6 #pragma warning(disable: 4711) // function selected for automatic inline expansion
7 #pragma warning(disable: 4514) // unreferenced inline removed
8 #endif
9
10 //
11 // bind_void_mf_test.cpp - test for bind<void> with member functions
12 //
13 // Copyright (c) 2008 Peter Dimov
14 // Copyright (c) 2014 Agustin Berge
15 //
16 // Distributed under the Boost Software License, Version 1.0. (See
17 // accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
19 //
20
21 #include <boost/bind/bind.hpp>
22 #include <boost/ref.hpp>
23 #include <boost/core/lightweight_test.hpp>
24
25 //
26
27 long global_result;
28
29 //
30
31 struct X
32 {
33 mutable unsigned int hash;
34
XX35 X(): hash(0) {}
36
f0X37 int f0() { f1(17); return 0; }
g0X38 int g0() const { g1(17); return 0; }
h0X39 void h0() { h1(17); }
40
f1X41 int f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
g1X42 int g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
h1X43 void h1(int a1) { hash = (hash * 17041 + a1 * 2) % 32768; }
44
f2X45 int f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
g2X46 int g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
h2X47 void h2(int a1, int a2) { h1(a1); h1(a2); }
48
f3X49 int f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
g3X50 int g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
h3X51 void h3(int a1, int a2, int a3) { h2(a1, a2); h1(a3); }
52
f4X53 int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
g4X54 int g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
h4X55 void h4(int a1, int a2, int a3, int a4) { h3(a1, a2, a3); h1(a4); }
56
f5X57 int f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
g5X58 int g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
h5X59 void h5(int a1, int a2, int a3, int a4, int a5) { h4(a1, a2, a3, a4); h1(a5); }
60
f6X61 int f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
g6X62 int g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
h6X63 void h6(int a1, int a2, int a3, int a4, int a5, int a6) { h5(a1, a2, a3, a4, a5); h1(a6); }
64
f7X65 int f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
g7X66 int g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
h7X67 void h7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { h6(a1, a2, a3, a4, a5, a6); h1(a7); }
68
f8X69 int f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
g8X70 int g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
h8X71 void h8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { h7(a1, a2, a3, a4, a5, a6, a7); h1(a8); }
72 };
73
member_function_test()74 void member_function_test()
75 {
76 using namespace boost;
77
78 X x;
79
80 // 0
81
82 bind<void>(&X::f0, &x)();
83 bind<void>(&X::f0, ref(x))();
84
85 bind<void>(&X::g0, &x)();
86 bind<void>(&X::g0, x)();
87 bind<void>(&X::g0, ref(x))();
88
89 bind<void>(&X::h0, x)();
90
91 // 1
92
93 bind<void>(&X::f1, &x, 1)();
94 bind<void>(&X::f1, ref(x), 1)();
95
96 bind<void>(&X::g1, &x, 1)();
97 bind<void>(&X::g1, x, 1)();
98 bind<void>(&X::g1, ref(x), 1)();
99
100 bind<void>(&X::h1, x, 1)();
101
102 // 2
103
104 bind<void>(&X::f2, &x, 1, 2)();
105 bind<void>(&X::f2, ref(x), 1, 2)();
106
107 bind<void>(&X::g2, &x, 1, 2)();
108 bind<void>(&X::g2, x, 1, 2)();
109 bind<void>(&X::g2, ref(x), 1, 2)();
110
111 bind<void>(&X::h2, x, 1, 2)();
112
113 // 3
114
115 bind<void>(&X::f3, &x, 1, 2, 3)();
116 bind<void>(&X::f3, ref(x), 1, 2, 3)();
117
118 bind<void>(&X::g3, &x, 1, 2, 3)();
119 bind<void>(&X::g3, x, 1, 2, 3)();
120 bind<void>(&X::g3, ref(x), 1, 2, 3)();
121
122 bind<void>(&X::h3, x, 1, 2, 3)();
123
124 // 4
125
126 bind<void>(&X::f4, &x, 1, 2, 3, 4)();
127 bind<void>(&X::f4, ref(x), 1, 2, 3, 4)();
128
129 bind<void>(&X::g4, &x, 1, 2, 3, 4)();
130 bind<void>(&X::g4, x, 1, 2, 3, 4)();
131 bind<void>(&X::g4, ref(x), 1, 2, 3, 4)();
132
133 bind<void>(&X::h4, x, 1, 2, 3, 4)();
134
135 // 5
136
137 bind<void>(&X::f5, &x, 1, 2, 3, 4, 5)();
138 bind<void>(&X::f5, ref(x), 1, 2, 3, 4, 5)();
139
140 bind<void>(&X::g5, &x, 1, 2, 3, 4, 5)();
141 bind<void>(&X::g5, x, 1, 2, 3, 4, 5)();
142 bind<void>(&X::g5, ref(x), 1, 2, 3, 4, 5)();
143
144 bind<void>(&X::h5, x, 1, 2, 3, 4, 5)();
145
146 // 6
147
148 bind<void>(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
149 bind<void>(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)();
150
151 bind<void>(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
152 bind<void>(&X::g6, x, 1, 2, 3, 4, 5, 6)();
153 bind<void>(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)();
154
155 bind<void>(&X::h6, x, 1, 2, 3, 4, 5, 6)();
156
157 // 7
158
159 bind<void>(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
160 bind<void>(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
161
162 bind<void>(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
163 bind<void>(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
164 bind<void>(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
165
166 bind<void>(&X::h7, x, 1, 2, 3, 4, 5, 6, 7)();
167
168 // 8
169
170 bind<void>(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
171 bind<void>(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
172
173 bind<void>(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
174 bind<void>(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
175 bind<void>(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
176
177 bind<void>(&X::h8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
178
179 BOOST_TEST( x.hash == 23558 );
180 }
181
main()182 int main()
183 {
184 member_function_test();
185
186 return boost::report_errors();
187 }
188