Boost logo

Boost :

From: Brian Braatz (brianb_at_[hidden])
Date: 2005-06-17 07:39:32

> "Brian Braatz" <brianb_at_[hidden]> writes:
> >
> > I am looking for a way to basically do this:
> >
> > typedef vector<int,float,float,char,int,int,int,double> types;
> > typedef vector<int,float,char, double> expected;
> > typedef unique_all< types, is_same<_1,_2> >::type result;
> >
> > BOOST_MPL_ASSERT(( equal< result,expected > ));
> >
> >
> > (note the examples I am using use integral types, in my situation I
> > not using integral types)
> >
[David Abrahams Writes:]
> If you don't need to preserve order, just stick them in an
> mpl::set<>. In fact, you might be able to use a set<> to begin with
> and just skip the vector<>.
> Otherwise, I would write a little algorithm based on the
> implementation of remove_if (which you can find nicely described in
> the online reference manual). Instead of passing along a predicate at
> each stage of the fold<>, pass along a set<> that accumulates the
> elements you've already seen. When the next element is already in the
> set<>, skip it.
> Try working that out for yourself; it'll be good for you ;-)
> If you get stuck, ask again!
[Brian Braatz Writes:]
:) Thank you for the advice.

There is a common mental pattern that occurs:

"Hmm.. there SHOULD be a SIMPLE way to do X."
(flip through MPL book, MPL ref manual, google boost archives, write
sample code)
"Hmm.. Ok I can see there maybe a way to do this COMPLETELY from
scratch, but I am not totally certain I need to do that. I need to keep
looking. There probably is a clever one liner to solve the problem"....

Your advice was EXACLY what I needed. (i..e how to THINK about the




Boost list run by bdawes at, gregod at, cpdaniel at, john at