Boost logo

Boost Users :

From: Joel de Guzman (joel_at_[hidden])
Date: 2006-08-15 22:48:02


Joel de Guzman wrote:
> Christian Henning wrote:
>> That's work in my sample code. Thanks.
>>
>> But what happens if the S structs are more heterogenious? Like:
>>
>> struct s3
>> {
>> static const int num_values = 4;
>>
>> int i;
>> float j;
>> int k;
>> double l;
>> };
>>
>> I'm sure there is some mpl magic possible.
>
> Fusion! :-)
>
> mpl::vector_c<4> consts;
> fusion::vector<int, float, int, double> vars;
> fusion::joint_view<consts, vars> s3(consts, vars);

Oops, that should be

      typedef mpl::vector_c<int, 4> consts_type;
      typedef fusion::vector<int, float, int, double> vars_type;

      vars_type vars;
      fusion::joint_view<consts_type, vars_type> s3(consts_type(), vars);

Anyway, I'm sure you got the point. With our 's3' above, we can,
for exemple, write (using boost::lambda):

     fusion::for_each(s3, cout << _1 << endl);

to print all the items.

I'll be putting Fusion in the Boost CVS soon. Try it! :)

Regards,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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