Boost logo

Boost Users :

Subject: Re: [Boost-users] [Fusion] Building parameter list for fusion::invoke
From: Vivek (vivek_at_[hidden])
Date: 2011-01-23 11:51:06


On Sun, Jan 23, 2011 at 2:40 AM, TONGARI <tongari95_at_[hidden]> wrote:

>
>
> 2011/1/23 Vivek <vivek_at_[hidden]>
>
> 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



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