Boost logo

Boost Users :

From: Karl Friedrich Walkow (walkow_at_[hidden])
Date: 2005-12-23 08:40:59


Hi Eduardo,

the fold algorithm iterates over a mpl-sequence. the function needs
three arguments as input: the sequence to iterate over, a "starting
condition" and a binary operation.
at every step of the iteration the algorithm applies two arguments to
the binary operation: the first argument is the output of the previous
invocation of the operation (at the first step that is the starting
condition). the second argument is the currently processed element from
your input sequence. the "starting condition" also determines the return
type of your fold-operation.
about the placeholders you only have to know that "_1" means the first
and "_2" stands for the second argument. if you don't have the line
"using namespace boost::mpl" in your code, the placeholders are
boost::mpl::_1 and boost::mpl::_2.
that should be all!

the algorithm from the example returns an integral constant with the
number of elements in the input sequence that are float types.
if is_float applied to the current element returns true, than the
integral constant will be incremented by one ("next<_1>"), otherwise it
will not be changed and so on.

Regards,
Karl


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