function.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*==============================================================================
  2. Copyright (c) 2001-2010 Joel de Guzman
  3. Copyright (c) 2010 Eric Niebler
  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_FUNCTION_HPP
  9. #define BOOST_PHOENIX_FUNCTION_FUNCTION_HPP
  10. #include <boost/phoenix/config.hpp>
  11. #include <boost/phoenix/core/limits.hpp>
  12. #include <boost/phoenix/core/detail/function_eval.hpp>
  13. #include <boost/utility/result_of.hpp>
  14. namespace boost { namespace phoenix
  15. {
  16. /////////////////////////////////////////////////////////////////////////////
  17. // Functions
  18. /////////////////////////////////////////////////////////////////////////////
  19. namespace expression
  20. {
  21. #if defined(BOOST_PHOENIX_NO_VARIADIC_FUNCTION)
  22. template <typename F, BOOST_PHOENIX_typename_A_void(BOOST_PHOENIX_ACTOR_LIMIT)>
  23. struct function
  24. : detail::expression::function_eval<F, BOOST_PHOENIX_A(BOOST_PHOENIX_ACTOR_LIMIT)>
  25. {};
  26. #else
  27. // TODO:
  28. #endif
  29. }
  30. // functor which returns our lazy function call extension
  31. template<typename F>
  32. struct function
  33. {
  34. BOOST_CONSTEXPR function()
  35. : f()
  36. {}
  37. BOOST_CONSTEXPR function(F f_)
  38. : f(f_)
  39. {}
  40. template <typename Sig>
  41. struct result;
  42. #if defined(BOOST_PHOENIX_NO_VARIADIC_FUNCTION)
  43. typename detail::expression::function_eval<F>::type const
  44. operator()() const
  45. {
  46. return detail::expression::function_eval<F>::make(f);
  47. }
  48. // Bring in the rest
  49. #include <boost/phoenix/function/detail/cpp03/function_operator.hpp>
  50. // Solves the result problem for F(X)
  51. template <typename This, typename A0>
  52. struct result<This(A0)>
  53. : detail::expression::function_eval<F,
  54. typename boost::remove_reference<A0>::type>
  55. {};
  56. // Solves the result problem for F(X,Y)
  57. template <typename This, typename A0, typename A1>
  58. struct result<This(A0,A1)>
  59. : detail::expression::function_eval<F,
  60. typename boost::remove_reference<A0>::type,
  61. typename boost::remove_reference<A1>::type>
  62. {};
  63. // Solves the result problem for F(X,Y,Z)
  64. template <typename This, typename A0, typename A1, typename A2>
  65. struct result<This(A0,A1,A2)>
  66. : detail::expression::function_eval<F,
  67. typename boost::remove_reference<A0>::type,
  68. typename boost::remove_reference<A1>::type,
  69. typename boost::remove_reference<A2>::type>
  70. {};
  71. // Solves the result problem for F(W,X,Y,Z)
  72. template <typename This, typename A0, typename A1,
  73. typename A2, typename A3>
  74. struct result<This(A0,A1,A2,A3)>
  75. : detail::expression::function_eval<F,
  76. typename boost::remove_reference<A0>::type,
  77. typename boost::remove_reference<A1>::type,
  78. typename boost::remove_reference<A2>::type,
  79. typename boost::remove_reference<A3>::type>
  80. {};
  81. // Solves the result problem for F(V,W,X,Y,Z)
  82. template <typename This, typename A0, typename A1,
  83. typename A2, typename A3,typename A4>
  84. struct result<This(A0,A1,A2,A3,A4)>
  85. : detail::expression::function_eval<F,
  86. typename boost::remove_reference<A0>::type,
  87. typename boost::remove_reference<A1>::type,
  88. typename boost::remove_reference<A2>::type,
  89. typename boost::remove_reference<A3>::type,
  90. typename boost::remove_reference<A4>::type>
  91. {};
  92. // Solves the result problem for F(U,V,W,X,Y,Z)
  93. template <typename This, typename A0, typename A1,
  94. typename A2, typename A3,typename A4,
  95. typename A5>
  96. struct result<This(A0,A1,A2,A3,A4,A5)>
  97. : detail::expression::function_eval<F,
  98. typename boost::remove_reference<A0>::type,
  99. typename boost::remove_reference<A1>::type,
  100. typename boost::remove_reference<A2>::type,
  101. typename boost::remove_reference<A3>::type,
  102. typename boost::remove_reference<A4>::type,
  103. typename boost::remove_reference<A5>::type>
  104. {};
  105. // Solves the result problem for F(T,U,V,W,X,Y,Z)
  106. template <typename This, typename A0, typename A1,
  107. typename A2, typename A3,typename A4,
  108. typename A5, typename A6>
  109. struct result<This(A0,A1,A2,A3,A4,A5,A6)>
  110. : detail::expression::function_eval<F,
  111. typename boost::remove_reference<A0>::type,
  112. typename boost::remove_reference<A1>::type,
  113. typename boost::remove_reference<A2>::type,
  114. typename boost::remove_reference<A3>::type,
  115. typename boost::remove_reference<A4>::type,
  116. typename boost::remove_reference<A5>::type,
  117. typename boost::remove_reference<A6>::type>
  118. {};
  119. #else
  120. // TODO:
  121. #endif
  122. F f;
  123. };
  124. }
  125. template<typename F>
  126. struct result_of<phoenix::function<F>()>
  127. : phoenix::detail::expression::function_eval<F>
  128. {};
  129. }
  130. #endif