• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/phoenix/core.hpp>
11 #include <boost/phoenix/bind.hpp>
12 
13 namespace test
14 {
15     void
test()16     test()
17     {
18         std::cout << "Test binding functions...\n";
19     }
20 
21     int
negate(int n)22     negate(int n)
23     {
24         return -n;
25     }
26 
27     int
plus(int a,int b)28     plus(int a, int b)
29     {
30         return a + b;
31     }
32 
33     int
plus4(int a,int b,int c,int d)34     plus4(int a, int b, int c, int d)
35     {
36         return a + b + c + d;
37     }
38 }
39 
40 int
main()41 main()
42 {
43     using boost::phoenix::bind;
44     using boost::phoenix::arg_names::arg1;
45     using boost::phoenix::arg_names::arg2;
46 
47     int a = 123;
48     int b = 256;
49 
50     bind(test::test)();
51     BOOST_TEST(bind(test::negate, arg1)(a) == -a);
52     BOOST_TEST(bind(test::plus, arg1, arg2)(a, b) == a+b);
53     BOOST_TEST(bind(test::plus4, arg1, arg2, 3, 4)(a, b) == a+b+3+4);
54 
55     return boost::report_errors();
56 }
57