/Src/Dependencies/Boost/boost/spirit/home/phoenix/scope/let.hpp

http://hadesmem.googlecode.com/ · C++ Header · 145 lines · 118 code · 19 blank · 8 comment · 0 complexity · 325b6acea7c3cc06e463d5ce850ed55a MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Copyright (c) 2004 Daniel Wallin
  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 PHOENIX_SCOPE_LET_HPP
  8. #define PHOENIX_SCOPE_LET_HPP
  9. #include <boost/spirit/home/phoenix/core/limits.hpp>
  10. #include <boost/spirit/home/phoenix/core/composite.hpp>
  11. #include <boost/spirit/home/phoenix/scope/scoped_environment.hpp>
  12. #include <boost/spirit/home/phoenix/scope/detail/local_variable.hpp>
  13. #include <boost/spirit/home/phoenix/detail/local_reference.hpp>
  14. #include <boost/spirit/home/phoenix/core/actor.hpp>
  15. #include <boost/fusion/include/transform.hpp>
  16. #include <boost/fusion/include/as_vector.hpp>
  17. #include <boost/mpl/eval_if.hpp>
  18. #include <boost/mpl/bool.hpp>
  19. namespace boost { namespace phoenix
  20. {
  21. template <typename Base, typename Vars, typename Map>
  22. struct let_actor : Base
  23. {
  24. typedef typename
  25. mpl::fold<
  26. Vars
  27. , mpl::false_
  28. , detail::compute_no_nullary
  29. >::type
  30. no_nullary;
  31. template <typename Env>
  32. struct result
  33. {
  34. typedef typename
  35. fusion::result_of::as_vector<
  36. typename fusion::result_of::transform<
  37. Vars
  38. , detail::initialize_local<Env>
  39. >::type
  40. >::type
  41. locals_type;
  42. typedef typename Base::template
  43. result<scoped_environment<Env, Env, locals_type, Map> >::type
  44. result_type;
  45. typedef typename
  46. detail::unwrap_local_reference<result_type>::type
  47. type;
  48. };
  49. let_actor(Base const& base, Vars const& vars)
  50. : Base(base), vars(vars) {}
  51. template <typename Env>
  52. typename result<Env>::type
  53. eval(Env const& env) const
  54. {
  55. typedef typename
  56. fusion::result_of::as_vector<
  57. typename fusion::result_of::transform<
  58. Vars
  59. , detail::initialize_local<Env>
  60. >::type
  61. >::type
  62. locals_type;
  63. locals_type locals =
  64. fusion::as_vector(
  65. fusion::transform(
  66. vars
  67. , detail::initialize_local<Env>(env)));
  68. typedef typename result<Env>::type RT;
  69. return RT(Base::eval(
  70. scoped_environment<Env, Env, locals_type, Map>(
  71. env
  72. , env
  73. , locals)));
  74. }
  75. Vars vars;
  76. };
  77. template <typename Vars, typename Map>
  78. struct let_actor_gen
  79. {
  80. template <typename Base>
  81. actor<let_actor<Base, Vars, Map> > const
  82. operator[](actor<Base> const& base) const
  83. {
  84. return let_actor<Base, Vars, Map>(base, vars);
  85. }
  86. let_actor_gen(Vars const& vars)
  87. : vars(vars) {}
  88. Vars vars;
  89. };
  90. template <typename Key>
  91. struct local_variable; // forward
  92. struct assign_eval; // forward
  93. struct let_gen
  94. {
  95. template <typename K0, typename V0>
  96. let_actor_gen<
  97. fusion::vector<V0>
  98. , detail::map_local_index_to_tuple<K0>
  99. >
  100. operator()(
  101. actor<composite<assign_eval, fusion::vector<local_variable<K0>, V0> > > const& a0
  102. ) const
  103. {
  104. return fusion::vector<V0>(fusion::at_c<1>(a0));
  105. }
  106. template <typename K0, typename K1, typename V0, typename V1>
  107. let_actor_gen<
  108. fusion::vector<V0, V1>
  109. , detail::map_local_index_to_tuple<K0, K1>
  110. >
  111. operator()(
  112. actor<composite<assign_eval, fusion::vector<local_variable<K0>, V0> > > const& a0
  113. , actor<composite<assign_eval, fusion::vector<local_variable<K1>, V1> > > const& a1
  114. ) const
  115. {
  116. return fusion::vector<V0, V1>(fusion::at_c<1>(a0), fusion::at_c<1>(a1));
  117. }
  118. // Bring in the rest...
  119. #define PHOENIX_LOCAL_GEN_NAME let_actor_gen
  120. #include <boost/spirit/home/phoenix/scope/detail/local_gen.hpp>
  121. #undef PHOENIX_LOCAL_GEN_NAME
  122. };
  123. let_gen const let = let_gen();
  124. }}
  125. #endif