1 // Boost.Function library
2
3 // Copyright Douglas Gregor 2002-2003. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8 // For more information, see http://www.boost.org
9
10 #include <boost/function.hpp>
11 #include <boost/lambda/lambda.hpp>
12 #include <boost/lambda/bind.hpp>
13 #include <boost/core/lightweight_test.hpp>
14 #include <iostream>
15 #include <cstdlib>
16
17
18 static unsigned
func_impl(int arg1,bool arg2,double arg3)19 func_impl(int arg1, bool arg2, double arg3)
20 {
21 using namespace std;
22 return abs (static_cast<int>((arg2 ? arg1 : 2 * arg1) * arg3));
23 }
24
main()25 int main()
26 {
27 using boost::function;
28 using namespace boost::lambda;
29
30 function <unsigned(bool, double)> f1 = bind(func_impl, 15, _1, _2);
31 BOOST_TEST_EQ( f1(true, 2.0), 30 );
32
33 function <unsigned(double)> f2 = boost::lambda::bind(f1, false, _1);
34 BOOST_TEST_EQ( f2(2.0), 60 );
35
36 function <unsigned()> f3 = boost::lambda::bind(f2, 4.0);
37 BOOST_TEST_EQ( f3(), 120 );
38
39 return boost::report_errors();
40 }
41