Sophie

Sophie

distrib > Mandriva > 10.0 > i586 > by-pkgid > ef9bad9e14fc2a68cb7c992c11d75f5e > files > 3083

libboost1-devel-1.31.0-1mdk.i586.rpm

<!doctype html public "-//ietf//dtd html//en">
<html><head><title>boost::mpl::replace_if</title>
<link rel="stylesheet" href="../mpl_wiki.css">
</head><body bgcolor="white">
<h1><a href="../Table_of_Contents.html"><img src="../mpl_logo.jpg" alt="[Home]" border=0 align="right"></a>replace_if</h1><h3>Synopsis</h3>
<p>
<pre>
template&lt;
      typename Sequence
    , typename Pred
    , typename NewType
    &gt;
struct replace_if
{
    typedef <em>unspecified</em> type;
};
</pre>
<p>
<h3>Description</h3>
<p>
Performs a conditional replacement operation on the sequence. The algorithm returns a new sequence which contains all the elements from <code>[begin&lt;Sequence&gt;::type, end&lt;Sequence&gt;::type)</code> range where every type that satisfies the predicate <code>Pred</code> has been replaced with a <code>NewType</code>. The result sequence preserves all the functional and performance characteristics of the original <code>Sequence</code>, including its size, but not identity. 
<p>
<h3>Definition</h3>
<p>
<pre>
#include "<a href="../../../../../boost/mpl/replace_if.hpp">boost/mpl/replace_if.hpp</a>"
</pre>
<p>
<h3>Parameters</h3>
<table border="1">
<tr><th>&nbsp;Parameter&nbsp;</th><th>&nbsp;Requirement&nbsp;</th><th>&nbsp;Description &nbsp;</th></tr>
<tr><td><code>Sequence</code></td><td>A model of <a href="../Extensible_Sequence.html">Extensible Sequence</a></td><td>The original sequence. </td></tr>
<tr><td><code>Pred</code></td><td>An unary Predicate [Lambda Expression]</td><td>The replacement condition. </td></tr>
<tr><td><code>NewType</code></td><td>A type</td><td>A type to replace with. </td></tr>
</table>
<p>
<h3>Expression semantics</h3>
<p>
<table border="1">
<tr><th>&nbsp;Expression&nbsp;</th><th>&nbsp;Expression&nbsp;type&nbsp;</th><th>&nbsp;Precondition&nbsp;</th><th>&nbsp;Semantics&nbsp;</th><th>&nbsp;Postcondition&nbsp;</th></tr>
<tr><td><code>typedef replace_if&lt;Sequence,Pred,NewType&gt;::type s;</code></td><td>A model of <a href="../Extensible_Sequence.html">Extensible Sequence</a></td><td></td><td>Equivalent to <code>typedef lambda&lt;Pred&gt;::type pred; typedef transform&lt; Sequence, if_&lt; apply1&lt;pred,_1&gt;,NewType,_1&gt; &gt;::type t;</code>.</td><td></td></tr>
</table>
<p>
<h3>Complexity</h3>
<p>
Linear. Performs exactly <code><a href="../Reference/size.html">size</a>&lt;Sequence&gt;::type::value</code> applications of <code>Pred</code>, and at most <code><a href="../Reference/size.html">size</a>&lt;Sequence&gt;::type::value</code> insertions.
<p>
<h3>Example</h3>
<p>
<pre>
typedef <a href="../Reference/list_c.html">list_c</a>&lt;int,1,4,5,2,7,5,3,5&gt;::type numbers;
typedef replace_if&lt; numbers, greater&lt;_,4&gt;, int_&lt;0&gt; &gt;::type result;
typedef <a href="../Reference/list_c.html">list_c</a>&lt;int,1,4,0,2,0,0,3,0&gt;::type answer;
BOOST_STATIC_ASSERT((<a href="../Reference/equal.html">equal</a>&lt; answer,result &gt;::type::value));
</pre>
<p>
<h3>See also</h3>
<p>
<a href="../Algorithms.html">Algorithms</a>, <code><a href="../Reference/replace.html">replace</a></code>, <code><a href="../Reference/transform.html">transform</a></code>
<p><hr>
<a href="../Table_of_Contents.html">Table of Contents</a><br>Last edited March 12, 2003 6:32 am</body></html>