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 //  bind_mf2_test.cpp - test for member functions w/ the type<> syntax
12 //
13 //  Copyright (c) 2005, 2008 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/bind.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     mutable unsigned int hash;
37 
XX38     X(): hash(0) {}
39 
f0X40     int f0() { f1(17); return 0; }
g0X41     int g0() const { g1(17); return 0; }
42 
f1X43     int f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
g1X44     int g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
45 
f2X46     int f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
g2X47     int g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
48 
f3X49     int f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
g3X50     int g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
51 
f4X52     int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
g4X53     int g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
54 
f5X55     int f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
g5X56     int g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
57 
f6X58     int f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
g6X59     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; }
60 
f7X61     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; }
g7X62     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; }
63 
f8X64     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; }
g8X65     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; }
66 };
67 
member_function_test()68 void member_function_test()
69 {
70     using namespace boost;
71 
72     X x;
73 
74     // 0
75 
76     bind( type<void>(), &X::f0, &x )();
77     bind( type<void>(), &X::f0, ref(x) )();
78 
79     bind( type<void>(), &X::g0, &x )();
80     bind( type<void>(), &X::g0, x )();
81     bind( type<void>(), &X::g0, ref(x) )();
82 
83     // 1
84 
85     bind( type<void>(), &X::f1, &x, 1 )();
86     bind( type<void>(), &X::f1, ref(x), 1 )();
87 
88     bind( type<void>(), &X::g1, &x, 1 )();
89     bind( type<void>(), &X::g1, x, 1 )();
90     bind( type<void>(), &X::g1, ref(x), 1 )();
91 
92     // 2
93 
94     bind( type<void>(), &X::f2, &x, 1, 2 )();
95     bind( type<void>(), &X::f2, ref(x), 1, 2 )();
96 
97     bind( type<void>(), &X::g2, &x, 1, 2 )();
98     bind( type<void>(), &X::g2, x, 1, 2 )();
99     bind( type<void>(), &X::g2, ref(x), 1, 2 )();
100 
101     // 3
102 
103     bind( type<void>(), &X::f3, &x, 1, 2, 3 )();
104     bind( type<void>(), &X::f3, ref(x), 1, 2, 3 )();
105 
106     bind( type<void>(), &X::g3, &x, 1, 2, 3 )();
107     bind( type<void>(), &X::g3, x, 1, 2, 3 )();
108     bind( type<void>(), &X::g3, ref(x), 1, 2, 3 )();
109 
110     // 4
111 
112     bind( type<void>(), &X::f4, &x, 1, 2, 3, 4 )();
113     bind( type<void>(), &X::f4, ref(x), 1, 2, 3, 4 )();
114 
115     bind( type<void>(), &X::g4, &x, 1, 2, 3, 4 )();
116     bind( type<void>(), &X::g4, x, 1, 2, 3, 4 )();
117     bind( type<void>(), &X::g4, ref(x), 1, 2, 3, 4 )();
118 
119     // 5
120 
121     bind( type<void>(), &X::f5, &x, 1, 2, 3, 4, 5 )();
122     bind( type<void>(), &X::f5, ref(x), 1, 2, 3, 4, 5 )();
123 
124     bind( type<void>(), &X::g5, &x, 1, 2, 3, 4, 5 )();
125     bind( type<void>(), &X::g5, x, 1, 2, 3, 4, 5 )();
126     bind( type<void>(), &X::g5, ref(x), 1, 2, 3, 4, 5 )();
127 
128     // 6
129 
130     bind( type<void>(), &X::f6, &x, 1, 2, 3, 4, 5, 6 )();
131     bind( type<void>(), &X::f6, ref(x), 1, 2, 3, 4, 5, 6 )();
132 
133     bind( type<void>(), &X::g6, &x, 1, 2, 3, 4, 5, 6 )();
134     bind( type<void>(), &X::g6, x, 1, 2, 3, 4, 5, 6 )();
135     bind( type<void>(), &X::g6, ref(x), 1, 2, 3, 4, 5, 6 )();
136 
137     // 7
138 
139     bind( type<void>(), &X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
140     bind( type<void>(), &X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
141 
142     bind( type<void>(), &X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
143     bind( type<void>(), &X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
144     bind( type<void>(), &X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
145 
146     // 8
147 
148     bind( type<void>(), &X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8 )();
149     bind( type<void>(), &X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
150 
151     bind( type<void>(), &X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8 )();
152     bind( type<void>(), &X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8 )();
153     bind( type<void>(), &X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
154 
155     BOOST_TEST( x.hash == 23558 );
156 }
157 
main()158 int main()
159 {
160     member_function_test();
161     return boost::report_errors();
162 }
163