Re: [Boost-users] [Fusion] Building parameter list for fusion::invoke

2011/1/22 Vivek <vivek_at_[hidden]>
Or alternatively, is there a direct way to initialize a fusion vector?
IIUC, its ctor just do the job, not? The problem is I don't know the arity or parameter types of the function being called. I just have a source of data (which can be simplified to TYPE data = data_source<TYPE>().pop();) and arbitrary functions being passed in. One alternative is to code-generate template specializations for a bunch of arity and use the constructor like you suggested. But I feel the "arity code generation" thing has been done so many times and so much better in boost that I should be able to use a transform or invoke function to take advantage of that. That's why I started trying to use fusion.

2011/1/23 Vivek <vivek@xmain.com>
2011/1/22 Vivek <vivek_at_[hidden]>
Or alternatively, is there a direct way to initialize a fusion vector?
IIUC, its ctor just do the job, not?
The problem is I don't know the arity or parameter types of the function being called. I just have a source of data (which can be simplified to TYPE data = data_source<TYPE>().pop();) and arbitrary functions being passed in.
Sorry if I missed your point...here comes an idea: Use Fusion's MPL sequences adapters, so you can have: typedef typename mpl::transform < parameter_types , from_data_source<mpl::_1> , mpl::back_inserter<mpl::vector<> > >::type data_source_provider; // a MPL sequence And invoke as: fs::invoke(f, data_source_provider()); where from_data_source<T> is defined as: template<class T> struct from_data_source { operator T() const { return data_source<T>().pop(); } }; Maybe your data_source<T>() is some singleton for the data source?

On Sun, Jan 23, 2011 at 2:40 AM, TONGARI <tongari95@gmail.com> wrote:
2011/1/23 Vivek <vivek@xmain.com>
2011/1/22 Vivek <vivek_at_[hidden]>
Or alternatively, is there a direct way to initialize a fusion vector?
IIUC, its ctor just do the job, not?
The problem is I don't know the arity or parameter types of the function being called. I just have a source of data (which can be simplified to TYPE data = data_source<TYPE>().pop();) and arbitrary functions being passed in.
Sorry if I missed your point...here comes an idea: Use Fusion's MPL sequences adapters, so you can have:
typedef typename mpl::transform < parameter_types , from_data_source<mpl::_1>
, mpl::back_inserter<mpl::vector<> > >::type data_source_provider; // a MPL sequence
And invoke as:
fs::invoke(f, data_source_provider());
where from_data_source<T> is defined as:
template<class T> struct from_data_source { operator T() const
{ return data_source<T>().pop(); } };
Maybe your data_source<T>() is some singleton for the data source?
That's perfect. I didn't make the connection that a function invocation only requires types that are *convertible* to the argument types, not necessarily exactly the argument types. And the conversion operator can handle fetching the data. And yes, the data source is a singleton. Thanks Vivek

2011/1/24 Vivek <vivek@xmain.com>
That's perfect. I didn't make the connection that a function invocation only requires types that are *convertible* to the argument types, not necessarily exactly the argument types. And the conversion operator can handle fetching the data. And yes, the data source is a singleton.
Still one thing to note: IIRC, the order of evaluations of args involved in a function call is not guaranteed, so I hope the order of "data_source<T>().pop()" called does not matter in your case, if it does matter, I'm not sure whether you'll get the right result...

On Sun, Jan 23, 2011 at 2:40 AM, TONGARI <tongari95@gmail.com> wrote: Use Fusion's MPL sequences adapters, so you can have:
typedef typename mpl::transform < parameter_types , from_data_source<mpl::_1>
, mpl::back_inserter<mpl::vector<> > >::type data_source_provider; // a MPL sequence
And invoke as:
fs::invoke(f, data_source_provider());
where from_data_source<T> is defined as:
template<class T> struct from_data_source { operator T() const
{ return data_source<T>().pop(); } };
Maybe your data_source<T>() is some singleton for the data source?
Hmm! That seems more succinct than the explicit recursion in the interpreter.hpp example. Apologies if this is a silly question, but suppose the object from which I'd like to obtain parameter values is locally constructed rather than global? How would I parameterize the mpl::transform expression above to pass in that object?

2011/1/24 Nat Linden <nat@lindenlab.com>
Hmm! That seems more succinct than the explicit recursion in the interpreter.hpp example.
Apologies if this is a silly question, but suppose the object from which I'd like to obtain parameter values is locally constructed rather than global? How would I parameterize the mpl::transform expression above to pass in that object?
Then it's where Fusion takes the place! :-) Also note my last mail that indicates a potential problem.
participants (3)
-
Nat Linden
-
TONGARI
-
Vivek