Fusion: added nview and friends, docs and tests

[SVN r56377]
This commit is contained in:
Hartmut Kaiser
2009-09-25 00:21:53 +00:00
parent 43645b3764
commit 10c0665ffa
258 changed files with 16390 additions and 13592 deletions

View File

@ -3,10 +3,10 @@
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Introduction</title>
<link rel="stylesheet" href="../../../../../doc/html/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.65.1">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Fusion 2.0">
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Fusion 2.0">
<link rel="previous" href="preface.html" title="Preface">
<link rel="prev" href="preface.html" title="Preface">
<link rel="next" href="quick_start.html" title="Quick Start">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@ -22,20 +22,17 @@
<div class="spirit-nav">
<a accesskey="p" href="preface.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="quick_start.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage">
<div><div><h2 class="title" style="clear: both">
<a name="fusion.introduction"></a><a href="introduction.html" title="Introduction">Introduction</a>
</h2></div></div>
<div></div>
</div>
<div class="section" title="Introduction">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="fusion.introduction"></a><a class="link" href="introduction.html" title="Introduction">Introduction</a>
</h2></div></div></div>
<p>
An advantage other languages such as Python and Lisp/ Scheme, ML and Haskell,
etc., over C++ is the ability to have heterogeneous containers that can hold
arbitrary element types. All the containers in the standard library can only
hold a specific type. A <tt class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span></tt>
can only hold <tt class="computeroutput"><span class="keyword">int</span></tt>s. A <tt class="computeroutput"><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;</span></tt> can
only hold elements of type <tt class="computeroutput"><span class="identifier">X</span></tt>,
hold a specific type. A <code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span></code>
can only hold <code class="computeroutput"><span class="keyword">int</span></code>s. A <code class="computeroutput"><span class="identifier">list</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;</span></code> can
only hold elements of type <code class="computeroutput"><span class="identifier">X</span></code>,
and so on.
</p>
<p>
@ -45,8 +42,8 @@
on virtual functions to provide polymorphic behavior since the actual type
is erased as soon as you store a pointer to a derived class to a pointer to
its base. The held objects must be related: you cannot hold objects of unrelated
types such as <tt class="computeroutput"><span class="keyword">char</span></tt>, <tt class="computeroutput"><span class="keyword">int</span></tt>, <tt class="computeroutput"><span class="keyword">class</span>
<span class="identifier">X</span></tt>, <tt class="computeroutput"><span class="keyword">float</span></tt>,
types such as <code class="computeroutput"><span class="keyword">char</span></code>, <code class="computeroutput"><span class="keyword">int</span></code>, <code class="computeroutput"><span class="keyword">class</span>
<span class="identifier">X</span></code>, <code class="computeroutput"><span class="keyword">float</span></code>,
etc. Oh sure you can use something like <a href="http://boost.org/doc/html/any.html" target="_top">Boost.Any</a>
to hold arbitrary types, but then you pay more in terms of runtime costs and
due to the fact that you practically erased all type information, you'll have
@ -55,7 +52,7 @@
<p>
The <a href="http://www.boost.org/libs/tuple/doc/tuple_users_guide.html" target="_top">Boost.Tuple</a>
library written by <a href="http://www.boost.org/people/jaakko_jarvi.htm" target="_top">Jaakko
Jarvi</a> provides heterogeneous containers in C++. The <tt class="computeroutput"><span class="identifier">tuple</span></tt>
Jarvi</a> provides heterogeneous containers in C++. The <code class="computeroutput"><span class="identifier">tuple</span></code>
is a basic data structure that can hold heterogeneous types. It's a good first
step, but it's not complete. What's missing are the algorithms. It's nice that
we can store and retrieve data to and from tuples, pass them around as arguments
@ -93,23 +90,23 @@
fusion algorithms are functional in nature such that algorithms are non mutating
(no side effects). However, due to the high cost of returning full sequences
such as vectors and lists, <span class="emphasis"><em>Views</em></span> are returned from Fusion
algorithms instead. For example, the <a href="algorithm/transformation/functions/transform.html" title="transform"><tt class="computeroutput"><span class="identifier">transform</span></tt></a> algorithm does not actually
return a transformed version of the original sequence. <a href="algorithm/transformation/functions/transform.html" title="transform"><tt class="computeroutput"><span class="identifier">transform</span></tt></a> returns a <a href="view/transform_view.html" title="transform_view"><tt class="computeroutput"><span class="identifier">transform_view</span></tt></a>. This view holds a
algorithms instead. For example, the <a class="link" href="algorithm/transformation/functions/transform.html" title="transform"><code class="computeroutput"><span class="identifier">transform</span></code></a> algorithm does not actually
return a transformed version of the original sequence. <a class="link" href="algorithm/transformation/functions/transform.html" title="transform"><code class="computeroutput"><span class="identifier">transform</span></code></a> returns a <a class="link" href="view/transform_view.html" title="transform_view"><code class="computeroutput"><span class="identifier">transform_view</span></code></a>. This view holds a
reference to the original sequence plus the transform function. Iteration over
the <a href="view/transform_view.html" title="transform_view"><tt class="computeroutput"><span class="identifier">transform_view</span></tt></a>
the <a class="link" href="view/transform_view.html" title="transform_view"><code class="computeroutput"><span class="identifier">transform_view</span></code></a>
will apply the transform function over the sequence elements on demand. This
<span class="emphasis"><em>lazy</em></span> evaluation scheme allows us to chain as many algorithms
as we want without incurring a high runtime penalty.
</p>
<p>
The <span class="emphasis"><em>lazy</em></span> evaluation scheme where algorithms return views
allows operations such as <a href="algorithm/transformation/functions/push_back.html" title="push_back"><tt class="computeroutput"><span class="identifier">push_back</span></tt></a> to be totally generic. In
Fusion, <a href="algorithm/transformation/functions/push_back.html" title="push_back"><tt class="computeroutput"><span class="identifier">push_back</span></tt></a> is actually a generic algorithm
that works on all sequences. Given an input sequence <tt class="computeroutput"><span class="identifier">s</span></tt>
and a value <tt class="computeroutput"><span class="identifier">x</span></tt>, Fusion's <a href="algorithm/transformation/functions/push_back.html" title="push_back"><tt class="computeroutput"><span class="identifier">push_back</span></tt></a> algorithm simply returns
a <a href="view/joint_view.html" title="joint_view"><tt class="computeroutput"><span class="identifier">joint_view</span></tt></a>:
a view that holds a reference to the original sequence <tt class="computeroutput"><span class="identifier">s</span></tt>
and the value <tt class="computeroutput"><span class="identifier">x</span></tt>. Functions
allows operations such as <a class="link" href="algorithm/transformation/functions/push_back.html" title="push_back"><code class="computeroutput"><span class="identifier">push_back</span></code></a> to be totally generic. In
Fusion, <a class="link" href="algorithm/transformation/functions/push_back.html" title="push_back"><code class="computeroutput"><span class="identifier">push_back</span></code></a> is actually a generic algorithm
that works on all sequences. Given an input sequence <code class="computeroutput"><span class="identifier">s</span></code>
and a value <code class="computeroutput"><span class="identifier">x</span></code>, Fusion's <a class="link" href="algorithm/transformation/functions/push_back.html" title="push_back"><code class="computeroutput"><span class="identifier">push_back</span></code></a> algorithm simply returns
a <a class="link" href="view/joint_view.html" title="joint_view"><code class="computeroutput"><span class="identifier">joint_view</span></code></a>:
a view that holds a reference to the original sequence <code class="computeroutput"><span class="identifier">s</span></code>
and the value <code class="computeroutput"><span class="identifier">x</span></code>. Functions
that were once sequence specific and need to be implemented N times over N
different sequences are now implemented only once.
</p>
@ -120,7 +117,7 @@
sequences are fully compatible with Fusion. You can work with Fusion sequences
on <a href="http://www.boost.org/libs/mpl/index.html" target="_top">MPL</a> if you
wish to work solely on types
<sup>[<a name="id353636" href="#ftn.id353636">1</a>]</sup>
<sup>[<a name="id555946" href="#ftn.id555946" class="footnote">1</a>]</sup>
. In <a href="http://www.boost.org/libs/mpl/index.html" target="_top">MPL</a>, Fusion
sequences follow <a href="http://www.boost.org/libs/mpl/index.html" target="_top">MPL</a>'s
sequence-type preserving semantics (i.e. algorithms preserve the original sequence
@ -135,10 +132,10 @@
</p>
<div class="footnotes">
<br><hr width="100" align="left">
<div class="footnote"><p><sup>[<a name="ftn.id353636" href="#id353636">1</a>] </sup>
<div class="footnote"><p><sup>[<a name="ftn.id555946" href="#id555946" class="para">1</a>] </sup>
Choose <a href="http://www.boost.org/libs/mpl/index.html" target="_top">MPL</a>
over fusion when doing pure type calculations. Once the static type calculation
is finished, you can instantiate a fusion sequence (see <a href="container/conversion/functions.html" title="Functions">Conversion</a>)
is finished, you can instantiate a fusion sequence (see <a class="link" href="container/conversion/functions.html" title="Functions">Conversion</a>)
for the runtime part.
</p></div>
</div>