adapt_function.hpp 7.0 KB

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