Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
Front Page / Algorithms / Transformation Algorithms / reverse_partition



      typename Seq
    , typename Pred
    , typename In1 = unspecified
    , typename In2 = unspecified
struct reverse_partition
    typedef unspecified type;


Returns a pair of sequences together containing all elements in the range [begin<Seq>::type, end<Seq>::type) split into two groups based on the predicate Pred. reverse_partition is a synonym for reverse_stable_partition.

[Note: This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a precise specification of the algorithm's details in all cases — end note]


#include <boost/mpl/partition.hpp>

Model of

Reversible Algorithm


Parameter Requirement Description
Seq Forward Sequence An original sequence.
Pred Unary Lambda Expression A partitioning predicate.
In1, In2 Inserter Output inserters.

Expression semantics

The semantics of an expression are defined only where they differ from, or are not defined in Reversible Algorithm.

For any Forward Sequence s, an unary Lambda Expression pred, and Inserters in1 and in2:

typedef reverse_partition<s,pred,in1,in2>::type r;
Return type:A pair.

Equivalent to

typedef reverse_stable_partition<s,pred,in1,in2>::type r;


Linear. Exactly size<s>::value applications of pred, and size<s>::value of summarized in1::operation / in2::operation applications.


template< typename N > struct is_odd : bool_<(N::value % 2)> {};

typedef partition<
    , is_odd<_1>
    , back_inserter< vector<> >
    , back_inserter< vector<> >
    >::type r;

BOOST_MPL_ASSERT(( equal< r::first, vector_c<int,9,7,5,3,1> > ));
BOOST_MPL_ASSERT(( equal< r::second, vector_c<int,8,6,4,2,0> > ));

See also

Transformation Algorithms, Reversible Algorithm, partition, reverse_stable_partition, sort