forked from boostorg/fusion
merge from trunk
[SVN r47205]
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
<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.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1">
|
||||
<link rel="start" 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="prev" href="preface.html" title="Preface">
|
||||
@ -12,10 +12,10 @@
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></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="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</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>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@ -24,15 +24,14 @@
|
||||
</div>
|
||||
<div class="section" lang="en">
|
||||
<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>
|
||||
<a name="fusion.introduction"></a><a 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 <code class="computeroutput"><span class="identifier">vector</span><span class="special"><</span><span class="keyword">int</span><span class="special">></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"><</span><span class="identifier">X</span><span class="special">></span></code> can
|
||||
only hold elements of type <code class="computeroutput"><span class="identifier">X</span></code>,
|
||||
hold a specific type. A <tt class="computeroutput"><span class="identifier">vector</span><span class="special"><</span><span class="keyword">int</span><span class="special">></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"><</span><span class="identifier">X</span><span class="special">></span></tt> can
|
||||
only hold elements of type <tt class="computeroutput"><span class="identifier">X</span></tt>,
|
||||
and so on.
|
||||
</p>
|
||||
<p>
|
||||
@ -42,8 +41,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 <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>,
|
||||
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>,
|
||||
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
|
||||
@ -52,7 +51,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 <code class="computeroutput"><span class="identifier">tuple</span></code>
|
||||
Jarvi</a> provides heterogeneous containers in C++. The <tt class="computeroutput"><span class="identifier">tuple</span></tt>
|
||||
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
|
||||
@ -90,23 +89,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 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
|
||||
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
|
||||
reference to the original sequence plus the transform function. Iteration over
|
||||
the <a class="link" href="view/transform_view.html" title="transform_view"><code class="computeroutput"><span class="identifier">transform_view</span></code></a>
|
||||
the <a href="view/transform_view.html" title="transform_view"><tt class="computeroutput"><span class="identifier">transform_view</span></tt></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 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
|
||||
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
|
||||
that were once sequence specific and need to be implemented N times over N
|
||||
different sequences are now implemented only once.
|
||||
</p>
|
||||
|
Reference in New Issue
Block a user