Re: [Boost-users] mpl::accumulate
Hello, can someone tell me what exactly a parameter State in the mpl::accumulate means. After the evaluation is finished, which type is returned by accumulate? State? Which types are passed to the binary ForwardOp? I do not exactly understand this example: typedef vector<long,float,short,double,float,long,long double> types; typedef accumulate< types , int_<0> , if_< is_float<_2>,next<_1>,_1 > >::type number_of_floats; With Kind Regards, Ovanes Markarian
"Ovanes Markarian" <om_boost@keywallet.com> writes:
Hello,
can someone tell me what exactly a parameter State in the mpl::accumulate means.
It's exactly like the second form of std::accumulate http://www.sgi.com/tech/stl/accumulate.html
After the evaluation is finished, which type is returned by accumulate? State?
No. For example, if the elements are (e1, e2, e3), the type returned is mpl::apply< binary_op , mpl::apply< binary_op , mpl::apply<binary_op, State, e1>::type , e2 >::type , e3 >::type or, in pseudocode, binary_op( binary_op( binary_op(State,e1), e2), e3)
Which types are passed to the binary ForwardOp?
See above.
I do not exactly understand this example:
typedef vector<long,float,short,double,float,long,long double> types;
typedef accumulate< types , int_<0> , if_< is_float<_2>,next<_1>,_1 > >::type number_of_floats;
The whole expression returns a type-representation of the number of instances of "float" in the sequence "types." State is int_<0>, a type-representation of the number zero. binary_op is lambda expression that returns either its first argument or a type-representation of its first argument plus one. <plug> BTW, http://www.boost-consulting.com/mplbook has a pretty good explanation of this material. </plug> HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Ovanes Markarian