Boost logo

Boost Users :

From: Karl Friedrich Walkow (walkow_at_[hidden])
Date: 2005-12-12 07:13:33


i try to find a solution for eliminating all duplicates of types in a
non-integral sequence.
the only extisting solution i found has a set< > as output, but i want
to keep the sequence type.
the following code _should_ solve the problem, but there seems to be
something wrong with it.

if someone has an idea...

#include <boost/mpl/assert.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/empty_sequence.hpp>
#include <boost/mpl/contains.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/joint_view.hpp>
#include <boost/mpl/single_view.hpp>
#include <boost/mpl/size.hpp>

using namespace boost::mpl;

struct E {};
struct F {};
struct G {};
struct H {};

int main(int argc, char* argv[]) {

     typedef vector< E, E, F, E, G, H, G, G, F, G >::type with_duplicates;

     typedef fold< with_duplicates, empty_sequence, if_< contains< _1,
_2 >::type, _1, joint_view< _1, single_view< _2 >::type >::type >::type
>::type without_duplicates;

     BOOST_MPL_ASSERT_RELATION(size<with_duplicates>::value, ==, 10);
     BOOST_MPL_ASSERT_RELATION(size<without_duplicates>::value, ==, 4);

     return 0;
}

much thanks in advance,
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