/*============================================================================= Copyright (c) 2001-2007 Joel de Guzman Copyright (c) 2004 Daniel Wallin Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ #ifndef PHOENIX_SCOPE_LAMBDA_HPP #define PHOENIX_SCOPE_LAMBDA_HPP #include #include #include #include #include #include #include #include namespace boost { namespace phoenix { template struct lambda_eval : Base { template struct result { typedef typename Base::template result >::type result_type; typedef typename detail::unwrap_local_reference::type type; }; lambda_eval( Base const& base , OuterEnv const& outer_env , Locals const& locals) : Base(base) , outer_env(outer_env) , locals(locals) {} template typename result::type eval(Env const& env) const { typedef typename result::type RT; return RT(Base::eval( scoped_environment( env, outer_env, locals))); } OuterEnv outer_env; mutable Locals locals; }; template struct lambda_actor { typedef typename mpl::fold< Vars , mpl::false_ , detail::compute_no_nullary >::type no_nullary; template struct result { typedef typename fusion::result_of::as_vector< typename fusion::result_of::transform< Vars , detail::initialize_local >::type >::type locals_type; typedef actor > type; }; lambda_actor(Base const& f, Vars const& vars) : f(f), vars(vars) {} template typename result::type eval(Env const& env) const { typedef typename result::type result_type; return result_type( f, env, fusion::as_vector( fusion::transform( vars , detail::initialize_local(env) ))); } Base f; Vars vars; }; template struct lambda_actor_gen { template actor > const operator[](actor const& f) const { return lambda_actor(f, vars); } lambda_actor_gen(Vars const& vars) : vars(vars) {} Vars vars; }; template struct local_variable; // forward struct assign_eval; // forward struct lambda_gen : lambda_actor_gen< fusion::vector<> , detail::map_local_index_to_tuple<> > { typedef lambda_actor_gen< fusion::vector<> , detail::map_local_index_to_tuple<> > base_type; lambda_gen() : base_type(fusion::vector<>()) { } template lambda_actor_gen< fusion::vector , detail::map_local_index_to_tuple > operator()( actor, V0> > > const& a0 ) const { return fusion::vector(fusion::at_c<1>(a0)); } template lambda_actor_gen< fusion::vector , detail::map_local_index_to_tuple > operator()( actor, V0> > > const& a0 , actor, V1> > > const& a1 ) const { return fusion::vector(fusion::at_c<1>(a0), fusion::at_c<1>(a1)); } // Bring in the rest... #define PHOENIX_LOCAL_GEN_NAME lambda_actor_gen #include #undef PHOENIX_LOCAL_GEN_NAME }; lambda_gen const lambda = lambda_gen(); }} #endif