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.7: 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#id1463">Reversible Algorithm</a></h1> 16<div class="section" id="id459"> 17<h3><a class="subsection-title" href="#description" name="description">Description</a></h3> 18<p>A <a class="reference internal" 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="id460"> 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 internal" 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 internal" href="./forward-sequence.html">Forward Sequence</a>s, and <tt class="literal"><span class="pre">in</span></tt> is an <a class="reference internal" href="./inserter.html">Inserter</a>.</p> 31<table border="1" class="docutils table"> 32<colgroup> 33<col width="48%" /> 34<col width="28%" /> 35<col width="23%" /> 36</colgroup> 37<thead valign="bottom"> 38<tr><th class="head">Expression</th> 39<th class="head">Type</th> 40<th class="head">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 internal" 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 internal" 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="id461"> 64<h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3> 65<pre class="literal-block"> 66typedef 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="docutils 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"><p class="first"><em>s</em><sub>1</sub> is an <a class="reference internal" href="./extensible-sequence.html">Extensible Sequence</a>.</p> 73</td> 74</tr> 75<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> 76<pre class="literal-block"> 77x< 78 <em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,... 79 , <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 > 80 >::type 81</pre> 82<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> 83<pre class="literal-block"> 84reverse_x< 85 <em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,... 86 , <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 > 87 >::type 88</pre> 89<p class="last">otherwise.</p> 90</td> 91</tr> 92</tbody> 93</table> 94<!-- .......................................................................... --> 95<pre class="literal-block"> 96typedef x<<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...in>::type t; 97</pre> 98<table class="docutils field-list" frame="void" rules="none"> 99<col class="field-name" /> 100<col class="field-body" /> 101<tbody valign="top"> 102<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 103<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> 104</tr> 105</tbody> 106</table> 107<!-- .......................................................................... --> 108<pre class="literal-block"> 109typedef reverse_x<<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,... <em>s</em><sub>n</sub>,... >::type t; 110</pre> 111<table class="docutils field-list" frame="void" rules="none"> 112<col class="field-name" /> 113<col class="field-body" /> 114<tbody valign="top"> 115<tr class="field"><th class="field-name">Precondition:</th><td class="field-body"><p class="first"><em>s</em><sub>1</sub> is an <a class="reference internal" href="./extensible-sequence.html">Extensible Sequence</a>.</p> 116</td> 117</tr> 118<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> 119<pre class="literal-block"> 120x< 121 <em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,... 122 , <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 > 123 >::type 124</pre> 125<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> 126<pre class="literal-block"> 127reverse_x< 128 <em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,... 129 , <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 > 130 >::type 131</pre> 132<p class="last">otherwise.</p> 133</td> 134</tr> 135</tbody> 136</table> 137<!-- .......................................................................... --> 138<pre class="literal-block"> 139typedef reverse_x<<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,... in>::type t; 140</pre> 141<table class="docutils field-list" frame="void" rules="none"> 142<col class="field-name" /> 143<col class="field-body" /> 144<tbody valign="top"> 145<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 146<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> 147</tr> 148</tbody> 149</table> 150</div> 151<div class="section" id="id462"> 152<h3><a class="subsection-title" href="#example" name="example">Example</a></h3> 153<pre class="literal-block"> 154typedef <a href="./transform.html" class="identifier">transform</a>< 155 <a href="./range-c.html" class="identifier">range_c</a><int,0,10> 156 , <a href="./plus.html" class="identifier">plus</a><<a href="./placeholders.html" class="identifier">_1</a>,<a href="./int.html" class="identifier">int_</a><7> > 157 , <a href="./back-inserter.html" class="identifier">back_inserter</a>< vector0<> > 158 >::type r1; 159 160typedef <a href="./transform.html" class="identifier">transform</a>< r1, <a href="./minus.html" class="identifier">minus</a><<a href="./placeholders.html" class="identifier">_1</a>,<a href="./int.html" class="identifier">int_</a><2> > >::type r2; 161typedef <a href="./reverse-transform.html" class="identifier">reverse_transform</a>< 162 r2 163 , <a href="./minus.html" class="identifier">minus</a><<a href="./placeholders.html" class="identifier">_1</a>,5> 164 , <a href="./front-inserter.html" class="identifier">front_inserter</a>< vector0<> > 165 >::type r3; 166 167<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> > )); 168<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> > )); 169<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> > )); 170</pre> 171</div> 172<div class="section" id="id463"> 173<h3><a class="subsection-title" href="#models" name="models">Models</a></h3> 174<ul class="simple"> 175<li><a class="reference internal" href="./transform.html">transform</a></li> 176<li><a class="reference internal" href="./remove.html">remove</a></li> 177<li><a class="reference internal" href="./replace.html">replace</a></li> 178</ul> 179</div> 180<div class="section" id="id464"> 181<h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3> 182<p><a class="reference internal" href="./transformation-algorithms.html">Transformation Algorithms</a>, <a class="reference internal" href="./inserter.html">Inserter</a></p> 183</div> 184</div> 185 186<div class="footer-separator"></div> 187<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> 188<td><div class="copyright-footer"><div class="copyright">Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams</div> 189Distributed under the Boost Software License, Version 1.0. (See accompanying 190file LICENSE_1_0.txt or copy at <a class="reference external" href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</div></td></tr></table></body> 191</html> 192