Scott Meyers wrote:
It will take me a few days to digest your comments
Hopefully not because they're confusing :-). I tried to increase
conciseness with my second post.
(this is largely new
territory for me), but I wanted to acknowledge your help now. Thanks
very much.
Thanks too -- a reader who's new to the territory is most valuable to
improve one's communication skills.
The problem comes down to that MPL can't know where one placeholder
expression starts and where another one ends (denoted by uppercase
identifiers, above):
Yes, I ran into this problem playing around as a result of the help
posted earlier. As I said, it will take me a while to get a grasp on
what you've done. I have to look a lot of stuff up and write a lot of
test cases :-)
There's a slightly altered approach to this problem attached to this
message for some additional fun.
Regards,
Tobias
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace mpl = boost::mpl;
using namespace mpl::placeholders;
using boost::is_same;
// contains_if
template
struct contains_if
: mpl::not_< boost::is_same::type,
typename mpl::end<Seq>::type> >
{ };
// test it
typedef mpl::vector<int> v1;
BOOST_MPL_ASSERT(( contains_if > ));
BOOST_MPL_ASSERT_NOT(( contains_if > ));
// contains implemented on top of it
//
// other than mpl::contains this version takes a binary predicate to parametrize
// comparison
template >
struct contains
// uses 'lambda', because 'bind' requires a Metafunction Class instead of an
// arbitrary Lambda Expressions
: contains_if< S, mpl::bind >
{ };
// test it
BOOST_MPL_ASSERT(( ::contains ));
BOOST_MPL_ASSERT_NOT(( ::contains ));
// a facility that allows to sustain the evaluation of placeholder expressions
template<typename PlaceholderExpr>
struct defer
{
template<typename IgnoredPlaceholder> struct get
{
typedef PlaceholderExpr type;
};
// return a dummy placeholder expression that evaluates to the
// original one (without substitution applied)
typedef typename defer<PlaceholderExpr>::template get<_> type;
};
// test it
BOOST_MPL_ASSERT(( is_same::type ,int>::type, _1> ));
BOOST_MPL_ASSERT(( is_same::type,
int>::type,int>::type, int> ));
// now implement includes on top of
template >
struct includes
: mpl::not_< contains_if< SubSeq, mpl::not_< contains > > >
{ };
// test it
typedef mpl::vector<int> v1;
typedef mpl::vector v2;
BOOST_MPL_ASSERT(( includes ));
BOOST_MPL_ASSERT_NOT(( includes ));