]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Algorithms/Transformation Algorithms//reverse_replace_if |150 |
2 | ||
3 | reverse_replace_if | |
4 | ================== | |
5 | ||
6 | ||
7 | Synopsis | |
8 | -------- | |
9 | ||
10 | .. parsed-literal:: | |
11 | ||
12 | template< | |
13 | typename Sequence | |
14 | , typename Pred | |
15 | , typename In = |unspecified| | |
16 | > | |
17 | struct reverse_replace_if | |
18 | { | |
19 | typedef |unspecified| type; | |
20 | }; | |
21 | ||
22 | ||
23 | ||
24 | Description | |
25 | ----------- | |
26 | ||
27 | Returns a reversed copy of the original sequence where every type that satisfies | |
28 | the predicate ``Pred`` has been replaced with ``NewType``. | |
29 | ||
30 | |transformation algorithm disclaimer| | |
31 | ||
32 | Header | |
33 | ------ | |
34 | ||
35 | .. parsed-literal:: | |
36 | ||
37 | #include <boost/mpl/replace_if.hpp> | |
38 | ||
39 | ||
40 | ||
41 | Model of | |
42 | -------- | |
43 | ||
44 | |Reversible Algorithm| | |
45 | ||
46 | ||
47 | Parameters | |
48 | ---------- | |
49 | ||
50 | +---------------+-----------------------------------+-------------------------------+ | |
51 | | Parameter | Requirement | Description | | |
52 | +===============+===================================+===============================+ | |
53 | | ``Sequence`` | |Forward Sequence| | An original sequence. | | |
54 | +---------------+-----------------------------------+-------------------------------+ | |
55 | | ``Pred`` | Unary |Lambda Expression| | A replacement condition. | | |
56 | +---------------+-----------------------------------+-------------------------------+ | |
57 | | ``NewType`` | Any type | A type to replace with. | | |
58 | +---------------+-----------------------------------+-------------------------------+ | |
59 | | ``In`` | |Inserter| | An inserter. | | |
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``, | |
69 | an |Inserter| ``in``, and arbitrary type ``x``: | |
70 | ||
71 | ||
72 | .. parsed-literal:: | |
73 | ||
74 | typedef reverse_replace_if<s,pred,x,in>::type r; | |
75 | ||
76 | :Return type: | |
77 | A type. | |
78 | ||
79 | :Semantics: | |
80 | Equivalent to | |
81 | ||
82 | .. parsed-literal:: | |
83 | ||
84 | typedef lambda<pred>::type p; | |
85 | typedef reverse_transform< s, if_< apply_wrap1<p,_1>,x,_1>, in >::type r; | |
86 | ||
87 | ||
88 | Complexity | |
89 | ---------- | |
90 | ||
91 | Linear. Performs exactly ``size<s>::value`` applications of ``pred``, and at most | |
92 | ``size<s>::value`` insertions. | |
93 | ||
94 | ||
95 | Example | |
96 | ------- | |
97 | ||
98 | .. parsed-literal:: | |
99 | ||
100 | typedef vector_c<int,1,4,5,2,7,5,3,5> numbers; | |
101 | typedef vector_c<int,1,4,0,2,0,0,3,0> expected; | |
102 | typedef reverse_replace_if< | |
103 | numbers | |
104 | , greater< _, int_<4> > | |
105 | , int_<0> | |
106 | , front_inserter< vector<> > | |
107 | >::type result; | |
108 | ||
109 | BOOST_MPL_ASSERT(( equal< result,expected, equal_to<_,_> > )); | |
110 | ||
111 | ||
112 | See also | |
113 | -------- | |
114 | ||
115 | |Transformation Algorithms|, |Reversible Algorithm|, |replace_if|, |reverse_replace|, |remove_if|, |transform| | |
116 | ||
117 | ||
118 |