1 /*=============================================================================
2 Copyright (c) 2001-2007 Joel de Guzman
3 Copyright (c) 2004 Daniel Wallin
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 PHOENIX_SCOPE_LET_HPP
9 #define PHOENIX_SCOPE_LET_HPP
11 #include <boost/spirit/home/phoenix/core/limits.hpp>
12 #include <boost/spirit/home/phoenix/core/composite.hpp>
13 #include <boost/spirit/home/phoenix/scope/scoped_environment.hpp>
14 #include <boost/spirit/home/phoenix/scope/detail/local_variable.hpp>
15 #include <boost/spirit/home/phoenix/detail/local_reference.hpp>
16 #include <boost/spirit/home/phoenix/core/actor.hpp>
17 #include <boost/fusion/include/transform.hpp>
18 #include <boost/fusion/include/as_vector.hpp>
19 #include <boost/mpl/eval_if.hpp>
20 #include <boost/mpl/bool.hpp>
22 namespace boost { namespace phoenix
24 template <typename Base, typename Vars, typename Map>
25 struct let_actor : Base
31 , detail::compute_no_nullary
35 template <typename Env>
39 fusion::result_of::as_vector<
40 typename fusion::result_of::transform<
42 , detail::initialize_local<Env>
47 typedef typename Base::template
48 result<scoped_environment<Env, Env, locals_type, Map> >::type
52 detail::unwrap_local_reference<result_type>::type
56 let_actor(Base const& base, Vars const& vars)
57 : Base(base), vars(vars) {}
59 template <typename Env>
60 typename result<Env>::type
61 eval(Env const& env) const
64 fusion::result_of::as_vector<
65 typename fusion::result_of::transform<
67 , detail::initialize_local<Env>
76 , detail::initialize_local<Env>(env)));
78 typedef typename result<Env>::type RT;
80 scoped_environment<Env, Env, locals_type, Map>(
89 template <typename Vars, typename Map>
92 template <typename Base>
93 actor<let_actor<Base, Vars, Map> > const
94 operator[](actor<Base> const& base) const
96 return let_actor<Base, Vars, Map>(base, vars);
99 let_actor_gen(Vars const& vars)
105 template <typename Key>
106 struct local_variable; // forward
107 struct assign_eval; // forward
111 template <typename K0, typename V0>
114 , detail::map_local_index_to_tuple<K0>
117 actor<composite<assign_eval, fusion::vector<local_variable<K0>, V0> > > const& a0
120 return fusion::vector<V0>(fusion::at_c<1>(a0));
123 template <typename K0, typename K1, typename V0, typename V1>
125 fusion::vector<V0, V1>
126 , detail::map_local_index_to_tuple<K0, K1>
129 actor<composite<assign_eval, fusion::vector<local_variable<K0>, V0> > > const& a0
130 , actor<composite<assign_eval, fusion::vector<local_variable<K1>, V1> > > const& a1
133 return fusion::vector<V0, V1>(fusion::at_c<1>(a0), fusion::at_c<1>(a1));
136 // Bring in the rest...
137 #define PHOENIX_LOCAL_GEN_NAME let_actor_gen
138 #include <boost/spirit/home/phoenix/scope/detail/local_gen.hpp>
139 #undef PHOENIX_LOCAL_GEN_NAME
142 let_gen const let = let_gen();