Boost logo

Boost :

From: Jaap Suter (J.Suter_at_[hidden])
Date: 2002-09-05 06:54:00


> 6. Any comment on the following code and why it doesn't compile?

Never mind this last code. I was being a n00b again. I changed it to the
following:

// Meta fuction;
template < typename Sequence, typename Element >
struct set_push_front
{
    typedef boost::mpl::if_<
        boost::mpl::contains< Sequence, Element >,
            Sequence,
            boost::mpl::push_front< Sequence, Element >::type
>::type type;
};

// Two lists;
typedef boost::mpl::vector_c< size_t, 0, 1, 2, 3, 4 > grade_list_1;
typedef boost::mpl::vector_c< size_t, 2, 3, 4 > grade_list_2;

// Combine the two;
typedef boost::mpl::fold<
        grade_list_2,
        grade_list_1,
        set_push_front< boost::mpl::_1, boost::mpl::_2 >
>::type combined_list;

// combined_list == 0, 1, 2, 3, 4;

Which works perfectly!

Thanks anyway :).

Regards,

Jaap Suter


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