Files
boost_fusion/doc/html/fusion/sequences/generation/functions/tiers.html
T
2007-02-25 22:02:27 +00:00

101 lines
8.7 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Tiers</title>
<link rel="stylesheet" href="../../../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.68.1">
<link rel="start" href="../../../../index.html" title="Chapter 1. Fusion 2.0">
<link rel="up" href="../functions.html" title="Functions">
<link rel="prev" href="make_map.html" title="make_map">
<link rel="next" href="list_tie.html" title="list_tie">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%">
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../../index.htm">Home</a></td>
<td align="center"><a href="../../../../../../../libraries.htm">Libraries</a></td>
<td align="center"><a href="../../../../../../../../people/people.htm">People</a></td>
<td align="center"><a href="../../../../../../../../more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
</table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="make_map.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../functions.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="list_tie.html"><img src="../../../../images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h5 class="title">
<a name="fusion.sequences.generation.functions.tiers"></a><a href="tiers.html" title="Tiers">Tiers</a></h5></div></div></div>
<p>
Tiers are sequences, where all elements are non-const reference types.
They are constructed with a call to a couple of <span class="emphasis"><em>tie</em></span>
function templates. The succeeding sections document the various <span class="emphasis"><em>tier</em></span>
flavors.
</p>
<div class="itemizedlist"><ul type="disc">
<li><a href="list_tie.html" title="list_tie"><code class="computeroutput"><span class="identifier">list_tie</span></code></a></li>
<li><a href="vector_tie.html" title="vector_tie"><code class="computeroutput"><span class="identifier">vector_tie</span></code></a></li>
</ul></div>
<p>
Example:
</p>
<pre class="programlisting">
<span class="keyword">int</span> <span class="identifier">i</span><span class="special">;</span> <span class="keyword">char</span> <span class="identifier">c</span><span class="special">;</span> <span class="keyword">double</span> <span class="identifier">d</span><span class="special">;</span>
<span class="special">...</span>
<a href="vector_tie.html" title="vector_tie"><code class="computeroutput"><span class="identifier">vector_tie</span></code></a><span class="special">(</span><span class="identifier">i</span><span class="special">,</span> <span class="identifier">c</span><span class="special">,</span> <span class="identifier">a</span><span class="special">);</span>
</pre>
<p>
The <a href="vector_tie.html" title="vector_tie"><code class="computeroutput"><span class="identifier">vector_tie</span></code></a> function creates
a <a href="../../containers/vector.html" title="vector"><code class="computeroutput"><span class="identifier">vector</span></code></a>
of type <code class="computeroutput"><a href="../../containers/vector.html" title="vector"><code class="computeroutput"><span class="identifier">vector</span></code></a><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&amp;,</span> <span class="keyword">char</span><span class="special">&amp;,</span> <span class="keyword">double</span><span class="special">&amp;&gt;</span></code>.
The same result could be achieved with the call <a href="make_vector.html" title="make_vector"><code class="computeroutput"><span class="identifier">make_vector</span></code></a>(<a href="http://www.boost.org/doc/html/ref.html" target="_top"><code class="computeroutput"><span class="identifier">ref</span></code></a>(i), <a href="http://www.boost.org/doc/html/ref.html" target="_top"><code class="computeroutput"><span class="identifier">ref</span></code></a>(c), <a href="http://www.boost.org/doc/html/ref.html" target="_top"><code class="computeroutput"><span class="identifier">ref</span></code></a>(a))
<sup>[<a name="id1043357" href="#ftn.id1043357">11</a>]</sup>
.
</p>
<p>
A <span class="emphasis"><em>tie</em></span> can be used to 'unpack' another tuple into
variables. E.g.:
</p>
<pre class="programlisting">
<span class="keyword">int</span> <span class="identifier">i</span><span class="special">;</span> <span class="keyword">char</span> <span class="identifier">c</span><span class="special">;</span> <span class="keyword">double</span> <span class="identifier">d</span><span class="special">;</span>
<a href="vector_tie.html" title="vector_tie"><code class="computeroutput"><span class="identifier">vector_tie</span></code></a><span class="special">(</span><span class="identifier">i</span><span class="special">,</span> <span class="identifier">c</span><span class="special">,</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">=</span> <a href="make_vector.html" title="make_vector"><code class="computeroutput"><span class="identifier">make_vector</span></code></a><span class="special">(</span><span class="number">1</span><span class="special">,</span><span class="char">'a'</span><span class="special">,</span> <span class="number">5.5</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">i</span> <span class="special">&lt;&lt;</span> <span class="string">" "</span> <span class="special">&lt;&lt;</span> <span class="identifier">c</span> <span class="special">&lt;&lt;</span> <span class="string">" "</span> <span class="special">&lt;&lt;</span> <span class="identifier">d</span><span class="special">;</span>
</pre>
<p>
This code prints 1 a 5.5 to the standard output stream. A sequence unpacking
operation like this is found for example in ML and Python. It is convenient
when calling functions which return sequences.
</p>
<a name="fusion.sequences.generation.functions.tiers.ignore"></a><h6>
<a name="id1043627"></a>
<a href="tiers.html#fusion.sequences.generation.functions.tiers.ignore">Ignore</a>
</h6>
<p>
There is also an object called <span class="emphasis"><em>ignore</em></span> which allows
you to ignore an element assigned by a sequence. The idea is that a function
may return a sequence, only part of which you are interested in. For
example:
</p>
<pre class="programlisting">
<span class="keyword">char</span> <span class="identifier">c</span><span class="special">;</span>
<a href="vector_tie.html" title="vector_tie"><code class="computeroutput"><span class="identifier">vector_tie</span></code></a><span class="special">(</span><span class="identifier">ignore</span><span class="special">,</span> <span class="identifier">c</span><span class="special">)</span> <span class="special">=</span> <a href="make_vector.html" title="make_vector"><code class="computeroutput"><span class="identifier">make_vector</span></code></a><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="char">'a'</span><span class="special">);</span>
</pre>
<div class="footnotes">
<br><hr width="100" align="left">
<div class="footnote"><p><sup>[<a name="ftn.id1043357" href="#id1043357">11</a>] </sup>
see <a href="http://www.boost.org/doc/html/ref.html" target="_top">Boost.Ref</a>
for details about <code class="computeroutput"><span class="identifier">ref</span></code>
</p></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><small>Copyright © 2001-2007 Joel de Guzman, Dan Marsden, Tobias
Schwinger</small></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="make_map.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../functions.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="list_tie.html"><img src="../../../../images/next.png" alt="Next"></a>
</div>
</body>
</html>