.. Algorithms/Transformation Algorithms//stable_partition |90 stable_partition ================ Synopsis -------- .. parsed-literal:: template< typename Seq , typename Pred , typename In1 = |unspecified| , typename In2 = |unspecified| > struct stable_partition { typedef |unspecified| type; }; Description ----------- Returns a pair of sequences together containing all elements in the range |begin/end| split into two groups based on the predicate ``Pred``. ``stable_partition`` is guaranteed to preserve the relative order of the elements in the resulting sequences. |transformation algorithm disclaimer| Header ------ .. parsed-literal:: #include Model of -------- |Reversible Algorithm| Parameters ---------- +-------------------+-----------------------------------+-------------------------------+ | Parameter | Requirement | Description | +===================+===================================+===============================+ | ``Seq`` | |Forward Sequence| | An original sequence. | +-------------------+-----------------------------------+-------------------------------+ | ``Pred`` | Unary |Lambda Expression| | A partitioning predicate. | +-------------------+-----------------------------------+-------------------------------+ | ``In1``, ``In2`` | |Inserter| | Output inserters. | +-------------------+-----------------------------------+-------------------------------+ Expression semantics -------------------- |Semantics disclaimer...| |Reversible Algorithm|. For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``, and |Inserter|\ s ``in1`` and ``in2``: .. parsed-literal:: typedef stable_partition::type r; :Return type: A |pair|. :Semantics: Equivalent to .. parsed-literal:: typedef lambda::type p; typedef lambda::type in1_op; typedef lambda::type in2_op; typedef fold< s , pair< in1::state, in2::state > , if_< apply_wrap\ ``1``\ , pair< apply_wrap\ ``2``\,_2>, second<_1> > , pair< first<_1>, apply_wrap\ ``2``\,_2> > > >::type r; Complexity ---------- Linear. Exactly ``size::value`` applications of ``pred``, and ``size::value`` of summarized ``in1::operation`` / ``in2::operation`` applications. Example ------- .. parsed-literal:: template< typename N > struct is_odd : bool_<(N::value % 2)> {}; typedef stable_partition< range_c , is_odd<_1> , back_inserter< vector<> > , back_inserter< vector<> > >::type r; BOOST_MPL_ASSERT(( equal< r::first, vector_c > )); BOOST_MPL_ASSERT(( equal< r::second, vector_c > )); See also -------- |Transformation Algorithms|, |Reversible Algorithm|, |reverse_stable_partition|, |partition|, |sort|, |transform|