adapt_function.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*==============================================================================
  2. Copyright (c) 2005-2010 Joel de Guzman
  3. Copyright (c) 2010 Thomas Heller
  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. #ifndef BOOST_PHOENIX_FUNCTION_ADAPT_FUNCTION_HPP
  8. #define BOOST_PHOENIX_FUNCTION_ADAPT_FUNCTION_HPP
  9. #include <boost/phoenix/core/limits.hpp>
  10. #include <boost/phoenix/core/detail/function_eval.hpp>
  11. #include <boost/preprocessor/repetition/repeat.hpp>
  12. #define BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY(RESULT, NAME, FUNC) \
  13. namespace detail \
  14. { \
  15. struct BOOST_PP_CAT(NAME, _impl_nullary) \
  16. { \
  17. typedef RESULT result_type; \
  18. \
  19. result_type \
  20. operator()() const \
  21. { \
  22. return FUNC(); \
  23. } \
  24. }; \
  25. } \
  26. \
  27. boost::phoenix::detail::expression::function_eval< \
  28. detail:: BOOST_PP_CAT(NAME, _impl_nullary) \
  29. >::type const \
  30. inline NAME() \
  31. { \
  32. return boost::phoenix::detail::expression:: \
  33. function_eval<detail:: BOOST_PP_CAT(NAME, _impl_nullary)> \
  34. ::make(detail:: BOOST_PP_CAT(NAME, _impl_nullary)()); \
  35. } \
  36. /**/
  37. #define BOOST_PHOENIX_ADAPT_FUNCTION(RESULT, NAME, FUNC, N) \
  38. namespace detail \
  39. { \
  40. struct BOOST_PP_CAT(BOOST_PP_CAT(NAME, _impl_), N) \
  41. { \
  42. template <typename Sig> \
  43. struct result; \
  44. \
  45. template <typename This, BOOST_PHOENIX_typename_A(N)> \
  46. struct result<This(BOOST_PHOENIX_A(N))> \
  47. {typedef RESULT type;}; \
  48. \
  49. template <BOOST_PHOENIX_typename_A(N)> \
  50. RESULT \
  51. operator()(BOOST_PHOENIX_A_ref_a(N)) const \
  52. { \
  53. return FUNC(BOOST_PHOENIX_a(N)); \
  54. } \
  55. }; \
  56. } \
  57. \
  58. template <BOOST_PHOENIX_typename_A(N)> \
  59. typename \
  60. boost::phoenix::detail::expression::function_eval< \
  61. detail:: BOOST_PP_CAT(BOOST_PP_CAT(NAME, _impl_), N) \
  62. , BOOST_PHOENIX_A(N)>::type const \
  63. inline NAME(BOOST_PHOENIX_A_const_ref_a(N)) \
  64. { \
  65. return boost::phoenix::detail::expression:: \
  66. function_eval< \
  67. detail:: BOOST_PP_CAT(BOOST_PP_CAT(NAME, _impl_), N) \
  68. , BOOST_PHOENIX_A(N) \
  69. >::make( \
  70. detail:: BOOST_PP_CAT(BOOST_PP_CAT(NAME, _impl_), N)() \
  71. , BOOST_PHOENIX_a(N) \
  72. ); \
  73. } \
  74. /**/
  75. #define BOOST_PHOENIX_ADAPT_FUNCTION_VARARG(RESULT, NAME, FUNC) \
  76. BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY(NAME, FUNC) \
  77. BOOST_PP_REPEAT_FROM_TO( \
  78. 1 \
  79. , BOOST_PHOENIX_LIMIT \
  80. , BOOST_PHOENIX_ADAPT_FUNCTION_VARARG_R \
  81. , (RESULT, NAME, FUNC) \
  82. ) \
  83. /**/
  84. #define BOOST_PHOENIX_ADAPT_FUNCTION_VARARG_R(Z, N, D) \
  85. BOOST_PHOENIX_ADAPT_FUNCTION( \
  86. BOOST_PP_TUPLE_ELEM(3, 0, D) \
  87. , BOOST_PP_TUPLE_ELEM(3, 1, D) \
  88. , BOOST_PP_TUPLE_ELEM(3, 2, D) \
  89. , N \
  90. ) \
  91. /**/
  92. #endif