bind_function_tests.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #include <iostream>
  7. #include <cmath>
  8. #include <boost/detail/lightweight_test.hpp>
  9. #include <boost/phoenix/core.hpp>
  10. #include <boost/phoenix/bind.hpp>
  11. namespace test
  12. {
  13. void
  14. test()
  15. {
  16. std::cout << "Test binding functions...\n";
  17. }
  18. int
  19. negate(int n)
  20. {
  21. return -n;
  22. }
  23. int
  24. plus(int a, int b)
  25. {
  26. return a + b;
  27. }
  28. int
  29. plus4(int a, int b, int c, int d)
  30. {
  31. return a + b + c + d;
  32. }
  33. }
  34. int
  35. main()
  36. {
  37. using boost::phoenix::bind;
  38. using boost::phoenix::arg_names::arg1;
  39. using boost::phoenix::arg_names::arg2;
  40. int a = 123;
  41. int b = 256;
  42. bind(test::test)();
  43. BOOST_TEST(bind(test::negate, arg1)(a) == -a);
  44. BOOST_TEST(bind(test::plus, arg1, arg2)(a, b) == a+b);
  45. BOOST_TEST(bind(test::plus4, arg1, arg2, 3, 4)(a, b) == a+b+3+4);
  46. return boost::report_errors();
  47. }