Boost logo

Boost Users :

From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-05-22 22:39:24


AMDG

Alfred Kohl wrote:
> I'd like to use MPL to remove elements of a set from another set.
>

Try this:

#include <boost/mpl/set.hpp>
#include <boost/mpl/remove_if.hpp>
#include <boost/mpl/has_key.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/insert.hpp>

using boost::mpl::set;

struct a {};
struct b {};
struct c {};

typedef set<a, b, c> input;
typedef set<b, c> remove_these;

struct set_inserter {
    typedef set<> state;
    typedef boost::mpl::insert<boost::mpl::_1, boost::mpl::_2> operation;
};

typedef boost::mpl::remove_if<input, boost::mpl::has_key<remove_these,
boost::mpl::_1>, set_inserter>::type result;

BOOST_MPL_ASSERT((boost::mpl::equal<result, set<a> >));

int main() {
}

In Christ,
Steven Watanabe


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