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 |
19 | func_impl(int arg1, bool arg2, double arg3) |
20 | { |
21 | using namespace std; |
22 | return abs (x: static_cast<int>((arg2 ? arg1 : 2 * arg1) * arg3)); |
23 | } |
24 | |
25 | int main() |
26 | { |
27 | using boost::function; |
28 | using namespace boost::lambda; |
29 | |
30 | function <unsigned(bool, double)> f1 = bind(a1&: func_impl, a2: 15, a3: _1, a4: _2); |
31 | BOOST_TEST_EQ( f1(true, 2.0), 30u ); |
32 | |
33 | function <unsigned(double)> f2 = boost::lambda::bind(a1: f1, a2: false, a3: _1); |
34 | BOOST_TEST_EQ( f2(2.0), 60u ); |
35 | |
36 | function <unsigned()> f3 = boost::lambda::bind(a1: f2, a2: 4.0); |
37 | BOOST_TEST_EQ( f3(), 120u ); |
38 | |
39 | return boost::report_errors(); |
40 | } |
41 | |