Boost logo

Boost :

From: Brian Braatz (brianb_at_[hidden])
Date: 2005-06-05 14:18:06


> >>
> >>template <class type_t, class sequence_t>
> >>struct copy_col_if_in_dest
> >>: public if_< typename is_same< typename deref<typename
> >>boost::mpl::find<sequence_t, type_t>::type >::type, type_t>,
> >
> > do_copy_col,
> >
> >>do_not_copy_col>::type
> >>{
> >>};
>
> This code has a problem when type_t is not in sequence_t: the
> past-the-end iterator gets dereferenced. I wrote a short program to do
> what you want (it's more explicit, it uses mpl::contains<>):
>
> #include <boost/mpl/vector.hpp>
> #include <boost/mpl/if.hpp>
> #include <boost/mpl/contains.hpp>
>
> namespace mpl = boost::mpl;
>
> struct do_copy_col {};
> struct dont_copy_col {};
>
> template<typename T, typename Seq>
> struct copy_col_if_in_dest
> : mpl::if_<
> mpl::contains<Seq, T>,
> do_copy_col,
> dont_copy_col
> >::type
> {
> };
>
> int main()
> {
> typedef mpl::vector<char, short, int, long> v;
> do_copy_col do_copy = copy_col_if_in_dest<int, v>();
> dont_copy_col dont_copy = copy_col_if_in_dest<bool, v>();
> return 0;
> }
>

[Brian Braatz Writes:]
Wow. Many THANKS- the mpl::contains<> is REALLY what I was looking for.
(Though the exercise of doing it with if_<> was a useful experience)

THANK YOU

( I have been burning the morning and afternoon oil here the last few
weeks trying to get a lib I am proposing ready for boost people to look
at)

-I am going to replace the code I had with the code you presented, and
make a note of your contribution.

THANKS AGAIN!

Brian


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