Boost logo

Boost :

From: Iain K.Hanson (iain.hanson_at_[hidden])
Date: 2002-12-12 11:23:59


I'm having a problem using fold with the example from the reference
page. I can get the following example from copy to comile as fold

    namespace mpl = boost::mpl;
    using mpl::_;

    typedef mpl::vector10_c<int,9,8,7,6,5,4,3,2,1,0> answer;

    typedef mpl::fold<
          mpl::range_c<int,0,10>
        , mpl::vector<>
        , mpl::push_front<_,_>
>::type result;

    BOOST_STATIC_ASSERT(mpl::size<result>::value == 10);
    BOOST_STATIC_ASSERT((mpl::equal< result,answer >::type::value));

but this won't:

    namespace mpl = boost::mpl;
    using mpl::_1;
    using mpl::_2;

    typedef mpl::vector<long,float,short,double,float,long,long double>
types;

    typedef mpl::fold<
        types
        , mpl::integral_c<long, 0>
        , mpl::if_< boost::is_float<_2>, mpl::next<_1>,_1 >
>::type number_of_floats;

typedef mpl::lambda< number_of_floats >::type func;

    BOOST_STATIC_ASSERT(( number_of_floats::value == 3 ));

I presume that the problem is here

        , mpl::if_< boost::is_float<_2>, mpl::next<_1>,_1 >
                    ^^^^^^^^^^^^^^^^^^^

as this is a non-mpl metafunction. The paper mentions using make_f[n]
but I can't find it.

Can any one tell me how to fix the above please?

Also, what are the requirement on a metafunction to be used with
lambda. A simple example would be useful.

Thanks

/ikh


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk