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_cv_test.cpp
12 //
13 // Copyright (c) 2004 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 // SGI-related compilers have odd compiler-synthesized ctors dtors
28 #ifdef __PATHSCALE__
XX29 X() {}
~XX30 ~X() {}
31 #endif
32
operator ()X33 int operator()()
34 {
35 return 17041;
36 }
37
operator ()X38 int operator()() const
39 {
40 return -17041;
41 }
42
operator ()X43 int operator()(int x1)
44 {
45 return x1;
46 }
47
operator ()X48 int operator()(int x1) const
49 {
50 return -x1;
51 }
52
operator ()X53 int operator()(int x1, int x2)
54 {
55 return x1+x2;
56 }
57
operator ()X58 int operator()(int x1, int x2) const
59 {
60 return -(x1+x2);
61 }
62
operator ()X63 int operator()(int x1, int x2, int x3)
64 {
65 return x1+x2+x3;
66 }
67
operator ()X68 int operator()(int x1, int x2, int x3) const
69 {
70 return -(x1+x2+x3);
71 }
72
operator ()X73 int operator()(int x1, int x2, int x3, int x4)
74 {
75 return x1+x2+x3+x4;
76 }
77
operator ()X78 int operator()(int x1, int x2, int x3, int x4) const
79 {
80 return -(x1+x2+x3+x4);
81 }
82
operator ()X83 int operator()(int x1, int x2, int x3, int x4, int x5)
84 {
85 return x1+x2+x3+x4+x5;
86 }
87
operator ()X88 int operator()(int x1, int x2, int x3, int x4, int x5) const
89 {
90 return -(x1+x2+x3+x4+x5);
91 }
92
operator ()X93 int operator()(int x1, int x2, int x3, int x4, int x5, int x6)
94 {
95 return x1+x2+x3+x4+x5+x6;
96 }
97
operator ()X98 int operator()(int x1, int x2, int x3, int x4, int x5, int x6) const
99 {
100 return -(x1+x2+x3+x4+x5+x6);
101 }
102
operator ()X103 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7)
104 {
105 return x1+x2+x3+x4+x5+x6+x7;
106 }
107
operator ()X108 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) const
109 {
110 return -(x1+x2+x3+x4+x5+x6+x7);
111 }
112
operator ()X113 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
114 {
115 return x1+x2+x3+x4+x5+x6+x7+x8;
116 }
117
operator ()X118 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) const
119 {
120 return -(x1+x2+x3+x4+x5+x6+x7+x8);
121 }
122
operator ()X123 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9)
124 {
125 return x1+x2+x3+x4+x5+x6+x7+x8+x9;
126 }
127
operator ()X128 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) const
129 {
130 return -(x1+x2+x3+x4+x5+x6+x7+x8+x9);
131 }
132 };
133
test(F f,int r)134 template<class F> void test(F f, int r)
135 {
136 F const & cf = f;
137 BOOST_TEST( cf() == -r );
138 BOOST_TEST( f() == r );
139 }
140
main()141 int main()
142 {
143 test( boost::bind<int>( X() ), 17041 );
144 test( boost::bind<int>( X(), 1 ), 1 );
145 test( boost::bind<int>( X(), 1, 2 ), 1+2 );
146 test( boost::bind<int>( X(), 1, 2, 3 ), 1+2+3 );
147 test( boost::bind<int>( X(), 1, 2, 3, 4 ), 1+2+3+4 );
148 test( boost::bind<int>( X(), 1, 2, 3, 4, 5 ), 1+2+3+4+5 );
149 test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6 ), 1+2+3+4+5+6 );
150 test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7 ), 1+2+3+4+5+6+7 );
151 test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 1+2+3+4+5+6+7+8 );
152 test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 1+2+3+4+5+6+7+8+9 );
153
154 return boost::report_errors();
155 }
156