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 // mem_fn_void_test.cpp - a test for mem_fn.hpp + void returns
12 //
13 // Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
14 //
15 // Distributed under the Boost Software License, Version 1.0. (See
16 // accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18 //
19
20 #include <boost/mem_fn.hpp>
21 #include <boost/shared_ptr.hpp>
22
23 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
24 #pragma warning(push, 3)
25 #endif
26
27 #include <iostream>
28
29 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
30 #pragma warning(pop)
31 #endif
32
33
34 struct X
35 {
36 mutable unsigned int hash;
37
XX38 X(): hash(0) {}
39
f0X40 void f0() { f1(17); }
g0X41 void g0() const { g1(17); }
42
f1X43 void f1(int a1) { hash = (hash * 17041 + a1) % 32768; }
g1X44 void g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; }
45
f2X46 void f2(int a1, int a2) { f1(a1); f1(a2); }
g2X47 void g2(int a1, int a2) const { g1(a1); g1(a2); }
48
f3X49 void f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); }
g3X50 void g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); }
51
f4X52 void f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); }
g4X53 void g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); }
54
f5X55 void f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); }
g5X56 void g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); }
57
f6X58 void f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); }
g6X59 void g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); }
60
f7X61 void f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); }
g7X62 void 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); }
63
f8X64 void 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); }
g8X65 void 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); }
66 };
67
detect_errors(bool x)68 int detect_errors(bool x)
69 {
70 if(x)
71 {
72 std::cerr << "no errors detected.\n";
73 return 0;
74 }
75 else
76 {
77 std::cerr << "test failed.\n";
78 return 1;
79 }
80 }
81
main()82 int main()
83 {
84 using boost::mem_fn;
85
86 X x;
87
88 X const & rcx = x;
89 X const * pcx = &x;
90
91 boost::shared_ptr<X> sp(new X);
92
93 mem_fn(&X::f0)(x);
94 mem_fn(&X::f0)(&x);
95 mem_fn(&X::f0)(sp);
96
97 mem_fn(&X::g0)(x);
98 mem_fn(&X::g0)(rcx);
99 mem_fn(&X::g0)(&x);
100 mem_fn(&X::g0)(pcx);
101 mem_fn(&X::g0)(sp);
102
103 mem_fn(&X::f1)(x, 1);
104 mem_fn(&X::f1)(&x, 1);
105 mem_fn(&X::f1)(sp, 1);
106
107 mem_fn(&X::g1)(x, 1);
108 mem_fn(&X::g1)(rcx, 1);
109 mem_fn(&X::g1)(&x, 1);
110 mem_fn(&X::g1)(pcx, 1);
111 mem_fn(&X::g1)(sp, 1);
112
113 mem_fn(&X::f2)(x, 1, 2);
114 mem_fn(&X::f2)(&x, 1, 2);
115 mem_fn(&X::f2)(sp, 1, 2);
116
117 mem_fn(&X::g2)(x, 1, 2);
118 mem_fn(&X::g2)(rcx, 1, 2);
119 mem_fn(&X::g2)(&x, 1, 2);
120 mem_fn(&X::g2)(pcx, 1, 2);
121 mem_fn(&X::g2)(sp, 1, 2);
122
123 mem_fn(&X::f3)(x, 1, 2, 3);
124 mem_fn(&X::f3)(&x, 1, 2, 3);
125 mem_fn(&X::f3)(sp, 1, 2, 3);
126
127 mem_fn(&X::g3)(x, 1, 2, 3);
128 mem_fn(&X::g3)(rcx, 1, 2, 3);
129 mem_fn(&X::g3)(&x, 1, 2, 3);
130 mem_fn(&X::g3)(pcx, 1, 2, 3);
131 mem_fn(&X::g3)(sp, 1, 2, 3);
132
133 mem_fn(&X::f4)(x, 1, 2, 3, 4);
134 mem_fn(&X::f4)(&x, 1, 2, 3, 4);
135 mem_fn(&X::f4)(sp, 1, 2, 3, 4);
136
137 mem_fn(&X::g4)(x, 1, 2, 3, 4);
138 mem_fn(&X::g4)(rcx, 1, 2, 3, 4);
139 mem_fn(&X::g4)(&x, 1, 2, 3, 4);
140 mem_fn(&X::g4)(pcx, 1, 2, 3, 4);
141 mem_fn(&X::g4)(sp, 1, 2, 3, 4);
142
143 mem_fn(&X::f5)(x, 1, 2, 3, 4, 5);
144 mem_fn(&X::f5)(&x, 1, 2, 3, 4, 5);
145 mem_fn(&X::f5)(sp, 1, 2, 3, 4, 5);
146
147 mem_fn(&X::g5)(x, 1, 2, 3, 4, 5);
148 mem_fn(&X::g5)(rcx, 1, 2, 3, 4, 5);
149 mem_fn(&X::g5)(&x, 1, 2, 3, 4, 5);
150 mem_fn(&X::g5)(pcx, 1, 2, 3, 4, 5);
151 mem_fn(&X::g5)(sp, 1, 2, 3, 4, 5);
152
153 mem_fn(&X::f6)(x, 1, 2, 3, 4, 5, 6);
154 mem_fn(&X::f6)(&x, 1, 2, 3, 4, 5, 6);
155 mem_fn(&X::f6)(sp, 1, 2, 3, 4, 5, 6);
156
157 mem_fn(&X::g6)(x, 1, 2, 3, 4, 5, 6);
158 mem_fn(&X::g6)(rcx, 1, 2, 3, 4, 5, 6);
159 mem_fn(&X::g6)(&x, 1, 2, 3, 4, 5, 6);
160 mem_fn(&X::g6)(pcx, 1, 2, 3, 4, 5, 6);
161 mem_fn(&X::g6)(sp, 1, 2, 3, 4, 5, 6);
162
163 mem_fn(&X::f7)(x, 1, 2, 3, 4, 5, 6, 7);
164 mem_fn(&X::f7)(&x, 1, 2, 3, 4, 5, 6, 7);
165 mem_fn(&X::f7)(sp, 1, 2, 3, 4, 5, 6, 7);
166
167 mem_fn(&X::g7)(x, 1, 2, 3, 4, 5, 6, 7);
168 mem_fn(&X::g7)(rcx, 1, 2, 3, 4, 5, 6, 7);
169 mem_fn(&X::g7)(&x, 1, 2, 3, 4, 5, 6, 7);
170 mem_fn(&X::g7)(pcx, 1, 2, 3, 4, 5, 6, 7);
171 mem_fn(&X::g7)(sp, 1, 2, 3, 4, 5, 6, 7);
172
173 mem_fn(&X::f8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
174 mem_fn(&X::f8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
175 mem_fn(&X::f8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
176
177 mem_fn(&X::g8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
178 mem_fn(&X::g8)(rcx, 1, 2, 3, 4, 5, 6, 7, 8);
179 mem_fn(&X::g8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
180 mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);
181 mem_fn(&X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
182
183 return detect_errors(x.hash == 17610 && sp->hash == 2155);
184 }
185