Boost logo

Boost Users :

Subject: [Boost-users] [phoenix][v3] Evaluating a terminal expression in the custom actions class.
From: Alexander Ospin (aospin_at_[hidden])
Date: 2011-03-02 09:03:46


Is it possible to evaluate terminal and custom_terminal expressions in the some
custom actions class? For instance how to implement "terminal_eval" to print
something in the following code?

#include <boost/phoenix/phoenix.hpp>
#include <iostream>

using namespace boost;

struct actions
{
     template <typename Rule, typename Dummy = void> struct when;
};

template <>
struct actions::when<phoenix::rule::terminal> :
     phoenix::call<terminal_eval> {};

int main()
{
     int var = 11;
     phoenix::eval(phoenix::val(var), phoenix::context(int(), actions()));
     return 0;
}

I've tried to use the following form, but encountered some compiler errors:
(GCC-4.2.1[FreeBSD], boost and phoenix were taken from SVN, latest versions)

struct terminal_eval
{
     typedef void result_type;
     template <typename Context, typename Expr>
     result_type operator ()(Context const &ctx, Expr const &expr)
     {
         std::cout << "terminal" << std::endl;
     }
};

../../../../boost.phoenix/boost/phoenix/core/call.hpp:32: error: invalid use of
incomplete type 'struct boost::phoenix::detail::call_impl<terminal_eval, const
boost::phoenix::actor<boost::proto::exprns_::expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<int>, 0l> >&, const int&, const actions&, 0l>'
../../../../boost.phoenix/boost/phoenix/core/call.hpp:22: error: declaration of
'struct boost::phoenix::detail::call_impl<terminal_eval, const
boost::phoenix::actor<boost::proto::exprns_::expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<int>, 0l> >&, const int&, const actions&, 0l>'

../../../../boost/boost/proto/transform/call.hpp:315: error: no type named
'result_type' in 'struct
boost::proto::switch_<boost::phoenix::meta_grammar>::impl<const
boost::phoenix::actor<boost::proto::exprns_::expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<int>, 0l> >&, const int&, const actions&>'
../../../../boost/boost/proto/transform/call.hpp:320: error: no type named
'result_type' in 'struct
boost::proto::switch_<boost::phoenix::meta_grammar>::impl<const
boost::phoenix::actor<boost::proto::exprns_::expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<int>, 0l> >&, const int&, const actions&>'

The same situation with the phoenix::ref and custom_terminal rule.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net