Re: [Boost-users] [fusion] problems with accumulate metafunction
Greetings.
I am kind of newbie to Boost.Fusion.
I have a sequence of "Field"s:
typedef fusion::vector<
Field
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
Benedetto Proietti schrieb:
Greetings.
I am kind of newbie to Boost.Fusion.
I have a sequence of "Field"s:
typedef fusion::vector< Field
, Field , Field , ... 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
::TypeSize + Field ::TypeSize + Field ::TypeSize + ... ; I tried playing with fusion::accumulate and mpl
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"? [snip]
An implementation based upon MPL's fold is easier than one based upon
Fusion's equivalent. That way you do not need to deal with ref-qualified
arguments.
#include
::type sum;
char is_correct[sum::value - 6 ? 0 : 1];
A fusion-only implementation probably looks like this:
#include
::type sum;
char is_correct[sum::value - 6 ? 0 : 1]; Both snippets are untested! -Christopher
participants (2)
-
Benedetto Proietti
-
Christopher Schmidt