|
Boost Users : |
Subject: Re: [Boost-users] Dynamic function call question
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-02-26 13:44:52
AMDG
Perry, Daniel wrote:
> No I was aware of the visitors. I am thinking more along the lines of
>
> template< Signature>
> void Execute( vector<variant> args, function<Signature> & Fun )
> {
> fusion::vector< parameter_types<Signature>::type > typed_args(
> magic_happens_here(args));
> fusion::invoke_procedure(Fun, typed_args);
> }
>
> What can I do to make the magic happen?
>
So the function has a fixed signature?
You'll need to adapt a vector to the fusion interface.
The easiest way it to convert it to a boost::array (which is a fusion
sequence)
and use transform (untested).
struct variant_get {
template<class Sig>
struct result {
typedef typename boost::mpl::at_c<parameter_types<Sig> >::type type;
};
template<class Arg, class Type>
Type operator(const Arg& arg, const Type& type) {
return(boost::get<Type>(arg)); }
};
template<class Signature>
void Execute(const vector<variant>& args, const function<Signature>& Fun) {
typedef typename parameter_types<Signature>::type param_types;
boost::array<variant,boost::mpl::size<param_types>::value> as_array;
typename fusion::as_vector<param_types>::type
typed_args(boost::fusion::transform(as_array, param_types, variant_get()));
}
In Christ,
Steven Watanabe
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