/Src/Dependencies/Boost/libs/spirit/phoenix/test/bind/bind_member_function_tests.cpp

http://hadesmem.googlecode.com/ · C++ · 76 lines · 62 code · 8 blank · 6 comment · 4 complexity · e05ec5ff26bae9f61cbd51a364b71cce MD5 · raw file

  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/noncopyable.hpp>
  10. #include <boost/spirit/include/phoenix_core.hpp>
  11. #include <boost/spirit/include/phoenix_operator.hpp>
  12. #include <boost/spirit/include/phoenix_bind.hpp>
  13. using namespace boost::phoenix;
  14. using namespace boost::phoenix::arg_names;
  15. using namespace std;
  16. namespace phx = boost::phoenix;
  17. namespace test
  18. {
  19. struct x : boost::noncopyable // test non-copyable (hold this by reference)
  20. {
  21. void
  22. test() const
  23. {
  24. cout << "Test binding member functions...\n";
  25. }
  26. };
  27. struct y : boost::noncopyable // test non-copyable (hold this by reference)
  28. {
  29. int
  30. negate(int n)
  31. {
  32. return -n;
  33. }
  34. };
  35. struct z : boost::noncopyable // test non-copyable (hold this by reference)
  36. {
  37. int
  38. plus(int a, int b)
  39. {
  40. return a + b;
  41. }
  42. };
  43. struct zz : boost::noncopyable // test non-copyable (hold this by reference)
  44. {
  45. int
  46. plus3(int a, int b, int c)
  47. {
  48. return a + b + c;
  49. }
  50. };
  51. }
  52. int
  53. main()
  54. {
  55. int a = 123;
  56. int b = 256;
  57. test::x x_;
  58. test::y y_;
  59. test::z z_;
  60. test::zz zz_;
  61. bind(&test::x::test, x_)();
  62. BOOST_TEST(bind(&test::y::negate, y_, arg1)(a) == -a);
  63. BOOST_TEST(bind(&test::z::plus, arg1, arg2, arg3)(z_, a, b) == a+b);
  64. BOOST_TEST(bind(&test::zz::plus3, zz_, arg1, arg2, arg3)(a, b, a) == a+b+a);
  65. BOOST_TEST(bind(&test::y::negate, &y_, 777)(a) == -777);
  66. return boost::report_errors();
  67. }