On 01/03/2012 09:17 AM, Josef Weinbub wrote:
On 01/-10/-28163 08:59 PM, Josef Weinbub wrote:
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.
....
Hi again!
Indeed I have overlooked something, being 'result_of' ... as provided by the Boost Utility library and adopted by the C++11 standard. Sorry for that, should have known ..
In case someone else wonders how to approach my problem, checkout the Boost.Utility::result_of documentation: http://www.boost.org/doc/libs/1_48_0/libs/utility/utility.htm#result_of
One has to nest a result struct with the functors parameter types in the Boost.Phoenix actor's evaluation functor. For the sake of completeness, in the following my previous evaluation functor is depicted again, but instead of the static "typedef int result_type; " we now use the nested result struct:
struct myactor_eval {
template<class> struct result;
template
struct result { // here we can relate the return type both to the state type // and to the functor's argument types ... typedef ..... type; }; template
typename myactor_eval::result< myactor_eval(StateExpr, Context) >::type operator()(StateExpr const& state_expr, Context & ctx) const { return ...; } }; Best, Josef
PS: Thank you, Joel, for noticing my post and forwarding it to Thomas - much appreciated!
Sorry I missed it, yes, the result_of protocol is used throughout the
library. Additionally you can access the context with special meta
functions. Looks like the documentation of those is currently incomplete ...
Have a look here:
http://www.boost.org/doc/libs/1_48_0/libs/phoenix/doc/html/phoenix/inside/ac...
At the bottom of this page is a list of functions and proto transforms
to access the environment inside the context. For every function, there
exists a boost::phoenix::result_of::*name* metafunction, where *name*
stands for thing you want to extract.
Let's say you want to compute the type of the first passed parameter:
// Extract the Environment, which is a fusion vector ...
typedef
typename boost::phoenix::result_of::env<Context>::type
env_type;
// Or using result_of:
typedef
typename boost::result_of<
boost::phoenix::functional::env(Context)
>::type
env_type;
// ... and extract the first argument:
typedef
typename boost::fusion::result_of::at_c