2
0
mirror of https://github.com/boostorg/phoenix.git synced 2026-02-19 14:42:14 +00:00

Spirit, Phoenix: mergine from trunk for BoostCon

[SVN r71925]
This commit is contained in:
Hartmut Kaiser
2011-05-13 19:14:18 +00:00
parent e343cfb527
commit afcc104add
36 changed files with 706 additions and 472 deletions

View File

@@ -15,12 +15,12 @@ struct factorial_impl
template <typename Sig>
struct result;
template <typename Arg>
template <typename This, typename Arg>
struct result<This(Arg)>
: result<This(Arg const &)>
{};
template <typename Arg>
template <typename This, typename Arg>
struct result<This(Arg &)>
{
typedef Arg type;
@@ -37,9 +37,10 @@ struct factorial_impl
int
main()
{
using boost::phoenix::arg_names::arg1;
boost::phoenix::function<factorial_impl> factorial;
using namespace boost::phoenix::arg_names::arg1;
int i = 4;
std::cout << factorial(i)() << std::endl;
std::cout << factorial(arg1)(i) << std::endl;
return 0;
}

View File

@@ -24,13 +24,15 @@ struct invert_actions
using phoenix::evaluator;
#ifdef _MSC_VER
// redifining evaluator, this is because MSVC chokes on function types like:
// F(G(...))
#define evaluator(A0, A1) proto::call<phoenix::evaluator(A0, A1)>
#endif
template <>
struct invert_actions::when<phoenix::rule::plus>
: proto::call<
proto::functional::make_expr<proto::tag::minus>(
phoenix::functional::make_minus(
evaluator(proto::_left, phoenix::_context)
, evaluator(proto::_right, phoenix::_context)
)
@@ -40,7 +42,7 @@ struct invert_actions::when<phoenix::rule::plus>
template <>
struct invert_actions::when<phoenix::rule::minus>
: proto::call<
proto::functional::make_expr<proto::tag::plus>(
phoenix::functional::make_plus(
evaluator(proto::_left, phoenix::_context)
, evaluator(proto::_right, phoenix::_context)
)
@@ -50,7 +52,7 @@ struct invert_actions::when<phoenix::rule::minus>
template <>
struct invert_actions::when<phoenix::rule::multiplies>
: proto::call<
proto::functional::make_expr<proto::tag::divides>(
phoenix::functional::make_divides(
evaluator(proto::_left, phoenix::_context)
, evaluator(proto::_right, phoenix::_context)
)
@@ -60,7 +62,7 @@ struct invert_actions::when<phoenix::rule::multiplies>
template <>
struct invert_actions::when<phoenix::rule::divides>
: proto::call<
proto::functional::make_expr<proto::tag::multiplies>(
phoenix::functional::make_multiplies(
evaluator(proto::_left, phoenix::_context)
, evaluator(proto::_right, phoenix::_context)
)
@@ -81,7 +83,7 @@ void print_expr(Expr const & expr)
phoenix::eval(
expr
, phoenix::context(
int()
phoenix::nothing
, invert_actions()
)
)
@@ -90,19 +92,21 @@ void print_expr(Expr const & expr)
}
template <typename Expr>
typename boost::result_of<
phoenix::evaluator(
typename
boost::phoenix::result_of::eval<
Expr const&
, phoenix::result_of::context<int, invert_actions>::type
)
>::type
, phoenix::result_of::make_context<
phoenix::result_of::make_env<>::type
, invert_actions
>::type
>::type
invert(Expr const & expr)
{
return
phoenix::eval(
expr
, phoenix::context(
int()
, phoenix::make_context(
phoenix::make_env()
, invert_actions()
)
);
@@ -122,9 +126,8 @@ int main()
print_expr(_1 * _2 / _3);
print_expr(_1 * _2 + _3);
print_expr(_1 * _2 - _3);
print_expr(phoenix::if_(_1 * _4)[_2 - _3]);
print_expr(if_(_1 * _4)[_2 - _3]);
print_expr(_1 * invert(_2 - _3));
}

View File

@@ -53,13 +53,10 @@ struct omp_for_gen
: init(init), cond(cond), step(step) {}
template <typename Do>
typename expression::omp_for<Init, Cond, Step, Do>::type const
typename result_of::make_omp_for<Init, Cond, Step, Do>::type const
operator[](Do const& do_) const
{
return
expression::
omp_for<Init, Cond, Step, Do>::
make(init, cond, step, do_);
return make_omp_for(init, cond, step, do_);
}
Init init;
@@ -95,19 +92,29 @@ struct parallel_actions::when<boost::phoenix::rule::for_>
// Doing the same as actor<Expr>::operator
template <typename Expr, typename A0, typename A1, typename A2>
typename boost::result_of<
boost::phoenix::evaluator(
Expr const &
, typename boost::phoenix::result_of::context<
boost::phoenix::vector4<Expr const *, A0 &, A1 &, A2 &>
, parallel_actions
typename boost::phoenix::result_of::eval<
Expr const &
, typename boost::phoenix::result_of::make_context<
typename boost::phoenix::result_of::make_env<
Expr const *
, A0 &
, A1 &
, A2 &
>::type
)
, parallel_actions
>::type
>::type
parallel_eval(Expr const & expr, A0 & a0, A1 & a1, A2 & a2)
parallel_eval(Expr & expr, A0 & a0, A1 & a1, A2 & a2)
{
boost::phoenix::vector4<Expr const *, A0 &, A1 &, A2 &> env = {boost::addressof(expr), a0, a1, a2};
return boost::phoenix::eval(expr, boost::phoenix::context(env, parallel_actions()));
Expr const * this_ = boost::addressof(expr);
return
boost::phoenix::eval(
expr
, boost::phoenix::make_context(
boost::phoenix::make_env(this_, a0, a1, a2)
, parallel_actions()
)
);
}
// changing evaluation mechanism on the fly
@@ -123,21 +130,21 @@ namespace boost { namespace phoenix
: proto::call<
evaluator(
proto::_child0
, functional::context(
, functional::make_context(
_env
, parallel_actions()
)
, int()
, unused()//mpl::void_()
)
>
{};
}}
template <typename Expr>
typename expression::parallel<Expr>::type const
typename result_of::make_parallel<Expr>::type
parallel(Expr const & expr)
{
return expression::parallel<Expr>::make(expr);
return make_parallel(expr);
}
////////////////////////////////////////////////////////////////////////////////
@@ -158,7 +165,7 @@ int main()
using boost::phoenix::lambda;
using boost::phoenix::nothing;
const int NUM = 67108864;
const int NUM = 1;
{
std::vector<int> a(NUM, 1);