Boost logo

Boost Users :

From: Scott Meyers (usenet_at_[hidden])
Date: 2007-03-17 14:57:30


I want to implement this:

// returns whether Seq1 includes each of the elements in Seq2
// using Pred to determine type equality
template<typename Seq1, // the putative superset
          typename Seq2, // the putative subset
          typename Pred> // whether T1 from Seq1 == T2 from Seq2
struct includes_if;

My ultimate goal is to be able to determine whether every element in
Seq2 is either in Seq1 or has a base class in Seq1. So the predicate
I'll be passing in is a metafunction class that invokes
std::tr1::is_base_of.

Here's my code, all but one line of which is supposed to be correct:

template<typename Seq1, // the putative superset
          typename Seq2, // the putative subset
          typename Pred> // whether T1 from Seq1 == T2 from Seq2
struct includes_if
: boost::is_same<
     typename mpl::find_if<
       Seq2,
       mpl::not_<mpl::contains_if<Seq1,
                                  lambda(T) is_base_of<mpl::_1, T> //!!
> >
>::type,
     typename mpl::end<Seq2>::type
>
{};

The line I don't know how to write is flagged, but the functionality I
want to express is shown.

In case it's relevant, here is the rest of my code:

// metafunction class for TR1-conforming is_base_of
struct is_base_of {
   template<typename T1, typename T2>
   struct apply: std::tr1::is_base_of<T1, T2> {};
};

// returns whether Seq contains an element satisfying Pred
template<typename Seq, typename Pred>
struct contains_if
: mpl::not_<
     boost::is_same<
       typename mpl::find_if< Seq, mpl::apply<Pred, mpl::_1> >::type,
       typename mpl::end<Seq>::type
>
>
{};

Thanks for all help,

Scott


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