function.hpp 5.2 KB

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