1 #include <boost/config.hpp>
2
3 #ifndef BOOST_MSVC
4
main()5 int main()
6 {
7 }
8
9 #else
10
11 #if defined(BOOST_MSVC)
12 #pragma warning(disable: 4786) // identifier truncated in debug info
13 #pragma warning(disable: 4710) // function not inlined
14 #pragma warning(disable: 4711) // function selected for automatic inline expansion
15 #pragma warning(disable: 4514) // unreferenced inline removed
16 #endif
17
18 //
19 // mem_fn_cdecl_test.cpp - a test for mem_fn.hpp + __cdecl
20 //
21 // Copyright (c) 2005 Peter Dimov
22 //
23 // Distributed under the Boost Software License, Version 1.0. (See
24 // accompanying file LICENSE_1_0.txt or copy at
25 // http://www.boost.org/LICENSE_1_0.txt)
26 //
27
28 #define BOOST_MEM_FN_ENABLE_CDECL
29
30 #include <boost/mem_fn.hpp>
31 #include <boost/shared_ptr.hpp>
32
33 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
34 #pragma warning(push, 3)
35 #endif
36
37 #include <iostream>
38
39 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
40 #pragma warning(pop)
41 #endif
42
43
44 struct X
45 {
46 mutable unsigned int hash;
47
XX48 X(): hash(0) {}
49
f0X50 int __cdecl f0() { f1(17); return 0; }
g0X51 int __cdecl g0() const { g1(17); return 0; }
52
f1X53 int __cdecl f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
g1X54 int __cdecl g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
55
f2X56 int __cdecl f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
g2X57 int __cdecl g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
58
f3X59 int __cdecl f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
g3X60 int __cdecl g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
61
f4X62 int __cdecl f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
g4X63 int __cdecl g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
64
f5X65 int __cdecl f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
g5X66 int __cdecl g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
67
f6X68 int __cdecl f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
g6X69 int __cdecl g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
70
f7X71 int __cdecl 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; }
g7X72 int __cdecl 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; }
73
f8X74 int __cdecl 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; }
g8X75 int __cdecl 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; }
76 };
77
detect_errors(bool x)78 int detect_errors(bool x)
79 {
80 if(x)
81 {
82 std::cerr << "no errors detected.\n";
83 return 0;
84 }
85 else
86 {
87 std::cerr << "test failed.\n";
88 return 1;
89 }
90 }
91
main()92 int main()
93 {
94 using boost::mem_fn;
95
96 X x;
97
98 X const & rcx = x;
99 X const * pcx = &x;
100
101 boost::shared_ptr<X> sp(new X);
102
103 mem_fn(&X::f0)(x);
104 mem_fn(&X::f0)(&x);
105 mem_fn(&X::f0)(sp);
106
107 mem_fn(&X::g0)(x);
108 mem_fn(&X::g0)(rcx);
109 mem_fn(&X::g0)(&x);
110 mem_fn(&X::g0)(pcx);
111 mem_fn(&X::g0)(sp);
112
113 mem_fn(&X::f1)(x, 1);
114 mem_fn(&X::f1)(&x, 1);
115 mem_fn(&X::f1)(sp, 1);
116
117 mem_fn(&X::g1)(x, 1);
118 mem_fn(&X::g1)(rcx, 1);
119 mem_fn(&X::g1)(&x, 1);
120 mem_fn(&X::g1)(pcx, 1);
121 mem_fn(&X::g1)(sp, 1);
122
123 mem_fn(&X::f2)(x, 1, 2);
124 mem_fn(&X::f2)(&x, 1, 2);
125 mem_fn(&X::f2)(sp, 1, 2);
126
127 mem_fn(&X::g2)(x, 1, 2);
128 mem_fn(&X::g2)(rcx, 1, 2);
129 mem_fn(&X::g2)(&x, 1, 2);
130 mem_fn(&X::g2)(pcx, 1, 2);
131 mem_fn(&X::g2)(sp, 1, 2);
132
133 mem_fn(&X::f3)(x, 1, 2, 3);
134 mem_fn(&X::f3)(&x, 1, 2, 3);
135 mem_fn(&X::f3)(sp, 1, 2, 3);
136
137 mem_fn(&X::g3)(x, 1, 2, 3);
138 mem_fn(&X::g3)(rcx, 1, 2, 3);
139 mem_fn(&X::g3)(&x, 1, 2, 3);
140 mem_fn(&X::g3)(pcx, 1, 2, 3);
141 mem_fn(&X::g3)(sp, 1, 2, 3);
142
143 mem_fn(&X::f4)(x, 1, 2, 3, 4);
144 mem_fn(&X::f4)(&x, 1, 2, 3, 4);
145 mem_fn(&X::f4)(sp, 1, 2, 3, 4);
146
147 mem_fn(&X::g4)(x, 1, 2, 3, 4);
148 mem_fn(&X::g4)(rcx, 1, 2, 3, 4);
149 mem_fn(&X::g4)(&x, 1, 2, 3, 4);
150 mem_fn(&X::g4)(pcx, 1, 2, 3, 4);
151 mem_fn(&X::g4)(sp, 1, 2, 3, 4);
152
153 mem_fn(&X::f5)(x, 1, 2, 3, 4, 5);
154 mem_fn(&X::f5)(&x, 1, 2, 3, 4, 5);
155 mem_fn(&X::f5)(sp, 1, 2, 3, 4, 5);
156
157 mem_fn(&X::g5)(x, 1, 2, 3, 4, 5);
158 mem_fn(&X::g5)(rcx, 1, 2, 3, 4, 5);
159 mem_fn(&X::g5)(&x, 1, 2, 3, 4, 5);
160 mem_fn(&X::g5)(pcx, 1, 2, 3, 4, 5);
161 mem_fn(&X::g5)(sp, 1, 2, 3, 4, 5);
162
163 mem_fn(&X::f6)(x, 1, 2, 3, 4, 5, 6);
164 mem_fn(&X::f6)(&x, 1, 2, 3, 4, 5, 6);
165 mem_fn(&X::f6)(sp, 1, 2, 3, 4, 5, 6);
166
167 mem_fn(&X::g6)(x, 1, 2, 3, 4, 5, 6);
168 mem_fn(&X::g6)(rcx, 1, 2, 3, 4, 5, 6);
169 mem_fn(&X::g6)(&x, 1, 2, 3, 4, 5, 6);
170 mem_fn(&X::g6)(pcx, 1, 2, 3, 4, 5, 6);
171 mem_fn(&X::g6)(sp, 1, 2, 3, 4, 5, 6);
172
173 mem_fn(&X::f7)(x, 1, 2, 3, 4, 5, 6, 7);
174 mem_fn(&X::f7)(&x, 1, 2, 3, 4, 5, 6, 7);
175 mem_fn(&X::f7)(sp, 1, 2, 3, 4, 5, 6, 7);
176
177 mem_fn(&X::g7)(x, 1, 2, 3, 4, 5, 6, 7);
178 mem_fn(&X::g7)(rcx, 1, 2, 3, 4, 5, 6, 7);
179 mem_fn(&X::g7)(&x, 1, 2, 3, 4, 5, 6, 7);
180 mem_fn(&X::g7)(pcx, 1, 2, 3, 4, 5, 6, 7);
181 mem_fn(&X::g7)(sp, 1, 2, 3, 4, 5, 6, 7);
182
183 mem_fn(&X::f8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
184 mem_fn(&X::f8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
185 mem_fn(&X::f8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
186
187 mem_fn(&X::g8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
188 mem_fn(&X::g8)(rcx, 1, 2, 3, 4, 5, 6, 7, 8);
189 mem_fn(&X::g8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
190 mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);
191 mem_fn(&X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
192
193 return detect_errors(x.hash == 17610 && sp->hash == 2155);
194 }
195
196 #endif
197