Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] problems with accumulate metafunction
From: Benedetto Proietti (benedetto73_at_[hidden])
Date: 2010-02-08 22:54:31


Greetings.

I am kind of newbie to Boost.Fusion.

I have a sequence of "Field"s:

typedef fusion::vector<
    Field<int, 3, Check1, ..>,
    Field<float, 8, Check2, ..>,
    Field<MyString, 2, Check3, ..>,
    ...
> MySequence;

Each "Field" knows how to (de)serialize, has some checking policy and a few
more little stuff.
"Field" also has a "int" property "TypeSize":

static const int TypeSize = somevalue_known_at_compile_time;

I'd like to traverse the type "MySequence" and get the sum of all the sizes
at compile time.
Like:
Field<int,3,Check1>::TypeSize + Field<float, 8, Check2>::TypeSize +
Field<MyString,2,Check3>::TypeSize + ... ;

I tried playing with fusion::accumulate and mpl<int_> but couldn't do it.
There's no much documentation/examples about fusion (correct me if I am
wrong please).
How can I get the accumulated sum of Field<...>::TypeSize of all the members
in "MySequence"?

Thanks in advance,
  Benedetto

PS: It's not really a priority (the cost of doing that at runtime once for
object is minimal), but I'd really like to fully understand Fusion, which I
have found very useful so far.



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