/Src/Dependencies/Boost/libs/phoenix/test/function/adapt_function.cpp

http://hadesmem.googlecode.com/ · C++ · 74 lines · 58 code · 10 blank · 6 comment · 4 complexity · e9591efcd41b63331d7ebee1a649cc44 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2011 Thomas Heller
  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/function.hpp>
  11. namespace impl
  12. {
  13. void
  14. test()
  15. {
  16. std::cout << "Test adapting 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. template <typename T>
  29. T
  30. plus(T a, T b, T c)
  31. {
  32. return a + b + c;
  33. }
  34. int
  35. plus4(int a, int b, int c, int d)
  36. {
  37. return a + b + c + d;
  38. }
  39. }
  40. BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY(void, test, impl::test)
  41. BOOST_PHOENIX_ADAPT_FUNCTION(int, negate, impl::negate, 1)
  42. BOOST_PHOENIX_ADAPT_FUNCTION(int, plus, impl::plus, 2)
  43. BOOST_PHOENIX_ADAPT_FUNCTION(
  44. typename boost::remove_reference<A0>::type
  45. , plus
  46. , impl::plus
  47. , 3
  48. )
  49. BOOST_PHOENIX_ADAPT_FUNCTION(int, plus4, impl::plus4, 4)
  50. int
  51. main()
  52. {
  53. using boost::phoenix::arg_names::arg1;
  54. using boost::phoenix::arg_names::arg2;
  55. int a = 123;
  56. int b = 256;
  57. test()();
  58. BOOST_TEST(::negate(arg1)(a) == -a);
  59. BOOST_TEST(::plus(arg1, arg2)(a, b) == a+b);
  60. BOOST_TEST(::plus(arg1, arg2, 3)(a, b) == a+b+3);
  61. BOOST_TEST(plus4(arg1, arg2, 3, 4)(a, b) == a+b+3+4);
  62. return boost::report_errors();
  63. }