1 /*=============================================================================
2 Copyright (c) 2001-2007 Joel de Guzman
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #include <iostream>
8 #include <cmath>
9 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/noncopyable.hpp>
11 #include <boost/phoenix/core.hpp>
12 #include <boost/phoenix/operator.hpp>
13 #include <boost/phoenix/bind.hpp>
14
15 namespace test
16 {
17 struct x //: boost::noncopyable // test non-copyable (hold this by reference)
18 {
19 void
testtest::x20 test() const
21 {
22 std::cout << "Test binding member functions...\n";
23 }
24 };
25
26 struct y //: boost::noncopyable // test non-copyable (hold this by reference)
27 {
28 int
negatetest::y29 negate(int n) const
30 {
31 return -n;
32 }
33 };
34
35 struct z //: boost::noncopyable // test non-copyable (hold this by reference)
36 {
37 int
plustest::z38 plus(int a, int b) const
39 {
40 return a + b;
41 }
42 };
43
44 struct zz //: boost::noncopyable // test non-copyable (hold this by reference)
45 {
46 int
plus3test::zz47 plus3(int a, int b, int c) const
48 {
49 return a + b + c;
50 }
51 };
52 }
53
54 int
main()55 main()
56 {
57 using boost::phoenix::bind;
58 using boost::phoenix::ref;
59 using boost::phoenix::arg_names::arg1;
60 using boost::phoenix::arg_names::arg2;
61 using boost::phoenix::arg_names::arg3;
62
63 int a = 123;
64 int b = 256;
65 test::x x_;
66 test::y y_;
67 test::z z_;
68 test::zz zz_;
69
70 bind(&test::x::test, x_)();
71 BOOST_TEST(bind(&test::y::negate, y_, arg1)(a) == -a);
72 BOOST_TEST(bind(&test::z::plus, arg1, arg2, arg3)(z_, a, b) == a+b);
73 BOOST_TEST(bind(&test::zz::plus3, zz_, arg1, arg2, arg3)(a, b, a) == a+b+a);
74 BOOST_TEST(bind(&test::y::negate, &y_, 777)(a) == -777);
75
76 return boost::report_errors();
77 }
78