|
Boost Users : |
Subject: Re: [Boost-users] mpl/fusion: metafunction to 'rangify'
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-12-23 15:13:01
>> typedef
>> boost::fusion::result_of::as_vector<boost::fusion::result_of::transform<
>> params,make_fixed_or_range>::type>::type
>> params_fixed_or_range;
>>
>> -Christopher
>It does.
>Of course, the return type of fusion::transform contains the compile-time
>information required.
>Thanks very much,
>Now I'll look at spirit (and some magic code to generate the Qi parser for
>this new sequence) to fill it up with values from an input stream.
I have simplified the code to http://codepad.org/NDM2Ub7z
I have a couple of needs now:
1. attempt to transform pfr back to params. This should succeed if all
elements of the fusion sequence are fixed values and throw an exception if
any of them is a range. Should I write this as a free floating function, as
a conversion operator?
2. there will be many params types, params_1 .... params_n, each of those
structs will yield after a fusion::transform the sequences
params_fixed_of_range_1... params_fixed_of_range_n.
I need the following behavior (I would write for this a free floating
template function, templated on the sequence type : one of the
params_fixed_of_range_i):
template <typename params_fixed_of_range>
void do_work(const params_fixed_of_range& seq_i) {
///
/// generate a inner for loop for all the ranges in seq_i
/// for e.g., if seq_i contains
/// { d1= 5.; d2= 4.0..5.0..0.1; d3=-1.5..1.5..0.6; i4=4..26..1;
i5=4; i6=0; i7=0; }
/// then I would want to generate the following code, or if impossible
/// maybe by runtime recursion
///
for (double d2=4.0; d2<=5.0; d2+=0.1)
for (double d3=-1.5; d3<=1.5; d3+=0.6)
for (unsigned int i4=4; i4<=26; i4+=1)
{
// I know d1=5. i5=4 i6=0 i7=0
// construct a params frm current d1,d2,d3,i4,i5,i6,i7
// do some work based on params
// return value, this will be used to plot graphs
}
};
This seems very doable with boost.fusion, and extremely complicated and not
flexible without it.
I realize there are a lot of questions into 1 email but appreciate the help
you can give me,
Best regards,
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