]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Algorithms/Transformation Algorithms//stable_partition |90 |
2 | ||
3 | stable_partition | |
4 | ================ | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename Seq | |
13 | , typename Pred | |
14 | , typename In1 = |unspecified| | |
15 | , typename In2 = |unspecified| | |
16 | > | |
17 | struct stable_partition | |
18 | { | |
19 | typedef |unspecified| type; | |
20 | }; | |
21 | ||
22 | ||
23 | Description | |
24 | ----------- | |
25 | ||
26 | Returns a pair of sequences together containing all elements in the range | |
27 | |begin/end<Seq>| split into two groups based on the predicate ``Pred``. | |
28 | ``stable_partition`` is guaranteed to preserve the relative order of the | |
29 | elements in the resulting sequences. | |
30 | ||
31 | ||
32 | |transformation algorithm disclaimer| | |
33 | ||
34 | ||
35 | Header | |
36 | ------ | |
37 | ||
38 | .. parsed-literal:: | |
39 | ||
40 | #include <boost/mpl/stable_partition.hpp> | |
41 | ||
42 | ||
43 | Model of | |
44 | -------- | |
45 | ||
46 | |Reversible Algorithm| | |
47 | ||
48 | ||
49 | Parameters | |
50 | ---------- | |
51 | ||
52 | +-------------------+-----------------------------------+-------------------------------+ | |
53 | | Parameter | Requirement | Description | | |
54 | +===================+===================================+===============================+ | |
55 | | ``Seq`` | |Forward Sequence| | An original sequence. | | |
56 | +-------------------+-----------------------------------+-------------------------------+ | |
57 | | ``Pred`` | Unary |Lambda Expression| | A partitioning predicate. | | |
58 | +-------------------+-----------------------------------+-------------------------------+ | |
59 | | ``In1``, ``In2`` | |Inserter| | Output inserters. | | |
60 | +-------------------+-----------------------------------+-------------------------------+ | |
61 | ||
62 | ||
63 | Expression semantics | |
64 | -------------------- | |
65 | ||
66 | |Semantics disclaimer...| |Reversible Algorithm|. | |
67 | ||
68 | For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``, and |Inserter|\ s | |
69 | ``in1`` and ``in2``: | |
70 | ||
71 | ||
72 | .. parsed-literal:: | |
73 | ||
74 | typedef stable_partition<s,pred,in1,in2>::type r; | |
75 | ||
76 | :Return type: | |
77 | A |pair|. | |
78 | ||
79 | :Semantics: | |
80 | Equivalent to | |
81 | ||
82 | .. parsed-literal:: | |
83 | ||
84 | typedef lambda<pred>::type p; | |
85 | typedef lambda<in1::operation>::type in1_op; | |
86 | typedef lambda<in2::operation>::type in2_op; | |
87 | ||
88 | typedef fold< | |
89 | s | |
90 | , pair< in1::state, in2::state > | |
91 | , if_< | |
92 | apply_wrap\ ``1``\<p,_2> | |
93 | , pair< apply_wrap\ ``2``\<in1_op,first<_1>,_2>, second<_1> > | |
94 | , pair< first<_1>, apply_wrap\ ``2``\<in2_op,second<_1>,_2> > | |
95 | > | |
96 | >::type r; | |
97 | ||
98 | ||
99 | Complexity | |
100 | ---------- | |
101 | ||
102 | Linear. Exactly ``size<s>::value`` applications of ``pred``, and ``size<s>::value`` | |
103 | of summarized ``in1::operation`` / ``in2::operation`` applications. | |
104 | ||
105 | ||
106 | Example | |
107 | ------- | |
108 | ||
109 | .. parsed-literal:: | |
110 | ||
111 | template< typename N > struct is_odd : bool_<(N::value % 2)> {}; | |
112 | ||
113 | typedef stable_partition< | |
114 | range_c<int,0,10> | |
115 | , is_odd<_1> | |
116 | , back_inserter< vector<> > | |
117 | , back_inserter< vector<> > | |
118 | >::type r; | |
119 | ||
120 | BOOST_MPL_ASSERT(( equal< r::first, vector_c<int,1,3,5,7,9> > )); | |
121 | BOOST_MPL_ASSERT(( equal< r::second, vector_c<int,0,2,4,6,8> > )); | |
122 | ||
123 | ||
124 | See also | |
125 | -------- | |
126 | ||
127 | |Transformation Algorithms|, |Reversible Algorithm|, |reverse_stable_partition|, |partition|, |sort|, |transform| | |
128 | ||
129 | ||
130 |