• 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_const_test.cpp - test const bind objects
12 //
13 //  Copyright (c) 2001-2004 Peter Dimov and Multi Media Ltd.
14 //  Copyright (c) 2001 David Abrahams
15 //
16 // Distributed under the Boost Software License, Version 1.0. (See
17 // accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
19 //
20 
21 #include <boost/bind/bind.hpp>
22 #include <boost/ref.hpp>
23 #include <boost/core/lightweight_test.hpp>
24 
25 using namespace boost::placeholders;
26 
27 //
28 
f_0()29 long f_0()
30 {
31     return 17041L;
32 }
33 
f_1(long a)34 long f_1(long a)
35 {
36     return a;
37 }
38 
f_2(long a,long b)39 long f_2(long a, long b)
40 {
41     return a + 10 * b;
42 }
43 
f_3(long a,long b,long c)44 long f_3(long a, long b, long c)
45 {
46     return a + 10 * b + 100 * c;
47 }
48 
f_4(long a,long b,long c,long d)49 long f_4(long a, long b, long c, long d)
50 {
51     return a + 10 * b + 100 * c + 1000 * d;
52 }
53 
f_5(long a,long b,long c,long d,long e)54 long f_5(long a, long b, long c, long d, long e)
55 {
56     return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
57 }
58 
f_6(long a,long b,long c,long d,long e,long f)59 long f_6(long a, long b, long c, long d, long e, long f)
60 {
61     return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
62 }
63 
f_7(long a,long b,long c,long d,long e,long f,long g)64 long f_7(long a, long b, long c, long d, long e, long f, long g)
65 {
66     return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
67 }
68 
f_8(long a,long b,long c,long d,long e,long f,long g,long h)69 long f_8(long a, long b, long c, long d, long e, long f, long g, long h)
70 {
71     return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
72 }
73 
f_9(long a,long b,long c,long d,long e,long f,long g,long h,long i)74 long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
75 {
76     return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
77 }
78 
79 long global_result;
80 
fv_0()81 void fv_0()
82 {
83     global_result = 17041L;
84 }
85 
fv_1(long a)86 void fv_1(long a)
87 {
88     global_result = a;
89 }
90 
fv_2(long a,long b)91 void fv_2(long a, long b)
92 {
93     global_result = a + 10 * b;
94 }
95 
fv_3(long a,long b,long c)96 void fv_3(long a, long b, long c)
97 {
98     global_result = a + 10 * b + 100 * c;
99 }
100 
fv_4(long a,long b,long c,long d)101 void fv_4(long a, long b, long c, long d)
102 {
103     global_result = a + 10 * b + 100 * c + 1000 * d;
104 }
105 
fv_5(long a,long b,long c,long d,long e)106 void fv_5(long a, long b, long c, long d, long e)
107 {
108     global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
109 }
110 
fv_6(long a,long b,long c,long d,long e,long f)111 void fv_6(long a, long b, long c, long d, long e, long f)
112 {
113     global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
114 }
115 
fv_7(long a,long b,long c,long d,long e,long f,long g)116 void fv_7(long a, long b, long c, long d, long e, long f, long g)
117 {
118     global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
119 }
120 
fv_8(long a,long b,long c,long d,long e,long f,long g,long h)121 void fv_8(long a, long b, long c, long d, long e, long f, long g, long h)
122 {
123     global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
124 }
125 
fv_9(long a,long b,long c,long d,long e,long f,long g,long h,long i)126 void fv_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
127 {
128     global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
129 }
130 
test(F const & f,A const & a)131 template<class F, class A> long test(F const & f, A const & a)
132 {
133     return f(a);
134 }
135 
testv(F const & f,A const & a)136 template<class F, class A> long testv(F const & f, A const & a)
137 {
138     f(a);
139     return global_result;
140 }
141 
function_test()142 void function_test()
143 {
144     using namespace boost;
145 
146     int const i = 1;
147 
148     BOOST_TEST( test( bind(f_0), i ) == 17041L );
149     BOOST_TEST( test( bind(f_1, _1), i ) == 1L );
150     BOOST_TEST( test( bind(f_2, _1, 2), i ) == 21L );
151     BOOST_TEST( test( bind(f_3, _1, 2, 3), i ) == 321L );
152     BOOST_TEST( test( bind(f_4, _1, 2, 3, 4), i ) == 4321L );
153     BOOST_TEST( test( bind(f_5, _1, 2, 3, 4, 5), i ) == 54321L );
154     BOOST_TEST( test( bind(f_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
155     BOOST_TEST( test( bind(f_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
156     BOOST_TEST( test( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
157     BOOST_TEST( test( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
158 
159     BOOST_TEST( testv( bind(fv_0), i ) == 17041L );
160     BOOST_TEST( testv( bind(fv_1, _1), i ) == 1L );
161     BOOST_TEST( testv( bind(fv_2, _1, 2), i ) == 21L );
162     BOOST_TEST( testv( bind(fv_3, _1, 2, 3), i ) == 321L );
163     BOOST_TEST( testv( bind(fv_4, _1, 2, 3, 4), i ) == 4321L );
164     BOOST_TEST( testv( bind(fv_5, _1, 2, 3, 4, 5), i ) == 54321L );
165     BOOST_TEST( testv( bind(fv_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
166     BOOST_TEST( testv( bind(fv_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
167     BOOST_TEST( testv( bind(fv_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
168     BOOST_TEST( testv( bind(fv_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
169 }
170 
main()171 int main()
172 {
173     function_test();
174     return boost::report_errors();
175 }
176