]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #include <boost/config.hpp> |
2 | ||
b32b8144 FG |
3 | #ifndef BOOST_MSVC |
4 | ||
5 | int main() | |
6 | { | |
7 | } | |
8 | ||
9 | #else | |
10 | ||
7c673cae FG |
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 | // bind_cdecl_mf_test.cpp - test for bind.hpp + __cdecl (member functions) | |
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/bind.hpp> | |
31 | ||
32 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) | |
33 | #pragma warning(push, 3) | |
34 | #endif | |
35 | ||
36 | #include <iostream> | |
37 | ||
38 | #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) | |
39 | #pragma warning(pop) | |
40 | #endif | |
41 | ||
42 | #include <boost/detail/lightweight_test.hpp> | |
43 | ||
44 | struct X | |
45 | { | |
46 | mutable unsigned int hash; | |
47 | ||
48 | X(): hash(0) {} | |
49 | ||
50 | int __cdecl f0() { f1(17); return 0; } | |
51 | int __cdecl g0() const { g1(17); return 0; } | |
52 | ||
53 | int __cdecl f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; } | |
54 | int __cdecl g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; } | |
55 | ||
56 | int __cdecl f2(int a1, int a2) { f1(a1); f1(a2); return 0; } | |
57 | int __cdecl g2(int a1, int a2) const { g1(a1); g1(a2); return 0; } | |
58 | ||
59 | int __cdecl f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; } | |
60 | int __cdecl g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; } | |
61 | ||
62 | int __cdecl f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; } | |
63 | int __cdecl g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; } | |
64 | ||
65 | int __cdecl f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; } | |
66 | int __cdecl g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; } | |
67 | ||
68 | 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; } | |
69 | 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 | ||
71 | 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; } | |
72 | 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 | ||
74 | 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; } | |
75 | 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 | ||
78 | void member_function_test() | |
79 | { | |
80 | using namespace boost; | |
81 | ||
82 | X x; | |
83 | ||
84 | // 0 | |
85 | ||
86 | bind(&X::f0, &x)(); | |
87 | bind(&X::f0, ref(x))(); | |
88 | ||
89 | bind(&X::g0, &x)(); | |
90 | bind(&X::g0, x)(); | |
91 | bind(&X::g0, ref(x))(); | |
92 | ||
93 | // 1 | |
94 | ||
95 | bind(&X::f1, &x, 1)(); | |
96 | bind(&X::f1, ref(x), 1)(); | |
97 | ||
98 | bind(&X::g1, &x, 1)(); | |
99 | bind(&X::g1, x, 1)(); | |
100 | bind(&X::g1, ref(x), 1)(); | |
101 | ||
102 | // 2 | |
103 | ||
104 | bind(&X::f2, &x, 1, 2)(); | |
105 | bind(&X::f2, ref(x), 1, 2)(); | |
106 | ||
107 | bind(&X::g2, &x, 1, 2)(); | |
108 | bind(&X::g2, x, 1, 2)(); | |
109 | bind(&X::g2, ref(x), 1, 2)(); | |
110 | ||
111 | // 3 | |
112 | ||
113 | bind(&X::f3, &x, 1, 2, 3)(); | |
114 | bind(&X::f3, ref(x), 1, 2, 3)(); | |
115 | ||
116 | bind(&X::g3, &x, 1, 2, 3)(); | |
117 | bind(&X::g3, x, 1, 2, 3)(); | |
118 | bind(&X::g3, ref(x), 1, 2, 3)(); | |
119 | ||
120 | // 4 | |
121 | ||
122 | bind(&X::f4, &x, 1, 2, 3, 4)(); | |
123 | bind(&X::f4, ref(x), 1, 2, 3, 4)(); | |
124 | ||
125 | bind(&X::g4, &x, 1, 2, 3, 4)(); | |
126 | bind(&X::g4, x, 1, 2, 3, 4)(); | |
127 | bind(&X::g4, ref(x), 1, 2, 3, 4)(); | |
128 | ||
129 | // 5 | |
130 | ||
131 | bind(&X::f5, &x, 1, 2, 3, 4, 5)(); | |
132 | bind(&X::f5, ref(x), 1, 2, 3, 4, 5)(); | |
133 | ||
134 | bind(&X::g5, &x, 1, 2, 3, 4, 5)(); | |
135 | bind(&X::g5, x, 1, 2, 3, 4, 5)(); | |
136 | bind(&X::g5, ref(x), 1, 2, 3, 4, 5)(); | |
137 | ||
138 | // 6 | |
139 | ||
140 | bind(&X::f6, &x, 1, 2, 3, 4, 5, 6)(); | |
141 | bind(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)(); | |
142 | ||
143 | bind(&X::g6, &x, 1, 2, 3, 4, 5, 6)(); | |
144 | bind(&X::g6, x, 1, 2, 3, 4, 5, 6)(); | |
145 | bind(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)(); | |
146 | ||
147 | // 7 | |
148 | ||
149 | bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)(); | |
150 | bind(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)(); | |
151 | ||
152 | bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)(); | |
153 | bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)(); | |
154 | bind(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)(); | |
155 | ||
156 | // 8 | |
157 | ||
158 | bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)(); | |
159 | bind(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)(); | |
160 | ||
161 | bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)(); | |
162 | bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)(); | |
163 | bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)(); | |
164 | ||
165 | BOOST_TEST( x.hash == 23558 ); | |
166 | } | |
167 | ||
168 | int main() | |
169 | { | |
170 | member_function_test(); | |
171 | return boost::report_errors(); | |
172 | } | |
b32b8144 FG |
173 | |
174 | #endif |