Boost logo

Boost :

From: Ariel Badichi (abadichi_at_[hidden])
Date: 2005-06-04 18:26:40


Brian Braatz wrote:
> HAHAHAHA
>
> Nevermind.

Just when I was about to post?

Anyways, concerning your original message:

>>
>>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;
}


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