• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/bind.hpp>
21 #include <boost/core/lightweight_test.hpp>
22 
23 //
24 
25 struct X
26 {
27     mutable unsigned int hash;
28 
XX29     X(): hash(0) {}
30 
f0X31     int f0() { f1(17); return 0; }
g0X32     int g0() const { g1(17); return 0; }
33 
f1X34     int f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
g1X35     int g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
36 
f2X37     int f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
g2X38     int g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
39 
f3X40     int f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
g3X41     int g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
42 
f4X43     int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
g4X44     int g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
45 
f5X46     int f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
g5X47     int g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
48 
f6X49     int f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
g6X50     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; }
51 
f7X52     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; }
g7X53     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; }
54 
f8X55     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; }
g8X56     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; }
57 };
58 
member_function_test()59 void member_function_test()
60 {
61     using namespace boost;
62 
63     X x;
64 
65     // 0
66 
67     bind( type<void>(), &X::f0, &x )();
68     bind( type<void>(), &X::f0, ref(x) )();
69 
70     bind( type<void>(), &X::g0, &x )();
71     bind( type<void>(), &X::g0, x )();
72     bind( type<void>(), &X::g0, ref(x) )();
73 
74     // 1
75 
76     bind( type<void>(), &X::f1, &x, 1 )();
77     bind( type<void>(), &X::f1, ref(x), 1 )();
78 
79     bind( type<void>(), &X::g1, &x, 1 )();
80     bind( type<void>(), &X::g1, x, 1 )();
81     bind( type<void>(), &X::g1, ref(x), 1 )();
82 
83     // 2
84 
85     bind( type<void>(), &X::f2, &x, 1, 2 )();
86     bind( type<void>(), &X::f2, ref(x), 1, 2 )();
87 
88     bind( type<void>(), &X::g2, &x, 1, 2 )();
89     bind( type<void>(), &X::g2, x, 1, 2 )();
90     bind( type<void>(), &X::g2, ref(x), 1, 2 )();
91 
92     // 3
93 
94     bind( type<void>(), &X::f3, &x, 1, 2, 3 )();
95     bind( type<void>(), &X::f3, ref(x), 1, 2, 3 )();
96 
97     bind( type<void>(), &X::g3, &x, 1, 2, 3 )();
98     bind( type<void>(), &X::g3, x, 1, 2, 3 )();
99     bind( type<void>(), &X::g3, ref(x), 1, 2, 3 )();
100 
101     // 4
102 
103     bind( type<void>(), &X::f4, &x, 1, 2, 3, 4 )();
104     bind( type<void>(), &X::f4, ref(x), 1, 2, 3, 4 )();
105 
106     bind( type<void>(), &X::g4, &x, 1, 2, 3, 4 )();
107     bind( type<void>(), &X::g4, x, 1, 2, 3, 4 )();
108     bind( type<void>(), &X::g4, ref(x), 1, 2, 3, 4 )();
109 
110     // 5
111 
112     bind( type<void>(), &X::f5, &x, 1, 2, 3, 4, 5 )();
113     bind( type<void>(), &X::f5, ref(x), 1, 2, 3, 4, 5 )();
114 
115     bind( type<void>(), &X::g5, &x, 1, 2, 3, 4, 5 )();
116     bind( type<void>(), &X::g5, x, 1, 2, 3, 4, 5 )();
117     bind( type<void>(), &X::g5, ref(x), 1, 2, 3, 4, 5 )();
118 
119     // 6
120 
121     bind( type<void>(), &X::f6, &x, 1, 2, 3, 4, 5, 6 )();
122     bind( type<void>(), &X::f6, ref(x), 1, 2, 3, 4, 5, 6 )();
123 
124     bind( type<void>(), &X::g6, &x, 1, 2, 3, 4, 5, 6 )();
125     bind( type<void>(), &X::g6, x, 1, 2, 3, 4, 5, 6 )();
126     bind( type<void>(), &X::g6, ref(x), 1, 2, 3, 4, 5, 6 )();
127 
128     // 7
129 
130     bind( type<void>(), &X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
131     bind( type<void>(), &X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
132 
133     bind( type<void>(), &X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
134     bind( type<void>(), &X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
135     bind( type<void>(), &X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
136 
137     // 8
138 
139     bind( type<void>(), &X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8 )();
140     bind( type<void>(), &X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
141 
142     bind( type<void>(), &X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8 )();
143     bind( type<void>(), &X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8 )();
144     bind( type<void>(), &X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
145 
146     BOOST_TEST( x.hash == 23558 );
147 }
148 
main()149 int main()
150 {
151     member_function_test();
152     return boost::report_errors();
153 }
154