From b4cde4f58b3af89a8a529e2a4c1bc62b54882a85 Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Thu, 10 Jun 2010 06:11:39 +0000 Subject: [PATCH] + the environment concept + better result_of modularization [SVN r62711] --- include/boost/phoenix/core/actor_result.hpp | 2 +- include/boost/phoenix/core/argument.hpp | 52 ++++++++------ include/boost/phoenix/core/as_actor.hpp | 77 ++++++++++++--------- include/boost/phoenix/core/environment.hpp | 43 ++++++++++++ include/boost/phoenix/core/is_actor.hpp | 2 +- 5 files changed, 121 insertions(+), 55 deletions(-) create mode 100644 include/boost/phoenix/core/environment.hpp diff --git a/include/boost/phoenix/core/actor_result.hpp b/include/boost/phoenix/core/actor_result.hpp index ff26fff..c878a57 100644 --- a/include/boost/phoenix/core/actor_result.hpp +++ b/include/boost/phoenix/core/actor_result.hpp @@ -19,7 +19,7 @@ namespace boost { namespace phoenix //////////////////////////////////////////////////////////////////////////// // Return type computation //////////////////////////////////////////////////////////////////////////// - template + template struct actor_result; template diff --git a/include/boost/phoenix/core/argument.hpp b/include/boost/phoenix/core/argument.hpp index c68832c..7928f04 100644 --- a/include/boost/phoenix/core/argument.hpp +++ b/include/boost/phoenix/core/argument.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -22,41 +23,48 @@ namespace boost { namespace phoenix { // function for evaluating argument placeholders like: _1 - struct argument + + namespace result_of { - template class Actor = actor > - struct as_actor : boost::phoenix::as_actor - {}; - - template - struct result; - - template - struct result - : fusion::result_of::at< + template + struct argument + : result_of::get_environment_argument< Env, typename boost::result_of::type> {}; + } + + struct argument + { + template + struct result; - template - typename boost::result_of::type - operator()(Env & env, N &) const + template + struct result + : result_of::argument + {}; + + template + typename result_of::argument::type + operator()(Env& env, N& n) const { - return fusion::at< - typename boost::result_of::type>(env); + return get_environment_argument()(env, eval(n)); } }; + + template + struct make_argument : boost::phoenix::as_actor {}; namespace placeholders { // Phoenix style names - argument::as_actor >::result_type const arg1 = {}; - argument::as_actor >::result_type const arg2 = {}; - argument::as_actor >::result_type const arg3 = {}; + make_argument >::type const arg1 = {}; + make_argument >::type const arg2 = {}; + make_argument >::type const arg3 = {}; // BLL style names - argument::as_actor >::result_type const _1 = {}; - argument::as_actor >::result_type const _2 = {}; - argument::as_actor >::result_type const _3 = {}; + make_argument >::type const _1 = {}; + make_argument >::type const _2 = {}; + make_argument >::type const _3 = {}; } namespace arg_names diff --git a/include/boost/phoenix/core/as_actor.hpp b/include/boost/phoenix/core/as_actor.hpp index 5a0edce..612ee18 100644 --- a/include/boost/phoenix/core/as_actor.hpp +++ b/include/boost/phoenix/core/as_actor.hpp @@ -42,6 +42,7 @@ namespace boost { namespace phoenix , env>::type base_type; typedef Actor result_type; + typedef result_type type; result_type operator()() const @@ -63,6 +64,7 @@ namespace boost { namespace phoenix , A0>::type base_type; typedef Actor result_type; + typedef result_type type; result_type operator()( typename call_traits::param_type a0 ) const @@ -72,7 +74,8 @@ namespace boost { namespace phoenix } }; - template class Actor, typename A0, typename A1> + template class Actor, + typename A0, typename A1> struct as_actor { typedef @@ -85,16 +88,20 @@ namespace boost { namespace phoenix , A1>::type base_type; typedef Actor result_type; + typedef result_type type; result_type - operator()( typename call_traits::param_type a0, typename call_traits::param_type a1 ) const + operator()( + typename call_traits::param_type a0, + typename call_traits::param_type a1) const { actor const e = {{funcwrap(), env(), a0, a1}}; return e; } }; - template class Actor, typename A0, typename A1, typename A2> + template class Actor, + typename A0, typename A1, typename A2> struct as_actor { typedef @@ -108,9 +115,13 @@ namespace boost { namespace phoenix , A2>::type base_type; typedef Actor result_type; + typedef result_type type; result_type - operator()( typename call_traits::param_type a0, typename call_traits::param_type a1, typename call_traits::param_type a2) const + operator()( + typename call_traits::param_type a0, + typename call_traits::param_type a1, + typename call_traits::param_type a2) const { actor const e = {{funcwrap(), env(), a0, a1, a2}}; return e; @@ -120,33 +131,37 @@ namespace boost { namespace phoenix }} /* -#define BOOST_PP_LOCAL_MACRO( N ) \ - namespace boost { namespace phoenix \ - { \ - template class Actor \ - BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)> \ - struct as_actor \ - { \ - typedef \ - typename proto::result_of::make_expr< \ - proto::tag::function \ - , proto::default_domain \ - , funcwrap< F > \ - , env BOOST_PP_ENUM_TRAILING_PARAMS(N, A) \ - >::type \ - base_type; \ - \ - typedef Actor result_type; \ - \ - result_type \ - operator()( \ - BOOST_PP_ENUM_BINARY_PARAMS(N, typename call_traits< A, >::param_type a)) const \ - { \ - actor const e = {{funcwrap< F >(), env() BOOST_PP_ENUM_TRAILING_PARAMS(N, a)}};\ - return e; \ - } \ - }; \ - }} +#define BOOST_PP_LOCAL_MACRO( N ) \ +namespace boost { namespace phoenix \ +{ \ + template class Actor \ + BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)> \ + struct as_actor \ + { \ + typedef \ + typename proto::result_of::make_expr< \ + proto::tag::function \ + , proto::default_domain \ + , funcwrap< F > \ + , env BOOST_PP_ENUM_TRAILING_PARAMS(N, A) \ + >::type \ + base_type; \ + \ + typedef Actor result_type; \ + typedef result_type type; \ + \ + result_type \ + operator()( \ + BOOST_PP_ENUM_BINARY_PARAMS(N, \ + typename call_traits< A, >::param_type a)) const \ + { \ + actor const e = {{ \ + funcwrap< F >(), env() BOOST_PP_ENUM_TRAILING_PARAMS(N, a) \ + }}; \ + return e; \ + } \ + }; \ +}} #define BOOST_PP_LOCAL_LIMITS ( 0, 3 ) #include BOOST_PP_LOCAL_ITERATE() diff --git a/include/boost/phoenix/core/environment.hpp b/include/boost/phoenix/core/environment.hpp new file mode 100644 index 0000000..7984fa2 --- /dev/null +++ b/include/boost/phoenix/core/environment.hpp @@ -0,0 +1,43 @@ +/*============================================================================== + Copyright (c) 2005-2010 Joel de Guzman + + 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_CORE_ENVIRONMENT_HPP +#define PHOENIX_CORE_ENVIRONMENT_HPP + +#include + +namespace boost { namespace phoenix +{ +// template +// struct is_environment : fusion::is_sequence {}; + + namespace result_of + { + template + struct get_environment_argument + : fusion::result_of::at_c {}; + } + + // Get the Nth argument from the environment + struct get_environment_argument + { + template + struct result; + + template + struct result + : result_of::get_environment_argument {}; + + template + typename result_of::get_environment_argument::type + operator()(Env& env, N) const + { + return fusion::at_c(env); + } + }; +}} + +#endif diff --git a/include/boost/phoenix/core/is_actor.hpp b/include/boost/phoenix/core/is_actor.hpp index 534e37b..7a4aa94 100644 --- a/include/boost/phoenix/core/is_actor.hpp +++ b/include/boost/phoenix/core/is_actor.hpp @@ -16,7 +16,7 @@ namespace boost { namespace phoenix // Tests if T is an actor. Evaluates to mpl::true_ or mpl::false_ // /////////////////////////////////////////////////////////////////////////////// - template + template struct is_actor : mpl::false_ {}; template