mirror of
https://github.com/boostorg/phoenix.git
synced 2026-02-14 13:02:10 +00:00
+ the environment concept
+ better result_of modularization [SVN r62711]
This commit is contained in:
@@ -19,7 +19,7 @@ namespace boost { namespace phoenix
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Return type computation
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
template<typename Sig>
|
||||
template <typename Sig, typename Enable = void>
|
||||
struct actor_result;
|
||||
|
||||
template <typename Actor>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <boost/phoenix/core/actor.hpp>
|
||||
#include <boost/phoenix/core/as_actor.hpp>
|
||||
#include <boost/phoenix/core/meta_grammar.hpp>
|
||||
#include <boost/phoenix/core/environment.hpp>
|
||||
|
||||
#include <boost/fusion/sequence/intrinsic/at.hpp>
|
||||
|
||||
@@ -22,41 +23,48 @@
|
||||
namespace boost { namespace phoenix
|
||||
{
|
||||
// function for evaluating argument placeholders like: _1
|
||||
struct argument
|
||||
|
||||
namespace result_of
|
||||
{
|
||||
template<typename N, template<typename> class Actor = actor >
|
||||
struct as_actor : boost::phoenix::as_actor<argument, Actor, N>
|
||||
{};
|
||||
|
||||
template<typename Signature>
|
||||
struct result;
|
||||
|
||||
template<typename This, typename Env, typename N>
|
||||
struct result<This(Env &, N &)>
|
||||
: fusion::result_of::at<
|
||||
template <typename Env, typename N>
|
||||
struct argument
|
||||
: result_of::get_environment_argument<
|
||||
Env, typename boost::result_of<eval_grammar(N)>::type>
|
||||
{};
|
||||
}
|
||||
|
||||
struct argument
|
||||
{
|
||||
template <typename Signature>
|
||||
struct result;
|
||||
|
||||
template<typename Env, typename N>
|
||||
typename boost::result_of<argument(Env &, N &)>::type
|
||||
operator()(Env & env, N &) const
|
||||
template <typename This, typename Env, typename N>
|
||||
struct result<This(Env&, N&)>
|
||||
: result_of::argument<Env, N>
|
||||
{};
|
||||
|
||||
template <typename Env, typename N>
|
||||
typename result_of::argument<Env, N>::type
|
||||
operator()(Env& env, N& n) const
|
||||
{
|
||||
return fusion::at<
|
||||
typename boost::result_of<eval_grammar(N)>::type>(env);
|
||||
return get_environment_argument()(env, eval(n));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename N>
|
||||
struct make_argument : boost::phoenix::as_actor<argument, actor, N> {};
|
||||
|
||||
namespace placeholders
|
||||
{
|
||||
// Phoenix style names
|
||||
argument::as_actor<mpl::int_<0> >::result_type const arg1 = {};
|
||||
argument::as_actor<mpl::int_<1> >::result_type const arg2 = {};
|
||||
argument::as_actor<mpl::int_<2> >::result_type const arg3 = {};
|
||||
make_argument<mpl::int_<0> >::type const arg1 = {};
|
||||
make_argument<mpl::int_<1> >::type const arg2 = {};
|
||||
make_argument<mpl::int_<2> >::type const arg3 = {};
|
||||
|
||||
// BLL style names
|
||||
argument::as_actor<mpl::int_<0> >::result_type const _1 = {};
|
||||
argument::as_actor<mpl::int_<1> >::result_type const _2 = {};
|
||||
argument::as_actor<mpl::int_<2> >::result_type const _3 = {};
|
||||
make_argument<mpl::int_<0> >::type const _1 = {};
|
||||
make_argument<mpl::int_<1> >::type const _2 = {};
|
||||
make_argument<mpl::int_<2> >::type const _3 = {};
|
||||
}
|
||||
|
||||
namespace arg_names
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace boost { namespace phoenix
|
||||
, env>::type
|
||||
base_type;
|
||||
typedef Actor<base_type> result_type;
|
||||
typedef result_type type;
|
||||
|
||||
result_type
|
||||
operator()() const
|
||||
@@ -63,6 +64,7 @@ namespace boost { namespace phoenix
|
||||
, A0>::type
|
||||
base_type;
|
||||
typedef Actor<base_type> result_type;
|
||||
typedef result_type type;
|
||||
|
||||
result_type
|
||||
operator()( typename call_traits<A0>::param_type a0 ) const
|
||||
@@ -72,7 +74,8 @@ namespace boost { namespace phoenix
|
||||
}
|
||||
};
|
||||
|
||||
template<typename F, template<typename> class Actor, typename A0, typename A1>
|
||||
template<typename F, template<typename> class Actor,
|
||||
typename A0, typename A1>
|
||||
struct as_actor<F, Actor, A0, A1>
|
||||
{
|
||||
typedef
|
||||
@@ -85,16 +88,20 @@ namespace boost { namespace phoenix
|
||||
, A1>::type
|
||||
base_type;
|
||||
typedef Actor<base_type> result_type;
|
||||
typedef result_type type;
|
||||
|
||||
result_type
|
||||
operator()( typename call_traits<A0>::param_type a0, typename call_traits<A1>::param_type a1 ) const
|
||||
operator()(
|
||||
typename call_traits<A0>::param_type a0,
|
||||
typename call_traits<A1>::param_type a1) const
|
||||
{
|
||||
actor<base_type> const e = {{funcwrap<F>(), env(), a0, a1}};
|
||||
return e;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename F, template<typename> class Actor, typename A0, typename A1, typename A2>
|
||||
template <typename F, template<typename> class Actor,
|
||||
typename A0, typename A1, typename A2>
|
||||
struct as_actor<F, Actor, A0, A1, A2>
|
||||
{
|
||||
typedef
|
||||
@@ -108,9 +115,13 @@ namespace boost { namespace phoenix
|
||||
, A2>::type
|
||||
base_type;
|
||||
typedef Actor<base_type> result_type;
|
||||
typedef result_type type;
|
||||
|
||||
result_type
|
||||
operator()( typename call_traits<A0>::param_type a0, typename call_traits<A1>::param_type a1, typename call_traits<A2>::param_type a2) const
|
||||
operator()(
|
||||
typename call_traits<A0>::param_type a0,
|
||||
typename call_traits<A1>::param_type a1,
|
||||
typename call_traits<A2>::param_type a2) const
|
||||
{
|
||||
actor<base_type> const e = {{funcwrap<F>(), 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<typename F, template<typename> class Actor \
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)> \
|
||||
struct as_actor<F, Actor BOOST_PP_ENUM_TRAILING_PARAMS(N, A)> \
|
||||
{ \
|
||||
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<base_type> result_type; \
|
||||
\
|
||||
result_type \
|
||||
operator()( \
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(N, typename call_traits< A, >::param_type a)) const \
|
||||
{ \
|
||||
actor<base_type> 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<typename F, template<typename> class Actor \
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(N, typename A)> \
|
||||
struct as_actor<F, Actor BOOST_PP_ENUM_TRAILING_PARAMS(N, A)> \
|
||||
{ \
|
||||
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<base_type> result_type; \
|
||||
typedef result_type type; \
|
||||
\
|
||||
result_type \
|
||||
operator()( \
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(N, \
|
||||
typename call_traits< A, >::param_type a)) const \
|
||||
{ \
|
||||
actor<base_type> 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()
|
||||
|
||||
43
include/boost/phoenix/core/environment.hpp
Normal file
43
include/boost/phoenix/core/environment.hpp
Normal file
@@ -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 <boost/fusion/support/is_sequence.hpp>
|
||||
|
||||
namespace boost { namespace phoenix
|
||||
{
|
||||
// template <typename T, typename Enable = void>
|
||||
// struct is_environment : fusion::is_sequence<T> {};
|
||||
|
||||
namespace result_of
|
||||
{
|
||||
template <typename Env, typename N>
|
||||
struct get_environment_argument
|
||||
: fusion::result_of::at_c<Env, N::value> {};
|
||||
}
|
||||
|
||||
// Get the Nth argument from the environment
|
||||
struct get_environment_argument
|
||||
{
|
||||
template <typename Sig>
|
||||
struct result;
|
||||
|
||||
template <typename This, typename Env, typename N>
|
||||
struct result<This(Env&, N)>
|
||||
: result_of::get_environment_argument<Env, N> {};
|
||||
|
||||
template <typename Env, typename N>
|
||||
typename result_of::get_environment_argument<Env, N>::type
|
||||
operator()(Env& env, N) const
|
||||
{
|
||||
return fusion::at_c<N::value>(env);
|
||||
}
|
||||
};
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -16,7 +16,7 @@ namespace boost { namespace phoenix
|
||||
// Tests if T is an actor. Evaluates to mpl::true_ or mpl::false_
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
template <typename T, typename Enable = void>
|
||||
struct is_actor : mpl::false_ {};
|
||||
|
||||
template <typename Expr>
|
||||
|
||||
Reference in New Issue
Block a user