• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. Algorithms/Transformation Algorithms//reverse_replace_if |150
2
3reverse_replace_if
4==================
5
6
7Synopsis
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
24Description
25-----------
26
27Returns a reversed copy of the original sequence where every type that satisfies
28the predicate ``Pred`` has been replaced with ``NewType``.
29
30|transformation algorithm disclaimer|
31
32Header
33------
34
35.. parsed-literal::
36
37    #include <boost/mpl/replace_if.hpp>
38
39
40
41Model of
42--------
43
44|Reversible Algorithm|
45
46
47Parameters
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
63Expression semantics
64--------------------
65
66|Semantics disclaimer...| |Reversible Algorithm|.
67
68For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``,
69an |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
88Complexity
89----------
90
91Linear. Performs exactly ``size<s>::value`` applications of ``pred``, and at most
92``size<s>::value`` insertions.
93
94
95Example
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
112See also
113--------
114
115|Transformation Algorithms|, |Reversible Algorithm|, |replace_if|, |reverse_replace|, |remove_if|, |transform|
116
117
118.. copyright:: Copyright �  2001-2009 Aleksey Gurtovoy and David Abrahams
119   Distributed under the Boost Software License, Version 1.0. (See accompanying
120   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
121