• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_eq_test.cpp - boost::mem_fn equality operator
12 //
13 //  Copyright (c) 2004 Peter Dimov
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 
22 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
23 #pragma warning(push, 3)
24 #endif
25 
26 #include <iostream>
27 
28 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
29 #pragma warning(pop)
30 #endif
31 
32 #include <boost/detail/lightweight_test.hpp>
33 
34 struct X
35 {
36     int dm_1;
37     int dm_2;
38 
39     // 0
40 
mf0_1X41     int mf0_1() { return 0; }
mf0_2X42     int mf0_2() { return 1; }
43 
cmf0_1X44     int cmf0_1() const { return 0; }
cmf0_2X45     int cmf0_2() const { return 1; }
46 
mf0v_1X47     void mf0v_1() {}
mf0v_2X48     void mf0v_2() { static int x; ++x; }
49 
cmf0v_1X50     void cmf0v_1() const {}
cmf0v_2X51     void cmf0v_2() const { static int x; ++x; }
52 
53     // 1
54 
mf1_1X55     int mf1_1(int) { return 0; }
mf1_2X56     int mf1_2(int) { return 1; }
57 
cmf1_1X58     int cmf1_1(int) const { return 0; }
cmf1_2X59     int cmf1_2(int) const { return 1; }
60 
mf1v_1X61     void mf1v_1(int) {}
mf1v_2X62     void mf1v_2(int) { static int x; ++x; }
63 
cmf1v_1X64     void cmf1v_1(int) const {}
cmf1v_2X65     void cmf1v_2(int) const { static int x; ++x; }
66 
67     // 2
68 
mf2_1X69     int mf2_1(int, int) { return 0; }
mf2_2X70     int mf2_2(int, int) { return 1; }
71 
cmf2_1X72     int cmf2_1(int, int) const { return 0; }
cmf2_2X73     int cmf2_2(int, int) const { return 1; }
74 
mf2v_1X75     void mf2v_1(int, int) {}
mf2v_2X76     void mf2v_2(int, int) { static int x; ++x; }
77 
cmf2v_1X78     void cmf2v_1(int, int) const {}
cmf2v_2X79     void cmf2v_2(int, int) const { static int x; ++x; }
80 
81     // 3
82 
mf3_1X83     int mf3_1(int, int, int) { return 0; }
mf3_2X84     int mf3_2(int, int, int) { return 1; }
85 
cmf3_1X86     int cmf3_1(int, int, int) const { return 0; }
cmf3_2X87     int cmf3_2(int, int, int) const { return 1; }
88 
mf3v_1X89     void mf3v_1(int, int, int) {}
mf3v_2X90     void mf3v_2(int, int, int) { static int x; ++x; }
91 
cmf3v_1X92     void cmf3v_1(int, int, int) const {}
cmf3v_2X93     void cmf3v_2(int, int, int) const { static int x; ++x; }
94 
95     // 4
96 
mf4_1X97     int mf4_1(int, int, int, int) { return 0; }
mf4_2X98     int mf4_2(int, int, int, int) { return 1; }
99 
cmf4_1X100     int cmf4_1(int, int, int, int) const { return 0; }
cmf4_2X101     int cmf4_2(int, int, int, int) const { return 1; }
102 
mf4v_1X103     void mf4v_1(int, int, int, int) {}
mf4v_2X104     void mf4v_2(int, int, int, int) { static int x; ++x; }
105 
cmf4v_1X106     void cmf4v_1(int, int, int, int) const {}
cmf4v_2X107     void cmf4v_2(int, int, int, int) const { static int x; ++x; }
108 
109     // 5
110 
mf5_1X111     int mf5_1(int, int, int, int, int) { return 0; }
mf5_2X112     int mf5_2(int, int, int, int, int) { return 1; }
113 
cmf5_1X114     int cmf5_1(int, int, int, int, int) const { return 0; }
cmf5_2X115     int cmf5_2(int, int, int, int, int) const { return 1; }
116 
mf5v_1X117     void mf5v_1(int, int, int, int, int) {}
mf5v_2X118     void mf5v_2(int, int, int, int, int) { static int x; ++x; }
119 
cmf5v_1X120     void cmf5v_1(int, int, int, int, int) const {}
cmf5v_2X121     void cmf5v_2(int, int, int, int, int) const { static int x; ++x; }
122 
123     // 6
124 
mf6_1X125     int mf6_1(int, int, int, int, int, int) { return 0; }
mf6_2X126     int mf6_2(int, int, int, int, int, int) { return 1; }
127 
cmf6_1X128     int cmf6_1(int, int, int, int, int, int) const { return 0; }
cmf6_2X129     int cmf6_2(int, int, int, int, int, int) const { return 1; }
130 
mf6v_1X131     void mf6v_1(int, int, int, int, int, int) {}
mf6v_2X132     void mf6v_2(int, int, int, int, int, int) { static int x; ++x; }
133 
cmf6v_1X134     void cmf6v_1(int, int, int, int, int, int) const {}
cmf6v_2X135     void cmf6v_2(int, int, int, int, int, int) const { static int x; ++x; }
136 
137     // 7
138 
mf7_1X139     int mf7_1(int, int, int, int, int, int, int) { return 0; }
mf7_2X140     int mf7_2(int, int, int, int, int, int, int) { return 1; }
141 
cmf7_1X142     int cmf7_1(int, int, int, int, int, int, int) const { return 0; }
cmf7_2X143     int cmf7_2(int, int, int, int, int, int, int) const { return 1; }
144 
mf7v_1X145     void mf7v_1(int, int, int, int, int, int, int) {}
mf7v_2X146     void mf7v_2(int, int, int, int, int, int, int) { static int x; ++x; }
147 
cmf7v_1X148     void cmf7v_1(int, int, int, int, int, int, int) const {}
cmf7v_2X149     void cmf7v_2(int, int, int, int, int, int, int) const { static int x; ++x; }
150 
151     // 8
152 
mf8_1X153     int mf8_1(int, int, int, int, int, int, int, int) { return 0; }
mf8_2X154     int mf8_2(int, int, int, int, int, int, int, int) { return 1; }
155 
cmf8_1X156     int cmf8_1(int, int, int, int, int, int, int, int) const { return 0; }
cmf8_2X157     int cmf8_2(int, int, int, int, int, int, int, int) const { return 1; }
158 
mf8v_1X159     void mf8v_1(int, int, int, int, int, int, int, int) {}
mf8v_2X160     void mf8v_2(int, int, int, int, int, int, int, int) { static int x; ++x; }
161 
cmf8v_1X162     void cmf8v_1(int, int, int, int, int, int, int, int) const {}
cmf8v_2X163     void cmf8v_2(int, int, int, int, int, int, int, int) const { static int x; ++x; }
164 
165 };
166 
main()167 int main()
168 {
169     BOOST_TEST( boost::mem_fn(&X::dm_1) == boost::mem_fn(&X::dm_1) );
170     BOOST_TEST( boost::mem_fn(&X::dm_1) != boost::mem_fn(&X::dm_2) );
171 
172     // 0
173 
174     BOOST_TEST( boost::mem_fn(&X::mf0_1) == boost::mem_fn(&X::mf0_1) );
175     BOOST_TEST( boost::mem_fn(&X::mf0_1) != boost::mem_fn(&X::mf0_2) );
176 
177     BOOST_TEST( boost::mem_fn(&X::cmf0_1) == boost::mem_fn(&X::cmf0_1) );
178     BOOST_TEST( boost::mem_fn(&X::cmf0_1) != boost::mem_fn(&X::cmf0_2) );
179 
180     BOOST_TEST( boost::mem_fn(&X::mf0v_1) == boost::mem_fn(&X::mf0v_1) );
181     BOOST_TEST( boost::mem_fn(&X::mf0v_1) != boost::mem_fn(&X::mf0v_2) );
182 
183     BOOST_TEST( boost::mem_fn(&X::cmf0v_1) == boost::mem_fn(&X::cmf0v_1) );
184     BOOST_TEST( boost::mem_fn(&X::cmf0v_1) != boost::mem_fn(&X::cmf0v_2) );
185 
186     // 1
187 
188     BOOST_TEST( boost::mem_fn(&X::mf1_1) == boost::mem_fn(&X::mf1_1) );
189     BOOST_TEST( boost::mem_fn(&X::mf1_1) != boost::mem_fn(&X::mf1_2) );
190 
191     BOOST_TEST( boost::mem_fn(&X::cmf1_1) == boost::mem_fn(&X::cmf1_1) );
192     BOOST_TEST( boost::mem_fn(&X::cmf1_1) != boost::mem_fn(&X::cmf1_2) );
193 
194     BOOST_TEST( boost::mem_fn(&X::mf1v_1) == boost::mem_fn(&X::mf1v_1) );
195     BOOST_TEST( boost::mem_fn(&X::mf1v_1) != boost::mem_fn(&X::mf1v_2) );
196 
197     BOOST_TEST( boost::mem_fn(&X::cmf1v_1) == boost::mem_fn(&X::cmf1v_1) );
198     BOOST_TEST( boost::mem_fn(&X::cmf1v_1) != boost::mem_fn(&X::cmf1v_2) );
199 
200     // 2
201 
202     BOOST_TEST( boost::mem_fn(&X::mf2_1) == boost::mem_fn(&X::mf2_1) );
203     BOOST_TEST( boost::mem_fn(&X::mf2_1) != boost::mem_fn(&X::mf2_2) );
204 
205     BOOST_TEST( boost::mem_fn(&X::cmf2_1) == boost::mem_fn(&X::cmf2_1) );
206     BOOST_TEST( boost::mem_fn(&X::cmf2_1) != boost::mem_fn(&X::cmf2_2) );
207 
208     BOOST_TEST( boost::mem_fn(&X::mf2v_1) == boost::mem_fn(&X::mf2v_1) );
209     BOOST_TEST( boost::mem_fn(&X::mf2v_1) != boost::mem_fn(&X::mf2v_2) );
210 
211     BOOST_TEST( boost::mem_fn(&X::cmf2v_1) == boost::mem_fn(&X::cmf2v_1) );
212     BOOST_TEST( boost::mem_fn(&X::cmf2v_1) != boost::mem_fn(&X::cmf2v_2) );
213 
214     // 3
215 
216     BOOST_TEST( boost::mem_fn(&X::mf3_1) == boost::mem_fn(&X::mf3_1) );
217     BOOST_TEST( boost::mem_fn(&X::mf3_1) != boost::mem_fn(&X::mf3_2) );
218 
219     BOOST_TEST( boost::mem_fn(&X::cmf3_1) == boost::mem_fn(&X::cmf3_1) );
220     BOOST_TEST( boost::mem_fn(&X::cmf3_1) != boost::mem_fn(&X::cmf3_2) );
221 
222     BOOST_TEST( boost::mem_fn(&X::mf3v_1) == boost::mem_fn(&X::mf3v_1) );
223     BOOST_TEST( boost::mem_fn(&X::mf3v_1) != boost::mem_fn(&X::mf3v_2) );
224 
225     BOOST_TEST( boost::mem_fn(&X::cmf3v_1) == boost::mem_fn(&X::cmf3v_1) );
226     BOOST_TEST( boost::mem_fn(&X::cmf3v_1) != boost::mem_fn(&X::cmf3v_2) );
227 
228     // 4
229 
230     BOOST_TEST( boost::mem_fn(&X::mf4_1) == boost::mem_fn(&X::mf4_1) );
231     BOOST_TEST( boost::mem_fn(&X::mf4_1) != boost::mem_fn(&X::mf4_2) );
232 
233     BOOST_TEST( boost::mem_fn(&X::cmf4_1) == boost::mem_fn(&X::cmf4_1) );
234     BOOST_TEST( boost::mem_fn(&X::cmf4_1) != boost::mem_fn(&X::cmf4_2) );
235 
236     BOOST_TEST( boost::mem_fn(&X::mf4v_1) == boost::mem_fn(&X::mf4v_1) );
237     BOOST_TEST( boost::mem_fn(&X::mf4v_1) != boost::mem_fn(&X::mf4v_2) );
238 
239     BOOST_TEST( boost::mem_fn(&X::cmf4v_1) == boost::mem_fn(&X::cmf4v_1) );
240     BOOST_TEST( boost::mem_fn(&X::cmf4v_1) != boost::mem_fn(&X::cmf4v_2) );
241 
242     // 5
243 
244     BOOST_TEST( boost::mem_fn(&X::mf5_1) == boost::mem_fn(&X::mf5_1) );
245     BOOST_TEST( boost::mem_fn(&X::mf5_1) != boost::mem_fn(&X::mf5_2) );
246 
247     BOOST_TEST( boost::mem_fn(&X::cmf5_1) == boost::mem_fn(&X::cmf5_1) );
248     BOOST_TEST( boost::mem_fn(&X::cmf5_1) != boost::mem_fn(&X::cmf5_2) );
249 
250     BOOST_TEST( boost::mem_fn(&X::mf5v_1) == boost::mem_fn(&X::mf5v_1) );
251     BOOST_TEST( boost::mem_fn(&X::mf5v_1) != boost::mem_fn(&X::mf5v_2) );
252 
253     BOOST_TEST( boost::mem_fn(&X::cmf5v_1) == boost::mem_fn(&X::cmf5v_1) );
254     BOOST_TEST( boost::mem_fn(&X::cmf5v_1) != boost::mem_fn(&X::cmf5v_2) );
255 
256     // 6
257 
258     BOOST_TEST( boost::mem_fn(&X::mf6_1) == boost::mem_fn(&X::mf6_1) );
259     BOOST_TEST( boost::mem_fn(&X::mf6_1) != boost::mem_fn(&X::mf6_2) );
260 
261     BOOST_TEST( boost::mem_fn(&X::cmf6_1) == boost::mem_fn(&X::cmf6_1) );
262     BOOST_TEST( boost::mem_fn(&X::cmf6_1) != boost::mem_fn(&X::cmf6_2) );
263 
264     BOOST_TEST( boost::mem_fn(&X::mf6v_1) == boost::mem_fn(&X::mf6v_1) );
265     BOOST_TEST( boost::mem_fn(&X::mf6v_1) != boost::mem_fn(&X::mf6v_2) );
266 
267     BOOST_TEST( boost::mem_fn(&X::cmf6v_1) == boost::mem_fn(&X::cmf6v_1) );
268     BOOST_TEST( boost::mem_fn(&X::cmf6v_1) != boost::mem_fn(&X::cmf6v_2) );
269 
270     // 7
271 
272     BOOST_TEST( boost::mem_fn(&X::mf7_1) == boost::mem_fn(&X::mf7_1) );
273     BOOST_TEST( boost::mem_fn(&X::mf7_1) != boost::mem_fn(&X::mf7_2) );
274 
275     BOOST_TEST( boost::mem_fn(&X::cmf7_1) == boost::mem_fn(&X::cmf7_1) );
276     BOOST_TEST( boost::mem_fn(&X::cmf7_1) != boost::mem_fn(&X::cmf7_2) );
277 
278     BOOST_TEST( boost::mem_fn(&X::mf7v_1) == boost::mem_fn(&X::mf7v_1) );
279     BOOST_TEST( boost::mem_fn(&X::mf7v_1) != boost::mem_fn(&X::mf7v_2) );
280 
281     BOOST_TEST( boost::mem_fn(&X::cmf7v_1) == boost::mem_fn(&X::cmf7v_1) );
282     BOOST_TEST( boost::mem_fn(&X::cmf7v_1) != boost::mem_fn(&X::cmf7v_2) );
283 
284     // 8
285 
286     BOOST_TEST( boost::mem_fn(&X::mf8_1) == boost::mem_fn(&X::mf8_1) );
287     BOOST_TEST( boost::mem_fn(&X::mf8_1) != boost::mem_fn(&X::mf8_2) );
288 
289     BOOST_TEST( boost::mem_fn(&X::cmf8_1) == boost::mem_fn(&X::cmf8_1) );
290     BOOST_TEST( boost::mem_fn(&X::cmf8_1) != boost::mem_fn(&X::cmf8_2) );
291 
292     BOOST_TEST( boost::mem_fn(&X::mf8v_1) == boost::mem_fn(&X::mf8v_1) );
293     BOOST_TEST( boost::mem_fn(&X::mf8v_1) != boost::mem_fn(&X::mf8v_2) );
294 
295     BOOST_TEST( boost::mem_fn(&X::cmf8v_1) == boost::mem_fn(&X::cmf8v_1) );
296     BOOST_TEST( boost::mem_fn(&X::cmf8v_1) != boost::mem_fn(&X::cmf8v_2) );
297 
298 
299     return boost::report_errors();
300 }
301