Files
range/doc/reference/adaptors/replaced.html
Neil Groves b0d1db7c2e Boost.RangeEx merged into Boost.Range
[SVN r60897]
2010-03-28 16:08:35 +00:00

108 lines
3.1 KiB
HTML
Executable File

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Boost.Range Range Adaptors </title>
<link rel="stylesheet" href="../style.css" type="text/css">
</head>
<body>
<table border="0" >
<tr>
<td ><img src="../../../boost.png" border="0" /></td>
<td ><h1 align="center">Boost.Range </h1></td>
</tr>
</table>
<h2> Range Adaptors </h2>
<hr />
<a name="replaced"></a>
<h4><code>replaced</code></h4>
<blockquote>
<pre>rng | boost::adaptors::replaced( new_value, old_value )</pre>
<pre>boost::make_replaced_range( rng, new_value, old_value )</pre>
</blockquote>
<ul>
<li>
<b>Precondition:</b>
<ul>
<li>
<code>new_value</code> is convertible to the value-type of
the range.
</li>
<li>
<code>old_value</code> is convertible to the value-type of
the range.
</li>
</ul>
</li>
<li>
<b>Postcondition:</b>
For all elements <code>x</code> in the returned range, the value
<code>x</code> is equal to the value of
<code>(y == old_value) ? new_value : y</code>
where <code>y</code> is the corresponding element in the original
range.
</li>
<li>
<b>Range Category:</b>
ForwardRange
</li>
</ul>
<hr />
<h3>Example</h3>
<pre>
<span class="keyword">#include</span> &lt;boost/range/adaptor/replaced.hpp&gt;
<span class="keyword">#include</span> &lt;boost/range/algorithm/copy.hpp&gt;
<span class="keyword">#include</span> &lt;boost/assign.hpp&gt;
<span class="keyword">#include</span> &lt;algorithm&gt;
<span class="keyword">#include</span> &lt;iostream&gt;
<span class="keyword">#include</span> &lt;vector&gt;
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
{
<span class="keyword">using namespace</span> boost::adaptors;
<span class="keyword">using namespace</span> boost::assign;
std::vector&lt;<span class="keyword">int</span>&gt; input;
input += 1,2,3,2,5,2,7,2,9;
boost::copy(
input | replaced(2, 10),
std::ostream_iterator&lt;<span class="keyword">int</span>&gt;(std::cout, ","));
<span class="keyword">return</span> 0;
}
</pre>
<p>
This produces the output: <br />
<code>
1,10,3,10,5,10,7,10,9
</code>
</p>
<hr />
<p>
(C) Copyright Neil Groves 2009
(C) Copyright Thorsten Ottosen 2003-2004
</p>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</body>
</html>