I've a meta-program that works fine with the regular boost mpl. It looks more like the following.
template <class Vector, class ResultKind, class Custom>
struct FilterChildrenIfNotOk
{
typedef typename
copy_if<Vector,
or_<is_same<boost::mpl::placeholders::_1, ResultKind>,
IsOk<boost::mpl::placeholders::_1,
ResultKind,
Custom> > >::type type;
};
I'm trying to compile it using variadic templates vector (mpl::vector). For that开发者_C百科, I'm using the implementation of variadic templates vector found here: https://svn.boost.org/svn/boost/sandbox/variadic_templates
I could not find usable implementations of copy_if, remove_if, and count_if in the repo, although there are some tests. Are those meta-programs there and I'm just not able to find them? Alternately, can you please help me implement one of them such that it also supports mpl placeholders. Thanks for your help in advance.
Let's start with an hint: fold is way more powerful than one would think. For example, counting the number of elements in a sequence just consists in applying fold
with the initial state 0 and the function that takes a state (the number of elements so far) and an element, and return the_state + 1
.
Now can you write count_if
, for example? (using fold
obviously)
If you don't manage to I will help you out until you succeed.
精彩评论