Boost logo

Boost Users :

Subject: Re: [Boost-users] fusion struct adapt macro, construct the struct from a fusion vector
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-01-18 21:01:05


----- Original Message -----
From: "Joel de Guzman" <joel_at_[hidden]>
To: <boost-users_at_[hidden]>
Sent: Monday, January 18, 2010 9:56 AM
Subject: Re: [Boost-users] fusion struct adapt macro, construct the struct
from a fusion vector

> On 1/17/2010 10:02 PM, Hicham Mouline wrote:
>> Hello,
>>
>> I have a
>> struct params {
>> ...
>> };
>>
>> and I have adapted it as a fusion sequence.
>>
>> However I can't construct a params from a boost::fusion::vector<> with
>> the same types.
>>
>> const params p( v ); // v is a fusion::vector with the same type
>> const params p = v; // both failed to compile
>
> Of course you can't, unless your struct params has a template constructor
> that accepts fusion sequences -- that's easy enough to do. Keep in mind
> that the adapt macro is non-intrusive. What happens in your struct is
> your business.
>
>> Do I need to actually write a specific ctor for params?
>
> Yes.
>
>> Will it change the result of the adapt macro?
>
> No.
>
>> Can I iterate with an algorithm over the vector at runtime to assign to p
>> from v?
>> with fusion::for_each() I couldn't write the functor that would let me
>> assign to p.
>
> Yep. Perhaps you can use zip_view to iterate both sequences in parallel.
> E.g. for_each(zip(p, v), f).
>
I am trying to write code that is as independent of the struct as possible.
The first thing that comes to my mind for the ctor is

struct params {
  ...// there are 7 members, in the 100 or so different structs I will have,
max 20 members maybe
  template <typename T1, ... typename T7>
  params(const fusion::vector<T1,...T7>& v);
};

This probably isn't what you meant.
How to generalize it to any fusion sequence?
Is it possible to generalize the number of template args?

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