• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>transform</title>
5<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../../index.html" title="Chapter 1. Range 2.0">
8<link rel="up" href="../mutating.html" title="Mutating algorithms">
9<link rel="prev" href="swap_ranges.html" title="swap_ranges">
10<link rel="next" href="unique.html" title="unique">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="swap_ranges.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../mutating.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="unique.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h5 class="title">
27<a name="range.reference.algorithms.mutating.transform"></a><a class="link" href="transform.html" title="transform">transform</a>
28</h5></div></div></div>
29<h6>
30<a name="range.reference.algorithms.mutating.transform.h0"></a>
31            <span class="phrase"><a name="range.reference.algorithms.mutating.transform.prototype"></a></span><a class="link" href="transform.html#range.reference.algorithms.mutating.transform.prototype">Prototype</a>
32          </h6>
33<p>
34</p>
35<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span>
36    <span class="keyword">class</span> <span class="identifier">SinglePassRange1</span><span class="special">,</span>
37    <span class="keyword">class</span> <span class="identifier">OutputIterator</span><span class="special">,</span>
38    <span class="keyword">class</span> <span class="identifier">UnaryOperation</span>
39<span class="special">&gt;</span>
40<span class="identifier">OutputIterator</span> <span class="identifier">transform</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">SinglePassRange1</span><span class="special">&amp;</span> <span class="identifier">rng</span><span class="special">,</span>
41                         <span class="identifier">OutputIterator</span> <span class="identifier">out</span><span class="special">,</span>
42                         <span class="identifier">UnaryOperation</span> <span class="identifier">fun</span><span class="special">);</span>
43
44<span class="keyword">template</span><span class="special">&lt;</span>
45    <span class="keyword">class</span> <span class="identifier">SinglePassRange1</span><span class="special">,</span>
46    <span class="keyword">class</span> <span class="identifier">SinglePassRange2</span><span class="special">,</span>
47    <span class="keyword">class</span> <span class="identifier">OutputIterator</span><span class="special">,</span>
48    <span class="keyword">class</span> <span class="identifier">BinaryOperation</span>
49<span class="special">&gt;</span>
50<span class="identifier">OutputIterator</span> <span class="identifier">transform</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">SinglePassRange1</span><span class="special">&amp;</span> <span class="identifier">rng1</span><span class="special">,</span>
51                         <span class="keyword">const</span> <span class="identifier">SinglePassRange2</span><span class="special">&amp;</span> <span class="identifier">rng2</span><span class="special">,</span>
52                         <span class="identifier">OutputIterator</span> <span class="identifier">out</span><span class="special">,</span>
53                         <span class="identifier">BinaryOperation</span> <span class="identifier">fun</span><span class="special">);</span>
54</pre>
55<p>
56          </p>
57<h6>
58<a name="range.reference.algorithms.mutating.transform.h1"></a>
59            <span class="phrase"><a name="range.reference.algorithms.mutating.transform.description"></a></span><a class="link" href="transform.html#range.reference.algorithms.mutating.transform.description">Description</a>
60          </h6>
61<p>
62            <span class="bold"><strong>UnaryOperation version:</strong></span>
63          </p>
64<p>
65            <code class="computeroutput"><span class="identifier">transform</span></code> assigns the
66            value <code class="computeroutput"><span class="identifier">y</span></code> to each element
67            <code class="computeroutput"><span class="special">[</span><span class="identifier">out</span><span class="special">,</span> <span class="identifier">out</span> <span class="special">+</span> <span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng</span><span class="special">)),</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">fun</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code> where <code class="computeroutput"><span class="identifier">x</span></code>
68            is the corresponding value to <code class="computeroutput"><span class="identifier">y</span></code>
69            in <code class="computeroutput"><span class="identifier">rng1</span></code>. The return value
70            is <code class="computeroutput"><span class="identifier">out</span> <span class="special">+</span>
71            <span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng</span><span class="special">)</span></code>.
72          </p>
73<p>
74            <span class="bold"><strong>BinaryOperation version:</strong></span>
75          </p>
76<p>
77            <code class="computeroutput"><span class="identifier">transform</span></code> assigns the
78            value <code class="computeroutput"><span class="identifier">z</span></code> to each element
79            <code class="computeroutput"><span class="special">[</span><span class="identifier">out</span><span class="special">,</span> <span class="identifier">out</span> <span class="special">+</span> <span class="identifier">min</span><span class="special">(</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng1</span><span class="special">),</span> <span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng2</span><span class="special">))),</span> <span class="identifier">z</span> <span class="special">=</span> <span class="identifier">fun</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span><span class="identifier">y</span><span class="special">)</span></code> where <code class="computeroutput"><span class="identifier">x</span></code>
80            is the corresponding value in <code class="computeroutput"><span class="identifier">rng1</span></code>
81            and <code class="computeroutput"><span class="identifier">y</span></code> is the corresponding
82            value in <code class="computeroutput"><span class="identifier">rng2</span></code>. This version
83            of <code class="computeroutput"><span class="identifier">transform</span></code> stops upon
84            reaching either the end of <code class="computeroutput"><span class="identifier">rng1</span></code>,
85            or the end of <code class="computeroutput"><span class="identifier">rng2</span></code>. Hence
86            there isn't a requirement for <code class="computeroutput"><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng1</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng2</span><span class="special">)</span></code>
87            since there is a safe guaranteed behaviour, unlike with the iterator
88            counterpart in the standard library.
89          </p>
90<p>
91            The return value is <code class="computeroutput"><span class="identifier">out</span> <span class="special">+</span> <span class="identifier">min</span><span class="special">(</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng1</span><span class="special">),</span> <span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng2</span><span class="special">))</span></code>.
92          </p>
93<h6>
94<a name="range.reference.algorithms.mutating.transform.h2"></a>
95            <span class="phrase"><a name="range.reference.algorithms.mutating.transform.definition"></a></span><a class="link" href="transform.html#range.reference.algorithms.mutating.transform.definition">Definition</a>
96          </h6>
97<p>
98            Defined in the header file <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">algorithm</span><span class="special">/</span><span class="identifier">transform</span><span class="special">.</span><span class="identifier">hpp</span></code>
99          </p>
100<h6>
101<a name="range.reference.algorithms.mutating.transform.h3"></a>
102            <span class="phrase"><a name="range.reference.algorithms.mutating.transform.requirements"></a></span><a class="link" href="transform.html#range.reference.algorithms.mutating.transform.requirements">Requirements</a>
103          </h6>
104<p>
105            <span class="bold"><strong>For the unary versions of transform:</strong></span>
106          </p>
107<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
108<li class="listitem">
109                <code class="computeroutput"><span class="identifier">SinglePassRange1</span></code>
110                is a model of the <a class="link" href="../../../concepts/single_pass_range.html" title="Single Pass Range">Single
111                Pass Range</a> Concept.
112              </li>
113<li class="listitem">
114                <code class="computeroutput"><span class="identifier">OutputIterator</span></code> is
115                a model of the <code class="computeroutput"><span class="identifier">OutputIteratorConcept</span></code>.
116              </li>
117<li class="listitem">
118                <code class="computeroutput"><span class="identifier">UnaryOperation</span></code> is
119                a model of the <code class="computeroutput"><span class="identifier">UnaryFunctionConcept</span></code>.
120              </li>
121<li class="listitem">
122                <code class="computeroutput"><span class="identifier">SinglePassRange1</span></code>'s
123                value type must be convertible to <code class="computeroutput"><span class="identifier">UnaryFunction</span></code>'s
124                argument type.
125              </li>
126<li class="listitem">
127                <code class="computeroutput"><span class="identifier">UnaryFunction</span></code>'s result
128                type must be convertible to a type in <code class="computeroutput"><span class="identifier">OutputIterator</span></code>'s
129                set of value types.
130              </li>
131</ul></div>
132<p>
133            <span class="bold"><strong>For the binary versions of transform:</strong></span>
134          </p>
135<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
136<li class="listitem">
137                <code class="computeroutput"><span class="identifier">SinglePassRange1</span></code>
138                is a model of the <a class="link" href="../../../concepts/single_pass_range.html" title="Single Pass Range">Single
139                Pass Range</a> Concept.
140              </li>
141<li class="listitem">
142                <code class="computeroutput"><span class="identifier">SinglePassRange2</span></code>
143                is a model of the <a class="link" href="../../../concepts/single_pass_range.html" title="Single Pass Range">Single
144                Pass Range</a> Concept.
145              </li>
146<li class="listitem">
147                <code class="computeroutput"><span class="identifier">OutputIterator</span></code> is
148                a model of the <code class="computeroutput"><span class="identifier">OutputIteratorConcept</span></code>.
149              </li>
150<li class="listitem">
151                <code class="computeroutput"><span class="identifier">BinaryOperation</span></code> is
152                a model of the <code class="computeroutput"><span class="identifier">BinaryFunctionConcept</span></code>.
153              </li>
154<li class="listitem">
155                <code class="computeroutput"><span class="identifier">SinglePassRange1</span></code>'s
156                value type must be convertible to <code class="computeroutput"><span class="identifier">BinaryFunction</span></code>'s
157                first argument type.
158              </li>
159<li class="listitem">
160                <code class="computeroutput"><span class="identifier">SinglePassRange2</span></code>'s
161                value type must be convertible to <code class="computeroutput"><span class="identifier">BinaryFunction</span></code>'s
162                second argument type.
163              </li>
164<li class="listitem">
165                <code class="computeroutput"><span class="identifier">BinaryOperation</span></code>'s
166                result type must be convertible to a type in <code class="computeroutput"><span class="identifier">OutputIterator</span></code>'s
167                set of value types.
168              </li>
169</ul></div>
170<h6>
171<a name="range.reference.algorithms.mutating.transform.h4"></a>
172            <span class="phrase"><a name="range.reference.algorithms.mutating.transform.precondition_"></a></span><a class="link" href="transform.html#range.reference.algorithms.mutating.transform.precondition_">Precondition:</a>
173          </h6>
174<p>
175            <span class="bold"><strong>For the unary version of transform:</strong></span>
176          </p>
177<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
178<li class="listitem">
179                <code class="computeroutput"><span class="identifier">out</span></code> is not an iterator
180                within the range <code class="computeroutput"><span class="special">[</span><span class="identifier">begin</span><span class="special">(</span><span class="identifier">rng1</span><span class="special">)</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">end</span><span class="special">(</span><span class="identifier">rng1</span><span class="special">))</span></code>.
181              </li>
182<li class="listitem">
183                <code class="computeroutput"><span class="special">[</span><span class="identifier">out</span><span class="special">,</span> <span class="identifier">out</span>
184                <span class="special">+</span> <span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng1</span><span class="special">))</span></code> is a valid range.
185              </li>
186</ul></div>
187<p>
188            <span class="bold"><strong>For the binary version of transform:</strong></span>
189          </p>
190<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
191<li class="listitem">
192                <code class="computeroutput"><span class="identifier">out</span></code> is not an iterator
193                within the range <code class="computeroutput"><span class="special">[</span><span class="identifier">begin</span><span class="special">(</span><span class="identifier">rng1</span><span class="special">)</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">end</span><span class="special">(</span><span class="identifier">rng1</span><span class="special">))</span></code>.
194              </li>
195<li class="listitem">
196                <code class="computeroutput"><span class="identifier">out</span></code> is not an iterator
197                within the range <code class="computeroutput"><span class="special">[</span><span class="identifier">begin</span><span class="special">(</span><span class="identifier">rng2</span><span class="special">)</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">end</span><span class="special">(</span><span class="identifier">rng2</span><span class="special">))</span></code>.
198              </li>
199<li class="listitem">
200                <code class="computeroutput"><span class="special">[</span><span class="identifier">out</span><span class="special">,</span> <span class="identifier">out</span>
201                <span class="special">+</span> <span class="identifier">min</span><span class="special">(</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng1</span><span class="special">),</span> <span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng2</span><span class="special">)))</span></code> is a valid range.
202              </li>
203</ul></div>
204<h6>
205<a name="range.reference.algorithms.mutating.transform.h5"></a>
206            <span class="phrase"><a name="range.reference.algorithms.mutating.transform.complexity"></a></span><a class="link" href="transform.html#range.reference.algorithms.mutating.transform.complexity">Complexity</a>
207          </h6>
208<p>
209            Linear. The operation is applied exactly <code class="computeroutput"><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng1</span><span class="special">)</span></code> for the unary version and <code class="computeroutput"><span class="identifier">min</span><span class="special">(</span><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng1</span><span class="special">),</span> <span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng2</span><span class="special">))</span></code>
210            for the binary version.
211          </p>
212</div>
213<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
214<td align="left"></td>
215<td align="right"><div class="copyright-footer">Copyright © 2003-2010 Thorsten Ottosen,
216      Neil Groves<p>
217        Distributed under the Boost Software License, Version 1.0. (See accompanying
218        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
219      </p>
220</div></td>
221</tr></table>
222<hr>
223<div class="spirit-nav">
224<a accesskey="p" href="swap_ranges.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../mutating.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="unique.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
225</div>
226</body>
227</html>
228