Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/mpl/doc/refmanual/reversible-algorithm.html @ 29

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

updated boost from 1_33_1 to 1_34_1

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