Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-06-12 09:51:24


"Ovanes Markarian" <om_boost_at_[hidden]> 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

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