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> <a href="./inserters.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./inserter.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./algorithms-concepts.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </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 |
---|
19 | transformation algorithms that iterate over their input sequence(s) |
---|
20 | in opposite directions. For each reversible |
---|
21 | algorithm <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>, |
---|
22 | that exhibits the exact semantics of <tt class="literal"><span class="pre">x</span></tt> except that the elements |
---|
23 | of its input sequence argument(s) are processed in the reverse |
---|
24 | order.</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<</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">>::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<</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>::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<</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">>::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<</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>::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"> |
---|
66 | typedef x<<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...>::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"> |
---|
76 | x< |
---|
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>< <a href="./clear.html" class="identifier">clear</a><<em>s</em><sub>1</sub>>::type > |
---|
79 | >::type |
---|
80 | </pre> |
---|
81 | <p>if <tt class="literal"><span class="pre">has_push_back<</span></tt><em>s</em><sub>1</sub><tt class="literal"><span class="pre">>::value</span> <span class="pre">==</span> <span class="pre">true</span></tt> and</p> |
---|
82 | <pre class="literal-block"> |
---|
83 | reverse_x< |
---|
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>< <a href="./clear.html" class="identifier">clear</a><<em>s</em><sub>1</sub>>::type > |
---|
86 | >::type |
---|
87 | </pre> |
---|
88 | <p class="last">otherwise.</p> |
---|
89 | </td> |
---|
90 | </tr> |
---|
91 | </tbody> |
---|
92 | </table> |
---|
93 | <!-- .......................................................................... --> |
---|
94 | <pre class="literal-block"> |
---|
95 | typedef x<<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...in>::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"> |
---|
108 | typedef reverse_x<<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,... <em>s</em><sub>n</sub>,... >::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"> |
---|
118 | x< |
---|
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>< <a href="./clear.html" class="identifier">clear</a><<em>s</em><sub>1</sub>>::type > |
---|
121 | >::type |
---|
122 | </pre> |
---|
123 | <p>if <tt class="literal"><span class="pre">has_push_front<</span></tt><em>s</em><sub>1</sub><tt class="literal"><span class="pre">>::value</span> <span class="pre">==</span> <span class="pre">true</span></tt> and</p> |
---|
124 | <pre class="literal-block"> |
---|
125 | reverse_x< |
---|
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>< <a href="./clear.html" class="identifier">clear</a><<em>s</em><sub>1</sub>>::type > |
---|
128 | >::type |
---|
129 | </pre> |
---|
130 | <p class="last">otherwise.</p> |
---|
131 | </td> |
---|
132 | </tr> |
---|
133 | </tbody> |
---|
134 | </table> |
---|
135 | <!-- .......................................................................... --> |
---|
136 | <pre class="literal-block"> |
---|
137 | typedef reverse_x<<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,... in>::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"> |
---|
152 | typedef <a href="./transform.html" class="identifier">transform</a>< |
---|
153 | <a href="./range-c.html" class="identifier">range_c</a><int,0,10> |
---|
154 | , <a href="./plus.html" class="identifier">plus</a><_1,<a href="./int.html" class="identifier">int_</a><7> > |
---|
155 | , <a href="./back-inserter.html" class="identifier">back_inserter</a>< vector0<> > |
---|
156 | >::type r1; |
---|
157 | |
---|
158 | typedef <a href="./transform.html" class="identifier">transform</a>< r1, <a href="./minus.html" class="identifier">minus</a><_1,<a href="./int.html" class="identifier">int_</a><2> > >::type r2; |
---|
159 | typedef <a href="./reverse-transform.html" class="identifier">reverse_transform</a>< |
---|
160 | r2 |
---|
161 | , <a href="./minus.html" class="identifier">minus</a><_1,5> |
---|
162 | , <a href="./front-inserter.html" class="identifier">front_inserter</a>< vector0<> > |
---|
163 | >::type r3; |
---|
164 | |
---|
165 | <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( <a href="./equal.html" class="identifier">equal</a><r1, <a href="./range-c.html" class="identifier">range_c</a><int,7,17> > )); |
---|
166 | <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( <a href="./equal.html" class="identifier">equal</a><r2, <a href="./range-c.html" class="identifier">range_c</a><int,5,15> > )); |
---|
167 | <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( <a href="./equal.html" class="identifier">equal</a><r3, <a href="./range-c.html" class="identifier">range_c</a><int,0,10> > )); |
---|
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> <a href="./inserters.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./inserter.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./algorithms-concepts.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td> |
---|
187 | </tr></table></body> |
---|
188 | </html> |
---|