Boost logo

Boost Users :

From: Scott Meyers (usenet_at_[hidden])
Date: 2007-03-29 02:52:22


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<typename Seq, typename T> 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<typename Seq, typename T>
struct eraseVal
   : mpl::eval_if<
       boost::is_same<typename mpl::find<Seq, T>::type,
                      typename mpl::end<Seq>::type>,
       typename mpl::identity<Seq>::type,
       eraseVal<typename mpl::erase<Seq,
                  typename mpl::find<Seq,T>::type,
                  typename mpl::next<typename mpl::find<Seq,T>::type>::type
>::type,
                T>
>
{};

My more procedural attempt looks better (to me), but it still doesn't compile:

template<typename Seq, typename T>
struct eraseVal {
   typedef typename mpl::find<Seq,T>::type iter;
   typedef typename mpl::eval_if<
     boost::is_same<iter,
                    typename mpl::end<Seq>::type>,
     typename mpl::identity<Seq>::type,
     typename eraseVal<typename mpl::erase<Seq,
                                           iter,
                                           mpl::next<iter>::type
>::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?

Thanks,

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