1 /*==============================================================================
2     Copyright (c) 2004 Peter Dimov
3     Copyright (c) 2005-2010 Joel de Guzman
4     Copyright (c) 2010 Thomas Heller
5 
6     Distributed under the Boost Software License, Version 1.0. (See accompanying
7     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 ==============================================================================*/
9 
10 #include <boost/config.hpp>
11 
12 #if defined(BOOST_MSVC)
13 #pragma warning(disable: 4786)  // identifier truncated in debug info
14 #pragma warning(disable: 4710)  // function not inlined
15 #pragma warning(disable: 4711)  // function selected for automatic inline expansion
16 #pragma warning(disable: 4514)  // unreferenced inline removed
17 #endif
18 
19 #include <boost/phoenix/core.hpp>
20 #include <boost/phoenix/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     typedef int result_type;
37 
operator ()X38     int operator()()
39     {
40         return 17041;
41     }
42 
operator ()X43     int operator()() const
44     {
45         return -17041;
46     }
47 
operator ()X48     int operator()(int x1)
49     {
50         return x1;
51     }
52 
operator ()X53     int operator()(int x1) const
54     {
55         return -x1;
56     }
57 
operator ()X58     int operator()(int x1, int x2)
59     {
60         return x1+x2;
61     }
62 
operator ()X63     int operator()(int x1, int x2) const
64     {
65         return -(x1+x2);
66     }
67 
operator ()X68     int operator()(int x1, int x2, int x3)
69     {
70         return x1+x2+x3;
71     }
72 
operator ()X73     int operator()(int x1, int x2, int x3) const
74     {
75         return -(x1+x2+x3);
76     }
77 
operator ()X78     int operator()(int x1, int x2, int x3, int x4)
79     {
80         return x1+x2+x3+x4;
81     }
82 
operator ()X83     int operator()(int x1, int x2, int x3, int x4) const
84     {
85         return -(x1+x2+x3+x4);
86     }
87 
operator ()X88     int operator()(int x1, int x2, int x3, int x4, int x5)
89     {
90         return x1+x2+x3+x4+x5;
91     }
92 
operator ()X93     int operator()(int x1, int x2, int x3, int x4, int x5) const
94     {
95         return -(x1+x2+x3+x4+x5);
96     }
97 
operator ()X98     int operator()(int x1, int x2, int x3, int x4, int x5, int x6)
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) const
104     {
105         return -(x1+x2+x3+x4+x5+x6);
106     }
107 
operator ()X108     int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7)
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) const
114     {
115         return -(x1+x2+x3+x4+x5+x6+x7);
116     }
117 
operator ()X118     int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
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) const
124     {
125         return -(x1+x2+x3+x4+x5+x6+x7+x8);
126     }
127 
operator ()X128     int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9)
129     {
130         return x1+x2+x3+x4+x5+x6+x7+x8+x9;
131     }
132 
operator ()X133     int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) const
134     {
135         return -(x1+x2+x3+x4+x5+x6+x7+x8+x9);
136     }
137 };
138 
test(F f,int r)139 template<class F> void test(F f, int r)
140 {
141     F const & cf = f;
142     BOOST_TEST( cf() == -r );
143     BOOST_TEST( f() == r );
144 
145 }
146 
main()147 int main()
148 {
149     using boost::phoenix::bind;
150     using boost::phoenix::ref;
151     using boost::phoenix::cref;
152 
153     test( bind(X()), 17041);
154     test( bind(X(), 1), 1);
155     test( bind(X(), 1, 2), 1+2);
156     test( bind(X(), 1, 2, 3), 1+2+3);
157     test( bind(X(), 1, 2, 3, 4), 1+2+3+4);
158     test( bind(X(), 1, 2, 3, 4, 5), 1+2+3+4+5);
159     test( bind(X(), 1, 2, 3, 4, 5, 6), 1+2+3+4+5+6);
160     test( bind(X(), 1, 2, 3, 4, 5, 6, 7), 1+2+3+4+5+6+7);
161     test( bind(X(), 1, 2, 3, 4, 5, 6, 7, 8), 1+2+3+4+5+6+7+8);
162     test( bind(X(), 1, 2, 3, 4, 5, 6, 7, 8, 9), 1+2+3+4+5+6+7+8+9);
163 
164     return boost::report_errors();
165 }
166