
Scott Meyers ha escrito:
Since set seems to be broken, I find myself wanting to implement this metafunction. It need work only for vectors:
// erase all occurrences of T in Seq template
struct eraseVal; After several hours and tens or hundreds of thousands of lines of error messages from three compilers, I am unable to get it working.
My attempt to do it the "right" way looks like this, and I must warn you in advance that it's not pretty, unless you like an approach that calls find three times with the same arguments:
template
struct eraseVal : mpl::eval_if< boost::is_same ::type, typename mpl::end<Seq>::type>, typename mpl::identity<Seq>::type, eraseVal ::type, typename mpl::next ::type>::type >::type, T> > {}; My more procedural attempt looks better (to me), but it still doesn't compile:
template
struct eraseVal { typedef typename mpl::find ::type iter; typedef typename mpl::eval_if< boost::is_same , typename mpl::identity<Seq>::type, typename eraseVal ::type, T>::type > type; }; God I miss iteration. And I really wish emacs would match angle brackets in C++ mode, sigh.
Can somebody please help me out?
Hello Scott, I see several problems with your procedural approach: the first one
is the ::type added to mpl::identity<Seq> and eraseVal<...> in the expression
typedef typename mpl::eval_if<
boost::is_same<...>,
typename mpl::identity<Seq>::type,
typename eraseVal<...>::type
> type;
Since eval_if is designed precisely to defer invocation of its argument
metafunctions the correct mode of use is
typedef typename mpl::eval_if<
boost::is_same<...>,
typename mpl::identity<Seq>,
typename eraseVal<...>
> type;
so that infinite recursion on eraseVal is avoided. But even after dropping those
::type's you still get errors like this:
[...]/boost/mpl/next_prior.hpp: In instantiation of `boost::mpl::next