blob: 257aaa9df5c474b9beede719202cba212c34815c [file] [log] [blame]
Brian Silvermance4aa8d2018-08-04 23:36:03 -07001#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.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
34struct X
35{
36 // SGI-related compilers have odd compiler-synthesized ctors dtors
37 #ifdef __PATHSCALE__
38 X() {}
39 ~X() {}
40 #endif
41
42 int operator()()
43 {
44 return 17041;
45 }
46
47 int operator()() const
48 {
49 return -17041;
50 }
51
52 int operator()(int x1)
53 {
54 return x1;
55 }
56
57 int operator()(int x1) const
58 {
59 return -x1;
60 }
61
62 int operator()(int x1, int x2)
63 {
64 return x1+x2;
65 }
66
67 int operator()(int x1, int x2) const
68 {
69 return -(x1+x2);
70 }
71
72 int operator()(int x1, int x2, int x3)
73 {
74 return x1+x2+x3;
75 }
76
77 int operator()(int x1, int x2, int x3) const
78 {
79 return -(x1+x2+x3);
80 }
81
82 int operator()(int x1, int x2, int x3, int x4)
83 {
84 return x1+x2+x3+x4;
85 }
86
87 int operator()(int x1, int x2, int x3, int x4) const
88 {
89 return -(x1+x2+x3+x4);
90 }
91
92 int operator()(int x1, int x2, int x3, int x4, int x5)
93 {
94 return x1+x2+x3+x4+x5;
95 }
96
97 int operator()(int x1, int x2, int x3, int x4, int x5) const
98 {
99 return -(x1+x2+x3+x4+x5);
100 }
101
102 int operator()(int x1, int x2, int x3, int x4, int x5, int x6)
103 {
104 return x1+x2+x3+x4+x5+x6;
105 }
106
107 int operator()(int x1, int x2, int x3, int x4, int x5, int x6) const
108 {
109 return -(x1+x2+x3+x4+x5+x6);
110 }
111
112 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7)
113 {
114 return x1+x2+x3+x4+x5+x6+x7;
115 }
116
117 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) const
118 {
119 return -(x1+x2+x3+x4+x5+x6+x7);
120 }
121
122 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
123 {
124 return x1+x2+x3+x4+x5+x6+x7+x8;
125 }
126
127 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) const
128 {
129 return -(x1+x2+x3+x4+x5+x6+x7+x8);
130 }
131
132 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9)
133 {
134 return x1+x2+x3+x4+x5+x6+x7+x8+x9;
135 }
136
137 int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) const
138 {
139 return -(x1+x2+x3+x4+x5+x6+x7+x8+x9);
140 }
141};
142
143template<class F> void test(F f, int r)
144{
145 F const & cf = f;
146 BOOST_TEST( cf() == -r );
147 BOOST_TEST( f() == r );
148}
149
150int main()
151{
152 test( boost::bind<int>( X() ), 17041 );
153 test( boost::bind<int>( X(), 1 ), 1 );
154 test( boost::bind<int>( X(), 1, 2 ), 1+2 );
155 test( boost::bind<int>( X(), 1, 2, 3 ), 1+2+3 );
156 test( boost::bind<int>( X(), 1, 2, 3, 4 ), 1+2+3+4 );
157 test( boost::bind<int>( X(), 1, 2, 3, 4, 5 ), 1+2+3+4+5 );
158 test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6 ), 1+2+3+4+5+6 );
159 test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7 ), 1+2+3+4+5+6+7 );
160 test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 1+2+3+4+5+6+7+8 );
161 test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 1+2+3+4+5+6+7+8+9 );
162
163 return boost::report_errors();
164}