Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/mpl/doc/refmanual/reversible-algorithm.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 12.8 KB
Line 
1<?xml version="1.0" encoding="utf-8" ?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
7<title>The MPL Reference Manual: Reversible Algorithm</title>
8<link rel="stylesheet" href="../style.css" type="text/css" />
9</head>
10<body class="docframe refmanual">
11<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./inserter.html" class="navigation-link">Prev</a>&nbsp;<a href="./inserters.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./inserter.html" class="navigation-link">Back</a>&nbsp;Along</span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./algorithms-concepts.html" class="navigation-link">Up</a>&nbsp;<a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td>
12<td class="header-group page-location"><a href="../refmanual.html" class="navigation-link">Front Page</a> / <a href="./algorithms.html" class="navigation-link">Algorithms</a> / <a href="./algorithms-concepts.html" class="navigation-link">Concepts</a> / <a href="./reversible-algorithm.html" class="navigation-link">Reversible Algorithm</a></td>
13</tr></table><div class="header-separator"></div>
14<div class="section" id="reversible-algorithm">
15<h1><a class="toc-backref" href="./algorithms-concepts.html#id391" name="reversible-algorithm">Reversible Algorithm</a></h1>
16<div class="section" id="reversible-description">
17<h3><a class="subsection-title" href="#description" name="description">Description</a></h3>
18<p>A <a class="reference" href="./reversible-algorithm.html">Reversible Algorithm</a> is a member of a pair of
19transformation algorithms that iterate over their input sequence(s)
20in opposite directions. For each reversible
21algorithm <tt class="literal"><span class="pre">x</span></tt> there exists a <em>counterpart</em> algorithm <tt class="literal"><span class="pre">reverse_x</span></tt>,
22that exhibits the exact semantics of <tt class="literal"><span class="pre">x</span></tt> except that the elements
23of its input sequence argument(s) are processed in the reverse
24order.</p>
25</div>
26<div class="section" id="reversible-expression-requirements">
27<h3><a class="subsection-title" href="#expression-requirements" name="expression-requirements">Expression requirements</a></h3>
28<p>In the following table and subsequent specifications, <tt class="literal"><span class="pre">x</span></tt> is a placeholder token for the actual
29<a class="reference" href="./reversible-algorithm.html">Reversible Algorithm</a>'s name, <em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub> are
30<a class="reference" href="./forward-sequence.html">Forward Sequence</a>s, and <tt class="literal"><span class="pre">in</span></tt> is an <a class="reference" href="./inserter.html">Inserter</a>.</p>
31<table border="1" class="table">
32<colgroup>
33<col width="48%" />
34<col width="28%" />
35<col width="23%" />
36</colgroup>
37<thead valign="bottom">
38<tr><th>Expression</th>
39<th>Type</th>
40<th>Complexity</th>
41</tr>
42</thead>
43<tbody valign="top">
44<tr><td><tt class="literal"><span class="pre">x&lt;</span></tt><em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>, ...<tt class="literal"><span class="pre">&gt;::type</span></tt></td>
45<td><a class="reference" href="./forward-sequence.html">Forward Sequence</a></td>
46<td>Unspecified.</td>
47</tr>
48<tr><td><tt class="literal"><span class="pre">x&lt;</span></tt><em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>, ... <tt class="literal"><span class="pre">in&gt;::type</span></tt></td>
49<td>Any type</td>
50<td>Unspecified.</td>
51</tr>
52<tr><td><tt class="literal"><span class="pre">reverse_x&lt;</span></tt><em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>, ...<tt class="literal"><span class="pre">&gt;::type</span></tt></td>
53<td><a class="reference" href="./forward-sequence.html">Forward Sequence</a></td>
54<td>Unspecified.</td>
55</tr>
56<tr><td><tt class="literal"><span class="pre">reverse_x&lt;</span></tt><em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>, ... <tt class="literal"><span class="pre">in&gt;::type</span></tt></td>
57<td>Any type</td>
58<td>Unspecified.</td>
59</tr>
60</tbody>
61</table>
62</div>
63<div class="section" id="reversible-expression-semantics">
64<h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3>
65<pre class="literal-block">
66typedef x&lt;<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...&gt;::type t;
67</pre>
68<table class="field-list" frame="void" rules="none">
69<col class="field-name" />
70<col class="field-body" />
71<tbody valign="top">
72<tr class="field"><th class="field-name">Precondition:</th><td class="field-body"><em>s</em><sub>1</sub> is an <a class="reference" href="./extensible-sequence.html">Extensible Sequence</a>.</td>
73</tr>
74<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first"><tt class="literal"><span class="pre">t</span></tt> is equivalent to</p>
75<pre class="literal-block">
76x&lt;
77      <em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...
78    , <a href="./back-inserter.html" class="identifier">back_inserter</a>&lt; <a href="./clear.html" class="identifier">clear</a>&lt;<em>s</em><sub>1</sub>&gt;::type &gt;   
79    &gt;::type
80</pre>
81<p>if <tt class="literal"><span class="pre">has_push_back&lt;</span></tt><em>s</em><sub>1</sub><tt class="literal"><span class="pre">&gt;::value</span> <span class="pre">==</span> <span class="pre">true</span></tt> and</p>
82<pre class="literal-block">
83reverse_x&lt;
84      <em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...
85    , <a href="./front-inserter.html" class="identifier">front_inserter</a>&lt; <a href="./clear.html" class="identifier">clear</a>&lt;<em>s</em><sub>1</sub>&gt;::type &gt;   
86    &gt;::type
87</pre>
88<p class="last">otherwise.</p>
89</td>
90</tr>
91</tbody>
92</table>
93<!-- .......................................................................... -->
94<pre class="literal-block">
95typedef x&lt;<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...in&gt;::type t;
96</pre>
97<table class="field-list" frame="void" rules="none">
98<col class="field-name" />
99<col class="field-body" />
100<tbody valign="top">
101<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><tt class="literal"><span class="pre">t</span></tt> is the result of an <tt class="literal"><span class="pre">x</span></tt> invocation with arguments
102<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,... <em>s</em><sub>n</sub>,...<tt class="literal"><span class="pre">in</span></tt>.</td>
103</tr>
104</tbody>
105</table>
106<!-- .......................................................................... -->
107<pre class="literal-block">
108typedef reverse_x&lt;<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,... <em>s</em><sub>n</sub>,... &gt;::type t;
109</pre>
110<table class="field-list" frame="void" rules="none">
111<col class="field-name" />
112<col class="field-body" />
113<tbody valign="top">
114<tr class="field"><th class="field-name">Precondition:</th><td class="field-body"><em>s</em><sub>1</sub> is an <a class="reference" href="./extensible-sequence.html">Extensible Sequence</a>.</td>
115</tr>
116<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first"><tt class="literal"><span class="pre">t</span></tt> is equivalent to</p>
117<pre class="literal-block">
118x&lt;
119      <em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...
120    , <a href="./front-inserter.html" class="identifier">front_inserter</a>&lt; <a href="./clear.html" class="identifier">clear</a>&lt;<em>s</em><sub>1</sub>&gt;::type &gt;   
121    &gt;::type
122</pre>
123<p>if <tt class="literal"><span class="pre">has_push_front&lt;</span></tt><em>s</em><sub>1</sub><tt class="literal"><span class="pre">&gt;::value</span> <span class="pre">==</span> <span class="pre">true</span></tt> and</p>
124<pre class="literal-block">
125reverse_x&lt;
126      <em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...
127    , <a href="./back-inserter.html" class="identifier">back_inserter</a>&lt; <a href="./clear.html" class="identifier">clear</a>&lt;<em>s</em><sub>1</sub>&gt;::type &gt;   
128    &gt;::type
129</pre>
130<p class="last">otherwise.</p>
131</td>
132</tr>
133</tbody>
134</table>
135<!-- .......................................................................... -->
136<pre class="literal-block">
137typedef reverse_x&lt;<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,... in&gt;::type t;
138</pre>
139<table class="field-list" frame="void" rules="none">
140<col class="field-name" />
141<col class="field-body" />
142<tbody valign="top">
143<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><tt class="literal"><span class="pre">t</span></tt> is the result of a <tt class="literal"><span class="pre">reverse_x</span></tt> invocation with arguments
144<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...<tt class="literal"><span class="pre">in</span></tt>.</td>
145</tr>
146</tbody>
147</table>
148</div>
149<div class="section" id="reversible-example">
150<h3><a class="subsection-title" href="#example" name="example">Example</a></h3>
151<pre class="literal-block">
152typedef <a href="./transform.html" class="identifier">transform</a>&lt; 
153      <a href="./range-c.html" class="identifier">range_c</a>&lt;int,0,10&gt;
154    , <a href="./plus.html" class="identifier">plus</a>&lt;_1,<a href="./int.html" class="identifier">int_</a>&lt;7&gt; &gt;
155    , <a href="./back-inserter.html" class="identifier">back_inserter</a>&lt; vector0&lt;&gt; &gt; 
156    &gt;::type r1;
157
158typedef <a href="./transform.html" class="identifier">transform</a>&lt; r1, <a href="./minus.html" class="identifier">minus</a>&lt;_1,<a href="./int.html" class="identifier">int_</a>&lt;2&gt; &gt; &gt;::type r2;
159typedef <a href="./reverse-transform.html" class="identifier">reverse_transform</a>&lt; 
160      r2
161    , <a href="./minus.html" class="identifier">minus</a>&lt;_1,5&gt; 
162    , <a href="./front-inserter.html" class="identifier">front_inserter</a>&lt; vector0&lt;&gt; &gt; 
163    &gt;::type r3;
164
165<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( <a href="./equal.html" class="identifier">equal</a>&lt;r1, <a href="./range-c.html" class="identifier">range_c</a>&lt;int,7,17&gt; &gt; ));
166<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( <a href="./equal.html" class="identifier">equal</a>&lt;r2, <a href="./range-c.html" class="identifier">range_c</a>&lt;int,5,15&gt; &gt; ));
167<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( <a href="./equal.html" class="identifier">equal</a>&lt;r3, <a href="./range-c.html" class="identifier">range_c</a>&lt;int,0,10&gt; > ));
168</pre>
169</div>
170<div class="section" id="reversible-models">
171<h3><a class="subsection-title" href="#models" name="models">Models</a></h3>
172<ul class="simple">
173<li><a class="refentry reference" href="./transform.html"><tt class="refentry literal"><span class="pre">transform</span></tt></a></li>
174<li><a class="refentry reference" href="./remove.html"><tt class="refentry literal"><span class="pre">remove</span></tt></a></li>
175<li><a class="refentry reference" href="./replace.html"><tt class="refentry literal"><span class="pre">replace</span></tt></a></li>
176</ul>
177</div>
178<div class="section" id="reversible-see-also">
179<h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3>
180<p><a class="reference" href="./transformation-algorithms.html">Transformation Algorithms</a>, <a class="reference" href="./inserter.html">Inserter</a></p>
181<!-- modtime: November 13, 2004 01:42:46 +0000 -->
182</div>
183</div>
184
185<div class="footer-separator"></div>
186<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./inserter.html" class="navigation-link">Prev</a>&nbsp;<a href="./inserters.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./inserter.html" class="navigation-link">Back</a>&nbsp;Along</span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./algorithms-concepts.html" class="navigation-link">Up</a>&nbsp;<a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td>
187</tr></table></body>
188</html>
Note: See TracBrowser for help on using the repository browser.