call.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*==============================================================================
  2. Copyright (c) 2005-2010 Joel de Guzman
  3. Copyright (c) 2011 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_CORE_CALL_HPP
  8. #define BOOST_PHOENIX_CORE_CALL_HPP
  9. #include <boost/phoenix/core/limits.hpp>
  10. #include <boost/phoenix/core/environment.hpp>
  11. #include <boost/proto/proto_fwd.hpp>
  12. #include <boost/proto/traits.hpp>
  13. #include <boost/proto/transform/impl.hpp>
  14. #ifndef BOOST_PHOENIX_NO_VARIADIC_CALL
  15. # include <boost/phoenix/core/detail/index_sequence.hpp>
  16. #endif
  17. namespace boost { namespace phoenix
  18. {
  19. namespace detail
  20. {
  21. template <
  22. typename Fun
  23. , typename Expr
  24. , typename State
  25. , typename Data
  26. , long Arity = proto::arity_of<Expr>::value
  27. >
  28. struct call_impl;
  29. template <typename Fun, typename Expr, typename State, typename Data>
  30. struct call_impl<Fun, Expr, State, Data, 0>
  31. : proto::transform_impl<Expr, State, Data>
  32. {
  33. typedef
  34. typename boost::phoenix::result_of::context<State, Data>::type
  35. context_type;
  36. typedef
  37. typename boost::result_of<
  38. Fun(Expr, context_type)
  39. >::type
  40. result_type;
  41. result_type operator()(
  42. typename call_impl::expr_param e
  43. , typename call_impl::state_param s
  44. , typename call_impl::data_param d
  45. ) const
  46. {
  47. return Fun()(e, boost::phoenix::context(s, d));
  48. }
  49. };
  50. #ifdef BOOST_PHOENIX_NO_VARIADIC_CALL
  51. #include <boost/phoenix/core/detail/cpp03/call.hpp>
  52. #else
  53. template <typename Fun, typename Expr, typename State, typename Data
  54. , typename Indices>
  55. struct call_impl_;
  56. template <typename Fun, typename Expr, typename State, typename Data
  57. , std::size_t... Indices>
  58. struct call_impl_<Fun, Expr, State, Data, index_sequence<Indices...> >
  59. : proto::transform_impl<Expr, State, Data>
  60. {
  61. typedef
  62. typename boost::phoenix::result_of::context<State, Data>::type
  63. context_type;
  64. template <std::size_t Index>
  65. struct result_of_expr
  66. {
  67. typedef
  68. typename proto::result_of::child_c<Expr, Index>::type
  69. type;
  70. };
  71. typedef
  72. typename boost::result_of<
  73. Fun(
  74. typename result_of_expr<Indices>::type...
  75. , context_type
  76. )
  77. >::type
  78. result_type;
  79. result_type operator()(
  80. typename call_impl_::expr_param e
  81. , typename call_impl_::state_param s
  82. , typename call_impl_::data_param d
  83. ) const
  84. {
  85. return
  86. Fun()(
  87. proto::child_c<Indices>(e)...
  88. , boost::phoenix::context(s, d)
  89. );
  90. }
  91. };
  92. template <typename Fun, typename Expr, typename State, typename Data, long Arity>
  93. struct call_impl
  94. : call_impl_<Fun, Expr, State, Data, typename make_index_sequence<Arity>::type>
  95. {
  96. };
  97. #endif
  98. }
  99. template <typename Fun, typename Dummy = void>
  100. struct call
  101. : proto::transform<call<Fun> >
  102. {
  103. template <typename Expr, typename State, typename Data>
  104. struct impl
  105. : detail::call_impl<Fun, Expr, State, Data>
  106. {};
  107. };
  108. }
  109. namespace proto
  110. {
  111. template <typename Fun, typename Dummy>
  112. struct is_callable<phoenix::call<Fun, Dummy> > : mpl::true_ {};
  113. }
  114. }
  115. #endif