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_test.cpp - mem_fn.hpp with rvalues
12 //
13 // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
14 // Copyright (c) 2005 Peter Dimov
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/mem_fn.hpp>
22 #include <boost/shared_ptr.hpp>
23
24 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
25 #pragma warning(push, 3)
26 #endif
27
28 #include <iostream>
29
30 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
31 #pragma warning(pop)
32 #endif
33
34 unsigned int hash = 0;
35
36 struct X
37 {
f0X38 int f0() { f1(17); return 0; }
g0X39 int g0() const { g1(17); return 0; }
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; }
43
f2X44 int f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
g2X45 int g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
46
f3X47 int f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
g3X48 int g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
49
f4X50 int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
g4X51 int g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
52
f5X53 int f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
g5X54 int g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
55
f6X56 int f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
g6X57 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; }
58
f7X59 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; }
g7X60 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; }
61
f8X62 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; }
g8X63 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; }
64 };
65
detect_errors(bool x)66 int detect_errors(bool x)
67 {
68 if( x )
69 {
70 std::cerr << "no errors detected.\n";
71 return 0;
72 }
73 else
74 {
75 std::cerr << "test failed.\n";
76 return 1;
77 }
78 }
79
make()80 boost::shared_ptr<X> make()
81 {
82 return boost::shared_ptr<X>( new X );
83 }
84
main()85 int main()
86 {
87 using boost::mem_fn;
88
89 mem_fn(&X::f0)( make() );
90 mem_fn(&X::g0)( make() );
91
92 mem_fn(&X::f1)( make(), 1 );
93 mem_fn(&X::g1)( make(), 1 );
94
95 mem_fn(&X::f2)( make(), 1, 2 );
96 mem_fn(&X::g2)( make(), 1, 2 );
97
98 mem_fn(&X::f3)( make(), 1, 2, 3 );
99 mem_fn(&X::g3)( make(), 1, 2, 3 );
100
101 mem_fn(&X::f4)( make(), 1, 2, 3, 4 );
102 mem_fn(&X::g4)( make(), 1, 2, 3, 4 );
103
104 mem_fn(&X::f5)( make(), 1, 2, 3, 4, 5 );
105 mem_fn(&X::g5)( make(), 1, 2, 3, 4, 5 );
106
107 mem_fn(&X::f6)( make(), 1, 2, 3, 4, 5, 6 );
108 mem_fn(&X::g6)( make(), 1, 2, 3, 4, 5, 6 );
109
110 mem_fn(&X::f7)( make(), 1, 2, 3, 4, 5, 6, 7 );
111 mem_fn(&X::g7)( make(), 1, 2, 3, 4, 5, 6, 7 );
112
113 mem_fn(&X::f8)( make(), 1, 2, 3, 4, 5, 6, 7, 8 );
114 mem_fn(&X::g8)( make(), 1, 2, 3, 4, 5, 6, 7, 8 );
115
116 return detect_errors( hash == 2155 );
117 }
118