]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Algorithms/Transformation Algorithms//partition |85 |
2 | ||
3 | 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 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 | ``partition`` is a synonym for |stable_partition|. | |
29 | ||
30 | |transformation algorithm disclaimer| | |
31 | ||
32 | ||
33 | Header | |
34 | ------ | |
35 | ||
36 | .. parsed-literal:: | |
37 | ||
38 | #include <boost/mpl/partition.hpp> | |
39 | ||
40 | ||
41 | Model of | |
42 | -------- | |
43 | ||
44 | |Reversible Algorithm| | |
45 | ||
46 | ||
47 | Parameters | |
48 | ---------- | |
49 | ||
50 | +-------------------+-----------------------------------+-------------------------------+ | |
51 | | Parameter | Requirement | Description | | |
52 | +===================+===================================+===============================+ | |
53 | | ``Seq`` | |Forward Sequence| | An original sequence. | | |
54 | +-------------------+-----------------------------------+-------------------------------+ | |
55 | | ``Pred`` | Unary |Lambda Expression| | A partitioning predicate. | | |
56 | +-------------------+-----------------------------------+-------------------------------+ | |
57 | | ``In1``, ``In2`` | |Inserter| | Output inserters. | | |
58 | +-------------------+-----------------------------------+-------------------------------+ | |
59 | ||
60 | ||
61 | Expression semantics | |
62 | -------------------- | |
63 | ||
64 | |Semantics disclaimer...| |Reversible Algorithm|. | |
65 | ||
66 | For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``, and |Inserter|\ s | |
67 | ``in1`` and ``in2``: | |
68 | ||
69 | ||
70 | .. parsed-literal:: | |
71 | ||
72 | typedef partition<s,pred,in1,in2>::type r; | |
73 | ||
74 | :Return type: | |
75 | A |pair|. | |
76 | ||
77 | :Semantics: | |
78 | Equivalent to | |
79 | ||
80 | .. parsed-literal:: | |
81 | ||
82 | typedef stable_partition<s,pred,in1,in2>::type r; | |
83 | ||
84 | ||
85 | Complexity | |
86 | ---------- | |
87 | ||
88 | Linear. Exactly ``size<s>::value`` applications of ``pred``, and ``size<s>::value`` | |
89 | of summarized ``in1::operation`` / ``in2::operation`` applications. | |
90 | ||
91 | ||
92 | Example | |
93 | ------- | |
94 | ||
95 | .. parsed-literal:: | |
96 | ||
97 | template< typename N > struct is_odd : bool_<(N::value % 2)> {}; | |
98 | ||
99 | typedef partition< | |
100 | range_c<int,0,10> | |
101 | , is_odd<_1> | |
102 | , back_inserter< vector<> > | |
103 | , back_inserter< vector<> > | |
104 | >::type r; | |
105 | ||
106 | BOOST_MPL_ASSERT(( equal< r::first, vector_c<int,1,3,5,7,9> > )); | |
107 | BOOST_MPL_ASSERT(( equal< r::second, vector_c<int,0,2,4,6,8> > )); | |
108 | ||
109 | ||
110 | See also | |
111 | -------- | |
112 | ||
113 | |Transformation Algorithms|, |Reversible Algorithm|, |reverse_partition|, |stable_partition|, |sort| | |
114 | ||
115 | ||
116 |