6f63e9d0c6
[SVN r64705]
192 lines
13 KiB
HTML
192 lines
13 KiB
HTML
<?xml version="1.0" encoding="utf-8" ?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="generator" content="Docutils 0.7: http://docutils.sourceforge.net/" />
|
|
<title>The MPL Reference Manual: Reversible Algorithm</title>
|
|
<link rel="stylesheet" href="../style.css" type="text/css" />
|
|
</head>
|
|
<body class="docframe refmanual">
|
|
<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>
|
|
<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>
|
|
</tr></table><div class="header-separator"></div>
|
|
<div class="section" id="reversible-algorithm">
|
|
<h1><a class="toc-backref" href="./algorithms-concepts.html#id1463">Reversible Algorithm</a></h1>
|
|
<div class="section" id="id459">
|
|
<h3><a class="subsection-title" href="#description" name="description">Description</a></h3>
|
|
<p>A <a class="reference internal" href="./reversible-algorithm.html">Reversible Algorithm</a> is a member of a pair of
|
|
transformation algorithms that iterate over their input sequence(s)
|
|
in opposite directions. For each reversible
|
|
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>,
|
|
that exhibits the exact semantics of <tt class="literal"><span class="pre">x</span></tt> except that the elements
|
|
of its input sequence argument(s) are processed in the reverse
|
|
order.</p>
|
|
</div>
|
|
<div class="section" id="id460">
|
|
<h3><a class="subsection-title" href="#expression-requirements" name="expression-requirements">Expression requirements</a></h3>
|
|
<p>In the following table and subsequent specifications, <tt class="literal"><span class="pre">x</span></tt> is a placeholder token for the actual
|
|
<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
|
|
<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>
|
|
<table border="1" class="docutils table">
|
|
<colgroup>
|
|
<col width="48%" />
|
|
<col width="28%" />
|
|
<col width="23%" />
|
|
</colgroup>
|
|
<thead valign="bottom">
|
|
<tr><th class="head">Expression</th>
|
|
<th class="head">Type</th>
|
|
<th class="head">Complexity</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody valign="top">
|
|
<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>
|
|
<td><a class="reference internal" href="./forward-sequence.html">Forward Sequence</a></td>
|
|
<td>Unspecified.</td>
|
|
</tr>
|
|
<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>
|
|
<td>Any type</td>
|
|
<td>Unspecified.</td>
|
|
</tr>
|
|
<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>
|
|
<td><a class="reference internal" href="./forward-sequence.html">Forward Sequence</a></td>
|
|
<td>Unspecified.</td>
|
|
</tr>
|
|
<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>
|
|
<td>Any type</td>
|
|
<td>Unspecified.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="section" id="id461">
|
|
<h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3>
|
|
<pre class="literal-block">
|
|
typedef x<<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...>::type t;
|
|
</pre>
|
|
<table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<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>
|
|
</td>
|
|
</tr>
|
|
<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>
|
|
<pre class="literal-block">
|
|
x<
|
|
<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...
|
|
, <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 >
|
|
>::type
|
|
</pre>
|
|
<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>
|
|
<pre class="literal-block">
|
|
reverse_x<
|
|
<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...
|
|
, <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 >
|
|
>::type
|
|
</pre>
|
|
<p class="last">otherwise.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<!-- .......................................................................... -->
|
|
<pre class="literal-block">
|
|
typedef x<<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...in>::type t;
|
|
</pre>
|
|
<table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<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
|
|
<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>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<!-- .......................................................................... -->
|
|
<pre class="literal-block">
|
|
typedef reverse_x<<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,... <em>s</em><sub>n</sub>,... >::type t;
|
|
</pre>
|
|
<table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<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>
|
|
</td>
|
|
</tr>
|
|
<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>
|
|
<pre class="literal-block">
|
|
x<
|
|
<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...
|
|
, <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 >
|
|
>::type
|
|
</pre>
|
|
<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>
|
|
<pre class="literal-block">
|
|
reverse_x<
|
|
<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,...
|
|
, <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 >
|
|
>::type
|
|
</pre>
|
|
<p class="last">otherwise.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<!-- .......................................................................... -->
|
|
<pre class="literal-block">
|
|
typedef reverse_x<<em>s</em><sub>1</sub>,<em>s</em><sub>2</sub>,...<em>s</em><sub>n</sub>,... in>::type t;
|
|
</pre>
|
|
<table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<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
|
|
<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>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="section" id="id462">
|
|
<h3><a class="subsection-title" href="#example" name="example">Example</a></h3>
|
|
<pre class="literal-block">
|
|
typedef <a href="./transform.html" class="identifier">transform</a><
|
|
<a href="./range-c.html" class="identifier">range_c</a><int,0,10>
|
|
, <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> >
|
|
, <a href="./back-inserter.html" class="identifier">back_inserter</a>< vector0<> >
|
|
>::type r1;
|
|
|
|
typedef <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;
|
|
typedef <a href="./reverse-transform.html" class="identifier">reverse_transform</a><
|
|
r2
|
|
, <a href="./minus.html" class="identifier">minus</a><<a href="./placeholders.html" class="identifier">_1</a>,5>
|
|
, <a href="./front-inserter.html" class="identifier">front_inserter</a>< vector0<> >
|
|
>::type r3;
|
|
|
|
<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> > ));
|
|
<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> > ));
|
|
<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> > ));
|
|
</pre>
|
|
</div>
|
|
<div class="section" id="id463">
|
|
<h3><a class="subsection-title" href="#models" name="models">Models</a></h3>
|
|
<ul class="simple">
|
|
<li><a class="reference internal" href="./transform.html">transform</a></li>
|
|
<li><a class="reference internal" href="./remove.html">remove</a></li>
|
|
<li><a class="reference internal" href="./replace.html">replace</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="section" id="id464">
|
|
<h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3>
|
|
<p><a class="reference internal" href="./transformation-algorithms.html">Transformation Algorithms</a>, <a class="reference internal" href="./inserter.html">Inserter</a></p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="footer-separator"></div>
|
|
<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>
|
|
<td><div class="copyright-footer"><div class="copyright">Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams</div>
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
file 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>
|
|
</html>
|