Boost logo

Boost Users :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2006-07-26 21:19:39


Eric Lemings writes:
> How would you combine the boost::mpl::partition and
> boost::mpl::unique algorithms such that an element that is not
> placed into the first inserter (for unique elements) is placed into
> the second inserter (for non-unique elements)?

I'm afraid you can't combine them literally, but you can use the
"Semantics" section from the algorithms' reference pages to get an
idea of how to approach this, e.g. (untested!):

template<
      typename Seq
    , typename Pred
    , typename In1
    , typename In2
>
struct unique_partition
    : fold<
          iterator_range<
              typename next< typename begin<Seq>::type >::type
            , typename end<Seq>::type
>
        , vector3<
              typename In1::state
            , typename In2::state
            , typename front<Seq>::type
>
        , if_<
              apply2< Pred, at<_1,int_<2> >, _2 >
            , vector3<
                  apply2< typename In1::operation, at<_1,int_<0> >, _2 >
                , at<_1,int_<1> >
                , _2
>
            , vector3<
                  at<_1,int_<0>
                , apply2< typename In2::operation, at<_1,int_<1> >, _2 >
                , _2
>
>
>
    {
    };

HTH,

-- 
Aleksey Gurtovoy
MetaCommunications Engineering

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