[mpl] remove duplicates in (non-integral) type sequences

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

Karl Friedrich Walkow <walkow@vwitme011.vkw.tu-dresden.de> writes:
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...
// untested template <class S> remove_duplicates { typedef typename fold< S , pair< typename clear<S>::type, set0<> > , if_< contains< second<_1>, _2 > , _1 , pair< push_back< first<_1>, _2> , insert< second<_1>, _2 > > > >::type::first type; }; HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com

Great, it works, thank you. According to the reference manual, the contains function works on every forward sequence, but that's not right... regards, karl
participants (2)
-
David Abrahams
-
Karl Friedrich Walkow