Eduardo Bezerra wrote:
Hi,
I'm having a hard time trying to understand what the placeholders _1 and _2 mean in the context of the mpl::fold algorithm.
From the Boost.Mpl Reference manual:
typedef vector
types; typedef fold< types , int_<0> , if_< is_float<_2>,next<_1>,_1 >
::type number_of_floats;
BOOST_MPL_ASSERT_RELATION( number_of_floats::value, ==, 4 );
_1 is the result holder, _2 is the current element. Let's for a moment translate the thing to some pseudo-code: number_of_floats = fold(types, 0, lambda(value, element){return is_float(element) ? value+1, value; }); Where fold is function fold(sequence, initial_value, func) { value = initial_value; for each element in sequence { value = func(value, element); } } _1 is value, _2 is element. Sebastian Redl