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_derived_test.cpp - tests mem_fn.hpp with derived objects |
12 | // |
13 | // Copyright (c) 2001, 2002 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 B |
35 | { |
36 | mutable unsigned int hash; |
37 | |
38 | B(): hash(0) {} |
39 | |
40 | int f0() { f1(a1: 17); return 0; } |
41 | int g0() const { g1(a1: 17); return 0; } |
42 | |
43 | int f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; } |
44 | int g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; } |
45 | |
46 | int f2(int a1, int a2) { f1(a1); f1(a1: a2); return 0; } |
47 | int g2(int a1, int a2) const { g1(a1); g1(a1: a2); return 0; } |
48 | |
49 | int f3(int a1, int a2, int a3) { f2(a1, a2); f1(a1: a3); return 0; } |
50 | int g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a1: a3); return 0; } |
51 | |
52 | int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a1: a4); return 0; } |
53 | int g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a1: a4); return 0; } |
54 | |
55 | int f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a1: a5); return 0; } |
56 | int g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a1: a5); return 0; } |
57 | |
58 | int f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a1: a6); return 0; } |
59 | int g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a1: a6); return 0; } |
60 | |
61 | int f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a1: a7); return 0; } |
62 | 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(a1: a7); return 0; } |
63 | |
64 | 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(a1: a8); return 0; } |
65 | 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(a1: a8); return 0; } |
66 | }; |
67 | |
68 | struct X: public B |
69 | { |
70 | }; |
71 | |
72 | int detect_errors(bool x) |
73 | { |
74 | if(x) |
75 | { |
76 | std::cerr << "no errors detected.\n" ; |
77 | return 0; |
78 | } |
79 | else |
80 | { |
81 | std::cerr << "test failed.\n" ; |
82 | return 1; |
83 | } |
84 | } |
85 | |
86 | int main() |
87 | { |
88 | using boost::mem_fn; |
89 | |
90 | X x; |
91 | |
92 | X const & rcx = x; |
93 | X const * pcx = &x; |
94 | |
95 | boost::shared_ptr<X> sp(new X); |
96 | |
97 | mem_fn(pmf: &X::f0)(x); |
98 | mem_fn(pmf: &X::f0)(&x); |
99 | mem_fn(pmf: &X::f0)(sp); |
100 | |
101 | mem_fn(pmf: &X::g0)(x); |
102 | mem_fn(pmf: &X::g0)(rcx); |
103 | mem_fn(pmf: &X::g0)(&x); |
104 | mem_fn(pmf: &X::g0)(pcx); |
105 | mem_fn(pmf: &X::g0)(sp); |
106 | |
107 | mem_fn(pmf: &X::f1)(x, 1); |
108 | mem_fn(pmf: &X::f1)(&x, 1); |
109 | mem_fn(pmf: &X::f1)(sp, 1); |
110 | |
111 | mem_fn(pmf: &X::g1)(x, 1); |
112 | mem_fn(pmf: &X::g1)(rcx, 1); |
113 | mem_fn(pmf: &X::g1)(&x, 1); |
114 | mem_fn(pmf: &X::g1)(pcx, 1); |
115 | mem_fn(pmf: &X::g1)(sp, 1); |
116 | |
117 | mem_fn(pmf: &X::f2)(x, 1, 2); |
118 | mem_fn(pmf: &X::f2)(&x, 1, 2); |
119 | mem_fn(pmf: &X::f2)(sp, 1, 2); |
120 | |
121 | mem_fn(pmf: &X::g2)(x, 1, 2); |
122 | mem_fn(pmf: &X::g2)(rcx, 1, 2); |
123 | mem_fn(pmf: &X::g2)(&x, 1, 2); |
124 | mem_fn(pmf: &X::g2)(pcx, 1, 2); |
125 | mem_fn(pmf: &X::g2)(sp, 1, 2); |
126 | |
127 | mem_fn(pmf: &X::f3)(x, 1, 2, 3); |
128 | mem_fn(pmf: &X::f3)(&x, 1, 2, 3); |
129 | mem_fn(pmf: &X::f3)(sp, 1, 2, 3); |
130 | |
131 | mem_fn(pmf: &X::g3)(x, 1, 2, 3); |
132 | mem_fn(pmf: &X::g3)(rcx, 1, 2, 3); |
133 | mem_fn(pmf: &X::g3)(&x, 1, 2, 3); |
134 | mem_fn(pmf: &X::g3)(pcx, 1, 2, 3); |
135 | mem_fn(pmf: &X::g3)(sp, 1, 2, 3); |
136 | |
137 | mem_fn(pmf: &X::f4)(x, 1, 2, 3, 4); |
138 | mem_fn(pmf: &X::f4)(&x, 1, 2, 3, 4); |
139 | mem_fn(pmf: &X::f4)(sp, 1, 2, 3, 4); |
140 | |
141 | mem_fn(pmf: &X::g4)(x, 1, 2, 3, 4); |
142 | mem_fn(pmf: &X::g4)(rcx, 1, 2, 3, 4); |
143 | mem_fn(pmf: &X::g4)(&x, 1, 2, 3, 4); |
144 | mem_fn(pmf: &X::g4)(pcx, 1, 2, 3, 4); |
145 | mem_fn(pmf: &X::g4)(sp, 1, 2, 3, 4); |
146 | |
147 | mem_fn(pmf: &X::f5)(x, 1, 2, 3, 4, 5); |
148 | mem_fn(pmf: &X::f5)(&x, 1, 2, 3, 4, 5); |
149 | mem_fn(pmf: &X::f5)(sp, 1, 2, 3, 4, 5); |
150 | |
151 | mem_fn(pmf: &X::g5)(x, 1, 2, 3, 4, 5); |
152 | mem_fn(pmf: &X::g5)(rcx, 1, 2, 3, 4, 5); |
153 | mem_fn(pmf: &X::g5)(&x, 1, 2, 3, 4, 5); |
154 | mem_fn(pmf: &X::g5)(pcx, 1, 2, 3, 4, 5); |
155 | mem_fn(pmf: &X::g5)(sp, 1, 2, 3, 4, 5); |
156 | |
157 | mem_fn(pmf: &X::f6)(x, 1, 2, 3, 4, 5, 6); |
158 | mem_fn(pmf: &X::f6)(&x, 1, 2, 3, 4, 5, 6); |
159 | mem_fn(pmf: &X::f6)(sp, 1, 2, 3, 4, 5, 6); |
160 | |
161 | mem_fn(pmf: &X::g6)(x, 1, 2, 3, 4, 5, 6); |
162 | mem_fn(pmf: &X::g6)(rcx, 1, 2, 3, 4, 5, 6); |
163 | mem_fn(pmf: &X::g6)(&x, 1, 2, 3, 4, 5, 6); |
164 | mem_fn(pmf: &X::g6)(pcx, 1, 2, 3, 4, 5, 6); |
165 | mem_fn(pmf: &X::g6)(sp, 1, 2, 3, 4, 5, 6); |
166 | |
167 | mem_fn(pmf: &X::f7)(x, 1, 2, 3, 4, 5, 6, 7); |
168 | mem_fn(pmf: &X::f7)(&x, 1, 2, 3, 4, 5, 6, 7); |
169 | mem_fn(pmf: &X::f7)(sp, 1, 2, 3, 4, 5, 6, 7); |
170 | |
171 | mem_fn(pmf: &X::g7)(x, 1, 2, 3, 4, 5, 6, 7); |
172 | mem_fn(pmf: &X::g7)(rcx, 1, 2, 3, 4, 5, 6, 7); |
173 | mem_fn(pmf: &X::g7)(&x, 1, 2, 3, 4, 5, 6, 7); |
174 | mem_fn(pmf: &X::g7)(pcx, 1, 2, 3, 4, 5, 6, 7); |
175 | mem_fn(pmf: &X::g7)(sp, 1, 2, 3, 4, 5, 6, 7); |
176 | |
177 | mem_fn(pmf: &X::f8)(x, 1, 2, 3, 4, 5, 6, 7, 8); |
178 | mem_fn(pmf: &X::f8)(&x, 1, 2, 3, 4, 5, 6, 7, 8); |
179 | mem_fn(pmf: &X::f8)(sp, 1, 2, 3, 4, 5, 6, 7, 8); |
180 | |
181 | mem_fn(pmf: &X::g8)(x, 1, 2, 3, 4, 5, 6, 7, 8); |
182 | mem_fn(pmf: &X::g8)(rcx, 1, 2, 3, 4, 5, 6, 7, 8); |
183 | mem_fn(pmf: &X::g8)(&x, 1, 2, 3, 4, 5, 6, 7, 8); |
184 | mem_fn(pmf: &X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8); |
185 | mem_fn(pmf: &X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8); |
186 | |
187 | return detect_errors(x: mem_fn(pm: &X::hash)(x) == 17610 && mem_fn(pm: &X::hash)(sp) == 2155); |
188 | } |
189 | |