...one of the most highly
regarded and expertly designed C++ library projects in the
world.

— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards

Front Page / Algorithms / Transformation Algorithms / reverse_replace_if |

template< typename Sequence , typename Pred , typename In =unspecified> struct reverse_replace_if { typedefunspecifiedtype; };

Returns a reversed copy of the original sequence where every type that satisfies
the predicate `Pred` has been replaced with `NewType`.

[*Note:* This wording applies to a no-inserter version(s) of the algorithm. See the
Expression semantics subsection for a precise specification of the algorithm's
details in all cases — *end note*]

#include <boost/mpl/replace_if.hpp>

Parameter | Requirement | Description |
---|---|---|

Sequence |
Forward Sequence | An original sequence. |

Pred |
Unary Lambda Expression | A replacement condition. |

NewType |
Any type | A type to replace with. |

In |
Inserter | An inserter. |

The semantics of an expression are defined only where they differ from, or are not defined in Reversible Algorithm.

For any Forward Sequence `s`, an unary Lambda Expression `pred`,
an Inserter `in`, and arbitrary type `x`:

typedef reverse_replace_if<s,pred,x,in>::type r;

Return type: | A type. |
---|---|

Semantics: | Equivalent to typedef lambda<pred>::type p; typedef reverse_transform< s, if_< apply_wrap1<p,_1>,x,_1>, in >::type r; |

Linear. Performs exactly `size<s>::value` applications of `pred`, and at most
`size<s>::value` insertions.

typedef vector_c<int,1,4,5,2,7,5,3,5> numbers; typedef vector_c<int,1,4,0,2,0,0,3,0> expected; typedef reverse_replace_if< numbers , greater< _, int_<4> > , int_<0> , front_inserter< vector<> > >::type result; BOOST_MPL_ASSERT(( equal< result,expected, equal_to<_,_> > ));