Boost logo

Boost Users :

Subject: [Boost-users] [Phoenix][v3] Argument/State dependent return type of actors?
From: Josef Weinbub (weinbub_at_[hidden])
Date: 2011-12-15 04:22:47


Hi

Recently I made myself familiar with Phoenix v3, more specifically with
actors.
I did a few test implementations, and I wondered if there is a
way to access the argument types (nested in the context's environment)
and/or the type of the state(s) (nested in the proto expression) for the
actor's result type declaration.

Have a look at the following actor dummy implementation, especially at the
line ''typedef int result_type;'': (for the sake of completeness, the
complete actor
implementation is provided)

------------------------------------------------------------
BOOST_PHOENIX_DEFINE_EXPRESSION(
     (boost)(phoenix)(myactor)
   , (boost::phoenix::meta_grammar)
)

struct myactor_eval {

    // ------------------------
    // the result type can not be made dependable from
    // one of the actors argument types .. it is
    //
    typedef int result_type;
    // ------------------------

    template <typename StateExpr, typename Context>
    result_type
    operator()(StateExpr const& state_expr, Context & ctx) const {
       return -1;
    }
};

namespace boost { namespace phoenix {
    template <>
    struct default_actions::when< rule::myactor>
       : boost::phoenix::call< ::myactor_eval> {};

    template <typename T>
    typename expression::myactor<T>::type const
    inline myactor(T& t) {
      return expression::myactor<T>::make(t);
    }
}}
------------------------------------------------------------

As I already stated, I wonder if there is a way to have access to the
argument and state types for the result type, maybe as it was possible
in Phoenix v2 via a nested template struct which got the same template
parameters
as the functor, like the simple example in the following:
------------------------------------------------------------
struct myactor_eval {

    template <typename StateExpr, typename Context>
    struct result {
        typedef typename result_of::env<Context>::type Environment;
        typedef typename remove_reference<
           Environment>::type::args_type Args;
        typedef typename result_of::value_at_c<
           Args, 0>::type Parameter;

        // make the result type argument dependent!
        typedef typename Parameter::value_type type;
    }; ...
};
------------------------------------------------------------

I do hope that I haven't overlooked something in the docs, sorry if I did.

Thanks for your support!

Cheers, Josef Weinbub


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